home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / mySQL / mysql-5.0.1-alpha-snapshot-win / data1.cab / Documentation / Docs / manual.txt < prev    next >
Encoding:
Text File  |  2004-07-28  |  3.4 MB  |  88,513 lines

Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
  1. START-INFO-DIR-ENTRY
  2. * mysql: (mysql).               MySQL documentation.
  3. END-INFO-DIR-ENTRY
  4.  
  5. Table of Contents
  6. *****************
  7.  
  8.  
  9. General Information
  10.   About This Manual
  11.     Conventions Used in This Manual
  12.   Overview of the MySQL Database Management System
  13.     History of MySQL
  14.     The Main Features of MySQL
  15.     MySQL Stability
  16.     How Big MySQL Tables Can Be
  17.     Year 2000 Compliance
  18.   Overview of MySQL AB
  19.     The Business Model and Services of MySQL AB
  20.       Support
  21.       Training and Certification
  22.       Consulting
  23.       Commercial Licenses
  24.       Partnering
  25.     Contact Information
  26.   MySQL Support and Licensing
  27.     Support Offered by MySQL AB
  28.     Copyrights and Licenses Used by MySQL
  29.     MySQL Licenses
  30.       Using the MySQL Software Under a Commercial License
  31.       Using the MySQL Software for Free Under GPL
  32.     MySQL AB Logos and Trademarks
  33.       The Original MySQL Logo
  34.       MySQL Logos That May Be Used Without Written Permission
  35.       When You Need Written Permission to Use MySQL Logos
  36.       MySQL AB Partnership Logos
  37.       Using the Word MySQL in Printed Text or Presentations
  38.       Using the Word MySQL in Company and Product Names
  39.   MySQL Development Roadmap
  40.     MySQL 4.0 in a Nutshell
  41.       Features Available in MySQL 4.0
  42.       The Embedded MySQL Server
  43.     MySQL 4.1 in a Nutshell
  44.       Features Available in MySQL 4.1
  45.       Stepwise Rollout
  46.       Ready for Immediate Development Use
  47.     MySQL 5.0: The Next Development Release
  48.   MySQL and the Future (the TODO)
  49.     New Features Planned for 4.1
  50.     New Features Planned for 5.0
  51.     New Features Planned for 5.1
  52.     New Features Planned for the Near Future
  53.     New Features Planned for the Mid-Term Future
  54.     New Features We Don't Plan to Implement
  55.   MySQL Information Sources
  56.     MySQL Mailing Lists
  57.       The MySQL Mailing Lists
  58.       Asking Questions or Reporting Bugs
  59.       How to Report Bugs or Problems
  60.       Guidelines for Answering Questions on the Mailing List
  61.     MySQL Community Support on IRC (Internet Relay Chat)
  62.   MySQL Standards Compliance
  63.     What Standards MySQL Follows
  64.     Selecting SQL Modes
  65.     Running MySQL in ANSI Mode
  66.     MySQL Extensions to Standard SQL
  67.     MySQL Differences from Standard SQL
  68.       Subqueries
  69.       `SELECT INTO TABLE'
  70.       Transactions and Atomic Operations
  71.       Stored Procedures and Triggers
  72.       Foreign Keys
  73.       Views
  74.       `--' as the Start of a Comment
  75.     How MySQL Deals with Constraints
  76.       Constraint `PRIMARY KEY' / `UNIQUE'
  77.       Constraint `NOT NULL' and `DEFAULT' Values
  78.       Constraint `ENUM' and `SET'
  79.     Known Errors and Design Deficiencies in MySQL
  80.       Errors in 3.23 Fixed in a Later MySQL Version
  81.       Errors in 4.0 Fixed in a Later MySQL Version
  82.       Open Bugs and Design Deficiencies in MySQL
  83.  
  84. Installing MySQL
  85.   General Installation Issues
  86.     Operating Systems Supported by MySQL
  87.     Choosing Which MySQL Distribution to Install
  88.       Choosing Which Version of MySQL to Install
  89.       Choosing a Distribution Format
  90.       How and When Updates Are Released
  91.       Release Philosophy--No Known Bugs in Releases
  92.       MySQL Binaries Compiled by MySQL AB
  93.     How to Get MySQL
  94.     Verifying Package Integrity Using MD5 Checksums or `GnuPG'
  95.       Verifying the MD5 Checksum
  96.       Signature Checking Using `GnuPG'
  97.       Signature Checking Using `RPM'
  98.     Installation Layouts
  99.   Standard MySQL Installation Using a Binary Distribution
  100.     Installing MySQL on Windows
  101.       Windows System Requirements
  102.       Installing a Windows Binary Distribution
  103.       Preparing the Windows MySQL Environment
  104.       Selecting a Windows Server
  105.       Starting the Server for the First Time
  106.       Starting MySQL from the Windows Command Line
  107.       Starting MySQL as a Windows Service
  108.       Troubleshooting a MySQL Installation Under Windows
  109.       Running MySQL Client Programs on Windows
  110.       MySQL on Windows Compared to MySQL on Unix
  111.     Installing MySQL on Linux
  112.     Installing MySQL on Mac OS X
  113.     Installing MySQL on NetWare
  114.     Installing MySQL on Other Unix-Like Systems
  115.   MySQL Installation Using a Source Distribution
  116.     Source Installation Overview
  117.     Typical `configure' Options
  118.     Installing from the Development Source Tree
  119.     Dealing with Problems Compiling MySQL
  120.     MIT-pthreads Notes
  121.     Installing MySQL from Source on Windows
  122.       Building MySQL Using VC++
  123.       Creating a Windows Source Package from the Latest Development Source
  124.     Compiling MySQL Clients on Windows
  125.   Post-Installation Setup and Testing
  126.     Windows Post-Installation Procedures
  127.     Unix Post-Installation Procedures
  128.       Problems Running `mysql_install_db'
  129.       Starting and Stopping MySQL Automatically
  130.       Starting and Troubleshooting the MySQL Server
  131.     Securing the Initial MySQL Accounts
  132.   Upgrading/Downgrading MySQL
  133.     Upgrading from Version 4.1 to 5.0
  134.     Upgrading from Version 4.0 to 4.1
  135.     Upgrading from Version 3.23 to 4.0
  136.     Upgrading from Version 3.22 to 3.23
  137.     Upgrading from Version 3.21 to 3.22
  138.     Upgrading from Version 3.20 to 3.21
  139.     Upgrading MySQL Under Windows
  140.     Upgrading the Grant Tables
  141.     Copying MySQL Databases to Another Machine
  142.   Operating System-Specific Notes
  143.     Linux Notes
  144.       Linux Operating System Notes
  145.       Linux Binary Distribution Notes
  146.       Linux Source Distribution Notes
  147.       Linux Post-Installation Notes
  148.       Linux x86 Notes
  149.       Linux SPARC Notes
  150.       Linux Alpha Notes
  151.       Linux PowerPC Notes
  152.       Linux MIPS Notes
  153.       Linux IA-64 Notes
  154.     Mac OS X Notes
  155.       Mac OS X 10.x (Darwin)
  156.       Mac OS X Server 1.2 (Rhapsody)
  157.     Solaris Notes
  158.       Solaris 2.7/2.8 Notes
  159.       Solaris x86 Notes
  160.     BSD Notes
  161.       FreeBSD Notes
  162.       NetBSD Notes
  163.       OpenBSD 2.5 Notes
  164.       OpenBSD 2.8 Notes
  165.       BSD/OS Version 2.x Notes
  166.       BSD/OS Version 3.x Notes
  167.       BSD/OS Version 4.x Notes
  168.     Other Unix Notes
  169.       HP-UX Version 10.20 Notes
  170.       HP-UX Version 11.x Notes
  171.       IBM-AIX notes
  172.       SunOS 4 Notes
  173.       Alpha-DEC-UNIX Notes (Tru64)
  174.       Alpha-DEC-OSF/1 Notes
  175.       SGI Irix Notes
  176.       SCO Notes
  177.       SCO UnixWare Version 7.1.x Notes
  178.     OS/2 Notes
  179.     BeOS Notes
  180.   Perl Installation Notes
  181.     Installing Perl on Unix
  182.     Installing ActiveState Perl on Windows
  183.     Problems Using the Perl `DBI'/`DBD' Interface
  184.  
  185. MySQL Tutorial
  186.   Connecting to and Disconnecting from the Server
  187.   Entering Queries
  188.   Creating and Using a Database
  189.     Creating and Selecting a Database
  190.     Creating a Table
  191.     Loading Data into a Table
  192.     Retrieving Information from a Table
  193.       Selecting All Data
  194.       Selecting Particular Rows
  195.       Selecting Particular Columns
  196.       Sorting Rows
  197.       Date Calculations
  198.       Working with `NULL' Values
  199.       Pattern Matching
  200.       Counting Rows
  201.       Using More Than one Table
  202.   Getting Information About Databases and Tables
  203.   Using `mysql' in Batch Mode
  204.   Examples of Common Queries
  205.     The Maximum Value for a Column
  206.     The Row Holding the Maximum of a Certain Column
  207.     Maximum of Column per Group
  208.     The Rows Holding the Group-wise Maximum of a Certain Field
  209.     Using User Variables
  210.     Using Foreign Keys
  211.     Searching on Two Keys
  212.     Calculating Visits Per Day
  213.     Using `AUTO_INCREMENT'
  214.   Queries from the Twin Project
  215.     Find All Non-distributed Twins
  216.     Show a Table of Twin Pair Status
  217.   Using MySQL with Apache
  218.  
  219. Using MySQL Programs
  220.   Overview of MySQL Programs
  221.   Invoking MySQL Programs
  222.   Specifying Program Options
  223.     Using Options on the Command Line
  224.     Using Option Files
  225.     Using Environment Variables to Specify Options
  226.     Using Options to Set Program Variables
  227.  
  228. Database Administration
  229.   The MySQL Server and Server Startup Scripts
  230.     Overview of the Server-Side Scripts and Utilities
  231.     The `mysqld-max' Extended MySQL Server
  232.     The `mysqld_safe' Server Startup Script
  233.     The `mysql.server' Server Startup Script
  234.     The `mysqld_multi' Program for Managing Multiple MySQL Servers
  235.   Configuring the MySQL Server
  236.     `mysqld' Command-Line Options
  237.     The Server SQL Mode
  238.     Server System Variables
  239.       Dynamic System Variables
  240.     Server Status Variables
  241.   General Security Issues
  242.     General Security Guidelines
  243.     Making MySQL Secure Against Attackers
  244.     Startup Options for `mysqld' Concerning Security
  245.     Security Issues with `LOAD DATA LOCAL'
  246.   The MySQL Access Privilege System
  247.     What the Privilege System Does
  248.     How the Privilege System Works
  249.     Privileges Provided by MySQL
  250.     Connecting to the MySQL Server
  251.     Access Control, Stage 1: Connection Verification
  252.     Access Control, Stage 2: Request Verification
  253.     When Privilege Changes Take Effect
  254.     Causes of `Access denied' Errors
  255.     Password Hashing in MySQL 4.1
  256.       Implications of Password Hashing Changes for Application Programs
  257.       Password Hashing in MySQL 4.1.0
  258.   MySQL User Account Management
  259.     MySQL Usernames and Passwords
  260.     Adding New User Accounts to MySQL
  261.     Removing User Accounts from MySQL
  262.     Limiting Account Resources
  263.     Assigning Account Passwords
  264.     Keeping Your Password Secure
  265.     Using Secure Connections
  266.       Basic SSL Concepts
  267.       Requirements
  268.       Setting Up SSL Certificates for MySQL
  269.       SSL `GRANT' Options
  270.       SSL Command-Line Options
  271.       Connecting to MySQL Remotely from Windows with SSH
  272.   Disaster Prevention and Recovery
  273.     Database Backups
  274.     Table Maintenance and Crash Recovery
  275.       `myisamchk' Invocation Syntax
  276.       General Options for `myisamchk'
  277.       Check Options for `myisamchk'
  278.       Repair Options for `myisamchk'
  279.       Other Options for `myisamchk'
  280.       `myisamchk' Memory Usage
  281.       Using `myisamchk' for Crash Recovery
  282.       How to Check `MyISAM' Tables for Errors
  283.       How to Repair Tables
  284.       Table Optimization
  285.     Setting Up a Table Maintenance Schedule
  286.     Getting Information About a Table
  287.   MySQL Localization and International Usage
  288.     The Character Set Used for Data and Sorting
  289.       Using the German Character Set
  290.     Setting the Error Message Language
  291.     Adding a New Character Set
  292.     The Character Definition Arrays
  293.     String Collating Support
  294.     Multi-Byte Character Support
  295.     Problems With Character Sets
  296.     MySQL Server Time Zone Support
  297.   The MySQL Log Files
  298.     The Error Log
  299.     The General Query Log
  300.     The Update Log
  301.     The Binary Log
  302.     The Slow Query Log
  303.     Log File Maintenance
  304.   Running Multiple MySQL Servers on the Same Machine
  305.     Running Multiple Servers on Windows
  306.       Starting Multiple Windows Servers at the Command Line
  307.       Starting Multiple Windows Servers as Services
  308.     Running Multiple Servers on Unix
  309.     Using Client Programs in a Multiple-Server Environment
  310.   The MySQL Query Cache
  311.     How the Query Cache Operates
  312.     Query Cache `SELECT' Options
  313.     Query Cache Configuration
  314.     Query Cache Status and Maintenance
  315.  
  316. Replication in MySQL
  317.   Introduction to Replication
  318.   Replication Implementation Overview
  319.   Replication Implementation Details
  320.     Replication Master Thread States
  321.     Replication Slave I/O Thread States
  322.     Replication Slave SQL Thread States
  323.     Replication Relay and Status Files
  324.   How to Set Up Replication
  325.   Replication Compatibility Between MySQL Versions
  326.   Upgrading a Replication Setup
  327.     Upgrading Replication to 4.0 or 4.1
  328.     Upgrading Replication to 5.0
  329.   Replication Features and Known Problems
  330.   Replication Startup Options
  331.   Replication FAQ
  332.   Troubleshooting Replication
  333.   Reporting Replication Bugs
  334.  
  335. MySQL Optimization
  336.   Optimization Overview
  337.     MySQL Design Limitations and Tradeoffs
  338.     Designing Applications for Portability
  339.     What We Have Used MySQL For
  340.     The MySQL Benchmark Suite
  341.     Using Your Own Benchmarks
  342.   Optimizing `SELECT' Statements and Other Queries
  343.     `EXPLAIN' Syntax (Get Information About a `SELECT')
  344.     Estimating Query Performance
  345.     Speed of `SELECT' Queries
  346.     How MySQL Optimizes `WHERE' Clauses
  347.     How MySQL Optimizes `OR' Clauses
  348.     How MySQL Optimizes `IS NULL'
  349.     How MySQL Optimizes `DISTINCT'
  350.     How MySQL Optimizes `LEFT JOIN' and `RIGHT JOIN'
  351.     How MySQL Optimizes `ORDER BY'
  352.     How MySQL Optimizes `LIMIT'
  353.     How to Avoid Table Scans
  354.     Speed of `INSERT' Statements
  355.     Speed of `UPDATE' Statements
  356.     Speed of `DELETE' Statements
  357.     Other Optimization Tips
  358.   Locking Issues
  359.     Locking Methods
  360.     Table Locking Issues
  361.   Optimizing Database Structure
  362.     Design Choices
  363.     Make Your Data as Small as Possible
  364.     Column Indexes
  365.     Multiple-Column Indexes
  366.     How MySQL Uses Indexes
  367.     The `MyISAM' Key Cache
  368.       Shared Key Cache Access
  369.       Multiple Key Caches
  370.       Midpoint Insertion Strategy
  371.       Index Preloading
  372.       Key Cache Block Size
  373.       Restructuring a Key Cache
  374.     How MySQL Counts Open Tables
  375.     How MySQL Opens and Closes Tables
  376.     Drawbacks to Creating Many Tables in the Same Database
  377.   Optimizing the MySQL Server
  378.     System Factors and Startup Parameter Tuning
  379.     Tuning Server Parameters
  380.     Controlling Query Optimizer Performance
  381.     How Compiling and Linking Affects the Speed of MySQL
  382.     How MySQL Uses Memory
  383.     How MySQL Uses DNS
  384.   Disk Issues
  385.     Using Symbolic Links
  386.       Using Symbolic Links for Databases on Unix
  387.       Using Symbolic Links for Tables on Unix
  388.       Using Symbolic Links for Databases on Windows
  389.  
  390. MySQL Client and Utility Programs
  391.   Overview of the Client-Side Scripts and Utilities
  392.   `myisampack', the MySQL Compressed Read-only Table Generator
  393.   `mysql', the Command-Line Tool
  394.     `mysql' Commands
  395.     Executing SQL Statements from a Text File
  396.     `mysql' Tips
  397.       Displaying Query Results Vertically
  398.       Using the `--safe-updates' Option
  399.       Disabling `mysql' Auto-Reconnect
  400.   `mysqladmin', Administering a MySQL Server
  401.   The `mysqlbinlog' Binary Log Utility
  402.   `mysqlcc', the MySQL Control Center
  403.   The `mysqlcheck' Table Maintenance and Repair Program
  404.   The `mysqldump' Database Backup Program
  405.   The `mysqlhotcopy' Database Backup Program
  406.   The `mysqlimport' Data Import Program
  407.   `mysqlshow', Showing Databases, Tables, and Columns
  408.   `perror', Explaining Error Codes
  409.   The `replace' String-Replacement Utility
  410.  
  411. MySQL Language Reference
  412.  
  413. Language Structure
  414.   Literal Values
  415.     Strings
  416.     Numbers
  417.     Hexadecimal Values
  418.     Boolean Values
  419.     `NULL' Values
  420.   Database, Table, Index, Column, and Alias Names
  421.     Identifier Qualifiers
  422.     Identifier Case Sensitivity
  423.   User Variables
  424.   System Variables
  425.     Structured System Variables
  426.   Comment Syntax
  427.   Treatment of Reserved Words in MySQL
  428.  
  429. Character Set Support
  430.   Character Sets and Collations in General
  431.   Character Sets and Collations in MySQL
  432.   Determining the Default Character Set and Collation
  433.     Server Character Set and Collation
  434.     Database Character Set and Collation
  435.     Table Character Set and Collation
  436.     Column Character Set and Collation
  437.     Examples of Character Set and Collation Assignment
  438.     Connection Character Sets and Collations
  439.     Character String Literal Character Set and Collation
  440.     Using `COLLATE' in SQL Statements
  441.     `COLLATE' Clause Precedence
  442.     `BINARY' Operator
  443.     Some Special Cases Where the Collation Determination Is Tricky
  444.     Collations Must Be for the Right Character Set
  445.     An Example of the Effect of Collation
  446.   Operations Affected by Character Set Support
  447.     Result Strings
  448.     `CONVERT()'
  449.     `CAST()'
  450.     `SHOW' Statements
  451.   Unicode Support
  452.   UTF8 for Metadata
  453.   Compatibility with Other DBMSs
  454.   New Character Set Configuration File Format
  455.   National Character Set
  456.   Upgrading Character Sets from MySQL 4.0
  457.     4.0 Character Sets and Corresponding 4.1 Character Set/Collation Pairs
  458.     Converting 4.0 Character Columns to 4.1 Format
  459.   Character Sets and Collations That MySQL Supports
  460.     Unicode Character Sets
  461.     West European Character Sets
  462.     Central European Character Sets
  463.     South European and Middle East Character Sets
  464.     Baltic Character Sets
  465.     Cyrillic Character Sets
  466.     Asian Character Sets
  467.  
  468. Column Types
  469.   Column Type Overview
  470.     Overview of Numeric Types
  471.     Overview of Date and Time Types
  472.     Overview of String Types
  473.   Numeric Types
  474.   Date and Time Types
  475.     The `DATETIME', `DATE', and `TIMESTAMP' Types
  476.       `TIMESTAMP' Properties Prior to MySQL 4.1
  477.       `TIMESTAMP' Properties as of MySQL 4.1
  478.     The `TIME' Type
  479.     The `YEAR' Type
  480.     Y2K Issues and Date Types
  481.   String Types
  482.     The `CHAR' and `VARCHAR' Types
  483.     The `BLOB' and `TEXT' Types
  484.     The `ENUM' Type
  485.     The `SET' Type
  486.   Column Type Storage Requirements
  487.   Choosing the Right Type for a Column
  488.   Using Column Types from Other Database Engines
  489.  
  490. Functions and Operators
  491.   Operators
  492.     Operator Precedence
  493.     Parentheses
  494.     Comparison Functions and Operators
  495.     Logical Operators
  496.     Case-sensitivity Operators
  497.   Control Flow Functions
  498.   String Functions
  499.     String Comparison Functions
  500.   Numeric Functions
  501.     Arithmetic Operators
  502.     Mathematical Functions
  503.   Date and Time Functions
  504.   Full-Text Search Functions
  505.     Boolean Full-Text Searches
  506.     Full-Text Searches with Query Expansion
  507.     Full-Text Restrictions
  508.     Fine-Tuning MySQL Full-Text Search
  509.     Full-Text Search TODO
  510.   Cast Functions
  511.   Other Functions
  512.     Bit Functions
  513.     Encryption Functions
  514.     Information Functions
  515.     Miscellaneous Functions
  516.   Functions and Modifiers for Use with `GROUP BY' Clauses
  517.     `GROUP BY' (Aggregate) Functions
  518.     `GROUP BY' Modifiers
  519.     `GROUP BY' with Hidden Fields
  520.  
  521. SQL Statement Syntax
  522.   Data Manipulation Statements
  523.     `DELETE' Syntax
  524.     `DO' Syntax
  525.     `HANDLER' Syntax
  526.     `INSERT' Syntax
  527.       `INSERT ... SELECT' Syntax
  528.       `INSERT DELAYED' Syntax
  529.     `LOAD DATA INFILE' Syntax
  530.     `REPLACE' Syntax
  531.     `SELECT' Syntax
  532.       `JOIN' Syntax
  533.       `UNION' Syntax
  534.     Subquery Syntax
  535.       The Subquery as Scalar Operand
  536.       Comparisons Using Subqueries
  537.       Subqueries with `ANY', `IN', and `SOME'
  538.       Subqueries with `ALL'
  539.       Correlated Subqueries
  540.       `EXISTS' and `NOT EXISTS'
  541.       Row Subqueries
  542.       Subqueries in the `FROM' clause
  543.       Subquery Errors
  544.       Optimizing Subqueries
  545.       Rewriting Subqueries as Joins for Earlier MySQL Versions
  546.     `TRUNCATE' Syntax
  547.     `UPDATE' Syntax
  548.   Data Definition Statements
  549.     `ALTER DATABASE' Syntax
  550.     `ALTER TABLE' Syntax
  551.     `CREATE DATABASE' Syntax
  552.     `CREATE INDEX' Syntax
  553.     `CREATE TABLE' Syntax
  554.       Silent Column Specification Changes
  555.     `DROP DATABASE' Syntax
  556.     `DROP INDEX' Syntax
  557.     `DROP TABLE' Syntax
  558.     `RENAME TABLE' Syntax
  559.   MySQL Utility Statements
  560.     `DESCRIBE' Syntax (Get Information About Columns)
  561.     `USE' Syntax
  562.   MySQL Transactional and Locking Statements
  563.     `START TRANSACTION', `COMMIT', and `ROLLBACK' Syntax
  564.     Statements That Cannot Be Rolled Back
  565.     Statements That Cause an Implicit Commit
  566.     `SAVEPOINT' and `ROLLBACK TO SAVEPOINT' Syntax
  567.     `LOCK TABLES' and `UNLOCK TABLES' Syntax
  568.     `SET TRANSACTION' Syntax
  569.   Database Administration Statements
  570.     Account Management Statements
  571.       `DROP USER' Syntax
  572.       `GRANT' and `REVOKE' Syntax
  573.       `SET PASSWORD' Syntax
  574.     Table Maintenance Statements
  575.       `ANALYZE TABLE' Syntax
  576.       `BACKUP TABLE' Syntax
  577.       `CHECK TABLE' Syntax
  578.       `CHECKSUM TABLE' Syntax
  579.       `OPTIMIZE TABLE' Syntax
  580.       `REPAIR TABLE' Syntax
  581.       `RESTORE TABLE' Syntax
  582.     `SET' and `SHOW' Syntax
  583.       `SET' Syntax
  584.       `SHOW CHARACTER SET' Syntax
  585.       `SHOW COLLATION' Syntax
  586.       `SHOW COLUMNS' Syntax
  587.       `SHOW CREATE DATABASE' Syntax
  588.       `SHOW CREATE TABLE' Syntax
  589.       `SHOW DATABASES' Syntax
  590.       `SHOW ENGINES' Syntax
  591.       `SHOW ERRORS' Syntax
  592.       `SHOW GRANTS' Syntax
  593.       `SHOW INDEX' Syntax
  594.       `SHOW INNODB STATUS' Syntax
  595.       `SHOW LOGS' Syntax
  596.       `SHOW PRIVILEGES' Syntax
  597.       `SHOW PROCESSLIST' Syntax
  598.       `SHOW STATUS' Syntax
  599.       `SHOW TABLE STATUS' Syntax
  600.       `SHOW TABLES' Syntax
  601.       `SHOW VARIABLES' Syntax
  602.       `SHOW WARNINGS' Syntax
  603.     Other Administrative Statements
  604.       `CACHE INDEX' Syntax
  605.       `FLUSH' Syntax
  606.       `KILL' Syntax
  607.       `LOAD INDEX INTO CACHE' Syntax
  608.       `RESET' Syntax
  609.   Replication Statements
  610.     SQL Statements for Controlling Master Servers
  611.       `PURGE MASTER LOGS' Syntax
  612.       `RESET MASTER' Syntax
  613.       `SET SQL_LOG_BIN' Syntax
  614.       `SHOW BINLOG EVENTS' Syntax
  615.       `SHOW MASTER LOGS' Syntax
  616.       `SHOW MASTER STATUS' Syntax
  617.       `SHOW SLAVE HOSTS' Syntax
  618.     SQL Statements for Controlling Slave Servers
  619.       `CHANGE MASTER TO' Syntax
  620.       `LOAD DATA FROM MASTER' Syntax
  621.       `LOAD TABLE TBL_NAME FROM MASTER' Syntax
  622.       `MASTER_POS_WAIT()' Syntax
  623.       `RESET SLAVE' Syntax
  624.       `SET GLOBAL SQL_SLAVE_SKIP_COUNTER' Syntax
  625.       `SHOW SLAVE STATUS' Syntax
  626.       `START SLAVE' Syntax
  627.       `STOP SLAVE' Syntax
  628.  
  629. MySQL Storage Engines and Table Types
  630.   The `MyISAM' Storage Engine
  631.     `MyISAM' Startup Options
  632.     Space Needed for Keys
  633.     `MyISAM' Table Storage Formats
  634.       Static (Fixed-Length) Table Characteristics
  635.       Dynamic Table Characteristics
  636.       Compressed Table Characteristics
  637.     `MyISAM' Table Problems
  638.       Corrupted `MyISAM' Tables
  639.       Problems from Tables Not Being Closed Properly
  640.   The `MERGE' Storage Engine
  641.     `MERGE' Table Problems
  642.   The `MEMORY' (`HEAP') Storage Engine
  643.   The `BDB' (`BerkeleyDB') Storage Engine
  644.     Operating Systems Supported by `BDB'
  645.     Installing `BDB'
  646.     `BDB' Startup Options
  647.     Characteristics of `BDB' Tables
  648.     Things We Need to Fix for `BDB'
  649.     Restrictions on `BDB' Tables
  650.     Errors That May Occur When Using `BDB' Tables
  651.   The `ISAM' Storage Engine
  652.  
  653. The `InnoDB' Storage Engine
  654.   `InnoDB' Overview
  655.   `InnoDB' Contact Information
  656.   `InnoDB' in MySQL 3.23
  657.   `InnoDB' Configuration
  658.   `InnoDB' Startup Options
  659.   Creating the `InnoDB' Tablespace
  660.     Dealing with `InnoDB' Initialization Problems
  661.   Creating `InnoDB' Tables
  662.     How to Use Transactions in `InnoDB' with Different APIs
  663.     Converting `MyISAM' Tables to `InnoDB'
  664.     How an `AUTO_INCREMENT' Column Works in `InnoDB'
  665.     `FOREIGN KEY' Constraints
  666.     `InnoDB' and MySQL Replication
  667.     Using Per-Table Tablespaces
  668.   Adding and Removing `InnoDB' Data and Log Files
  669.   Backing Up and Recovering an `InnoDB' Database
  670.     Forcing Recovery
  671.     Checkpoints
  672.   Moving an `InnoDB' Database to Another Machine
  673.   `InnoDB' Transaction Model and Locking
  674.     `InnoDB' and `AUTOCOMMIT'
  675.     `InnoDB' and `TRANSACTION ISOLATION LEVEL'
  676.     Consistent Non-Locking Read
  677.     Locking Reads `SELECT ... FOR UPDATE' and `SELECT ... LOCK IN SHARE MODE'
  678.     Next-Key Locking: Avoiding the Phantom Problem
  679.     An Example of How the Consistent Read Works in `InnoDB'
  680.     Locks Set by Different SQL Statements in `InnoDB'
  681.     When Does MySQL Implicitly Commit or Roll Back a Transaction?
  682.     Deadlock Detection and Rollback
  683.     How to Cope with Deadlocks
  684.   `InnoDB' Performance Tuning Tips
  685.     `SHOW INNODB STATUS' and the `InnoDB' Monitors
  686.   Implementation of Multi-Versioning
  687.   Table and Index Structures
  688.     Physical Structure of an Index
  689.     Insert Buffering
  690.     Adaptive Hash Indexes
  691.     Physical Record Structure
  692.   File Space Management and Disk I/O
  693.     Disk I/O
  694.     Using Raw Devices for the Tablespace
  695.     File Space Management
  696.     Defragmenting a Table
  697.   Error Handling
  698.     `InnoDB' Error Codes
  699.     Operating System Error Codes
  700.   Restrictions on `InnoDB' Tables
  701.   `InnoDB' Troubleshooting
  702.     Troubleshooting `InnoDB' Data Dictionary Operations
  703.  
  704. MySQL Cluster
  705.   MySQL Cluster Overview
  706.   Basic MySQL Cluster Concepts
  707.   MySQL Cluster Configuration
  708.     Building the Software
  709.     Installing the Software
  710.     Configuration File
  711.       An example configuration in a MySQL Cluster
  712.       Defining the computers in a MySQL Cluster
  713.       Defining the management server in a MySQL Cluster
  714.       Defining the storage nodes in a MySQL Cluster
  715.       Defining the MySQL Servers in a MySQL Cluster
  716.       Defining TCP/IP connections in a MySQL Cluster
  717.       Defining shared memory connections in a MySQL Cluster
  718.       Configuring recovery parts in a MySQL Cluster
  719.   Process Management in MySQL Cluster
  720.     MySQL Server Process Usage for MySQL Cluster
  721.     `ndbd', the Storage Engine Node Process
  722.     `ndb_mgmd', the Management Server Process
  723.     `ndb_mgm', the Management Client Process
  724.     Command Options for MySQL Cluster Processes
  725.       MySQL Cluster-Related Command Options for `mysqld'
  726.       Command Options for `ndbd'
  727.       Command Options for `ndb_mgmd'
  728.       Command Options for `ndb_mgm'
  729.   Management of MySQL Cluster
  730.  
  731. Introduction to MaxDB
  732.   History of MaxDB
  733.   Licensing and Support
  734.   MaxDB-Related Links
  735.   Basic Concepts of MaxDB
  736.   Feature Differences Between MaxDB and MySQL
  737.   Interoperability Features Between MaxDB and MySQL
  738.   Reserved Words in MaxDB
  739.  
  740. Spatial Extensions in MySQL
  741.   Introduction
  742.   The OpenGIS Geometry Model
  743.     The Geometry Class Hierarchy
  744.     Class `Geometry'
  745.     Class `Point'
  746.     Class `Curve'
  747.     Class `LineString'
  748.     Class `Surface'
  749.     Class `Polygon'
  750.     Class `GeometryCollection'
  751.     Class `MultiPoint'
  752.     Class `MultiCurve'
  753.     Class `MultiLineString'
  754.     Class `MultiSurface'
  755.     Class `MultiPolygon'
  756.   Supported Spatial Data Formats
  757.     Well-Known Text (WKT) Format
  758.     Well-Known Binary (WKB) Format
  759.   Creating a Spatially Enabled MySQL Database
  760.     MySQL Spatial Data Types
  761.     Creating Spatial Values
  762.       Creating Geometry Values Using WKT Functions
  763.       Creating Geometry Values Using WKB Functions
  764.       Creating Geometry Values Using MySQL-Specific Functions
  765.     Creating Spatial Columns
  766.     Populating Spatial Columns
  767.     Fetching Spatial Data
  768.       Fetching Spatial Data in Internal Format
  769.       Fetching Spatial Data in WKT Format
  770.       Fetching Spatial Data in WKB Format
  771.   Analyzing Spatial Information
  772.     Geometry Format Conversion Functions
  773.     `Geometry' Functions
  774.       General Geometry Functions
  775.       `Point' Functions
  776.       `LineString' Functions
  777.       `MultiLineString' Functions
  778.       `Polygon' Functions
  779.       `MultiPolygon' Functions
  780.       `GeometryCollection' Functions
  781.     Functions That Create New Geometries from Existing Ones
  782.       Geometry Functions That Produce New Geometries
  783.       Spatial Operators
  784.     Functions for Testing Spatial Relations Between Geometric Objects
  785.     Relations on Geometry Minimal Bounding Rectangles (MBRs)
  786.     Functions That Test Spatial Relationships Between Geometries
  787.   Optimizing Spatial Analysis
  788.     Creating Spatial Indexes
  789.     Using a Spatial Index
  790.   MySQL Conformance and Compatibility
  791.     GIS Features That Are Not Yet Implemented
  792.  
  793. Stored Procedures and Functions
  794.   Stored Procedure Syntax
  795.     Maintaining Stored Procedures
  796.       `CREATE PROCEDURE' and `CREATE FUNCTION'
  797.       `ALTER PROCEDURE' and `ALTER FUNCTION'
  798.       `DROP PROCEDURE' and `DROP FUNCTION'
  799.       `SHOW CREATE PROCEDURE' and `SHOW CREATE FUNCTION'
  800.     `SHOW PROCEDURE STATUS' and `SHOW FUNCTION STATUS'
  801.     `CALL'
  802.     `BEGIN ... END' Compound Statement
  803.     `DECLARE' Statement
  804.     Variables in Stored Procedures
  805.       `DECLARE' Local Variables
  806.       Variable `SET' Statement
  807.       `SELECT ... INTO' Statement
  808.     Conditions and Handlers
  809.       `DECLARE' Conditions
  810.       `DECLARE' Handlers
  811.     Cursors
  812.       Declaring Cursors
  813.       Cursor `OPEN' Statement
  814.       Cursor `FETCH' Statement
  815.       Cursor `CLOSE' Statement
  816.     Flow Control Constructs
  817.       `IF' Statement
  818.       `CASE' Statement
  819.       `LOOP' Statement
  820.       `LEAVE' Statement
  821.       `ITERATE' Statement
  822.       `REPEAT' Statement
  823.       `WHILE' Statement
  824.  
  825. MySQL APIs
  826.   MySQL Program Development Utilities
  827.     `msql2mysql', Convert mSQL Programs for Use with MySQL
  828.     `mysql_config', Get compile options for compiling clients
  829.   MySQL C API
  830.     C API Data types
  831.     C API Function Overview
  832.     C API Function Descriptions
  833.       `mysql_affected_rows()'
  834.       `mysql_change_user()'
  835.       `mysql_character_set_name()'
  836.       `mysql_close()'
  837.       `mysql_connect()'
  838.       `mysql_create_db()'
  839.       `mysql_data_seek()'
  840.       `mysql_debug()'
  841.       `mysql_drop_db()'
  842.       `mysql_dump_debug_info()'
  843.       `mysql_eof()'
  844.       `mysql_errno()'
  845.       `mysql_error()'
  846.       `mysql_escape_string()'
  847.       `mysql_fetch_field()'
  848.       `mysql_fetch_fields()'
  849.       `mysql_fetch_field_direct()'
  850.       `mysql_fetch_lengths()'
  851.       `mysql_fetch_row()'
  852.       `mysql_field_count()'
  853.       `mysql_field_seek()'
  854.       `mysql_field_tell()'
  855.       `mysql_free_result()'
  856.       `mysql_get_client_info()'
  857.       `mysql_get_client_version()'
  858.       `mysql_get_host_info()'
  859.       `mysql_get_proto_info()'
  860.       `mysql_get_server_info()'
  861.       `mysql_get_server_version()'
  862.       `mysql_info()'
  863.       `mysql_init()'
  864.       `mysql_insert_id()'
  865.       `mysql_kill()'
  866.       `mysql_list_dbs()'
  867.       `mysql_list_fields()'
  868.       `mysql_list_processes()'
  869.       `mysql_list_tables()'
  870.       `mysql_num_fields()'
  871.       `mysql_num_rows()'
  872.       `mysql_options()'
  873.       `mysql_ping()'
  874.       `mysql_query()'
  875.       `mysql_real_connect()'
  876.       `mysql_real_escape_string()'
  877.       `mysql_real_query()'
  878.       `mysql_reload()'
  879.       `mysql_row_seek()'
  880.       `mysql_row_tell()'
  881.       `mysql_select_db()'
  882.       `mysql_set_server_option()'
  883.       `mysql_shutdown()'
  884.       `mysql_sqlstate()'
  885.       `mysql_ssl_set()'
  886.       `mysql_stat()'
  887.       `mysql_store_result()'
  888.       `mysql_thread_id()'
  889.       `mysql_use_result()'
  890.       `mysql_warning_count()'
  891.       `mysql_commit()'
  892.       `mysql_rollback()'
  893.       `mysql_autocommit()'
  894.       `mysql_more_results()'
  895.       `mysql_next_result()'
  896.     C API Prepared Statements
  897.     C API Prepared Statement Data types
  898.     C API Prepared Statement Function Overview
  899.     C API Prepared Statement Function Descriptions
  900.       `mysql_stmt_init()'
  901.       `mysql_stmt_bind_param()'
  902.       `mysql_stmt_bind_result()'
  903.       `mysql_stmt_execute()'
  904.       `mysql_stmt_fetch()'
  905.       `mysql_stmt_fetch_column()'
  906.       `mysql_stmt_result_metadata()'
  907.       `mysql_stmt_param_count()'
  908.       `mysql_stmt_param_metadata()'
  909.       `mysql_stmt_prepare()'
  910.       `mysql_stmt_send_long_data()'
  911.       `mysql_stmt_affected_rows()'
  912.       `mysql_stmt_insert_id()'
  913.       `mysql_stmt_close()'
  914.       `mysql_stmt_data_seek()'
  915.       `mysql_stmt_errno()'
  916.       `mysql_stmt_error()'
  917.       `mysql_stmt_free_result()'
  918.       `mysql_stmt_num_rows()'
  919.       `mysql_stmt_reset()'
  920.       `mysql_stmt_row_seek()'
  921.       `mysql_stmt_row_tell()'
  922.       `mysql_stmt_sqlstate()'
  923.       `mysql_stmt_store_result()'
  924.       `mysql_stmt_attr_set()'
  925.       `mysql_stmt_attr_get()'
  926.     C API Handling of Multiple Query Execution
  927.     C API Handling of Date and Time Values
  928.     C API Threaded Function Descriptions
  929.       `my_init()'
  930.       `mysql_thread_init()'
  931.       `mysql_thread_end()'
  932.       `mysql_thread_safe()'
  933.     C API Embedded Server Function Descriptions
  934.       `mysql_server_init()'
  935.       `mysql_server_end()'
  936.     Common questions and problems when using the C API
  937.       Why `mysql_store_result()' Sometimes Returns `NULL' After `mysql_query()' Returns Success
  938.       What Results You Can Get from a Query
  939.       How to Get the Unique ID for the Last Inserted Row
  940.       Problems Linking with the C API
  941.     Building Client Programs
  942.     How to Make a Threaded Client
  943.     libmysqld, the Embedded MySQL Server Library
  944.       Overview of the Embedded MySQL Server Library
  945.       Compiling Programs with `libmysqld'
  946.       Restrictions when using the Embedded MySQL Server
  947.       Using Option Files with the Embedded Server
  948.       Things left to do in Embedded Server (TODO)
  949.       A Simple Embedded Server Example
  950.       Licensing the Embedded Server
  951.   MySQL ODBC Support
  952.     How to Install MyODBC
  953.     How to Fill in the Various Fields in the ODBC Administrator Program
  954.     Connect parameters for MyODBC
  955.     How to Report Problems with MyODBC
  956.     Programs Known to Work with MyODBC
  957.     How to Get the Value of an `AUTO_INCREMENT' Column in ODBC
  958.     Reporting Problems with MyODBC
  959.   MySQL Java Connectivity (JDBC)
  960.   MySQL PHP API
  961.     Common Problems with MySQL and PHP
  962.   MySQL Perl API
  963.   MySQL C++ API
  964.     Borland C++
  965.   MySQL Python API
  966.   MySQL Tcl API
  967.   MySQL Eiffel Wrapper
  968.  
  969. Error Handling in MySQL
  970.  
  971. Extending MySQL
  972.   MySQL Internals
  973.     MySQL Threads
  974.     MySQL Test Suite
  975.       Running the MySQL Test Suite
  976.       Extending the MySQL Test Suite
  977.       Reporting Bugs in the MySQL Test Suite
  978.   Adding New Functions to MySQL
  979.     `CREATE FUNCTION/DROP FUNCTION' Syntax
  980.     Adding a New User-defined Function
  981.       UDF Calling Sequences for simple functions
  982.       UDF Calling Sequences for aggregate functions
  983.       Argument Processing
  984.       Return Values and Error Handling
  985.       Compiling and Installing User-defined Functions
  986.     Adding a New Native Function
  987.   Adding New Procedures to MySQL
  988.     Procedure Analyse
  989.     Writing a Procedure
  990.  
  991. Problems and Common Errors
  992.   How to Determine What Is Causing a Problem
  993.   Common Errors When Using MySQL Programs
  994.     `Access denied'
  995.     `Can't connect to [local] MySQL server'
  996.     `Client does not support authentication protocol'
  997.     Password Fails When Entered Interactively
  998.     `Host 'HOST_NAME' is blocked'
  999.     `Too many connections'
  1000.     `Out of memory'
  1001.     `MySQL server has gone away'
  1002.     `Packet too large'
  1003.     Communication Errors and Aborted Connections
  1004.     `The table is full'
  1005.     `Can't create/write to file'
  1006.     `Commands out of sync'
  1007.     `Ignoring user'
  1008.     `Table 'TBL_NAME' doesn't exist'
  1009.     `Can't initialize character set'
  1010.     File Not Found
  1011.   Installation-Related Issues
  1012.     Problems Linking to the MySQL Client Library
  1013.     How to Run MySQL as a Normal User
  1014.     Problems with File Permissions
  1015.   Administration-Related Issues
  1016.     How to Reset the Root Password
  1017.     What to Do If MySQL Keeps Crashing
  1018.     How MySQL Handles a Full Disk
  1019.     Where MySQL Stores Temporary Files
  1020.     How to Protect or Change the MySQL Socket File `/tmp/mysql.sock'
  1021.     Time Zone Problems
  1022.   Query-Related Issues
  1023.     Case Sensitivity in Searches
  1024.     Problems Using `DATE' Columns
  1025.     Problems with `NULL' Values
  1026.     Problems with Column Aliases
  1027.     Rollback Failure for Non-Transactional Tables
  1028.     Deleting Rows from Related Tables
  1029.     Solving Problems with No Matching Rows
  1030.     Problems with Floating-Point Comparisons
  1031.   Optimizer-Related Issues
  1032.   Table Definition-Related Issues
  1033.     Problems with `ALTER TABLE'
  1034.     How to Change the Order of Columns in a Table
  1035.     `TEMPORARY TABLE' Problems
  1036.  
  1037. Credits
  1038.   Developers at MySQL AB
  1039.   Contributors to MySQL
  1040.   Documenters and translators
  1041.   Libraries used by and included with MySQL
  1042.   Packages that support MySQL
  1043.   Tools that were used to create MySQL
  1044.   Supporters of MySQL
  1045.  
  1046. MySQL Change History
  1047.   Changes in release 5.0.x (Development)
  1048.     Changes in release 5.0.2 (not released yet)
  1049.     Changes in release 5.0.1 (to be released soon)
  1050.     Changes in release 5.0.0 (22 Dec 2003: Alpha)
  1051.   Changes in release 4.1.x (Beta)
  1052.     Changes in release 4.1.4 (to be released soon)
  1053.     Changes in release 4.1.3 (28 Jun 2004: Beta)
  1054.     Changes in release 4.1.2 (28 May 2004)
  1055.     Changes in release 4.1.1 (01 Dec 2003)
  1056.     Changes in release 4.1.0 (03 Apr 2003: Alpha)
  1057.   Changes in release 4.0.x (Production)
  1058.     Changes in release 4.0.21 (not released yet)
  1059.     Changes in release 4.0.20 (17 May 2004)
  1060.     Changes in release 4.0.19 (04 May 2004)
  1061.     Changes in release 4.0.18 (12 Feb 2004)
  1062.     Changes in release 4.0.17 (14 Dec 2003)
  1063.     Changes in release 4.0.16 (17 Oct 2003)
  1064.     Changes in release 4.0.15 (03 Sep 2003)
  1065.     Changes in release 4.0.14 (18 Jul 2003)
  1066.     Changes in release 4.0.13 (16 May 2003)
  1067.     Changes in release 4.0.12 (15 Mar 2003: Production)
  1068.     Changes in release 4.0.11 (20 Feb 2003)
  1069.     Changes in release 4.0.10 (29 Jan 2003)
  1070.     Changes in release 4.0.9 (09 Jan 2003)
  1071.     Changes in release 4.0.8 (07 Jan 2003)
  1072.     Changes in release 4.0.7 (20 Dec 2002)
  1073.     Changes in release 4.0.6 (14 Dec 2002: Gamma)
  1074.     Changes in release 4.0.5 (13 Nov 2002)
  1075.     Changes in release 4.0.4 (29 Sep 2002)
  1076.     Changes in release 4.0.3 (26 Aug 2002: Beta)
  1077.     Changes in release 4.0.2 (01 Jul 2002)
  1078.     Changes in release 4.0.1 (23 Dec 2001)
  1079.     Changes in release 4.0.0 (Oct 2001: Alpha)
  1080.   Changes in release 3.23.x (Recent; still supported)
  1081.     Changes in release 3.23.59 (not released yet)
  1082.     Changes in release 3.23.58 (11 Sep 2003)
  1083.     Changes in release 3.23.57 (06 Jun 2003)
  1084.     Changes in release 3.23.56 (13 Mar 2003)
  1085.     Changes in release 3.23.55 (23 Jan 2003)
  1086.     Changes in release 3.23.54 (05 Dec 2002)
  1087.     Changes in release 3.23.53 (09 Oct 2002)
  1088.     Changes in release 3.23.52 (14 Aug 2002)
  1089.     Changes in release 3.23.51 (31 May 2002)
  1090.     Changes in release 3.23.50 (21 Apr 2002)
  1091.     Changes in release 3.23.49
  1092.     Changes in release 3.23.48 (07 Feb 2002)
  1093.     Changes in release 3.23.47 (27 Dec 2001)
  1094.     Changes in release 3.23.46 (29 Nov 2001)
  1095.     Changes in release 3.23.45 (22 Nov 2001)
  1096.     Changes in release 3.23.44 (31 Oct 2001)
  1097.     Changes in release 3.23.43 (04 Oct 2001)
  1098.     Changes in release 3.23.42 (08 Sep 2001)
  1099.     Changes in release 3.23.41 (11 Aug 2001)
  1100.     Changes in release 3.23.40
  1101.     Changes in release 3.23.39 (12 Jun 2001)
  1102.     Changes in release 3.23.38 (09 May 2001)
  1103.     Changes in release 3.23.37 (17 Apr 2001)
  1104.     Changes in release 3.23.36 (27 Mar 2001)
  1105.     Changes in release 3.23.35 (15 Mar 2001)
  1106.     Changes in release 3.23.34a
  1107.     Changes in release 3.23.34 (10 Mar 2001)
  1108.     Changes in release 3.23.33 (09 Feb 2001)
  1109.     Changes in release 3.23.32 (22 Jan 2001: Production)
  1110.     Changes in release 3.23.31 (17 Jan 2001)
  1111.     Changes in release 3.23.30 (04 Jan 2001)
  1112.     Changes in release 3.23.29 (16 Dec 2000)
  1113.     Changes in release 3.23.28 (22 Nov 2000: Gamma)
  1114.     Changes in release 3.23.27 (24 Oct 2000)
  1115.     Changes in release 3.23.26 (18 Oct 2000)
  1116.     Changes in release 3.23.25 (29 Sep 2000)
  1117.     Changes in release 3.23.24 (08 Sep 2000)
  1118.     Changes in release 3.23.23 (01 Sep 2000)
  1119.     Changes in release 3.23.22 (31 Jul 2000)
  1120.     Changes in release 3.23.21
  1121.     Changes in release 3.23.20
  1122.     Changes in release 3.23.19
  1123.     Changes in release 3.23.18
  1124.     Changes in release 3.23.17
  1125.     Changes in release 3.23.16
  1126.     Changes in release 3.23.15 (May 2000: Beta)
  1127.     Changes in release 3.23.14
  1128.     Changes in release 3.23.13
  1129.     Changes in release 3.23.12 (07 Mar 2000)
  1130.     Changes in release 3.23.11
  1131.     Changes in release 3.23.10
  1132.     Changes in release 3.23.9
  1133.     Changes in release 3.23.8 (02 Jan 2000)
  1134.     Changes in release 3.23.7 (10 Dec 1999)
  1135.     Changes in release 3.23.6
  1136.     Changes in release 3.23.5 (20 Oct 1999)
  1137.     Changes in release 3.23.4 (28 Sep 1999)
  1138.     Changes in release 3.23.3
  1139.     Changes in release 3.23.2 (09 Aug 1999)
  1140.     Changes in release 3.23.1
  1141.     Changes in release 3.23.0 (05 Aug 1999: Alpha)
  1142.   Changes in release 3.22.x (Old; discontinued)
  1143.     Changes in release 3.22.35
  1144.     Changes in release 3.22.34
  1145.     Changes in release 3.22.33
  1146.     Changes in release 3.22.32 (14 Feb 2000)
  1147.     Changes in release 3.22.31
  1148.     Changes in release 3.22.30
  1149.     Changes in release 3.22.29 (02 Jan 2000)
  1150.     Changes in release 3.22.28 (20 Oct 1999)
  1151.     Changes in release 3.22.27
  1152.     Changes in release 3.22.26 (16 Sep 1999)
  1153.     Changes in release 3.22.25
  1154.     Changes in release 3.22.24 (05 Jul 1999)
  1155.     Changes in release 3.22.23 (08 Jun 1999)
  1156.     Changes in release 3.22.22 (30 Apr 1999)
  1157.     Changes in release 3.22.21
  1158.     Changes in release 3.22.20 (18 Mar 1999)
  1159.     Changes in release 3.22.19 (Mar 1999: Production)
  1160.     Changes in release 3.22.18
  1161.     Changes in release 3.22.17
  1162.     Changes in release 3.22.16 (Feb 1999: Gamma)
  1163.     Changes in release 3.22.15
  1164.     Changes in release 3.22.14
  1165.     Changes in release 3.22.13
  1166.     Changes in release 3.22.12
  1167.     Changes in release 3.22.11
  1168.     Changes in release 3.22.10
  1169.     Changes in release 3.22.9
  1170.     Changes in release 3.22.8
  1171.     Changes in release 3.22.7 (Sep 1998: Beta)
  1172.     Changes in release 3.22.6
  1173.     Changes in release 3.22.5
  1174.     Changes in release 3.22.4
  1175.     Changes in release 3.22.3
  1176.     Changes in release 3.22.2
  1177.     Changes in release 3.22.1 (Jun 1998: Alpha)
  1178.     Changes in release 3.22.0
  1179.   Changes in release 3.21.x
  1180.     Changes in release 3.21.33
  1181.     Changes in release 3.21.32
  1182.     Changes in release 3.21.31
  1183.     Changes in release 3.21.30
  1184.     Changes in release 3.21.29
  1185.     Changes in release 3.21.28
  1186.     Changes in release 3.21.27
  1187.     Changes in release 3.21.26
  1188.     Changes in release 3.21.25
  1189.     Changes in release 3.21.24
  1190.     Changes in release 3.21.23
  1191.     Changes in release 3.21.22
  1192.     Changes in release 3.21.21a
  1193.     Changes in release 3.21.21
  1194.     Changes in release 3.21.20
  1195.     Changes in release 3.21.19
  1196.     Changes in release 3.21.18
  1197.     Changes in release 3.21.17
  1198.     Changes in release 3.21.16
  1199.     Changes in release 3.21.15
  1200.     Changes in release 3.21.14b
  1201.     Changes in release 3.21.14a
  1202.     Changes in release 3.21.13
  1203.     Changes in release 3.21.12
  1204.     Changes in release 3.21.11
  1205.     Changes in release 3.21.10
  1206.     Changes in release 3.21.9
  1207.     Changes in release 3.21.8
  1208.     Changes in release 3.21.7
  1209.     Changes in release 3.21.6
  1210.     Changes in release 3.21.5
  1211.     Changes in release 3.21.4
  1212.     Changes in release 3.21.3
  1213.     Changes in release 3.21.2
  1214.     Changes in release 3.21.0
  1215.   Changes in release 3.20.x
  1216.     Changes in release 3.20.18
  1217.     Changes in release 3.20.17
  1218.     Changes in release 3.20.16
  1219.     Changes in release 3.20.15
  1220.     Changes in release 3.20.14
  1221.     Changes in release 3.20.13
  1222.     Changes in release 3.20.11
  1223.     Changes in release 3.20.10
  1224.     Changes in release 3.20.9
  1225.     Changes in release 3.20.8
  1226.     Changes in release 3.20.7
  1227.     Changes in release 3.20.6
  1228.     Changes in release 3.20.3
  1229.     Changes in release 3.20.0
  1230.   Changes in release 3.19.x
  1231.     Changes in release 3.19.5
  1232.     Changes in release 3.19.4
  1233.     Changes in release 3.19.3
  1234.   `InnoDB' Change History
  1235.     MySQL/InnoDB-4.0.21, not released yet
  1236.     MySQL/InnoDB-4.1.3, June 28, 2004
  1237.     MySQL/InnoDB-4.1.2, May 30, 2004
  1238.     MySQL/InnoDB-4.0.20, May 18, 2004
  1239.     MySQL/InnoDB-4.0.19, May 4, 2004
  1240.     MySQL/InnoDB-4.0.18, February 13, 2004
  1241.     MySQL/InnoDB-5.0.0, December 24, 2003
  1242.     MySQL/InnoDB-4.0.17, December 17, 2003
  1243.     MySQL/InnoDB-4.1.1, December 4, 2003
  1244.     MySQL/InnoDB-4.0.16, October 22, 2003
  1245.     MySQL/InnoDB-3.23.58, September 15, 2003
  1246.     MySQL/InnoDB-4.0.15, September 10, 2003
  1247.     MySQL/InnoDB-4.0.14, July 22, 2003
  1248.     MySQL/InnoDB-3.23.57, June 20, 2003
  1249.     MySQL/InnoDB-4.0.13, May 20, 2003
  1250.     MySQL/InnoDB-4.1.0, April 3, 2003
  1251.     MySQL/InnoDB-3.23.56, March 17, 2003
  1252.     MySQL/InnoDB-4.0.12, March 18, 2003
  1253.     MySQL/InnoDB-4.0.11, February 25, 2003
  1254.     MySQL/InnoDB-4.0.10, February 4, 2003
  1255.     MySQL/InnoDB-3.23.55, January 24, 2003
  1256.     MySQL/InnoDB-4.0.9, January 14, 2003
  1257.     MySQL/InnoDB-4.0.8, January 7, 2003
  1258.     MySQL/InnoDB-4.0.7, December 26, 2002
  1259.     MySQL/InnoDB-4.0.6, December 19, 2002
  1260.     MySQL/InnoDB-3.23.54, December 12, 2002
  1261.     MySQL/InnoDB-4.0.5, November 18, 2002
  1262.     MySQL/InnoDB-3.23.53, October 9, 2002
  1263.     MySQL/InnoDB-4.0.4, October 2, 2002
  1264.     MySQL/InnoDB-4.0.3, August 28, 2002
  1265.     MySQL/InnoDB-3.23.52, August 16, 2002
  1266.     MySQL/InnoDB-4.0.2, July 10, 2002
  1267.     MySQL/InnoDB-3.23.51, June 12, 2002
  1268.     MySQL/InnoDB-3.23.50, April 23, 2002
  1269.     MySQL/InnoDB-3.23.49, February 17, 2002
  1270.     MySQL/InnoDB-3.23.48, February 9, 2002
  1271.     MySQL/InnoDB-3.23.47, December 28, 2001
  1272.     MySQL/InnoDB-4.0.1, December 23, 2001
  1273.     MySQL/InnoDB-3.23.46, November 30, 2001
  1274.     MySQL/InnoDB-3.23.45, November 23, 2001
  1275.     MySQL/InnoDB-3.23.44, November 2, 2001
  1276.     MySQL/InnoDB-3.23.43, October 4, 2001
  1277.     MySQL/InnoDB-3.23.42, September 9, 2001
  1278.     MySQL/InnoDB-3.23.41, August 13, 2001
  1279.     MySQL/InnoDB-3.23.40, July 16, 2001
  1280.     MySQL/InnoDB-3.23.39, June 13, 2001
  1281.     MySQL/InnoDB-3.23.38, May 12, 2001
  1282.  
  1283. Porting to Other Systems
  1284.   Debugging a MySQL Server
  1285.     Compiling MySQL for Debugging
  1286.     Creating Trace Files
  1287.     Debugging `mysqld' under `gdb'
  1288.     Using a Stack Trace
  1289.     Using Log Files to Find Cause of Errors in `mysqld'
  1290.     Making a Test Case If You Experience Table Corruption
  1291.   Debugging a MySQL Client
  1292.   The DBUG Package
  1293.   Comments about RTS Threads
  1294.   Differences Between Thread Packages
  1295.  
  1296. Environment Variables
  1297.  
  1298. MySQL Regular Expressions
  1299.  
  1300. GNU General Public License
  1301.  
  1302. MySQL FOSS License Exception
  1303.  
  1304. SQL Command, Type, and Function Index
  1305.  
  1306. Concept Index
  1307.  
  1308.  
  1309. This is the Reference Manual for the MySQL Database System.  It
  1310. documents MySQL up to Version 5.0.1-alpha, but is also applicable for
  1311. older versions of the MySQL software (such as 3.23 or 4.0-production)
  1312. because functional changes are indicated with reference to a version
  1313. number.
  1314.  
  1315. General Information
  1316. *******************
  1317.  
  1318. The MySQL (R) software delivers a very fast, multi-threaded,
  1319. multi-user, and robust SQL (Structured Query Language) database server.
  1320. MySQL Server is intended for mission-critical, heavy-load production
  1321. systems as well as for embedding into mass-deployed software.  MySQL is
  1322. a registered trademark of MySQL AB.
  1323.  
  1324. The MySQL software is Dual Licensed. Users can choose to use the MySQL
  1325. software as an Open Source/Free Software product under the terms of the
  1326. GNU General Public License (`http://www.fsf.org/licenses/') or can
  1327. purchase a standard commercial license from MySQL AB.  *Note Licensing
  1328. and Support::.
  1329.  
  1330. The MySQL Web site (`http://www.mysql.com/') provides the latest
  1331. information about the MySQL software.
  1332.  
  1333. The following list describes some sections of particular interest in
  1334. this manual:
  1335.  
  1336.    * For information about the company behind the MySQL Database Server,
  1337.      see *Note What is MySQL AB::.
  1338.  
  1339.    * For a discussion about the capabilities of the MySQL Database
  1340.      Server, see *Note Features::.
  1341.  
  1342.    * For installation instructions, see *Note Installing::.
  1343.  
  1344.    * For tips on porting the MySQL Database Software to new
  1345.      architectures or operating systems, see *Note Porting::.
  1346.  
  1347.    * For information about upgrading from a Version 4.0 release, see
  1348.      *Note Upgrading-from-4.0::.
  1349.  
  1350.    * For information about upgrading from a Version 3.23 release, see
  1351.      *Note Upgrading-from-3.23::.
  1352.  
  1353.    * For information about upgrading from a Version 3.22 release, see
  1354.      *Note Upgrading-from-3.22::.
  1355.  
  1356.    * For a tutorial introduction to the MySQL Database Server, see
  1357.      *Note Tutorial::.
  1358.  
  1359.    * For examples of SQL and benchmarking information, see the
  1360.      benchmarking directory (`sql-bench' in the distribution).
  1361.  
  1362.    * For a history of new features and bugfixes, see *Note News::.
  1363.  
  1364.    * For a list of currently known bugs and misfeatures, see *Note
  1365.      Bugs::.
  1366.  
  1367.    * For future plans, see *Note TODO::.
  1368.  
  1369.    * For a list of all the contributors to this project, see *Note
  1370.      Credits::.
  1371.  
  1372. *Important*:
  1373.  
  1374. Reports of errors (often called "bugs"), as well as questions and
  1375. comments, should be sent to the general MySQL mailing list.  *Note
  1376. Mailing-list::.  *Note Bug reports::.
  1377.  
  1378. The `mysqlbug' script should be used to generate bug reports on Unix.
  1379. (Windows distributions contain a file named `mysqlbug.txt' in the base
  1380. directory that can be used as a template for a bug report.)
  1381.  
  1382. For source distributions, the `mysqlbug' script can be found in the
  1383. `scripts' directory. For binary distributions, `mysqlbug' can be found
  1384. in the `bin' directory (`/usr/bin' for the `MySQL-server' RPM package).
  1385.  
  1386. If you have found a sensitive security bug in MySQL Server, please let
  1387. us know immediately by sending an email message to <security@mysql.com>.
  1388.  
  1389. About This Manual
  1390. =================
  1391.  
  1392. This is the Reference Manual for the MySQL Database System.  It
  1393. documents MySQL up to Version 5.0.1-alpha, but is also applicable for
  1394. older versions of the MySQL software (such as 3.23 or 4.0-production)
  1395. because functional changes are indicated with reference to a version
  1396. number.
  1397.  
  1398. Because this manual serves as a reference, it does not provide general
  1399. instruction on SQL or relational database concepts. It also will not
  1400. teach you how to use your operating system or command-line interpreter.
  1401.  
  1402. The MySQL Database Software is under constant development, and the
  1403. Reference Manual is updated frequently as well.  The most recent
  1404. version of the manual is available online in searchable form at
  1405. `http://dev.mysql.com/doc/'.  Other formats also are available,
  1406. including HTML, PDF, and Windows CHM versions.
  1407.  
  1408. The primary document is the Texinfo file.  The HTML version is produced
  1409. automatically using a modified version of `texi2html'.  The plain text
  1410. and Info versions are produced with `makeinfo'.  The PostScript version
  1411. is produced using `texi2dvi' and `dvips'.  The PDF version is produced
  1412. with `pdftex'.
  1413.  
  1414. If you have any suggestions concerning additions or corrections to this
  1415. manual, please send them to the documentation team at <docs@mysql.com>.
  1416.  
  1417. This manual was initially written by David Axmark and Michael "Monty"
  1418. Widenius. It is now maintained by the MySQL Documentation Team,
  1419. consisting of Arjen Lentz, Paul DuBois, and Stefan Hinz.  For the many
  1420. other contributors, see *Note Credits::.
  1421.  
  1422. The copyright (2004) to this manual is owned by the Swedish company
  1423. MySQL AB. *Note Copyright::.  MySQL and the MySQL logo are (registered)
  1424. trademarks of MySQL AB.  Other trademarks and registered trademarks
  1425. referred to in this manual are the property of their respective owners,
  1426. and are used for identification purposes only.
  1427.  
  1428. Conventions Used in This Manual
  1429. -------------------------------
  1430.  
  1431. This manual uses certain typographical conventions:
  1432.  
  1433. `constant'
  1434.      Constant-width font is used for command names and options; SQL
  1435.      statements; database, table, and column names; C and Perl code;
  1436.      and environment variables.  Example: "To see how `mysqladmin'
  1437.      works, invoke it with the `--help' option."
  1438.  
  1439. CONSTANT ITALIC
  1440.      Italic constant-width font is used to indicate variable input for
  1441.      which you should substitute a value of your own choosing.
  1442.  
  1443. `filename'
  1444.      Constant-width font with surrounding quotes is used for filenames
  1445.      and pathnames.  Example: "The distribution is installed under the
  1446.      `/usr/local/' directory."
  1447.  
  1448. `c'
  1449.      Constant-width font with surrounding quotes is also used to
  1450.      indicate character sequences.  Example: "To specify a wildcard,
  1451.      use the `%' character."
  1452.  
  1453. _italic_
  1454.      Italic font is used for emphasis, _like this_.
  1455.  
  1456. *boldface*
  1457.      Boldface font is used in table headings and to convey *especially
  1458.      strong emphasis*.
  1459.  
  1460. When commands are shown that are meant to be executed from within a
  1461. particular program, the program is indicated by a prompt shown before
  1462. the command.  For example, `shell>' indicates a command that you
  1463. execute from your login shell, and `mysql>' indicates a statement that
  1464. you execute from the `mysql' client program:
  1465.  
  1466.      shell> type a shell command here
  1467.      mysql> type a mysql statement here
  1468.  
  1469. The "shell" is your command interpreter. On Unix, this is typically a
  1470. program such as `sh' or `csh'. On Windows, the equivalent program is
  1471. `command.com' or `cmd.exe', typically run in a console window.
  1472.  
  1473. When you enter a command or statement shown in an example, do not type
  1474. the prompt shown in the example.
  1475.  
  1476. Database, table, and column names must often be substituted into
  1477. statements.  To indicate that such substitution is necessary, this
  1478. manual uses DB_NAME, TBL_NAME, and COL_NAME.  For example, you might
  1479. see a statement like this:
  1480.  
  1481.      mysql> SELECT COL_NAME FROM DB_NAME.TBL_NAME;
  1482.  
  1483. This means that if you were to enter a similar statement, you would
  1484. supply your own database, table, and column names, perhaps like this:
  1485.  
  1486.      mysql> SELECT author_name FROM biblio_db.author_list;
  1487.  
  1488. SQL keywords are not case sensitive and may be written in uppercase or
  1489. lowercase.  This manual uses uppercase.
  1490.  
  1491. In syntax descriptions, square brackets (`[' and `]') are used to
  1492. indicate optional words or clauses.  For example, in the following
  1493. statement, `IF EXISTS' is optional:
  1494.  
  1495.      DROP TABLE [IF EXISTS] TBL_NAME
  1496.  
  1497. When a syntax element consists of a number of alternatives, the
  1498. alternatives are separated by vertical bars (`|').  When one member
  1499. from a set of choices _may_ be chosen, the alternatives are listed
  1500. within square brackets (`[' and `]'):
  1501.  
  1502.      TRIM([[BOTH | LEADING | TRAILING] [REMSTR] FROM] STR)
  1503.  
  1504. When one member from a set of choices _must_ be chosen, the
  1505. alternatives are listed within braces (`{' and `}'):
  1506.  
  1507.      {DESCRIBE | DESC} TBL_NAME [COL_NAME | WILD]
  1508.  
  1509. An ellipsis (`...') indicates the omission of a section of a statement,
  1510. typically to provide a shorter version of more complex syntax. For
  1511. example, `INSERT ... SELECT' is shorthand for the form of `INSERT'
  1512. statement that is followed by a `SELECT' statement.
  1513.  
  1514. An ellipsis can also indicate that the preceding syntax element of a
  1515. statement may be repeated. In the following example, multiple
  1516. RESET_OPTION values may be given, with each of those after the first
  1517. preceded by commas:
  1518.  
  1519.      RESET RESET_OPTION [,RESET_OPTION] ...
  1520.  
  1521. Commands for setting shell variables are shown using Bourne shell
  1522. syntax.  For example, the sequence to set an environment variable and
  1523. run a command looks like this in Bourne shell syntax:
  1524.  
  1525.      shell> VARNAME=VALUE SOME_COMMAND
  1526.  
  1527. If you are using `csh' or `tcsh', you must issue commands somewhat
  1528. differently.  You would execute the sequence just shown like this:
  1529.  
  1530.      shell> setenv VARNAME VALUE
  1531.      shell> SOME_COMMAND
  1532.  
  1533. Overview of the MySQL Database Management System
  1534. ================================================
  1535.  
  1536. MySQL, the most popular Open Source SQL database management system, is
  1537. developed, distributed, and supported by MySQL AB.  MySQL AB is a
  1538. commercial company, founded by the MySQL developers, that builds its
  1539. business by providing services around the MySQL database management
  1540. system.  *Note What is MySQL AB::.
  1541.  
  1542. The MySQL Web site (`http://www.mysql.com/') provides the latest
  1543. information about MySQL software and MySQL AB.
  1544.  
  1545. MySQL is a database management system.
  1546.      A database is a structured collection of data.  It may be anything
  1547.      from a simple shopping list to a picture gallery or the vast
  1548.      amounts of information in a corporate network.  To add, access,
  1549.      and process data stored in a computer database, you need a
  1550.      database management system such as MySQL Server.  Since computers
  1551.      are very good at handling large amounts of data, database
  1552.      management systems play a central role in computing, as standalone
  1553.      utilities or as parts of other applications.
  1554.  
  1555. MySQL is a relational database management system.
  1556.      A relational database stores data in separate tables rather than
  1557.      putting all the data in one big storeroom.  This adds speed and
  1558.      flexibility.  The SQL part of "MySQL" stands for "Structured Query
  1559.      Language." SQL is the most common standardized language used to
  1560.      access databases and is defined by the ANSI/ISO SQL Standard. The
  1561.      SQL standard has been evolving since 1986 and several versions
  1562.      exist. In this manual, "SQL-92" refers to the standard released in
  1563.      1992, "SQL:1999" refers to the standard released in 1999, and
  1564.      "SQL:2003" refers to the current version of the standard.  We use
  1565.      the phrase "the SQL standard" to mean the current version of the
  1566.      SQL Standard at any time.
  1567.  
  1568. MySQL software is Open Source.
  1569.      Open Source means that it is possible for anyone to use and modify
  1570.      the software.  Anybody can download the MySQL software from the
  1571.      Internet and use it without paying anything.  If you wish, you may
  1572.      study the source code and change it to suit your needs.  The MySQL
  1573.      software uses the GPL (GNU General Public License),
  1574.      `http://www.fsf.org/licenses/', to define what you may and may not
  1575.      do with the software in different situations.  If you feel
  1576.      uncomfortable with the GPL or need to embed MySQL code into a
  1577.      commercial application, you can buy a commercially licensed
  1578.      version from us.  *Note MySQL licenses::.
  1579.  
  1580. The MySQL Database Server is very fast, reliable, and easy to use.
  1581.      If that is what you are looking for, you should give it a try.
  1582.      MySQL Server also has a practical set of features developed in
  1583.      close cooperation with our users.  You can find a performance
  1584.      comparison of MySQL Server with other database managers on our
  1585.      benchmark page.  *Note MySQL Benchmarks::.
  1586.  
  1587.      MySQL Server was originally developed to handle large databases
  1588.      much faster than existing solutions and has been successfully used
  1589.      in highly demanding production environments for several years.
  1590.      Although under constant development, MySQL Server today offers a
  1591.      rich and useful set of functions.  Its connectivity, speed, and
  1592.      security make MySQL Server highly suited for accessing databases
  1593.      on the Internet.
  1594.  
  1595. MySQL Server works in client/server or embedded systems.
  1596.      The MySQL Database Software is a client/server system that consists
  1597.      of a multi-threaded SQL server that supports different backends,
  1598.      several different client programs and libraries, administrative
  1599.      tools, and a wide range of application programming interfaces
  1600.      (APIs).
  1601.  
  1602.      We also provide MySQL Server as an embedded multi-threaded library
  1603.      that you can link into your application to get a smaller, faster,
  1604.      easier-to-manage product.
  1605.  
  1606. A large amount of contributed MySQL software is available.
  1607.      It is very likely that you will find that your favorite
  1608.      application or language already supports the MySQL Database Server.
  1609.  
  1610. The official way to pronounce "MySQL" is "My Ess Que Ell" (not "my
  1611. sequel"), but we don't mind if you pronounce it as "my sequel" or in
  1612. some other localized way.
  1613.  
  1614. History of MySQL
  1615. ----------------
  1616.  
  1617. We started out with the intention of using `mSQL' to connect to our
  1618. tables using our own fast low-level (ISAM) routines. However, after some
  1619. testing, we came to the conclusion that `mSQL' was not fast enough or
  1620. flexible enough for our needs.  This resulted in a new SQL interface to
  1621. our database but with almost the same API interface as `mSQL'.  This
  1622. API was designed to allow third-party code that was written for use
  1623. with `mSQL' to be ported easily for use with MySQL.
  1624.  
  1625. The derivation of the name MySQL is not clear.  Our base directory and
  1626. a large number of our libraries and tools have had the prefix "my" for
  1627. well over 10 years.  However, co-founder Monty Widenius's daughter is
  1628. also named My.  Which of the two gave its name to MySQL is still a
  1629. mystery, even for us.
  1630.  
  1631. The name of the MySQL Dolphin (our logo) is "Sakila," which was chosen
  1632. by the founders of MySQL AB from a huge list of names suggested by users
  1633. in our "Name the Dolphin" contest. The winning name was submitted by
  1634. Ambrose Twebaze, an Open Source software developer from Swaziland,
  1635. Africa.  According to Ambrose, the name Sakila has its roots in
  1636. SiSwati, the local language of Swaziland. Sakila is also the name of a
  1637. town in Arusha, Tanzania, near Ambrose's country of origin, Uganda.
  1638.  
  1639. The Main Features of MySQL
  1640. --------------------------
  1641.  
  1642. The following list describes some of the important characteristics of
  1643. the MySQL Database Software. See also *Note Roadmap:: for more
  1644. information about current and upcoming features.
  1645.  
  1646. Internals and Portability
  1647.         * Written in C and C++.
  1648.  
  1649.         * Tested with a broad range of different compilers.
  1650.  
  1651.         * Works on many different platforms.  *Note Which OS::.
  1652.  
  1653.         * Uses GNU Automake, Autoconf, and Libtool for portability.
  1654.  
  1655.         * APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and
  1656.           Tcl are available.  *Note Clients::.
  1657.  
  1658.         * Fully multi-threaded using kernel threads.  It can easily use
  1659.           multiple CPUs if they are available.
  1660.  
  1661.         * Provides transactional and non-transactional storage engines.
  1662.  
  1663.         * Uses very fast B-tree disk tables (`MyISAM') with index
  1664.           compression.
  1665.  
  1666.         * Relatively easy to add another storage engine. This is useful
  1667.           if you want to add an SQL interface to an in-house database.
  1668.  
  1669.         * A very fast thread-based memory allocation system.
  1670.  
  1671.         * Very fast joins using an optimized one-sweep multi-join.
  1672.  
  1673.         * In-memory hash tables, which are used as temporary tables.
  1674.  
  1675.         * SQL functions are implemented using a highly optimized class
  1676.           library and should be as fast as possible.  Usually there is
  1677.           no memory allocation at all after query initialization.
  1678.  
  1679.         * The MySQL code is tested with Purify (a commercial memory
  1680.           leakage detector) as well as with Valgrind, a GPL tool
  1681.           (`http://developer.kde.org/~sewardj/').
  1682.  
  1683.         * The server is available as a separate program for use in a
  1684.           client/server networked environment.  It is also available as
  1685.           a library that can be embedded (linked) into standalone
  1686.           applications. Such applications can be used in isolation or
  1687.           in environments where no network is available.
  1688.  
  1689. Column Types
  1690.         * Many column types: signed/unsigned integers 1, 2, 3, 4, and 8
  1691.           bytes long, `FLOAT', `DOUBLE', `CHAR', `VARCHAR', `TEXT',
  1692.           `BLOB', `DATE', `TIME', `DATETIME', `TIMESTAMP', `YEAR',
  1693.           `SET', `ENUM', and OpenGIS spatial types.  *Note Column
  1694.           types::.
  1695.  
  1696.         * Fixed-length and variable-length records.
  1697.  
  1698. Statements and Functions
  1699.         * Full operator and function support in the `SELECT' and `WHERE'
  1700.           clauses of queries.  For example:
  1701.  
  1702.                mysql> SELECT CONCAT(first_name, ' ', last_name)
  1703.                    -> FROM citizen
  1704.                    -> WHERE income/dependents > 10000 AND age > 30;
  1705.  
  1706.         * Full support for SQL `GROUP BY' and `ORDER BY' clauses.
  1707.           Support for group functions (`COUNT()', `COUNT(DISTINCT ...)',
  1708.           `AVG()', `STD()', `SUM()', `MAX()', `MIN()', and
  1709.           `GROUP_CONCAT()').
  1710.  
  1711.         * Support for `LEFT OUTER JOIN' and `RIGHT OUTER JOIN' with
  1712.           both standard SQL and ODBC syntax.
  1713.  
  1714.         * Support for aliases on tables and columns as required by
  1715.           standard SQL.
  1716.  
  1717.         * `DELETE', `INSERT', `REPLACE', and `UPDATE' return the number
  1718.           of rows that were changed (affected).  It is possible to
  1719.           return the number of rows matched instead by setting a flag
  1720.           when connecting to the server.
  1721.  
  1722.         * The MySQL-specific `SHOW' command can be used to retrieve
  1723.           information about databases, tables, and indexes.  The
  1724.           `EXPLAIN' command can be used to determine how the optimizer
  1725.           resolves a query.
  1726.  
  1727.         * Function names do not clash with table or column names.  For
  1728.           example, `ABS' is a valid column name.  The only restriction
  1729.           is that for a function call, no spaces are allowed between
  1730.           the function name and the `(' that follows it.  *Note
  1731.           Reserved words::.
  1732.  
  1733.         * You can mix tables from different databases in the same query
  1734.           (as of MySQL 3.22).
  1735.  
  1736. Security
  1737.         * A privilege and password system that is very flexible and
  1738.           secure, and that allows host-based verification.  Passwords
  1739.           are secure because all password traffic is encrypted when you
  1740.           connect to a server.
  1741.  
  1742. Scalability and Limits
  1743.         * Handles large databases.  We use MySQL Server with databases
  1744.           that contain 50 million records. We also know of users who
  1745.           use MySQL Server with 60,000 tables and about 5,000,000,000
  1746.           rows.
  1747.  
  1748.         * Up to 64 indexes per table are allowed (32 before MySQL
  1749.           4.1.2).  Each index may consist of 1 to 16 columns or parts
  1750.           of columns.  The maximum index width is 1000 bytes (500
  1751.           before MySQL 4.1.2).  An index may use a prefix of a column
  1752.           for `CHAR', `VARCHAR', `BLOB', or `TEXT' column types.
  1753.  
  1754. Connectivity
  1755.         * Clients can connect to the MySQL server using TCP/IP sockets
  1756.           on any platform.  On Windows systems in the NT family (NT,
  1757.           2000, or XP), clients can connect using named pipes. On Unix
  1758.           systems, clients can connect using Unix domain socket files.
  1759.  
  1760.         * The Connector/ODBC interface provides MySQL support for
  1761.           client programs that use ODBC (Open Database Connectivity)
  1762.           connections.  For example, you can use MS Access to connect
  1763.           to your MySQL server.  Clients can be run on Windows or Unix.
  1764.           Connector/ODBC source is available.  All ODBC 2.5 functions
  1765.           are supported, as are many others.  *Note ODBC::.
  1766.  
  1767.         * The Connector/JDBC interface provides MySQL support for Java
  1768.           client programs that use JDBC connections.  Clients can be
  1769.           run on Windows or Unix.  Connector/JDBC source is available.
  1770.           *Note Java::.
  1771.  
  1772. Localization
  1773.         * The server can provide error messages to clients in many
  1774.           languages.  *Note Languages::.
  1775.  
  1776.         * Full support for several different character sets, including
  1777.           `latin1' (ISO-8859-1), `german', `big5', `ujis', and more.
  1778.           For example, the Scandinavian characters `a^', `a"' and `o"'
  1779.           are allowed in table and column names.  Unicode support is
  1780.           available as of MySQL 4.1.
  1781.  
  1782.         * All data is saved in the chosen character set.  All
  1783.           comparisons for normal string columns are case-insensitive.
  1784.  
  1785.         * Sorting is done according to the chosen character set (using
  1786.           Swedish collation by default).  It is possible to change this
  1787.           when the MySQL server is started.  To see an example of very
  1788.           advanced sorting, look at the Czech sorting code.  MySQL
  1789.           Server supports many different character sets that can be
  1790.           specified at compile time and runtime.
  1791.  
  1792. Clients and Tools
  1793.         * The MySQL server has built-in support for SQL statements to
  1794.           check, optimize, and repair tables.  These statements are
  1795.           available from the command line through the `mysqlcheck'
  1796.           client. MySQL also includes `myisamchk', a very fast
  1797.           command-line utility for performing these operations on
  1798.           `MyISAM' tables.  *Note MySQL Database Administration::.
  1799.  
  1800.         * All MySQL programs can be invoked with the `--help' or `-?'
  1801.           options to obtain online assistance.
  1802.  
  1803. MySQL Stability
  1804. ---------------
  1805.  
  1806. This section addresses the questions, "_How stable is MySQL Server?_"
  1807. and, "_Can I depend on MySQL Server in this project?_" We will try to
  1808. clarify these issues and answer some important questions that concern
  1809. many potential users. The information in this section is based on data
  1810. gathered from the mailing lists, which are very active in identifying
  1811. problems as well as reporting types of use.
  1812.  
  1813. The original code stems back to the early 1980s. It provides a stable
  1814. code base, and the `ISAM' table format used by the original storage
  1815. engine remains backward-compatible.  At TcX, the predecessor of MySQL
  1816. AB, MySQL code has worked in projects since mid-1996, without any
  1817. problems.  When the MySQL Database Software initially was released to a
  1818. wider public, our new users quickly found some pieces of untested code.
  1819. Each new release since then has had fewer portability problems, even
  1820. though each new release has also had many new features.
  1821.  
  1822. Each release of the MySQL Server has been usable. Problems have occurred
  1823. only when users try code from the "gray zones."  Naturally, new users
  1824. don't know what the gray zones are; this section therefore attempts to
  1825. document those areas that are currently known.  The descriptions mostly
  1826. deal with Version 3.23 and 4.0 of MySQL Server.  All known and reported
  1827. bugs are fixed in the latest version, with the exception of those
  1828. listed in the bugs section, which are design-related.  *Note Bugs::.
  1829.  
  1830. The MySQL Server design is multi-layered with independent modules.
  1831. Some of the newer modules are listed here with an indication of how
  1832. well-tested each of them is:
  1833.  
  1834. Replication (Gamma)
  1835.      Large groups of servers using replication are in production use,
  1836.      with good results. Work on enhanced replication features is
  1837.      continuing in MySQL 5.x.
  1838.  
  1839. `InnoDB' tables (Stable)
  1840.      The `InnoDB' transactional storage engine has been declared stable
  1841.      in the MySQL 3.23 tree, starting from version 3.23.49.  `InnoDB'
  1842.      is being used in large, heavy-load production systems.
  1843.  
  1844. `BDB' tables (Gamma)
  1845.      The `Berkeley DB' code is very stable, but we are still improving
  1846.      the `BDB' transactional storage engine interface in MySQL Server,
  1847.      so it will take some time before this is as well tested as the
  1848.      other table types.
  1849.  
  1850. Full-text searches (Beta)
  1851.      Full-text searching works but is not yet widely used.  Important
  1852.      enhancements have been implemented in MySQL 4.0.
  1853.  
  1854. `Connector/ODBC' 3.51 (Stable)
  1855.      `Connector/ODBC' 3.51 uses ODBC SDK 3.51 and is in wide production
  1856.      use.  Some issues brought up appear to be application-related and
  1857.      independent of the ODBC driver or underlying database server.
  1858.  
  1859. Automatic recovery of `MyISAM' tables (Gamma)
  1860.      This status applies only to the new code in the `MyISAM' storage
  1861.      engine that checks when opening a table whether it was closed
  1862.      properly and executes an automatic check or repair of the table if
  1863.      it wasn't.
  1864.  
  1865. How Big MySQL Tables Can Be
  1866. ---------------------------
  1867.  
  1868. MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the
  1869. `MyISAM' storage engine in MySQL 3.23, the maximum table size was
  1870. increased to 8 million terabytes (2 ^ 63 bytes). With this larger
  1871. allowed table size, the maximum effective table size for MySQL
  1872. databases now usually is determined by operating system constraints on
  1873. file sizes, not by MySQL internal limits.
  1874.  
  1875. The `InnoDB' storage engine maintains `InnoDB' tables within a
  1876. tablespace that can be created from several files. This allows a table
  1877. to exceed the maximum individual file size. The tablespace can include
  1878. raw disk partitions, which allows extremely large tables. The maximum
  1879. tablespace size is 64TB.
  1880.  
  1881. The following table lists some examples of operating system file-size
  1882. limits:
  1883.  
  1884. *Operating System*     *File-size Limit*
  1885. Linux-Intel 32-bit     2GB, much more when using LFS
  1886. Linux-Alpha            8TB (?)
  1887. Solaris 2.5.1          2GB (4GB possible with patch)
  1888. Solaris 2.6            4GB (can be changed with flag)
  1889. Solaris 2.7 Intel      4GB
  1890. Solaris 2.7            512GB
  1891. UltraSPARC             
  1892. NetWare w/NSS          8TB
  1893. filesystem             
  1894.  
  1895. On Linux 2.2, you can get `MyISAM' tables larger than 2GB in size by
  1896. using the Large File Support (LFS) patch for the ext2 filesystem. On
  1897. Linux 2.4, patches also exist for ReiserFS to get support for big
  1898. files. Most current Linux distributions are based on kernel 2.4 and
  1899. already include all the required LFS patches. However, the maximum
  1900. available file size still depends on several factors, one of them being
  1901. the filesystem used to store MySQL tables.
  1902.  
  1903. For a detailed overview about LFS in Linux, have a look at Andreas
  1904. Jaeger's `Large File Support in Linux' page at
  1905. `http://www.suse.de/~aj/linux_lfs.html'.
  1906.  
  1907. By default, MySQL creates `MyISAM' tables with an internal structure
  1908. that allows a maximum size of about 4GB.  You can check the maximum
  1909. table size for a table with the `SHOW TABLE STATUS' statement or with
  1910. `myisamchk -dv TBL_NAME'.  *Note `SHOW': SHOW.
  1911.  
  1912. If you need a `MyISAM' table that will be larger than 4GB in size (and
  1913. your operating system supports large files), the `CREATE TABLE'
  1914. statement allows `AVG_ROW_LENGTH' and `MAX_ROWS' options.  *Note
  1915. `CREATE TABLE': CREATE TABLE.  You can also change these options with
  1916. `ALTER TABLE' after the table has been created, to increase the table's
  1917. maximum allowable size.  *Note `ALTER TABLE': ALTER TABLE.
  1918.  
  1919. Other ways to work around file-size limits for `MyISAM' tables are as
  1920. follows:
  1921.  
  1922.    * If your large table is read-only, you can use `myisampack' to
  1923.      compress it.  `myisampack' usually compresses a table by at least
  1924.      50%, so you can have, in effect, much bigger tables.  `myisampack'
  1925.      also can merge multiple tables into a single table.  *Note
  1926.      `myisampack': myisampack.
  1927.  
  1928.    * Another way to get around the operating system file limit for
  1929.      `MyISAM' data files is by using the `RAID' options.  *Note `CREATE
  1930.      TABLE': CREATE TABLE.
  1931.  
  1932.    * MySQL includes a `MERGE' library that allows you to handle a
  1933.      collection of `MyISAM' tables that have identical structure as a
  1934.      single `MERGE' table.  *Note `MERGE' tables: MERGE.
  1935.  
  1936.  
  1937. Year 2000 Compliance
  1938. --------------------
  1939.  
  1940. The MySQL Server itself has no problems with Year 2000 (Y2K) compliance:
  1941.  
  1942.    * MySQL Server uses Unix time functions that handle dates into the
  1943.      year `2037' for `TIMESTAMP' values. For `DATE' and `DATETIME'
  1944.      values, dates through the year `9999' are accepted.
  1945.  
  1946.    * All MySQL date functions are implemented in one source file,
  1947.      `sql/time.cc', and are coded very carefully to be year 2000-safe.
  1948.  
  1949.    * In MySQL 3.22 and later, the `YEAR' column type can store years
  1950.      `0' and `1901' to `2155' in one byte and display them using two or
  1951.      four digits.  All two-digit years are considered to be in the range
  1952.      `1970' to `2069', which means that if you store `01' in a `YEAR'
  1953.      column, MySQL Server treats it as `2001'.
  1954.  
  1955. The following simple demonstration illustrates that MySQL Server has no
  1956. problems with `DATE' or `DATETIME' values through the year 9999, and no
  1957. problems with `TIMESTAMP' values until after the year 2030:
  1958.  
  1959.      mysql> DROP TABLE IF EXISTS y2k;
  1960.      Query OK, 0 rows affected (0.01 sec)
  1961.      
  1962.      mysql> CREATE TABLE y2k (date DATE,
  1963.          ->                   date_time DATETIME,
  1964.          ->                   time_stamp TIMESTAMP);
  1965.      Query OK, 0 rows affected (0.01 sec)
  1966.      
  1967.      mysql> INSERT INTO y2k VALUES
  1968.          -> ('1998-12-31','1998-12-31 23:59:59',19981231235959),
  1969.          -> ('1999-01-01','1999-01-01 00:00:00',19990101000000),
  1970.          -> ('1999-09-09','1999-09-09 23:59:59',19990909235959),
  1971.          -> ('2000-01-01','2000-01-01 00:00:00',20000101000000),
  1972.          -> ('2000-02-28','2000-02-28 00:00:00',20000228000000),
  1973.          -> ('2000-02-29','2000-02-29 00:00:00',20000229000000),
  1974.          -> ('2000-03-01','2000-03-01 00:00:00',20000301000000),
  1975.          -> ('2000-12-31','2000-12-31 23:59:59',20001231235959),
  1976.          -> ('2001-01-01','2001-01-01 00:00:00',20010101000000),
  1977.          -> ('2004-12-31','2004-12-31 23:59:59',20041231235959),
  1978.          -> ('2005-01-01','2005-01-01 00:00:00',20050101000000),
  1979.          -> ('2030-01-01','2030-01-01 00:00:00',20300101000000),
  1980.          -> ('2040-01-01','2040-01-01 00:00:00',20400101000000),
  1981.          -> ('9999-12-31','9999-12-31 23:59:59',99991231235959);
  1982.      Query OK, 14 rows affected (0.01 sec)
  1983.      Records: 14  Duplicates: 0  Warnings: 2
  1984.      
  1985.      mysql> SELECT * FROM y2k;
  1986.      +------------+---------------------+----------------+
  1987.      | date       | date_time           | time_stamp     |
  1988.      +------------+---------------------+----------------+
  1989.      | 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
  1990.      | 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
  1991.      | 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
  1992.      | 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
  1993.      | 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
  1994.      | 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
  1995.      | 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
  1996.      | 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
  1997.      | 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
  1998.      | 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
  1999.      | 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
  2000.      | 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
  2001.      | 2040-01-01 | 2040-01-01 00:00:00 | 00000000000000 |
  2002.      | 9999-12-31 | 9999-12-31 23:59:59 | 00000000000000 |
  2003.      +------------+---------------------+----------------+
  2004.      14 rows in set (0.00 sec)
  2005.  
  2006. The final two `TIMESTAMP' column values are zero because the year
  2007. values (`2040', `9999') exceed the `TIMESTAMP' maximum.  The
  2008. `TIMESTAMP' data type, which is used to store the current time,
  2009. supports values that range from `19700101000000' to `20300101000000' on
  2010. 32-bit machines (signed value).  On 64-bit machines, `TIMESTAMP'
  2011. handles values up to `2106' (unsigned value).
  2012.  
  2013. Although MySQL Server itself is Y2K-safe, you may run into problems if
  2014. you use it with applications that are not Y2K-safe.  For example, many
  2015. old applications store or manipulate years using two-digit values
  2016. (which are ambiguous) rather than four-digit values.  This problem may
  2017. be compounded by applications that use values such as `00' or `99' as
  2018. "missing" value indicators.  Unfortunately, these problems may be
  2019. difficult to fix because different applications may be written by
  2020. different programmers, each of whom may use a different set of
  2021. conventions and date-handling functions.
  2022.  
  2023. Thus, even though MySQL Server has no Y2K problems, it is the
  2024. application's responsibility to provide unambiguous input.  See *Note
  2025. Y2K issues:: for MySQL Server's rules for dealing with ambiguous date
  2026. input data that contains two-digit year values.
  2027.  
  2028. Overview of MySQL AB
  2029. ====================
  2030.  
  2031. MySQL AB is the company of the MySQL founders and main developers.
  2032. MySQL AB was originally established in Sweden by David Axmark, Allan
  2033. Larsson, and Michael "Monty" Widenius.
  2034.  
  2035. The developers of the MySQL server are all employed by the company.  We
  2036. are a virtual organization with people in a dozen countries around the
  2037. world. We communicate extensively over the Internet every day with one
  2038. another and with our users, supporters, and partners.
  2039.  
  2040. We are dedicated to developing the MySQL database software and
  2041. promoting it to new users. MySQL AB owns the copyright to the MySQL
  2042. source code, the MySQL logo and (registered) trademark, and this
  2043. manual. *Note What-is::.
  2044.  
  2045. The MySQL core values show our dedication to MySQL and Open Source.
  2046.  
  2047. These core values direct how MySQL AB works with the MySQL server
  2048. software:
  2049.  
  2050.    * To be the best and the most widely used database in the world
  2051.  
  2052.    * To be available and affordable by all
  2053.  
  2054.    * To be easy to use
  2055.  
  2056.    * To be continuously improved while remaining fast and safe
  2057.  
  2058.    * To be fun to use and improve
  2059.  
  2060.    * To be free from bugs
  2061.  
  2062. These are the core values of the company MySQL AB and its employees:
  2063.  
  2064.    * We subscribe to the Open Source philosophy and support the Open
  2065.      Source community
  2066.  
  2067.    * We aim to be good citizens
  2068.  
  2069.    * We prefer partners that share our values and mindset
  2070.  
  2071.    * We answer email and provide support
  2072.  
  2073.    * We are a virtual company, networking with others
  2074.  
  2075.    * We work against software patents
  2076.  
  2077. The MySQL Web site (`http://www.mysql.com/') provides the latest
  2078. information about MySQL and MySQL AB.
  2079.  
  2080. By the way, the "AB" part of the company name is the acronym for the
  2081. Swedish "aktiebolag," or "stock company." It translates to "MySQL,
  2082. Inc." In fact, MySQL, Inc. and MySQL GmbH are examples of MySQL AB
  2083. subsidiaries. They are located in the US and Germany, respectively.
  2084.  
  2085. The Business Model and Services of MySQL AB
  2086. -------------------------------------------
  2087.  
  2088. One of the most common questions we encounter is, "_How can you make a
  2089. living from something you give away for free?_" This is how:
  2090.  
  2091.    * MySQL AB makes money on support, services, commercial licenses,
  2092.      and royalties.
  2093.  
  2094.    * We use these revenues to fund product development and to expand
  2095.      the MySQL business.
  2096.  
  2097. The company has been profitable since its inception. In October 2001,
  2098. we accepted venture financing from leading Scandinavian investors and a
  2099. handful of business angels. This investment is used to solidify our
  2100. business model and build a basis for sustainable growth.
  2101.  
  2102. Support
  2103. .......
  2104.  
  2105. MySQL AB is run and owned by the founders and main developers of the
  2106. MySQL database. The developers are committed to providing support to
  2107. customers and other users in order to stay in touch with their needs
  2108. and problems. All our support is provided by qualified developers.
  2109. Really tricky questions are answered by Michael "Monty" Widenius,
  2110. principal author of the MySQL Server.
  2111.  
  2112. Paying customers receive high-quality support directly from MySQL AB.
  2113. MySQL AB also provides the MySQL mailing lists as a community resource
  2114. where anyone may ask questions.
  2115.  
  2116. For more information and ordering support at various levels, see *Note
  2117. Licensing and Support::.
  2118.  
  2119. Training and Certification
  2120. ..........................
  2121.  
  2122. MySQL AB delivers MySQL and related training worldwide.  We offer both
  2123. open courses and in-house courses tailored to the specific needs of
  2124. your company. MySQL Training is also available through our partners,
  2125. the Authorized MySQL Training Centers.
  2126.  
  2127. Our training material uses the same sample databases used in our
  2128. documentation and our sample applications, and is always updated to
  2129. reflect the latest MySQL version. Our trainers are backed by the
  2130. development team to guarantee the quality of the training and the
  2131. continuous development of the course material. This also ensures that
  2132. no questions raised during the courses remain unanswered.
  2133.  
  2134. Attending our training courses will enable you to achieve your MySQL
  2135. application goals. You will also:
  2136.    * Save time
  2137.  
  2138.    * Improve the performance of your applications
  2139.  
  2140.    * Reduce or eliminate the need for additional hardware, decreasing
  2141.      cost
  2142.  
  2143.    * Enhance security.
  2144.  
  2145.    * Increase customer and co-worker satisfaction
  2146.  
  2147.    * Prepare yourself for MySQL Certification
  2148.  
  2149. If you are interested in our training as a potential participant or as
  2150. a training partner, please visit the training section at
  2151. `http://www.mysql.com/training/', or send email to <training@mysql.com>.
  2152.  
  2153. For details about the MySQL Certification Program, please see
  2154. `http://www.mysql.com/certification/'.
  2155.  
  2156. Consulting
  2157. ..........
  2158.  
  2159. MySQL AB and its Authorized Partners offer consulting services to users
  2160. of MySQL Server and to those who embed MySQL Server in their own
  2161. software, all over the world.
  2162.  
  2163. Our consultants can help you design and tune your databases, construct
  2164. efficient queries, tune your platform for optimal performance, resolve
  2165. migration issues, set up replication, build robust transactional
  2166. applications, and more.  We also help customers embed MySQL Server in
  2167. their products and applications for large-scale deployment.
  2168.  
  2169. Our consultants work in close collaboration with our development team,
  2170. which ensures the technical quality of our professional services.
  2171. Consulting assignments range from two-day power-start sessions to
  2172. projects that span weeks and months. Our expertise covers not only
  2173. MySQL Server, it also extends into programming and scripting languages
  2174. such as PHP, Perl, and more.
  2175.  
  2176. If you are interested in our consulting services or want to become a
  2177. consulting partner, please visit the consulting section of our Web site
  2178. at `http://www.mysql.com/consulting/' or contact our consulting staff
  2179. at <consulting@mysql.com>.
  2180.  
  2181. Commercial Licenses
  2182. ...................
  2183.  
  2184. The MySQL database is released under the GNU General Public License
  2185. (GPL).  This means that the MySQL software can be used free of charge
  2186. under the GPL. If you do not want to be bound by the GPL terms (such as
  2187. the requirement that your application must also be GPL), you may
  2188. purchase a commercial license for the same product from MySQL AB; see
  2189. `https://order.mysql.com/'.  Since MySQL AB owns the copyright to the
  2190. MySQL source code, we are able to employ Dual Licensing, which means
  2191. that the same product is available under GPL and under a commercial
  2192. license. This does not in any way affect the Open Source commitment of
  2193. MySQL AB. For details about when a commercial license is required,
  2194. please see *Note MySQL licenses::.
  2195.  
  2196. We also sell commercial licenses of third-party Open Source GPL
  2197. software that adds value to MySQL Server. A good example is the
  2198. `InnoDB' transactional storage engine that offers `ACID' support,
  2199. row-level locking, crash recovery, multi-versioning, foreign key
  2200. support, and more. *Note InnoDB::.
  2201.  
  2202. Partnering
  2203. ..........
  2204.  
  2205. MySQL AB has a worldwide partner program that covers training courses,
  2206. consulting and support, publications, plus reselling and distributing
  2207. MySQL and related products. MySQL AB Partners get visibility on the
  2208. `http://www.mysql.com/' Web site and the right to use special versions
  2209. of the MySQL (registered) trademarks to identify their products and
  2210. promote their business.
  2211.  
  2212. If you are interested in becoming a MySQL AB Partner, please email
  2213. <partner@mysql.com>.
  2214.  
  2215. The word MySQL and the MySQL dolphin logo are (registered) trademarks
  2216. of MySQL AB. *Note MySQL AB Logos and Trademarks::.  These trademarks
  2217. represent a significant value that the MySQL founders have built over
  2218. the years.
  2219.  
  2220. The MySQL Web site (`http://www.mysql.com/') is popular among
  2221. developers and users. In December 2003, we served 16 million page views.
  2222. Our visitors represent a group that makes purchase decisions and
  2223. recommendations for both software and hardware. Twelve percent of our
  2224. visitors authorize purchase decisions, and only nine percent have no
  2225. involvement at all in purchase decisions. More than 65% have made one or
  2226. more online business purchases within the last half-year, and 70% plan
  2227. to make one in the next few months.
  2228.  
  2229. Contact Information
  2230. -------------------
  2231.  
  2232. The MySQL Web site (`http://www.mysql.com/') provides the latest
  2233. information about MySQL and MySQL AB.
  2234.  
  2235. For press services and inquiries not covered in our news releases
  2236. (`http://www.mysql.com/news-and-events/'), please send email to
  2237. <press@mysql.com>.
  2238.  
  2239. If you have a support contract with MySQL AB, you will get timely,
  2240. precise answers to your technical questions about the MySQL software.
  2241. For more information, see *Note Support::.  On our Web site, see
  2242. `http://www.mysql.com/support/', or send email to <sales@mysql.com>.
  2243.  
  2244. For information about MySQL training, please visit the training section
  2245. at `http://www.mysql.com/training/', or send email to
  2246. <training@mysql.com>.  *Note Business Services Training::.
  2247.  
  2248. For information on the MySQL Certification Program, please see
  2249. `http://www.mysql.com/certification/'.  *Note Business Services
  2250. Training::.
  2251.  
  2252. If you're interested in consulting, please visit the consulting section
  2253. of our Web site at `http://www.mysql.com/consulting/', or send email to
  2254. <consulting@mysql.com>.  *Note Business Services Consulting::.
  2255.  
  2256. Commercial licenses may be purchased online at
  2257. `https://order.mysql.com/'. There you will also find information on how
  2258. to fax your purchase order to MySQL AB. More information about
  2259. licensing can be found at `http://www.mysql.com/products/licensing/'.
  2260. If you have questions regarding licensing or you want a quote for
  2261. high-volume licensing, please fill in the contact form on our Web site
  2262. (`http://www.mysql.com/'), or send email to <licensing@mysql.com> (for
  2263. licensing questions) or to <sales@mysql.com> (for sales inquiries).
  2264. *Note MySQL licenses::.
  2265.  
  2266. If you represent a business that is interested in partnering with MySQL
  2267. AB, please send email to <partner@mysql.com>.  *Note Business Services
  2268. Partnering::.
  2269.  
  2270. For more information on the MySQL trademark policy, refer to
  2271. `http://www.mysql.com/company/trademark.html', or send email to
  2272. <trademark@mysql.com>.  *Note MySQL AB Logos and Trademarks::.
  2273.  
  2274. If you are interested in any of the MySQL AB jobs listed in our jobs
  2275. section (`http://www.mysql.com/company/jobs/'), please send email to
  2276. <jobs@mysql.com>.  Please do not send your CV as an attachment, but
  2277. rather as plain text at the end of your email message.
  2278.  
  2279. For general discussion among our many users, please direct your
  2280. attention to the appropriate mailing list.  *Note Questions::.
  2281.  
  2282. Reports of errors (often called "bugs"), as well as questions and
  2283. comments, should be sent to the general MySQL mailing list.  *Note
  2284. Mailing-list::.  If you have found a sensitive security bug in MySQL
  2285. Server, please let us know immediately by sending email to
  2286. <security@mysql.com>.  *Note Bug reports::.
  2287.  
  2288. If you have benchmark results that we can publish, please contact us
  2289. via email at <benchmarks@mysql.com>.
  2290.  
  2291. If you have suggestions concerning additions or corrections to this
  2292. manual, please send them to the documentation team via email at
  2293. <docs@mysql.com>.
  2294.  
  2295. For questions or comments about the workings or content of the MySQL
  2296. Web site (`http://www.mysql.com/'), please send email to
  2297. <webmaster@mysql.com>.
  2298.  
  2299. MySQL AB has a privacy policy, which can be read at
  2300. `http://www.mysql.com/company/privacy.html'.  For any queries regarding
  2301. this policy, please send email to <privacy@mysql.com>.
  2302.  
  2303. For all other inquiries, please send email to <info@mysql.com>.
  2304.  
  2305. MySQL Support and Licensing
  2306. ===========================
  2307.  
  2308. This section describes MySQL support and licensing arrangements.
  2309.  
  2310. Support Offered by MySQL AB
  2311. ---------------------------
  2312.  
  2313. Technical support from MySQL AB means individualized answers to your
  2314. unique problems direct from the software engineers who code the MySQL
  2315. database engine.
  2316.  
  2317. We try to take a broad and inclusive view of technical support. Almost
  2318. any problem involving MySQL software is important to us if it's
  2319. important to you.  Typically customers seek help on how to get
  2320. different commands and utilities to work, remove performance
  2321. bottlenecks, restore crashed systems, understand the impact of
  2322. operating system or networking issues on MySQL, set up best practices
  2323. for backup and recovery, utilize APIs, and so on.  Our support covers
  2324. only the MySQL server and our own utilities, not third-party products
  2325. that access the MySQL server, although we try to help with these where
  2326. we can.
  2327.  
  2328. Detailed information about our various support options is given at
  2329. `http://www.mysql.com/support/', where support contracts can also be
  2330. ordered online.  To contact our sales staff, send email to
  2331. <sales@mysql.com>.
  2332.  
  2333. Technical support is like life insurance. You can live happily without
  2334. it for years. However, when your hour arrives, it becomes critically
  2335. important, but it's too late to buy it.  If you use MySQL Server for
  2336. important applications and encounter sudden difficulties, it may be too
  2337. time-consuming to figure out all the answers yourself. You may need
  2338. immediate access to the most experienced MySQL troubleshooters
  2339. available, those employed by MySQL AB.
  2340.  
  2341. Copyrights and Licenses Used by MySQL
  2342. -------------------------------------
  2343.  
  2344. MySQL AB owns the copyright to the MySQL source code, the MySQL logos
  2345. and (registered) trademarks, and this manual.  *Note What is MySQL AB::.
  2346. Several different licenses are relevant to the MySQL distribution:
  2347.  
  2348.   1. All the MySQL-specific source in the server, the `mysqlclient'
  2349.      library and the client, as well as the GNU `readline' library, are
  2350.      covered by the GNU General Public License.  *Note GPL license::.
  2351.      The text of this license can be found as the file `COPYING' in
  2352.      MySQL distributions.
  2353.  
  2354.   2. The GNU `getopt' library is covered by the GNU Lesser General
  2355.      Public License.  See `http://www.fsf.org/licenses/'.
  2356.  
  2357.   3. Some parts of the source (the `regexp' library) are covered by a
  2358.      Berkeley-style copyright.
  2359.  
  2360.   4. Older versions of MySQL (3.22 and earlier) are subject to a
  2361.      stricter license
  2362.      (`http://www.mysql.com/products/licensing/mypl.html').  See the
  2363.      documentation of the specific version for information.
  2364.  
  2365.   5. The MySQL Reference Manual is _not_ distributed under a GPL-style
  2366.      license. Use of the manual is subject to the following terms:
  2367.         * Conversion to other formats is allowed, but the actual content
  2368.           may not be altered or edited in any way.
  2369.  
  2370.         * You may create a printed copy for your own personal use.
  2371.  
  2372.         * For all other uses, such as selling printed copies or using
  2373.           (parts of) the manual in another publication, prior written
  2374.           agreement from MySQL AB is required.
  2375.      Please send an email message to <docs@mysql.com> for more
  2376.      information or if you are interested in doing a translation.
  2377.  
  2378. For information about how the MySQL licenses work in practice, please
  2379. refer to *Note MySQL licenses:: and *Note MySQL AB Logos and
  2380. Trademarks::.
  2381.  
  2382. MySQL Licenses
  2383. --------------
  2384.  
  2385. The MySQL software is released under the GNU General Public License
  2386. (GPL), which is probably the best known Open Source license.  The
  2387. formal terms of the GPL license can be found at
  2388. `http://www.fsf.org/licenses/'.  See also
  2389. `http://www.fsf.org/licenses/gpl-faq.html' and
  2390. `http://www.gnu.org/philosophy/enforcing-gpl.html'.
  2391.  
  2392. Our GPL licensing is supported by an optional license exception that
  2393. enables many Free/Libre and Open Source Software ("FLOSS") applications
  2394. to include the GPL-licensed MySQL client libraries despite the fact
  2395. that not all FLOSS licenses are compatible with the GPL. For details,
  2396. see `http://www.mysql.com/products/licensing/foss-exception.html'.
  2397.  
  2398. Because the MySQL software is released under the GPL, it may often be
  2399. used for free, but for certain uses you may want or need to buy
  2400. commercial licenses from MySQL AB at `https://order.mysql.com/'.  See
  2401. `http://www.mysql.com/products/licensing/' for more information.
  2402.  
  2403. Older versions of MySQL (3.22 and earlier) are subject to a stricter
  2404. license (`http://www.mysql.com/products/licensing/mypl.html').  See the
  2405. documentation of the specific version for information.
  2406.  
  2407. Please note that the use of the MySQL software under commercial
  2408. license, GPL, or the old MySQL license does not automatically give you
  2409. the right to use MySQL AB (registered) trademarks.  *Note MySQL AB
  2410. Logos and Trademarks::.
  2411.  
  2412. Using the MySQL Software Under a Commercial License
  2413. ...................................................
  2414.  
  2415. The GPL license is contagious in the sense that when a program is
  2416. linked to a GPL program, all the source code for all the parts of the
  2417. resulting product must also be released under the GPL.  If you do not
  2418. follow this GPL requirement, you break the license terms and forfeit
  2419. your right to use the GPL program altogether.  You also risk damages.
  2420.  
  2421. You need a commercial license under these conditions:
  2422.  
  2423.    * When you link a program with any GPL code from the MySQL software
  2424.      and don't want the resulting product to be licensed under GPL,
  2425.      perhaps because you want to build a commercial product or keep the
  2426.      added non-GPL code closed source for other reasons. When purchasing
  2427.      commercial licenses, you are not using the MySQL software under
  2428.      GPL even though it's the same code.
  2429.  
  2430.    * When you distribute a non-GPL application that works _only_ with
  2431.      the MySQL software and ship it with the MySQL software. This type
  2432.      of solution is considered to be linking even if it's done over a
  2433.      network.
  2434.  
  2435.    * When you distribute copies of the MySQL software without providing
  2436.      the source code as required under the GPL license.
  2437.  
  2438.    * When you want to support the further development of the MySQL
  2439.      database even if you don't formally need a commercial license.
  2440.      Purchasing support directly from MySQL AB is another good way of
  2441.      contributing to the development of the MySQL software, with
  2442.      immediate advantages for you.  *Note Support::.
  2443.  
  2444. Our GPL licensing is supported by an optional license exception that
  2445. enables many Free/Libre and Open Source Software ("FLOSS") applications
  2446. to include the GPL-licensed MySQL client libraries despite the fact
  2447. that not all FLOSS licenses are compatible with the GPL. For details,
  2448. see `http://www.mysql.com/products/licensing/foss-exception.html'.
  2449.  
  2450. If you require a commercial license, you will need one for each
  2451. installation of the MySQL software. This covers any number of CPUs on a
  2452. machine, and there is no artificial limit on the number of clients that
  2453. connect to the server in any way.
  2454.  
  2455. For commercial licenses, please visit our Web site at
  2456. `http://www.mysql.com/products/licensing/'.  For support contracts, see
  2457. `http://www.mysql.com/support/'.  If you have special needs, please
  2458. contact our sales staff via email at <sales@mysql.com>.
  2459.  
  2460. Using the MySQL Software for Free Under GPL
  2461. ...........................................
  2462.  
  2463. You can use the MySQL software for free under the GPL if you adhere to
  2464. the conditions of the GPL.  For additional details about the GPL,
  2465. including answers to common questions, see the generic FAQ from the
  2466. Free Software Foundation at `http://www.fsf.org/licenses/gpl-faq.html'.
  2467.  
  2468. Our GPL licensing is supported by an optional license exception that
  2469. enables many Free/Libre and Open Source Software ("FLOSS") applications
  2470. to include the GPL-licensed MySQL client libraries despite the fact
  2471. that not all FLOSS licenses are compatible with the GPL. For details,
  2472. see `http://www.mysql.com/products/licensing/foss-exception.html'.
  2473.  
  2474. Common uses of the GPL include:
  2475.  
  2476.    * When you distribute both your own application and the MySQL source
  2477.      code under the GPL with your product.
  2478.  
  2479.    * When you distribute the MySQL source code bundled with other
  2480.      programs that are not linked to or dependent on the MySQL system
  2481.      for their functionality even if you sell the distribution
  2482.      commercially.  This is called "mere aggregation" in the GPL
  2483.      license.
  2484.  
  2485.    * When you are not distributing _any_ part of the MySQL system, you
  2486.      can use it for free.
  2487.  
  2488.    * When you are an Internet Service Provider (ISP), offering Web
  2489.      hosting with MySQL servers for your customers.  We encourage
  2490.      people to use ISPs that have MySQL support, because doing so will
  2491.      give them the confidence that their ISP will, in fact, have the
  2492.      resources to solve any problems they may experience with the MySQL
  2493.      installation. Even if an ISP does not have a commercial license
  2494.      for MySQL Server, their customers should at least be given read
  2495.      access to the source of the MySQL installation so that the
  2496.      customers can verify that it is correctly patched.
  2497.  
  2498.    * When you use the MySQL database software in conjunction with a Web
  2499.      server, you do not need a commercial license (so long as it is not
  2500.      a product you distribute). This is true even if you run a
  2501.      commercial Web server that uses MySQL Server, because you are not
  2502.      distributing any part of the MySQL system. However, in this case
  2503.      we would like you to purchase MySQL support because the MySQL
  2504.      software is helping your enterprise.
  2505.  
  2506. If your use of MySQL database software does not require a commercial
  2507. license, we encourage you to purchase support from MySQL AB anyway.
  2508. This way you contribute toward MySQL development and also gain
  2509. immediate advantages for yourself. *Note Support::.
  2510.  
  2511. If you use the MySQL database software in a commercial context such
  2512. that you profit by its use, we ask that you further the development of
  2513. the MySQL software by purchasing some level of support.  We feel that
  2514. if the MySQL database helps your business, it is reasonable to ask that
  2515. you help MySQL AB.  (Otherwise, if you ask us support questions, you
  2516. are not only using for free something into which we've put a lot a
  2517. work, you're asking us to provide free support, too.)
  2518.  
  2519. MySQL AB Logos and Trademarks
  2520. -----------------------------
  2521.  
  2522. Many users of the MySQL database want to display the MySQL AB dolphin
  2523. logo on their Web sites, books, or boxed products. We welcome and
  2524. encourage this, although it should be noted that the word MySQL and the
  2525. MySQL dolphin logo are (registered) trademarks of MySQL AB and may only
  2526. be used as stated in our trademark policy at
  2527. `http://www.mysql.com/company/trademark.html'.
  2528.  
  2529. The Original MySQL Logo
  2530. .......................
  2531.  
  2532. The MySQL dolphin logo was designed by the Finnish advertising agency
  2533. Priority in 2001.  The dolphin was chosen as a suitable symbol for the
  2534. MySQL database management system, which is like a smart, fast, and lean
  2535. animal, effortlessly navigating oceans of data. We also happen to like
  2536. dolphins.
  2537.  
  2538. The original MySQL logo may only be used by representatives of MySQL AB
  2539. and by those having a written agreement allowing them to do so.
  2540.  
  2541. MySQL Logos That May Be Used Without Written Permission
  2542. .......................................................
  2543.  
  2544. We have designed a set of special _Conditional Use_ logos that may be
  2545. downloaded from our Web site at `http://www.mysql.com/press/logos.html'
  2546. and used on third-party Web sites without written permission from MySQL
  2547. AB.  The use of these logos is not entirely unrestricted but, as the
  2548. name implies, subject to our trademark policy that is also available on
  2549. our Web site. You should read through the trademark policy if you plan
  2550. to use them. The requirements are basically as follows:
  2551.  
  2552.    * Use the logo you need as displayed on the `http://www.mysql.com/'
  2553.      site. You may scale it to fit your needs, but may not change
  2554.      colors or design, or alter the graphics in any way.
  2555.  
  2556.    * Make it evident that you, and not MySQL AB, are the creator and
  2557.      owner of the site that displays the MySQL (registered) trademark.
  2558.  
  2559.    * Don't use the trademark in a way that is detrimental to MySQL AB
  2560.      or to the value of MySQL AB trademarks. We reserve the right to
  2561.      revoke the right to use the MySQL AB trademark.
  2562.  
  2563.    * If you use the trademark on a Web site, make it clickable, leading
  2564.      directly to `http://www.mysql.com/'.
  2565.  
  2566.    * If you use the MySQL database under GPL in an application, your
  2567.      application must be Open Source and must be able to connect to a
  2568.      MySQL server.
  2569.  
  2570. Contact us via email at <trademark@mysql.com> to inquire about special
  2571. arrangements to fit your needs.
  2572.  
  2573. When You Need Written Permission to Use MySQL Logos
  2574. ...................................................
  2575.  
  2576. You need written permission from MySQL AB before using MySQL logos in
  2577. the following cases:
  2578.  
  2579.    * When displaying any MySQL AB logo anywhere except on your Web site.
  2580.  
  2581.    * When displaying any MySQL AB logo except the _Conditional Use_
  2582.      logos (mentioned previously) on Web sites or elsewhere.
  2583.  
  2584. Due to legal and commercial reasons, we monitor the use of MySQL
  2585. (registered) trademarks on products, books, and other items.  We
  2586. usually require a fee for displaying MySQL AB logos on commercial
  2587. products, since we think it is reasonable that some of the revenue is
  2588. returned to fund further development of the MySQL database.
  2589.  
  2590. MySQL AB Partnership Logos
  2591. ..........................
  2592.  
  2593. MySQL partnership logos may be used only by companies and persons
  2594. having a written partnership agreement with MySQL AB. Partnerships
  2595. include certification as a MySQL trainer or consultant.  For more
  2596. information, please see *Note Partnering: Business Services Partnering.
  2597.  
  2598. Using the Word MySQL in Printed Text or Presentations
  2599. .....................................................
  2600.  
  2601. MySQL AB welcomes references to the MySQL database, but it should be
  2602. noted that the word MySQL is a registered trademark of MySQL AB.
  2603. Because of this, you must append the "registered trademark" notice
  2604. symbol (`R') to the first or most prominent use of the word MySQL in a
  2605. text and, where appropriate, state that MySQL is a registered trademark
  2606. of MySQL AB. For more information, please refer to our trademark policy
  2607. at `http://www.mysql.com/company/trademark.html'.
  2608.  
  2609. Using the Word MySQL in Company and Product Names
  2610. .................................................
  2611.  
  2612. Use of the word MySQL in company or product names or in Internet domain
  2613. names is not allowed without written permission from MySQL AB.
  2614.  
  2615. MySQL Development Roadmap
  2616. =========================
  2617.  
  2618. This section provides a snapshot of the MySQL development roadmap,
  2619. including major features implemented or planned for MySQL 4.0, 4.1,
  2620. 5.0, and 5.1.  The following sections provide information for each
  2621. release series.
  2622.  
  2623. The production release series is MySQL 4.0, which was declared stable
  2624. for production use as of Version 4.0.12, released in March 2003. This
  2625. means that future 4.0 development will be limited only to making
  2626. bugfixes. For the older MySQL 3.23 series, only critical bugfixes will
  2627. be made.
  2628.  
  2629. Active MySQL development currently is taking place in the MySQL 4.1 and
  2630. 5.0 release series. This means that new features are being added to
  2631. MySQL 4.1 and MySQL 5.0.  4.1 is available in beta status, and 5.0 is
  2632. available in alpha status.
  2633.  
  2634. Before upgrading from one release series to the next, please see the
  2635. notes at *Note Upgrade::.
  2636.  
  2637. Plans for some of the most requested features are summarized in the
  2638. following table.
  2639.  
  2640. *Feature*              *MySQL Series*
  2641. Unions                 4.0
  2642. Subqueries             4.1
  2643. R-trees                4.1 (for `MyISAM' tables)
  2644. Stored procedures      5.0
  2645. Views                  5.0
  2646. Cursors                5.0
  2647. Foreign keys           5.1 (already implemented in 3.23 for
  2648.                        `InnoDB')
  2649. Triggers               5.1
  2650. Full outer join        5.1
  2651. Constraints            5.1
  2652.  
  2653. MySQL 4.0 in a Nutshell
  2654. -----------------------
  2655.  
  2656. Long awaited by our users, MySQL Server 4.0 is now available in
  2657. production status.
  2658.  
  2659. MySQL 4.0 is available for download at `http://dev.mysql.com/' and from
  2660. our mirrors. MySQL 4.0 has been tested by a large number of users and
  2661. is in production use at many large sites.
  2662.  
  2663. The major new features of MySQL Server 4.0 are geared toward our
  2664. existing business and community users, enhancing the MySQL database
  2665. software as the solution for mission-critical, heavy-load database
  2666. systems.  Other new features target the users of embedded databases.
  2667.  
  2668. Features Available in MySQL 4.0
  2669. ...............................
  2670.  
  2671. Speed enhancements
  2672.         * MySQL 4.0 has a query cache that can give a huge speed boost
  2673.           to applications with repetitive queries. *Note Query Cache::.
  2674.  
  2675.         * Version 4.0 further increases the speed of MySQL Server in a
  2676.           number of areas, such as bulk `INSERT' statements, searching
  2677.           on packed indexes, full-text searching (using `FULLTEXT'
  2678.           indexes), and `COUNT(DISTINCT)'.
  2679.  
  2680. Embedded MySQL Server introduced
  2681.         * The new Embedded Server library can easily be used to create
  2682.           standalone and embedded applications.  The embedded server
  2683.           provides an alternative to using MySQL in a client/server
  2684.           environment.  *Note Nutshell Embedded MySQL::.
  2685.  
  2686. `InnoDB' storage engine as standard
  2687.         * The `InnoDB' storage engine is now offered as a standard
  2688.           feature of the MySQL server. This means full support for ACID
  2689.           transactions, foreign keys with cascading `UPDATE' and
  2690.           `DELETE', and row-level locking are now standard features.
  2691.           *Note `InnoDB': InnoDB.
  2692.  
  2693. New functionality
  2694.         * The enhanced `FULLTEXT' search properties of MySQL Server 4.0
  2695.           enables `FULLTEXT' indexing of large text masses with both
  2696.           binary and natural-language searching logic. You can
  2697.           customize minimal word length and define your own stop word
  2698.           lists in any human language, enabling a new set of
  2699.           applications to be built with MySQL Server.  *Note Fulltext
  2700.           Search::.
  2701.  
  2702. Standards compliance, portability, and migration
  2703.         * Many users will also be happy to learn that MySQL Server now
  2704.           supports the `UNION' statement, a long-awaited standard SQL
  2705.           feature.
  2706.  
  2707.         * MySQL now runs natively on the Novell NetWare platform
  2708.           beginning with NetWare 6.0.  *Note NetWare installation::.
  2709.  
  2710.         * Features to simplify migration from other database systems to
  2711.           MySQL Server include `TRUNCATE TABLE' (as in Oracle).
  2712.  
  2713. Internationalization
  2714.         * Our German, Austrian, and Swiss users will note that MySQL
  2715.           4.0 now supports a new character set, `latin1_de', which
  2716.           ensures that the _German sorting order_ sorts words with
  2717.           umlauts in the same order as do German telephone books.
  2718.  
  2719. Usability enhancements
  2720.      In the process of implementing features for new users, we have not
  2721.      forgotten requests from our loyal community of existing users.
  2722.  
  2723.         * Most `mysqld' parameters (startup options) can now be set
  2724.           without taking down the server. This is a convenient feature
  2725.           for database administrators (DBAs).  *Note `SET OPTION': SET
  2726.           OPTION.
  2727.  
  2728.         * Multiple-table `DELETE' and `UPDATE' statements have been
  2729.           added.
  2730.  
  2731.         * On Windows, symbolic link handling at the database level is
  2732.           enabled by default.  On Unix, the `MyISAM' storage engine now
  2733.           supports symbolic linking at the table level (and not just
  2734.           the database level as before).
  2735.  
  2736.         * `SQL_CALC_FOUND_ROWS' and `FOUND_ROWS()' are new functions
  2737.           that make it possible to find out the number of rows a
  2738.           `SELECT' query that includes a `LIMIT' clause would have
  2739.           returned without that clause.
  2740.  
  2741. The news section of this manual includes a more in-depth list of
  2742. features.  *Note News-4.0.x::.
  2743.  
  2744. The Embedded MySQL Server
  2745. .........................
  2746.  
  2747. The `libmysqld' embedded server library makes MySQL Server suitable for
  2748. a vastly expanded realm of applications. By using this library,
  2749. developers can embed MySQL Server into various applications and
  2750. electronics devices, where the end user has no knowledge of there
  2751. actually being an underlying database. Embedded MySQL Server is ideal
  2752. for use behind the scenes in Internet appliances, public kiosks, turnkey
  2753. hardware/software combination units, high performance Internet servers,
  2754. self-contained databases distributed on CD-ROM, and so on.
  2755.  
  2756. Many users of `libmysqld' will benefit from the MySQL Dual Licensing.
  2757. For those not wishing to be bound by the GPL, the software is also made
  2758. available under a commercial license.  The embedded MySQL library uses
  2759. the same interface as the normal client library, so it is convenient
  2760. and easy to use.  *Note `libmysqld': libmysqld.
  2761.  
  2762. On windows there are two different libraries:
  2763.  
  2764. `libmysqld.lib'        Dynamic library for threadded applications.
  2765. `mysqldemb.lib'        Static library for not threaded
  2766.                        applications.
  2767.  
  2768. MySQL 4.1 in a Nutshell
  2769. -----------------------
  2770.  
  2771. MySQL Server 4.0 laid the foundation for new features implemented in
  2772. MySQL 4.1, such as subqueries and Unicode support, and for the work on
  2773. stored procedures being done in version 5.0.  These features come at
  2774. the top of the wish list of many of our customers.
  2775.  
  2776. With these additions, critics of the MySQL Database Server have to be
  2777. more imaginative than ever in pointing out deficiencies in the MySQL
  2778. database management system. Already well-known for its stability,
  2779. speed, and ease of use, MySQL Server is able to fulfill the requirement
  2780. checklists of very demanding buyers.
  2781.  
  2782. Features Available in MySQL 4.1
  2783. ...............................
  2784.  
  2785. The MySQL 4.1 features listed in this section already are implemented.
  2786. A few other MySQL 4.1 features are still planned; see *Note TODO MySQL
  2787. 4.1::.
  2788.  
  2789. Most new features being coded are or will be available in MySQL 5.0.
  2790. *Note TODO MySQL 5.0::.
  2791.  
  2792. Support for subqueries and derived tables
  2793.         * A "subquery" is a `SELECT' statement nested within another
  2794.           statement.  A "derived table" (an unnamed view) is a subquery
  2795.           in the `FROM' clause of another statement.  *Note
  2796.           Subqueries::.
  2797.  
  2798. Speed enhancements
  2799.         * Faster binary client/server protocol with support for
  2800.           prepared statements and parameter binding.  *Note C API
  2801.           Prepared statements::.
  2802.  
  2803.         * `BTREE' indexing is now supported for `HEAP' tables,
  2804.           significantly improving response time for non-exact searches.
  2805.  
  2806. New functionality
  2807.         * `CREATE TABLE TBL_NAME2 LIKE TBL_NAME1' allows you to create,
  2808.           with a single statement, a new table with a structure exactly
  2809.           like that of an existing table.
  2810.  
  2811.         * The `MyISAM' storage engine now supports OpenGIS spatial
  2812.           types for storing geographical data.  *Note Spatial
  2813.           extensions in MySQL::.
  2814.  
  2815.         * Replication can be done over SSL connections.
  2816.  
  2817. Standards compliance, portability, and migration
  2818.         * The new client/server protocol adds the ability to pass
  2819.           multiple warnings to the client, rather than only a single
  2820.           result. This makes it much easier to track problems that
  2821.           occur in operations such as bulk data loading.
  2822.  
  2823.         * `SHOW WARNINGS' shows warnings for the last command.  *Note
  2824.           `SHOW WARNINGS': SHOW WARNINGS.
  2825.  
  2826. Internationalization and Localization
  2827.         * To support applications that require the use of local
  2828.           languages, the MySQL software now offers extensive Unicode
  2829.           support through the `utf8' and `ucs2' character sets.
  2830.  
  2831.         * Character sets can now be defined per column, table, and
  2832.           database.  This allows for a high degree of flexibility in
  2833.           application design, particularly for multi-language Web sites.
  2834.  
  2835.         * For documentation for this improved character set support,
  2836.           see *Note Charset::.
  2837.  
  2838.         * Per-connection time zones are supported, allowing individual
  2839.           clients to select their own time zone when necessary.
  2840.  
  2841. Usability enhancements
  2842.         * In response to popular demand, we have added a server-based
  2843.           `HELP' command that can be used to get help information for
  2844.           SQL statements.  The advantage of having this information on
  2845.           the server side is that the information is always applicable
  2846.           to the particular server version that you actually are using.
  2847.           Because this information is available by issuing an SQL
  2848.           statement, any client can be written to access it.  For
  2849.           example, the `help' command of the `mysql' command-line client
  2850.           has been modified to have this capability.
  2851.  
  2852.         * In the new client/server protocol, multiple statements can be
  2853.           issued with a single call.  *Note C API multiple queries::.
  2854.  
  2855.         * The new client/server protocol also supports returning
  2856.           multiple result sets.  This might occur as a result of
  2857.           sending multiple statements, for example.
  2858.  
  2859.         * A new `INSERT ... ON DUPLICATE KEY UPDATE ...' syntax has been
  2860.           implemented. This allows you to `UPDATE' an existing row if
  2861.           the `INSERT' would have caused a duplicate in a `PRIMARY' or
  2862.           `UNIQUE' index.  *Note `INSERT': INSERT.
  2863.  
  2864.         * A new aggregate function, `GROUP_CONCAT()' adds the extremely
  2865.           useful capability of concatenating column values from grouped
  2866.           rows into a single result string.  *Note Group by functions
  2867.           and modifiers::.
  2868.  
  2869. The news section of this manual includes a more in-depth list of
  2870. features.  *Note News-4.1.x::.
  2871.  
  2872. Stepwise Rollout
  2873. ................
  2874.  
  2875. New features are being added to MySQL 4.1. The beta version is already
  2876. available for download. *Note Nutshell Ready for Immediate Use::.
  2877.  
  2878. The set of features being added to version 4.1 is mostly fixed.
  2879. Additional development is already ongoing for version 5.0.  MySQL 4.1
  2880. is going through the steps of _Alpha_ (during which time new features
  2881. might still be added/changed), _Beta_ (when we have feature freeze and
  2882. only bug corrections will be done), and _Gamma_ (indicating that a
  2883. production release is just weeks ahead).  At the end of this process,
  2884. MySQL 4.1 will become the new production release.
  2885.  
  2886. Ready for Immediate Development Use
  2887. ...................................
  2888.  
  2889. MySQL 4.1 is currently in the beta stage, and binaries are available
  2890. for download at `http://dev.mysql.com/downloads/mysql/4.1.html'.  All
  2891. binary releases pass our extensive test suite without any errors on the
  2892. platforms on which we test.  *Note News-4.1.x::.
  2893.  
  2894. For those wishing to use the most recent development source for MySQL
  2895. 4.1, we make our 4.1 BitKeeper repository publicly available.  *Note
  2896. Installing source tree::.
  2897.  
  2898. MySQL 5.0: The Next Development Release
  2899. ---------------------------------------
  2900.  
  2901. New development for MySQL is focused on the 5.0 release, featuring
  2902. stored procedures and other new features.  *Note TODO MySQL 5.0::.
  2903.  
  2904. For those wishing to take a look at the bleeding edge of MySQL
  2905. development, we make our BitKeeper repository for MySQL version 5.0
  2906. publicly available.  *Note Installing source tree::.  As of December
  2907. 2003, binary builds of version 5.0 are also available.
  2908.  
  2909. MySQL and the Future (the TODO)
  2910. ===============================
  2911.  
  2912. This section summarizes the features that we plan to implement in MySQL
  2913. Server. The items are ordered by release series. Within a list, items
  2914. are shown in approximately the order they will be done.
  2915.  
  2916. *Note*: If you are an enterprise-level user with an urgent need for a
  2917. particular feature, please contact <sales@mysql.com> to discuss
  2918. sponsoring options. Targeted financing by sponsor companies allows us
  2919. to allocate additional resources for specific purposes.  One example of
  2920. a feature sponsored in the past is replication.
  2921.  
  2922. New Features Planned for 4.1
  2923. ----------------------------
  2924.  
  2925. The following features are not yet implemented in MySQL 4.1, but are
  2926. planned for implementation as MySQL 4.1 moves into its beta phase.  For
  2927. a list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  2928. features::.
  2929.  
  2930.    * Stable OpenSSL support (MySQL 4.0 supports rudimentary, not 100%
  2931.      tested, support for OpenSSL).
  2932.  
  2933.    * More testing of prepared statements.
  2934.  
  2935.    * More testing of multiple character sets for one table.
  2936.  
  2937. New Features Planned for 5.0
  2938. ----------------------------
  2939.  
  2940. The following features are planned for inclusion into MySQL 5.0.  Some
  2941. of the features such as stored procedures are complete and are included
  2942. in MySQL 5.0 alpha, which is available now.  Others such as cursors are
  2943. only partially available. Expect these and other features to mature and
  2944. be fully supported in upcoming releases.
  2945.  
  2946. Note that because we have many developers that are working on different
  2947. projects, there will also be many additional features. There is also a
  2948. small chance that some of these features will be added to MySQL 4.1.
  2949. For a list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  2950. features::.
  2951.  
  2952. For those wishing to take a look at the bleeding edge of MySQL
  2953. development, we make our BitKeeper repository for MySQL version 5.0
  2954. publicly available.  *Note Installing source tree::.  As of December
  2955. 2003, binary builds of version 5.0 are also available.
  2956.  
  2957.  
  2958.      Views, implemented in stepwise fashion up to full functionality.
  2959.      *Note ANSI diff Views::.
  2960.  
  2961. Stored Procedures
  2962.         * Stored procedures currently are implemented, based on the
  2963.           SQL:2003 standard.  *Note Stored Procedures::.
  2964.  
  2965.  
  2966. New functionality
  2967.         * Elementary cursor support.  *Note Cursors::.
  2968.  
  2969.         * The ability to specify explicitly for `MyISAM' tables that an
  2970.           index should be created as an `RTREE' index.  (In MySQL 4.1,
  2971.           `RTREE' indexes are used internally for geometrical data that
  2972.           use GIS data types, but cannot be created on request.)
  2973.  
  2974.         * Dynamic length rows for `MEMORY' tables.
  2975.  
  2976. Standards compliance, portability and migration
  2977.         * Add true `VARCHAR' support (column lengths longer than 255,
  2978.           and no stripping of trailing whitespace).  There is already
  2979.           support for this in the `MyISAM' storage engine, but it is
  2980.           not yet available at the user level.
  2981.  
  2982. Speed enhancements
  2983.         * `SHOW COLUMNS FROM TBL_NAME' (used by the `mysql' client to
  2984.           allow expansions of column names) should not open the table,
  2985.           only the definition file. This will require less memory and
  2986.           be much faster.
  2987.  
  2988.         * Allow `DELETE' on `MyISAM' tables to use the record cache.
  2989.           To do this, we need to update the threads record cache when
  2990.           we update the `.MYD' file.
  2991.  
  2992.         * Better support for `MEMORY' tables:
  2993.              * Dynamic length rows.
  2994.  
  2995.              * Faster row handling (less copying).
  2996.  
  2997. Usability enhancements
  2998.         * Resolving the issue of `RENAME TABLE' on a table used in an
  2999.           active `MERGE' table possibly corrupting the table.
  3000.  
  3001. The news section of this manual includes a more in-depth list of
  3002. features.  *Note News-5.0.x::.
  3003.  
  3004. New Features Planned for 5.1
  3005. ----------------------------
  3006.  
  3007. New functionality
  3008.         * `FOREIGN KEY' support for all table types, not just `InnoDB'.
  3009.  
  3010.         * Column-level constraints.  *Note Constraints::.
  3011.  
  3012.         * Online backup with very low performance penalty.  The online
  3013.           backup will make it easy to add a new replication slave
  3014.           without taking down the master.
  3015.  
  3016. Speed enhancements
  3017.         * New text based table definition file format (`.frm' files)
  3018.           and a table cache for table definitions.  This will enable us
  3019.           to do faster queries of table structures and do more
  3020.           efficient foreign key support.
  3021.  
  3022.         * Optimize the `BIT' type to take one bit. (`BIT' now takes one
  3023.           byte; it is treated as a synonym for `TINYINT'.)
  3024.  
  3025. Usability enhancements
  3026.         * Add options to the client/server protocol to get progress
  3027.           notes for long running commands.
  3028.  
  3029.         * Implement `RENAME DATABASE'. To make this safe for all
  3030.           storage engines, it should work as follows:
  3031.             1. Create the new database.
  3032.  
  3033.             2. For every table, do a rename of the table to another
  3034.                database, as we do with the `RENAME' command.
  3035.  
  3036.             3. Drop the old database.
  3037.  
  3038.         * New internal file interface change.  This will make all file
  3039.           handling much more general and make it easier to add
  3040.           extensions like RAID.
  3041.  
  3042. New Features Planned for the Near Future
  3043. ----------------------------------------
  3044.  
  3045. New functionality
  3046.         * Oracle-like `CONNECT BY PRIOR' to search tree-like
  3047.           (hierarchical) structures.
  3048.  
  3049.         * Add all missing standard SQL and ODBC 3.0 types.
  3050.  
  3051.         * Add `SUM(DISTINCT)'.
  3052.  
  3053.         * `INSERT SQL_CONCURRENT' and `mysqld --concurrent-insert' to do
  3054.           a concurrent insert at the end of a table if the table is
  3055.           read-locked.
  3056.  
  3057.         * Allow variables to be updated in `UPDATE' statements. For
  3058.           example: `UPDATE foo SET @a:=a+b,a=@a, b=@a+c'.
  3059.  
  3060.         * Change when user variables are updated so that you can use
  3061.           them with `GROUP BY', as in the following statement: `SELECT
  3062.           id, @a:=COUNT(*), SUM(SUM_COL)/@a FROM TBL_NAME GROUP BY id'.
  3063.  
  3064.         * Add an `IMAGE' option to `LOAD DATA INFILE' to not update
  3065.           `TIMESTAMP' and `AUTO_INCREMENT' columns.
  3066.  
  3067.         * Add `LOAD DATA INFILE ... UPDATE' syntax that works like this:
  3068.              * For tables with primary keys, if an input record
  3069.                contains a primary key value, existing rows matching
  3070.                that primary key value are updated from the remainder of
  3071.                the input columns. However, columns corresponding to
  3072.                columns that are _missing_ from the input record are not
  3073.                touched.
  3074.  
  3075.              * For tables with primary keys, if an input record does
  3076.                not contain the primary key value or is missing some
  3077.                part of the key, the record is treated as `LOAD DATA
  3078.                INFILE ... REPLACE INTO'.
  3079.  
  3080.         * Make `LOAD DATA INFILE' understand syntax like this:
  3081.                LOAD DATA INFILE 'FILE_NAME.txt' INTO TABLE TBL_NAME
  3082.                     TEXT_FIELDS (text_col1, text_col2, text_col3)
  3083.                     SET table_col1=CONCAT(text_col1, text_col2),
  3084.                         table_col3=23
  3085.                     IGNORE text_col3
  3086.           This can be used to skip over extra columns in the text file,
  3087.           or update columns based on expressions of the read data.
  3088.  
  3089.         * New functions for working with `SET' type columns:
  3090.              * `ADD_TO_SET(VALUE,SET)'
  3091.  
  3092.              * `REMOVE_FROM_SET(VALUE,SET)'
  3093.  
  3094.         * If you abort `mysql' in the middle of a query, you should open
  3095.           another connection and kill the old running query.
  3096.           Alternatively, an attempt should be made to detect this in
  3097.           the server.
  3098.  
  3099.         * Add a storage engine interface for table information so that
  3100.           you can use it as a system table. This would be a bit slow if
  3101.           you requested information about all tables, but very
  3102.           flexible.  `SHOW INFO FROM TBL_NAME' for basic table
  3103.           information should be implemented.
  3104.  
  3105.         * Allow `SELECT a FROM TBL_NAME1 LEFT JOIN TBL_NAME2 USING
  3106.           (a)'; in this case `a' is assumed to come from TBL_NAME1.
  3107.  
  3108.         * `DELETE' and `REPLACE' options to the `UPDATE' statement
  3109.           (this will delete rows when a duplicate-key error occurs
  3110.           while updating).
  3111.  
  3112.         * Change the format of `DATETIME' to store fractions of seconds.
  3113.  
  3114.         * Make it possible to use the new GNU `regexp' library instead
  3115.           of the current one (the new library should be much faster
  3116.           than the current one).
  3117.  
  3118. Standards compliance, portability and migration
  3119.         * Don't add automatic `DEFAULT' values to columns.  Produce an
  3120.           error for any `INSERT' statement that is missing a value for
  3121.           a column that has no `DEFAULT'.
  3122.  
  3123.         * Add `ANY()', `EVERY()', and `SOME()' group functions. In
  3124.           standard SQL, these work only on boolean columns, but we can
  3125.           extend these to work on any columns or expressions by
  3126.           treating a value of zero as FALSE and non-zero values as TRUE.
  3127.  
  3128.         * Fix the type of `MAX(column)' to be the same as the column
  3129.           type:
  3130.                mysql> CREATE TABLE t1 (a DATE);
  3131.                mysql> INSERT INTO t1 VALUES (NOW());
  3132.                mysql> CREATE TABLE t2 SELECT MAX(a) FROM t1;
  3133.                mysql> SHOW COLUMNS FROM t2;
  3134.  
  3135. Speed enhancements
  3136.         * Don't allow more than a defined number of threads to run
  3137.           `MyISAM' recovery at the same time.
  3138.  
  3139.         * Change `INSERT INTO ... SELECT' to optionally use concurrent
  3140.           inserts.
  3141.  
  3142.         * Add an option to periodically flush key pages for tables with
  3143.           delayed keys if they haven't been used in a while.
  3144.  
  3145.         * Allow join on key parts (optimization issue).
  3146.  
  3147.         * Add a log file analyzer that can extract information about
  3148.           which tables are hit most often, how often multiple-table
  3149.           joins are executed, and so on. This should help users
  3150.           identify areas of table design that could be optimized to
  3151.           execute much more efficient queries.
  3152.  
  3153. Usability enhancements
  3154.         * Return the original column types when doing `SELECT
  3155.           MIN(column) ... GROUP BY'.
  3156.  
  3157.         * Make it possible to specify `long_query_time' with a
  3158.           granularity in microseconds.
  3159.  
  3160.         * Link the `myisampack' code into the server so that it can
  3161.           perform `PACK' or `COMPRESS' operations.
  3162.  
  3163.         * Add a temporary key buffer cache during
  3164.           `INSERT/DELETE/UPDATE' so that we can gracefully recover if
  3165.           the index file gets full.
  3166.  
  3167.         * If you perform an `ALTER TABLE' on a table that is symlinked
  3168.           to another disk, create temporary tables on that disk.
  3169.  
  3170.         * Implement a `DATE/DATETIME' type that handles time zone
  3171.           information properly, to make dealing with dates in different
  3172.           time zones easier.
  3173.  
  3174.         * Fix `configure' so that all libraries (like `MyISAM') can be
  3175.           compiled without threads.
  3176.  
  3177.         * Allow user variables as `LIMIT' arguments; for example,
  3178.           `LIMIT @a,@b'.
  3179.  
  3180.         * Automatic output from `mysql' to a Web browser.
  3181.  
  3182.         * `LOCK DATABASES' (with various options).
  3183.  
  3184.         * Many more variables for `SHOW STATUS'.  Record reads and
  3185.           updates.  Selects on a single table and selects with joins.
  3186.           Mean number of tables in selects. Number of `ORDER BY' and
  3187.           `GROUP BY' queries.
  3188.  
  3189.         * `mysqladmin copy database new-database'; this requires a
  3190.           `COPY' operation to be added to `mysqld'.
  3191.  
  3192.         * Processlist output should indicate the number of
  3193.           queries/threads.
  3194.  
  3195.         * `SHOW HOSTS' for printing information about the hostname
  3196.           cache.
  3197.  
  3198.         * Change table names from empty strings to `NULL' for
  3199.           calculated columns.
  3200.  
  3201.         * Don't use `Item_copy_string' on numerical values to avoid
  3202.           number-to-string-to-number conversion in case of `SELECT
  3203.           COUNT(*)*(id+0) FROM TBL_NAME GROUP BY id'.
  3204.  
  3205.         * Change so that `ALTER TABLE' doesn't abort clients that
  3206.           execute `INSERT DELAYED'.
  3207.  
  3208.         * Fix so that when columns are referenced in an `UPDATE' clause,
  3209.           they contain the old values from before the update started.
  3210.  
  3211. New operating systems
  3212.         * Port the MySQL clients to LynxOS.
  3213.  
  3214. New Features Planned for the Mid-Term Future
  3215. --------------------------------------------
  3216.  
  3217.    * Implement function:
  3218.      `get_changed_tables(timeout,table1,table2,...)'.
  3219.  
  3220.    * Change reading through tables to use `mmap()' when possible. Now
  3221.      only compressed tables use `mmap()'.
  3222.  
  3223.    * Make the automatic timestamp code nicer.  Add timestamps to the
  3224.      update log with `SET TIMESTAMP=val;'.
  3225.  
  3226.    * Use read/write mutex in some places to get more speed.
  3227.  
  3228.    * Automatically close some tables if a table, temporary table, or
  3229.      temporary file gets error 23 (too many open files).
  3230.  
  3231.    * Better constant propagation. When an occurrence of COL_NAME=N is
  3232.      found in an expression, for some constant `n', replace other
  3233.      occurrences of COL_NAME within the expression with `n'.
  3234.      Currently, this is done only for some simple cases.
  3235.  
  3236.    * Change all const expressions with calculated expressions if
  3237.      possible.
  3238.  
  3239.    * Optimize KEY = EXPR comparisons. At the moment, only KEY = COLUMN
  3240.      or KEY = CONSTANT comparisons are optimized.
  3241.  
  3242.    * Join some of the copy functions for nicer code.
  3243.  
  3244.    * Change `sql_yacc.yy' to an inline parser to reduce its size and get
  3245.      better error messages.
  3246.  
  3247.    * Change the parser to use only one rule per different number of
  3248.      arguments in function.
  3249.  
  3250.    * Use of full calculation names in the order part (for Access97).
  3251.  
  3252.    * `MINUS', `INTERSECT', and `FULL OUTER JOIN'.  (Currently `UNION'
  3253.      and `LEFT|RIGHT OUTER JOIN' are supported.)
  3254.  
  3255.    * Allow `SQL_OPTION MAX_SELECT_TIME=val', for placing a time limit
  3256.      on a query.
  3257.  
  3258.    * Allow updates to be logged to a database.
  3259.  
  3260.    * Enhance `LIMIT' to allow retrieval of data from the end of a
  3261.      result set.
  3262.  
  3263.    * Alarm around client connect/read/write functions.
  3264.  
  3265.    * Please note the changes to `mysqld_safe': According to FSSTND
  3266.      (which Debian tries to follow), PID files should go into
  3267.      `/var/run/<progname>.pid' and log files into `/var/log'. It would
  3268.      be nice if you could put the "DATADIR" in the first declaration of
  3269.      "pidfile" and "log" so that the placement of these files can be
  3270.      changed with a single statement.
  3271.  
  3272.    * Allow a client to request logging.
  3273.  
  3274.    * Allow the `LOAD DATA INFILE' statement to read files that have
  3275.      been compressed with `gzip'.
  3276.  
  3277.    * Fix sorting and grouping of `BLOB' columns (partly solved now).
  3278.  
  3279.    * Change to use semaphores when counting threads.  One should first
  3280.      implement a semaphore library for MIT-pthreads.
  3281.  
  3282.    * Add full support for `JOIN' with parentheses.
  3283.  
  3284.    * As an alternative to the one-thread-per-connection model, manage a
  3285.      pool of threads to handle queries.
  3286.  
  3287.    * Allow `GET_LOCK()' to obtain more than one lock.  When doing this,
  3288.      it is also necessary to handle the possible deadlocks this change
  3289.      will introduce.
  3290.  
  3291. New Features We Don't Plan to Implement
  3292. ---------------------------------------
  3293.  
  3294. We aim toward full compliance with ANSI/ISO SQL. There are no features
  3295. we plan not to implement.
  3296.  
  3297. MySQL Information Sources
  3298. =========================
  3299.  
  3300. MySQL Mailing Lists
  3301. -------------------
  3302.  
  3303. This section introduces the MySQL mailing lists and provides guidelines
  3304. as to how the lists should be used. When you subscribe to a mailing
  3305. list, you will receive all postings to the list as email messages. You
  3306. can also send your own questions and answers to the list.
  3307.  
  3308. The MySQL Mailing Lists
  3309. .......................
  3310.  
  3311. To subscribe to or unsubscribe from any of the mailing lists described
  3312. in this section, visit `http://lists.mysql.com/'.  Please _do not_ send
  3313. messages about subscribing or unsubscribing to any of the mailing
  3314. lists, because such messages are distributed automatically to thousands
  3315. of other users.
  3316.  
  3317. Your local site may have many subscribers to a MySQL mailing list.  If
  3318. so, the site may have a local mailing list, so that messages sent from
  3319. `lists.mysql.com' to your site are propagated to the local list.  In
  3320. such cases, please contact your system administrator to be added to or
  3321. dropped from the local MySQL list.
  3322.  
  3323. If you wish to have traffic for a mailing list go to a separate mailbox
  3324. in your mail program, set up a filter based on the message headers.
  3325. You can use either the `List-ID:' or `Delivered-To:' headers to identify
  3326. list messages.
  3327.  
  3328. The MySQL mailing lists are as follows:
  3329.  
  3330. `announce'
  3331.      This list is for announcements of new versions of MySQL and related
  3332.      programs.  This is a low-volume list to which all MySQL users
  3333.      should subscribe.
  3334.  
  3335. `mysql'
  3336.      This is the main list for general MySQL discussion.  Please note
  3337.      that some topics are better discussed on the more-specialized
  3338.      lists.  If you post to the wrong list, you may not get an answer.
  3339.  
  3340. `mysql-digest'
  3341.      This is the `mysql' list in digest form.  Subscribing to this list
  3342.      means you will get all list messages, sent as one large mail
  3343.      message once a day.
  3344.  
  3345. `bugs'
  3346.      This list will be of interest to you if you want to stay informed
  3347.      about issues reported since the last release of MySQL or if you
  3348.      want to be actively involved in the process of bug hunting and
  3349.      fixing.  *Note Bug reports::.
  3350.  
  3351. `bugs-digest'
  3352.      This is the `bugs' list in digest form.
  3353.  
  3354. `internals'
  3355.      This list is for people who work on the MySQL code.  This is also
  3356.      the forum for discussions on MySQL development and for posting
  3357.      patches.
  3358.  
  3359. `internals-digest'
  3360.      This is the `internals' list in digest form.
  3361.  
  3362. `mysqldoc'
  3363.      This list is for people who work on the MySQL documentation:
  3364.      people from MySQL AB, translators, and other community members.
  3365.  
  3366. `mysqldoc-digest'
  3367.      This is the `mysqldoc' list in digest form.
  3368.  
  3369. `benchmarks'
  3370.      This list is for anyone interested in performance issues.
  3371.      Discussions concentrate on database performance (not limited to
  3372.      MySQL), but also include broader categories such as performance of
  3373.      the kernel, filesystem, disk system, and so on.
  3374.  
  3375. `benchmarks-digest'
  3376.      This is the `benchmarks' list in digest form.
  3377.  
  3378. `packagers'
  3379.      This list is for discussions on packaging and distributing MySQL.
  3380.      This is the forum used by distribution maintainers to exchange
  3381.      ideas on packaging MySQL and on ensuring that MySQL looks and
  3382.      feels as similar as possible on all supported platforms and
  3383.      operating systems.
  3384.  
  3385. `packagers-digest'
  3386.      This is the `packagers' list in digest form.
  3387.  
  3388. `java'
  3389.      This list is for discussions about the MySQL server and Java. It
  3390.      is mostly used to discuss JDBC drivers, including MySQL
  3391.      Connector/J.
  3392.  
  3393. `java-digest'
  3394.      This is the `java' list in digest form.
  3395.  
  3396. `win32'
  3397.      This list is for all topics concerning the MySQL software on
  3398.      Microsoft operating systems, such as Windows 9x, Me, NT, 2000, and
  3399.      XP.
  3400.  
  3401. `win32-digest'
  3402.      This is the `win32' list in digest form.
  3403.  
  3404. `myodbc'
  3405.      This list is for all topics concerning connecting to the MySQL
  3406.      server with ODBC.
  3407.  
  3408. `myodbc-digest'
  3409.      This is the `myodbc' list in digest form.
  3410.  
  3411. `gui-tools'
  3412.      This list is for all topics concerning MySQL GUI tools, including
  3413.      `MySQL Administrator' and the `MySQL Control Center' graphical
  3414.      client.
  3415.  
  3416. `gui-tools-digest'
  3417.      This is the `gui-tools' list in digest form.
  3418.  
  3419. `cluster'
  3420.      This list is for discussion of MYSQL Cluster.
  3421.  
  3422. `cluster-digest'
  3423.      This is the `cluster' list in digest form.
  3424.  
  3425. `plusplus'
  3426.      This list is for all topics concerning programming with the C++
  3427.      API for MySQL.
  3428.  
  3429. `plusplus-digest'
  3430.      This is the `plusplus' list in digest form.
  3431.  
  3432. `msql-mysql-modules'
  3433.      This list is for all topics concerning the Perl support for MySQL
  3434.      with `msql-mysql-modules', which is now named `DBD::mysql'.
  3435.  
  3436. `msql-mysql-modules-digest'
  3437.      This is the `msql-mysql-modules' list in digest form.
  3438.  
  3439. If you're unable to get an answer to your questions from a MySQL mailing
  3440. list, one option is to purchase support from MySQL AB. This will put you
  3441. in direct contact with MySQL developers. *Note Support::.
  3442.  
  3443. The following table shows some MySQL mailing lists in languages other
  3444. than English.  These lists are not operated by MySQL AB.
  3445.  
  3446. `<mysql-france-subscribe@yahoogroups.com>'
  3447.      A French mailing list.
  3448.  
  3449. `<list@tinc.net>'
  3450.      A Korean mailing list.  Email `subscribe mysql your@email.address'
  3451.      to this list.
  3452.  
  3453. `<mysql-de-request@lists.4t2.com>'
  3454.      A German mailing list.  Email `subscribe mysql-de
  3455.      your@email.address' to this list.  You can find information about
  3456.      this mailing list at `http://www.4t2.com/mysql/'.
  3457.  
  3458. `<mysql-br-request@listas.linkway.com.br>'
  3459.      A Portuguese mailing list.  Email `subscribe mysql-br
  3460.      your@email.address' to this list.
  3461.  
  3462. `<mysql-alta@elistas.net>'
  3463.      A Spanish mailing list.  Email `subscribe mysql
  3464.      your@email.address' to this list.
  3465.  
  3466. Asking Questions or Reporting Bugs
  3467. ..................................
  3468.  
  3469. Before posting a bug report or question, please do the following:
  3470.  
  3471.    * Start by searching the MySQL online manual at
  3472.      `http://dev.mysql.com/doc/'.  We try to keep the manual up to date
  3473.      by updating it frequently with solutions to newly found problems.
  3474.      The change history (`http://dev.mysql.com/doc/mysql/en/News.html')
  3475.      can be particularly useful since it is quite possible that a newer
  3476.      version already contains a solution to your problem.
  3477.  
  3478.    * Search in the bugs database at `http://bugs.mysql.com/' to see
  3479.      whether the bug has already been reported and fixed.
  3480.  
  3481.    * Search the MySQL mailing list archives at
  3482.      `http://lists.mysql.com/'.
  3483.  
  3484.    * You can also use `http://www.mysql.com/search/' to search all the
  3485.      Web pages (including the manual) that are located at the MySQL AB
  3486.      Web site.
  3487.  
  3488. If you can't find an answer in the manual or the archives, check with
  3489. your local MySQL expert.  If you still can't find an answer to your
  3490. question, please follow the guidelines on sending mail to a MySQL
  3491. mailing list, outlined in the next section, before contacting us.
  3492.  
  3493. How to Report Bugs or Problems
  3494. ..............................
  3495.  
  3496. The normal place to report bugs is `http://bugs.mysql.com/', which is
  3497. the address for our bugs database.  This database is public, and can be
  3498. browsed and searched by anyone.  If you log in to the system, you will
  3499. also be able to enter new reports.
  3500.  
  3501. Writing a good bug report takes patience, but doing it right the first
  3502. time saves time both for us and for yourself.  A good bug report,
  3503. containing a full test case for the bug, makes it very likely that we
  3504. will fix the bug in the next release.  This section will help you write
  3505. your report correctly so that you don't waste your time doing things
  3506. that may not help us much or at all.
  3507.  
  3508. We encourage everyone to use the `mysqlbug' script to generate a bug
  3509. report (or a report about any problem).  `mysqlbug' can be found in the
  3510. `scripts' directory (source distribution) and in the `bin' directory
  3511. under your MySQL installation directory (binary distribution).  If you
  3512. are unable to use `mysqlbug' (for example, if you are running on
  3513. Windows), it is still vital that you include all the necessary
  3514. information noted in this section (most importantly, a description of
  3515. the operating system and the MySQL version).
  3516.  
  3517. The `mysqlbug' script helps you generate a report by determining much
  3518. of the following information automatically, but if something important
  3519. is missing, please include it with your message.  Please read this
  3520. section carefully and make sure that all the information described here
  3521. is included in your report.
  3522.  
  3523. Preferably, you should test the problem using the latest production or
  3524. development version of MySQL Server before posting.  Anyone should be
  3525. able to repeat the bug by just using `mysql test < script_file' on the
  3526. included test case or by running the shell or Perl script that is
  3527. included in the bug report.
  3528.  
  3529. All bugs posted in the bugs database at `http://bugs.mysql.com/' will
  3530. be corrected or documented in the next MySQL release. If only minor
  3531. code changes are needed to correct a problem, we may also post a patch
  3532. that fixes the problem.
  3533.  
  3534. If you have found a sensitive security bug in MySQL, you can send email
  3535. to <security@mysql.com>.
  3536.  
  3537. If you have a repeatable bug report, please report it to the bugs
  3538. database at `http://bugs.mysql.com/'.  Note that even in this case it's
  3539. good to run the `mysqlbug' script first to find information about your
  3540. system.  Any bug that we are able to repeat has a high chance of being
  3541. fixed in the next MySQL release.
  3542.  
  3543. To report other problems, you can use one of the MySQL mailing lists.
  3544.  
  3545. Remember that it is possible for us to respond to a message containing
  3546. too much information, but not to one containing too little.  People
  3547. often omit facts because they think they know the cause of a problem
  3548. and assume that some details don't matter.  A good principle is this:
  3549. If you are in doubt about stating something, state it.  It is faster
  3550. and less troublesome to write a couple more lines in your report than
  3551. to wait longer for the answer if we must ask you to provide information
  3552. that was missing from the initial report.
  3553.  
  3554. The most common errors made in bug reports are (a) not including the
  3555. version number of the MySQL distribution used, and (b) not fully
  3556. describing the platform on which the MySQL server is installed
  3557. (including the platform type and version number).  This is highly
  3558. relevant information, and in 99 cases out of 100, the bug report is
  3559. useless without it.  Very often we get questions like, "Why doesn't
  3560. this work for me?" Then we find that the feature requested wasn't
  3561. implemented in that MySQL version, or that a bug described in a report
  3562. has already been fixed in newer MySQL versions.  Sometimes the error is
  3563. platform-dependent; in such cases, it is next to impossible for us to
  3564. fix anything without knowing the operating system and the version
  3565. number of the platform.
  3566.  
  3567. If you compiled MySQL from source, remember also to provide information
  3568. about your compiler, if it is related to the problem.  Often people
  3569. find bugs in compilers and think the problem is MySQL-related.  Most
  3570. compilers are under development all the time and become better version
  3571. by version.  To determine whether your problem depends on your
  3572. compiler, we need to know what compiler you use.  Note that every
  3573. compiling problem should be regarded as a bug and reported accordingly.
  3574.  
  3575. It is most helpful when a good description of the problem is included
  3576. in the bug report.  That is, give a good example of everything you did
  3577. that led to the problem and describe, in exact detail, the problem
  3578. itself.  The best reports are those that include a full example showing
  3579. how to reproduce the bug or problem.  *Note Reproduceable test case::.
  3580.  
  3581. If a program produces an error message, it is very important to include
  3582. the message in your report.  If we try to search for something from the
  3583. archives using programs, it is better that the error message reported
  3584. exactly matches the one that the program produces.  (Even the
  3585. lettercase should be observed.)  You should never try to reproduce from
  3586. memory what the error message was; instead, copy and paste the entire
  3587. message into your report.
  3588.  
  3589. If you have a problem with Connector/ODBC (MyODBC), please try to
  3590. generate a MyODBC trace file and send it with your report.  *Note
  3591. MyODBC bug report::.
  3592.  
  3593. Please remember that many of the people who will read your report will
  3594. do so using an 80-column display.  When generating reports or examples
  3595. using the `mysql' command-line tool, you should therefore use the
  3596. `--vertical' option (or the `\G' statement terminator) for output that
  3597. would exceed the available width for such a display (for example, with
  3598. the `EXPLAIN SELECT' statement; see the example later in this section).
  3599.  
  3600. Please include the following information in your report:
  3601.  
  3602.    * The version number of the MySQL distribution you are using (for
  3603.      example, MySQL 4.0.12). You can find out which version you are
  3604.      running by executing `mysqladmin version'.  The `mysqladmin'
  3605.      program can be found in the `bin' directory under your MySQL
  3606.      installation directory.
  3607.  
  3608.    * The manufacturer and model of the machine on which you experience
  3609.      the problem.
  3610.  
  3611.    * The operating system name and version.  If you work with Windows,
  3612.      you can usually get the name and version number by double-clicking
  3613.      your My Computer icon and pulling down the "Help/About Windows"
  3614.      menu.  For most Unix-like operating systems, you can get this
  3615.      information by executing the command `uname -a'.
  3616.  
  3617.    * Sometimes the amount of memory (real and virtual) is relevant. If
  3618.      in doubt, include these values.
  3619.  
  3620.    * If you are using a source distribution of the MySQL software, the
  3621.      name and version number of the compiler used are needed.  If you
  3622.      have a binary distribution, the distribution name is needed.
  3623.  
  3624.    * If the problem occurs during compilation, include the exact error
  3625.      messages and also a few lines of context around the offending code
  3626.      in the file where the error occurs.
  3627.  
  3628.    * If `mysqld' died, you should also report the query that crashed
  3629.      `mysqld'.  You can usually find this out by running `mysqld' with
  3630.      query logging enabled, and then looking in the log after `mysqld'
  3631.      crashes *Note Using log files::.
  3632.  
  3633.    * If a database table is related to the problem, include the output
  3634.      from `mysqldump --no-data DB_NAME TBL_NAME'.  This is very easy to
  3635.      do and is a powerful way to get information about any table in a
  3636.      database.  The information will help us create a situation
  3637.      matching the one you have.
  3638.  
  3639.    * For speed-related bugs or problems with `SELECT' statements, you
  3640.      should always include the output of `EXPLAIN SELECT ...', and at
  3641.      least the number of rows that the `SELECT' statement produces.  You
  3642.      should also include the output from `SHOW CREATE TABLE TBL_NAME'
  3643.      for each involved table. The more information you give about your
  3644.      situation, the more likely it is that someone can help you.
  3645.  
  3646.      The following is an example of a very good bug report. It should
  3647.      be posted with the `mysqlbug' script.  The example uses the `mysql'
  3648.      command-line tool. Note the use of the `\G' statement terminator
  3649.      for statements whose output width would otherwise exceed that of
  3650.      an 80-column display device.
  3651.  
  3652.           mysql> SHOW VARIABLES;
  3653.           mysql> SHOW COLUMNS FROM ...\G
  3654.                  <output from SHOW COLUMNS>
  3655.           mysql> EXPLAIN SELECT ...\G
  3656.                  <output from EXPLAIN>
  3657.           mysql> FLUSH STATUS;
  3658.           mysql> SELECT ...;
  3659.                  <A short version of the output from SELECT,
  3660.                  including the time taken to run the query>
  3661.           mysql> SHOW STATUS;
  3662.                  <output from SHOW STATUS>
  3663.  
  3664.    * If a bug or problem occurs while running `mysqld', try to provide
  3665.      an input script that will reproduce the anomaly.  This script
  3666.      should include any necessary source files.  The more closely the
  3667.      script can reproduce your situation, the better.  If you can make
  3668.      a reproducible test case, you should post it on
  3669.      `http://bugs.mysql.com/' for high-priority treatment.
  3670.  
  3671.      If you can't provide a script, you should at least include the
  3672.      output from `mysqladmin variables extended-status processlist' in
  3673.      your mail to provide some information on how your system is
  3674.      performing.
  3675.  
  3676.    * If you can't produce a test case with only a few rows, or if the
  3677.      test table is too big to be mailed to the mailing list (more than
  3678.      10 rows), you should dump your tables using `mysqldump' and create
  3679.      a `README' file that describes your problem.
  3680.  
  3681.      Create a compressed archive of your files using `tar' and `gzip'
  3682.      or `zip', and use FTP to transfer the archive to
  3683.      `ftp://ftp.mysql.com/pub/mysql/upload/'.  Then enter the problem
  3684.      into our bugs database at `http://bugs.mysql.com/'.
  3685.  
  3686.    * If you think that the MySQL server produces a strange result from
  3687.      a query, include not only the result, but also your opinion of
  3688.      what the result should be, and an account describing the basis for
  3689.      your opinion.
  3690.  
  3691.    * When giving an example of the problem, it's better to use the
  3692.      variable names, table names, and so on that exist in your actual
  3693.      situation than to come up with new names.  The problem could be
  3694.      related to the name of a variable or table.  These cases are rare,
  3695.      perhaps, but it is better to be safe than sorry.  After all, it
  3696.      should be easier for you to provide an example that uses your
  3697.      actual situation, and it is by all means better for us.  In case
  3698.      you have data that you don't want to show to others, you can use
  3699.      FTP to transfer it to `ftp://ftp.mysql.com/pub/mysql/upload/'.  If
  3700.      the information is really top secret and you don't want to show it
  3701.      even to us, then go ahead and provide an example using other
  3702.      names, but please regard this as the last choice.
  3703.  
  3704.    * Include all the options given to the relevant programs, if
  3705.      possible.  For example, indicate the options that you use when you
  3706.      start the `mysqld' server as well as the options that you use to
  3707.      run any MySQL client programs.  The options to programs such as
  3708.      `mysqld' and `mysql', and to the `configure' script, are often
  3709.      keys to answers and are very relevant.  It is never a bad idea to
  3710.      include them.  If you use any modules, such as Perl or PHP, please
  3711.      include the version numbers of those as well.
  3712.  
  3713.    * If your question is related to the privilege system, please
  3714.      include the output of `mysqlaccess', the output of `mysqladmin
  3715.      reload', and all the error messages you get when trying to
  3716.      connect.  When you test your privileges, you should first run
  3717.      `mysqlaccess'.  After this, execute `mysqladmin reload version'
  3718.      and try to connect with the program that gives you trouble.
  3719.      `mysqlaccess' can be found in the `bin' directory under your MySQL
  3720.      installation directory.
  3721.  
  3722.    * If you have a patch for a bug, do include it.  But don't assume
  3723.      that the patch is all we need, or that we will use it, if you
  3724.      don't provide some necessary information such as test cases
  3725.      showing the bug that your patch fixes.  We might find problems
  3726.      with your patch or we might not understand it at all; if so, we
  3727.      can't use it.
  3728.  
  3729.      If we can't verify exactly what the purpose of the patch is, we
  3730.      won't use it.  Test cases will help us here.  Show that the patch
  3731.      will handle all the situations that may occur.  If we find a
  3732.      borderline case (even a rare one) where the patch won't work, it
  3733.      may be useless.
  3734.  
  3735.    * Guesses about what the bug is, why it occurs, or what it depends on
  3736.      are usually wrong.  Even the MySQL team can't guess such things
  3737.      without first using a debugger to determine the real cause of a
  3738.      bug.
  3739.  
  3740.    * Indicate in your bug report that you have checked the reference
  3741.      manual and mail archive so that others know you have tried to
  3742.      solve the problem yourself.
  3743.  
  3744.    * If you get a `parse error', please check your syntax closely.  If
  3745.      you can't find something wrong with it, it's extremely likely that
  3746.      your current version of MySQL Server doesn't support the syntax
  3747.      you are using.  If you are using the current version and the
  3748.      manual at `http://dev.mysql.com/doc/' doesn't cover the syntax you
  3749.      are using, MySQL Server doesn't support your query.  In this case,
  3750.      your only options are to implement the syntax yourself or email
  3751.      <licensing@mysql.com> and ask for an offer to implement it.
  3752.  
  3753.      If the manual covers the syntax you are using, but you have an
  3754.      older version of MySQL Server, you should check the MySQL change
  3755.      history to see when the syntax was implemented.  In this case, you
  3756.      have the option of upgrading to a newer version of MySQL Server.
  3757.      *Note News::.
  3758.  
  3759.    * If your problem is that your data appears corrupt or you get errors
  3760.      when you access a particular table, you should first check and
  3761.      then try to repair your tables with `CHECK TABLE' and `REPAIR
  3762.      TABLE' or with `myisamchk'.  *Note MySQL Database Administration::.
  3763.  
  3764.      If you are running Windows, please verify that
  3765.      `lower_case_table_names' is 1 or 2 with `SHOW VARIABLES LIKE
  3766.      'lower_case_table_names''.
  3767.  
  3768.    * If you often get corrupted tables, you should try to find out when
  3769.      and why this happens.  In this case, the error log in the MySQL
  3770.      data directory may contain some information about what happened.
  3771.      (This is the file with the `.err' suffix in the name.)  *Note
  3772.      Error log::.  Please include any relevant information from this
  3773.      file in your bug report.  Normally `mysqld' should _never_ crash a
  3774.      table if nothing killed it in the middle of an update.  If you can
  3775.      find the cause of `mysqld' dying, it's much easier for us to
  3776.      provide you with a fix for the problem.  *Note What is crashing::.
  3777.  
  3778.    * If possible, download and install the most recent version of MySQL
  3779.      Server and check whether it solves your problem.  All versions of
  3780.      the MySQL software are thoroughly tested and should work without
  3781.      problems.  We believe in making everything as backward-compatible
  3782.      as possible, and you should be able to switch MySQL versions
  3783.      without difficulty.  *Note Which version::.
  3784.  
  3785. If you are a support customer, please cross-post the bug report to
  3786. <mysql-support@mysql.com> for higher-priority treatment, as well as to
  3787. the appropriate mailing list to see whether someone else has
  3788. experienced (and perhaps solved) the problem.
  3789.  
  3790. For information on reporting bugs in `MyODBC', see *Note ODBC
  3791. Problems::.
  3792.  
  3793. For solutions to some common problems, see *Note Problems::.
  3794.  
  3795. When answers are sent to you individually and not to the mailing list,
  3796. it is considered good etiquette to summarize the answers and send the
  3797. summary to the mailing list so that others may have the benefit of
  3798. responses you received that helped you solve your problem.
  3799.  
  3800. Guidelines for Answering Questions on the Mailing List
  3801. ......................................................
  3802.  
  3803. If you consider your answer to have broad interest, you may want to
  3804. post it to the mailing list instead of replying directly to the
  3805. individual who asked.  Try to make your answer general enough that
  3806. people other than the original poster may benefit from it.  When you
  3807. post to the list, please make sure that your answer is not a
  3808. duplication of a previous answer.
  3809.  
  3810. Try to summarize the essential part of the question in your reply;
  3811. don't feel obliged to quote the entire original message.
  3812.  
  3813. Please don't post mail messages from your browser with HTML mode turned
  3814. on.  Many users don't read mail with a browser.
  3815.  
  3816. MySQL Community Support on IRC (Internet Relay Chat)
  3817. ----------------------------------------------------
  3818.  
  3819. In addition to the various MySQL mailing lists, you can find experienced
  3820. community people on `IRC' (`Internet Relay Chat').  These are the best
  3821. networks/channels currently known to us:
  3822.  
  3823.    * *freenode* (see `http://www.freenode.net/' for servers)
  3824.         * `#mysql' Primarily MySQL questions, but other database and
  3825.           general SQL questions are welcome.  Questions about PHP, Perl
  3826.           or C in combination with MySQL are also common.
  3827.  
  3828.    * *EFnet* (see `http://www.efnet.org/' for servers)
  3829.         * `#mysql' MySQL questions.
  3830.  
  3831. If you are looking for IRC client software to connect to an IRC network,
  3832. take a look at `X-Chat' (`http://www.xchat.org/').  X-Chat (GPL
  3833. licensed) is available for Unix as well as for Windows platforms.
  3834.  
  3835. MySQL Standards Compliance
  3836. ==========================
  3837.  
  3838. This section describes how MySQL relates to the ANSI/ISO SQL standards.
  3839. MySQL Server has many extensions to the SQL standard, and here you will
  3840. find out what they are and how to use them.  You will also find
  3841. information about functionality missing from MySQL Server, and how to
  3842. work around some differences.
  3843.  
  3844. The SQL standard has been evolving since 1986 and several versions
  3845. exist. In this manual, "SQL-92" refers to the standard released in 1992,
  3846. "SQL:1999" refers to the standard released in 1999, and "SQL:2003"
  3847. refers to the current version of the standard.  We use the phrase "the
  3848. SQL standard" to mean the current version of the SQL Standard at any
  3849. time.
  3850.  
  3851. Our goal is to not restrict MySQL Server usability for any usage
  3852. without a very good reason for doing so.  Even if we don't have the
  3853. resources to perform  development for every possible use, we are always
  3854. willing to help and offer suggestions to people who are trying to use
  3855. MySQL Server in new territories.
  3856.  
  3857. One of our main goals with the product is to continue to work toward
  3858. compliance with the SQL standard, but without sacrificing speed or
  3859. reliability.  We are not afraid to add extensions to SQL or support for
  3860. non-SQL features if this greatly increases the usability of MySQL
  3861. Server for a large segment of our user base.  The `HANDLER' interface
  3862. in MySQL Server 4.0 is an example of this strategy. *Note `HANDLER':
  3863. HANDLER.
  3864.  
  3865. We will continue to support transactional and non-transactional
  3866. databases to satisfy both mission-critical 24/7 usage and heavy Web or
  3867. logging usage.
  3868.  
  3869. MySQL Server was originally designed to work with medium size databases
  3870. (10-100 million rows, or about 100MB per table) on small computer
  3871. systems.  Today MySQL Server handles terabyte-size databases, but the
  3872. code can also be compiled in a reduced version suitable for hand-held
  3873. and embedded devices.  The compact design of the MySQL server makes
  3874. development in both directions possible without any conflicts in the
  3875. source tree.
  3876.  
  3877. Currently, we are not targeting realtime support, although MySQL
  3878. replication capabilities already offer significant functionality.
  3879.  
  3880. Database cluster support now exists through third-party clustering
  3881. solutions as well as the integration of our acquired NDB Cluster
  3882. technology into a new storage engine, available from version 4.1.2.
  3883. *Note NDBCluster::.
  3884.  
  3885. We are also looking at providing XML support in the database server.
  3886.  
  3887. What Standards MySQL Follows
  3888. ----------------------------
  3889.  
  3890. We are aiming toward supporting the full ANSI/ISO SQL standard, but
  3891. without making concessions to speed and quality of the code.
  3892.  
  3893. ODBC levels 0-3.51.
  3894.  
  3895. Selecting SQL Modes
  3896. -------------------
  3897.  
  3898. The MySQL server can operate in different SQL modes, and can apply these
  3899. modes differentially for different clients. This allows applications to
  3900. tailor server operation to their own requirements.
  3901.  
  3902. Modes define what SQL syntax MySQL should support and what kind of
  3903. validation checks it should perform on the data.  This makes it easier
  3904. to use MySQL in a lot of different environments and to use MySQL
  3905. together with other database servers.
  3906.  
  3907. You can set the default SQL mode by starting `mysqld' with the
  3908. `--sql-mode="modes"' option. Beginning with MySQL 4.1, you can also
  3909. change the mode after startup time by setting the `sql_mode' variable
  3910. with a `SET [SESSION|GLOBAL] sql_mode='modes'' statement.
  3911.  
  3912. For more information on setting the server mode, see *Note Server SQL
  3913. mode::.
  3914.  
  3915. Running MySQL in ANSI Mode
  3916. --------------------------
  3917.  
  3918. You can tell `mysqld' to use the ANSI mode with the `--ansi' startup
  3919. option. *Note Server options::.
  3920.  
  3921. Running the server in ANSI mode is the same as starting it with these
  3922. options (specify the `--sql_mode' value on a single line):
  3923.  
  3924.      --transaction-isolation=SERIALIZABLE
  3925.      --sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,
  3926.      IGNORE_SPACE,ONLY_FULL_GROUP_BY
  3927.  
  3928. In MySQL 4.1, you can achieve the same effect with these two statements
  3929. (specify the `sql_mode' value on a single line):
  3930.  
  3931.      SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  3932.      SET GLOBAL sql_mode = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,
  3933.      IGNORE_SPACE,ONLY_FULL_GROUP_BY';
  3934.  
  3935. *Note SQL mode::.
  3936.  
  3937. In MySQL 4.1.1, the `sql_mode' options shown can be also be set with
  3938. this statement:
  3939.  
  3940.      SET GLOBAL sql_mode='ansi';
  3941.  
  3942. In this case, the value of the `sql_mode' variable will be set to all
  3943. options that are relevant for ANSI mode. You can check the result like
  3944. this:
  3945.  
  3946.      mysql> SET GLOBAL sql_mode='ansi';
  3947.      mysql> SELECT @@global.sql_mode;
  3948.              -> 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,
  3949.                  IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI';
  3950.  
  3951. MySQL Extensions to Standard SQL
  3952. --------------------------------
  3953.  
  3954. MySQL Server includes some extensions that you probably will not find in
  3955. other SQL databases.  Be warned that if you use them, your code will
  3956. not be portable to other SQL servers.  In some cases, you can write
  3957. code that includes MySQL extensions, but is still portable, by using
  3958. comments of the form `/*! ... */'.  In this case, MySQL Server will
  3959. parse and execute the code within the comment as it would any other
  3960. MySQL statement, but other SQL servers will ignore the extensions.  For
  3961. example:
  3962.  
  3963.      SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
  3964.  
  3965. If you add a version number after the `!' character, the syntax within
  3966. the comment will be executed only if the MySQL version is equal to or
  3967. newer than the specified version number:
  3968.  
  3969.      CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
  3970.  
  3971. This means that if you have Version 3.23.02 or newer, MySQL Server will
  3972. use the `TEMPORARY' keyword.
  3973.  
  3974. The following descriptions list MySQL extensions, organized by category.
  3975.  
  3976. Organization of data on disk
  3977.      MySQL Server maps each database to a directory under the MySQL
  3978.      data directory, and tables within a database to filenames in the
  3979.      database directory.  This has a few implications:
  3980.  
  3981.         * Database names and table names are case sensitive in MySQL
  3982.           Server on operating systems that have case-sensitive
  3983.           filenames (such as most Unix systems). *Note Name case
  3984.           sensitivity::.
  3985.  
  3986.         * You can use standard system commands to back up, rename,
  3987.           move, delete, and copy tables that are managed by the
  3988.           `MyISAM' or `ISAM' storage engines.  For example, to rename a
  3989.           `MyISAM' table, rename the `.MYD', `.MYI', and `.frm' files
  3990.           to which the table corresponds.
  3991.  
  3992.      Database, table, index, column, or alias names may begin with a
  3993.      digit (but may not consist solely of digits).
  3994.  
  3995. General language syntax
  3996.         * Strings may be enclosed by either `"' or `'', not just by `''.
  3997.  
  3998.         * Use of `\' as an escape character in strings.
  3999.  
  4000.         * In SQL statements, you can access tables from different
  4001.           databases with the DB_NAME.TBL_NAME syntax.  Some SQL servers
  4002.           provide the same functionality but call this `User space'.
  4003.           MySQL Server doesn't support tablespaces such as used in
  4004.           statements like this: `CREATE TABLE ralph.my_table...IN
  4005.           my_tablespace'.
  4006.  
  4007.  
  4008. SQL statement syntax
  4009.         * The `ANALYZE TABLE', `CHECK TABLE', `OPTIMIZE TABLE', and
  4010.           `REPAIR TABLE' statements.
  4011.  
  4012.         * The `CREATE DATABASE' and `DROP DATABASE' statements.  *Note
  4013.           `CREATE DATABASE': CREATE DATABASE.
  4014.  
  4015.         * The `DO' statement.
  4016.  
  4017.         * `EXPLAIN SELECT' to get a description of how tables are
  4018.           joined.
  4019.  
  4020.         * The `FLUSH' and `RESET' statements.
  4021.  
  4022.         * The `SET' statement. *Note `SET': SET OPTION.
  4023.  
  4024.         * The `SHOW' statement.  *Note `SHOW': SHOW.
  4025.  
  4026.         * Use of `LOAD DATA INFILE'. In many cases, this syntax is
  4027.           compatible with Oracle's `LOAD DATA INFILE'. *Note `LOAD
  4028.           DATA': LOAD DATA.
  4029.  
  4030.         * Use of `RENAME TABLE'. *Note `RENAME TABLE': RENAME TABLE.
  4031.  
  4032.         * Use of `REPLACE' instead of `DELETE' + `INSERT'.  *Note
  4033.           `REPLACE': REPLACE.
  4034.  
  4035.         * Use of `CHANGE col_name', `DROP col_name', or `DROP INDEX',
  4036.           `IGNORE' or `RENAME' in an `ALTER TABLE' statement.  Use of
  4037.           multiple `ADD', `ALTER', `DROP', or `CHANGE' clauses in an
  4038.           `ALTER TABLE' statement.  *Note `ALTER TABLE': ALTER TABLE.
  4039.  
  4040.         * Use of index names, indexes on a prefix of a field, and use of
  4041.           `INDEX' or `KEY' in a `CREATE TABLE' statement. *Note `CREATE
  4042.           TABLE': CREATE TABLE.
  4043.  
  4044.         * Use of `TEMPORARY' or `IF NOT EXISTS' with `CREATE TABLE'.
  4045.  
  4046.         * Use of `IF EXISTS' with `DROP TABLE'.
  4047.  
  4048.         * You can drop multiple tables with a single `DROP TABLE'
  4049.           statement.
  4050.  
  4051.         * The `ORDER BY' and `LIMIT' clauses of the `UPDATE' and
  4052.           `DELETE' statements.
  4053.  
  4054.         * `INSERT INTO ... SET col_name = ...' syntax.
  4055.  
  4056.         * The `DELAYED' clause of the `INSERT' and `REPLACE' statements.
  4057.  
  4058.         * The `LOW_PRIORITY' clause of the `INSERT', `REPLACE',
  4059.           `DELETE', and `UPDATE' statements.
  4060.  
  4061.         * Use of `INTO OUTFILE' and `STRAIGHT_JOIN' in a `SELECT'
  4062.           statement. *Note `SELECT': SELECT.
  4063.  
  4064.         * The `SQL_SMALL_RESULT' option in a `SELECT' statement.
  4065.  
  4066.         * You don't need to name all selected columns in the `GROUP BY'
  4067.           part.  This gives better performance for some very specific,
  4068.           but quite normal queries.  *Note Group by functions and
  4069.           modifiers::.
  4070.  
  4071.         * You can specify `ASC' and `DESC' with `GROUP BY'.
  4072.  
  4073.         * The ability to set variables in a statement with the `:='
  4074.           assignment operator:
  4075.                mysql> SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg
  4076.                    -> FROM test_table;
  4077.                mysql> SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  4078.  
  4079.  
  4080. Column types
  4081.         * The column types `MEDIUMINT', `SET', `ENUM', and the
  4082.           different `BLOB' and `TEXT' types.
  4083.  
  4084.         * The column attributes `AUTO_INCREMENT', `BINARY', `NULL',
  4085.           `UNSIGNED', and `ZEROFILL'.
  4086.  
  4087. Functions and operators
  4088.         * To make it easier for users who come from other SQL
  4089.           environments, MySQL Server supports aliases for many
  4090.           functions. For example, all string functions support both
  4091.           standard SQL syntax and ODBC syntax.
  4092.  
  4093.         * MySQL Server understands the `||' and `&&' operators to mean
  4094.           logical OR and AND, as in the C programming language.  In
  4095.           MySQL Server, `||' and `OR' are synonyms, as are `&&' and
  4096.           `AND'.  Because of this nice syntax, MySQL Server doesn't
  4097.           support the standard SQL `||' operator for string
  4098.           concatenation; use `CONCAT()' instead. Because `CONCAT()'
  4099.           takes any number of arguments, it's easy to convert use of
  4100.           the `||' operator to MySQL Server.
  4101.  
  4102.         * Use of `COUNT(DISTINCT list)' where `list' has more than one
  4103.           element.
  4104.  
  4105.         * All string comparisons are case-insensitive by default, with
  4106.           sort ordering determined by the current character set
  4107.           (ISO-8859-1 Latin1 by default).  If you don't like this, you
  4108.           should declare your columns with the `BINARY' attribute or
  4109.           use the `BINARY' cast, which causes comparisons to be done
  4110.           using the underlying character code values rather then a
  4111.           lexical ordering.
  4112.  
  4113.         * The `%' operator is a synonym for `MOD()'.  That is, `N % M'
  4114.           is equivalent to `MOD(N,M)'.  `%' is supported for C
  4115.           programmers and for compatibility with PostgreSQL.
  4116.  
  4117.         * The `=', `<>', `<=' ,`<', `>=',`>', `<<', `>>', `<=>', `AND',
  4118.           `OR', or `LIKE' operators may be used in column comparisons
  4119.           to the left of the `FROM' in `SELECT' statements.  For
  4120.           example:
  4121.  
  4122.                mysql> SELECT col1=1 AND col2=2 FROM TBL_NAME;
  4123.  
  4124.         * The `LAST_INSERT_ID()' function that returns the most recent
  4125.           `AUTO_INCREMENT' value.  *Note Information functions::.
  4126.  
  4127.         * `LIKE' is allowed on numeric columns.
  4128.  
  4129.         * The `REGEXP' and `NOT REGEXP' extended regular expression
  4130.           operators.
  4131.  
  4132.         * `CONCAT()' or `CHAR()' with one argument or more than two
  4133.           arguments.  (In MySQL Server, these functions can take any
  4134.           number of arguments.)
  4135.  
  4136.         * The `BIT_COUNT()', `CASE', `ELT()', `FROM_DAYS()',
  4137.           `FORMAT()', `IF()', `PASSWORD()', `ENCRYPT()', `MD5()',
  4138.           `ENCODE()', `DECODE()', `PERIOD_ADD()', `PERIOD_DIFF()',
  4139.           `TO_DAYS()', and `WEEKDAY()' functions.
  4140.  
  4141.         * Use of `TRIM()' to trim substrings.  Standard SQL supports
  4142.           removal of single characters only.
  4143.  
  4144.         * The `GROUP BY' functions `STD()', `BIT_OR()', `BIT_AND()',
  4145.           `BIT_XOR()', and `GROUP_CONCAT()'.  *Note Group by functions
  4146.           and modifiers::.
  4147.  
  4148. For a prioritized list indicating when new extensions will be added to
  4149. MySQL Server, you should consult the online MySQL TODO list at
  4150. `http://dev.mysql.com/doc/mysql/en/TODO.html'.  That is the latest
  4151. version of the TODO list in this manual. *Note TODO::.
  4152.  
  4153. MySQL Differences from Standard SQL
  4154. -----------------------------------
  4155.  
  4156. We try to make MySQL Server follow the ANSI SQL standard and the ODBC
  4157. SQL standard, but MySQL Server performs operations differently in some
  4158. cases:
  4159.  
  4160.    * For `VARCHAR' columns, trailing spaces are removed when the value
  4161.      is stored. *Note Bugs::.
  4162.  
  4163.    * In some cases, `CHAR' columns are silently converted to `VARCHAR'
  4164.      columns when you define a table or alter its structure.  *Note
  4165.      Silent column changes::.
  4166.  
  4167.    * Privileges for a table are not automatically revoked when you
  4168.      delete a table. You must explicitly issue a `REVOKE' statement to
  4169.      revoke privileges for a table. *Note `GRANT': GRANT.
  4170.  
  4171. Subqueries
  4172. ..........
  4173.  
  4174. MySQL 4.1 supports subqueries and derived tables.  A "subquery" is a
  4175. `SELECT' statement nested within another statement.  A "derived table"
  4176. (an unnamed view) is a subquery in the `FROM' clause of another
  4177. statement.  *Note Subqueries::.
  4178.  
  4179. For MySQL versions older than 4.1, most subqueries can be rewritten
  4180. using joins or other methods.  See *Note Rewriting subqueries:: for
  4181. examples that show how to do this.
  4182.  
  4183. `SELECT INTO TABLE'
  4184. ...................
  4185.  
  4186. MySQL Server doesn't support the Sybase SQL extension: `SELECT ... INTO
  4187. TABLE ...'.  Instead, MySQL Server supports the standard SQL syntax
  4188. `INSERT INTO ... SELECT ...', which is basically the same thing. *Note
  4189. `INSERT SELECT': INSERT SELECT.
  4190.  
  4191.      INSERT INTO tbl_temp2 (fld_id)
  4192.          SELECT tbl_temp1.fld_order_id
  4193.          FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
  4194.  
  4195. Alternatively, you can use `SELECT INTO OUTFILE ...' or `CREATE TABLE
  4196. ... SELECT'.
  4197.  
  4198. From version 5.0, MySQL supports `SELECT ... INTO' with user variables.
  4199. The same syntax may also be used inside stored procedures using cursors
  4200. and local variables.  *Note SELECT INTO Statement::.
  4201.  
  4202. Transactions and Atomic Operations
  4203. ..................................
  4204.  
  4205. MySQL Server (version 3.23-max and all versions 4.0 and above) supports
  4206. transactions with the `InnoDB' and `BDB' transactional storage engines.
  4207. `InnoDB' provides _full_ `ACID' compliance.  *Note Table types::.
  4208.  
  4209. The other non-transactional storage engines in MySQL Server (such as
  4210. `MyISAM') follow a different paradigm for data integrity called "atomic
  4211. operations." In transactional terms, `MyISAM' tables effectively always
  4212. operate in `AUTOCOMMIT=1' mode.  Atomic operations often offer
  4213. comparable integrity with higher performance.
  4214.  
  4215. With MySQL Server supporting both paradigms, you can decide whether your
  4216. applications are best served by the speed of atomic operations or the
  4217. use of transactional features. This choice can be made on a per-table
  4218. basis.
  4219.  
  4220. As noted, the trade-off for transactional versus non-transactional table
  4221. types lies mostly in performance. Transactional tables have
  4222. significantly higher memory and diskspace requirements, and more CPU
  4223. overhead.  On the other hand, transactional table types such as
  4224. `InnoDB' also offer many significant features. MySQL Server's modular
  4225. design allows the concurrent use of different storage engines to suit
  4226. different requirements and deliver optimum performance in all
  4227. situations.
  4228.  
  4229. But how do you use the features of MySQL Server to maintain rigorous
  4230. integrity even with the non-transactional `MyISAM' tables, and how do
  4231. these features compare with the transactional table types?
  4232.  
  4233.   1. If your applications are written in a way that is dependent on
  4234.      being able to call `ROLLBACK' rather than `COMMIT' in critical
  4235.      situations, transactions are more convenient. Transactions also
  4236.      ensure that unfinished updates or corrupting activities are not
  4237.      committed to the database; the server is given the opportunity to
  4238.      do an automatic rollback and your database is saved.
  4239.  
  4240.      If you use non-transactional tables, MySQL Server in almost all
  4241.      cases allows you to resolve potential problems by including simple
  4242.      checks before updates and by running simple scripts that check the
  4243.      databases for inconsistencies and automatically repair or warn if
  4244.      such an inconsistency occurs. Note that just by using the MySQL
  4245.      log or even adding one extra log, you can normally fix tables
  4246.      perfectly with no data integrity loss.
  4247.  
  4248.   2. More often than not, critical transactional updates can be
  4249.      rewritten to be atomic. Generally speaking, all integrity problems
  4250.      that transactions solve can be done with `LOCK TABLES' or atomic
  4251.      updates, ensuring that you never will get an automatic abort from
  4252.      the server, which is a common problem with transactional database
  4253.      systems.
  4254.  
  4255.   3. Even a transactional system can lose data if the server goes down.
  4256.      The difference between different systems lies in just how small the
  4257.      time-lag is where they could lose data. No system is 100% secure,
  4258.      only "secure enough." Even Oracle, reputed to be the safest of
  4259.      transactional database systems, is reported to sometimes lose data
  4260.      in such situations.
  4261.  
  4262.      To be safe with MySQL Server, whether or not using transactional
  4263.      tables, you only need to have backups and have binary logging
  4264.      turned on. With this you can recover from any situation that you
  4265.      could with any other transactional database system.  It is always
  4266.      good to have backups, regardless of which database system you use.
  4267.  
  4268. The transactional paradigm has its benefits and its drawbacks. Many
  4269. users and application developers depend on the ease with which they can
  4270. code around problems where an abort appears to be, or is necessary.
  4271. However, even if you are new to the atomic operations paradigm, or more
  4272. familiar with transactions, do consider the speed benefit that
  4273. non-transactional tables can offer on the order of three to five times
  4274. the speed of the fastest and most optimally tuned transactional tables.
  4275.  
  4276. In situations where integrity is of highest importance, MySQL Server
  4277. offers transaction-level reliability and integrity even for
  4278. non-transactional tables.  If you lock tables with `LOCK TABLES', all
  4279. updates will stall until any integrity checks are made. If you obtain a
  4280. `READ LOCAL' lock (as opposed to a write lock) for a table that allows
  4281. concurrent inserts at the end of the table, reads are allowed, as are
  4282. inserts by other clients.  The new inserted records will not be seen by
  4283. the client that has the read lock until it releases the lock.  With
  4284. `INSERT DELAYED', you can queue inserts into a local queue, until the
  4285. locks are released, without having the client wait for the insert to
  4286. complete. *Note INSERT DELAYED::.
  4287.  
  4288. "Atomic," in the sense that we mean it, is nothing magical. It only
  4289. means that you can be sure that while each specific update is running,
  4290. no other user can interfere with it, and there will never be an
  4291. automatic rollback (which can happen with transactional tables if you
  4292. are not very careful).  MySQL Server also guarantees that there will
  4293. not be any dirty reads.
  4294.  
  4295. Following are some techniques for working with non-transactional tables:
  4296.  
  4297.    * Loops that need transactions normally can be coded with the help of
  4298.      `LOCK TABLES', and you don't need cursors to update records on the
  4299.      fly.
  4300.  
  4301.    * To avoid using `ROLLBACK', you can use the following strategy:
  4302.  
  4303.        1. Use `LOCK TABLES' to lock all the tables you want to access.
  4304.  
  4305.        2. Test the conditions that must be true before performing the
  4306.           update.
  4307.  
  4308.        3. Update if everything is okay.
  4309.  
  4310.        4. Use `UNLOCK TABLES' to release your locks.
  4311.  
  4312.      This is usually a much faster method than using transactions with
  4313.      possible rollbacks, although not always. The only situation this
  4314.      solution doesn't handle is when someone kills the threads in the
  4315.      middle of an update. In this case, all locks will be released but
  4316.      some of the updates may not have been executed.
  4317.  
  4318.    * You can also use functions to update records in a single operation.
  4319.      You can get a very efficient application by using the following
  4320.      techniques:
  4321.  
  4322.         * Modify columns relative to their current value.
  4323.  
  4324.         * Update only those columns that actually have changed.
  4325.  
  4326.      For example, when we are doing updates to some customer
  4327.      information, we update only the customer data that has changed and
  4328.      test only that none of the changed data, or data that depends on
  4329.      the changed data, has changed compared to the original row. The
  4330.      test for changed data is done with the `WHERE' clause in the
  4331.      `UPDATE' statement. If the record wasn't updated, we give the
  4332.      client a message: "Some of the data you have changed has been
  4333.      changed by another user." Then we show the old row versus the new
  4334.      row in a window so that the user can decide which version of the
  4335.      customer record to use.
  4336.  
  4337.      This gives us something that is similar to column locking but is
  4338.      actually even better because we only update some of the columns,
  4339.      using values that are relative to their current values.  This
  4340.      means that typical `UPDATE' statements look something like these:
  4341.  
  4342.           UPDATE tablename SET pay_back=pay_back+125;
  4343.           
  4344.           UPDATE customer
  4345.             SET
  4346.               customer_date='current_date',
  4347.               address='new address',
  4348.               phone='new phone',
  4349.               money_owed_to_us=money_owed_to_us-125
  4350.             WHERE
  4351.               customer_id=id AND address='old address' AND phone='old phone';
  4352.  
  4353.      This is very efficient and works even if another client has
  4354.      changed the values in the `pay_back' or `money_owed_to_us' columns.
  4355.  
  4356.    * In many cases, users have wanted `LOCK TABLES' and/or `ROLLBACK'
  4357.      for the purpose of managing unique identifiers.  This can be
  4358.      handled much more efficiently without locking or rolling back by
  4359.      using an `AUTO_INCREMENT' column and either the `LAST_INSERT_ID()'
  4360.      SQL function or the `mysql_insert_id()' C API function.  *Note
  4361.      Information functions::.  *Note `mysql_insert_id()':
  4362.      mysql_insert_id.
  4363.  
  4364.      You can generally code around the need for row-level locking. Some
  4365.      situations really do need it, and `InnoDB' tables support
  4366.      row-level locking. With `MyISAM' tables, you can use a flag column
  4367.      in the table and do something like the following:
  4368.  
  4369.           UPDATE TBL_NAME SET row_flag=1 WHERE id=ID;
  4370.  
  4371.      MySQL returns 1 for the number of affected rows if the row was
  4372.      found and `row_flag' wasn't already 1 in the original row.
  4373.  
  4374.      You can think of it as though MySQL Server changed the preceding
  4375.      query to:
  4376.  
  4377.           UPDATE TBL_NAME SET row_flag=1 WHERE id=ID AND row_flag <> 1;
  4378.  
  4379. Stored Procedures and Triggers
  4380. ..............................
  4381.  
  4382. Stored procedures are implemented in MySQL version 5.0.  *Note Stored
  4383. Procedures::.
  4384.  
  4385. Triggers are scheduled for implementation in MySQL version 5.1. A
  4386. "trigger" is effectively a type of stored procedure, one that is
  4387. invoked when a particular event occurs.  For example, you could set up
  4388. a stored procedure that is triggered each time a record is deleted from
  4389. a transactional table, and that stored procedure automatically deletes
  4390. the corresponding customer from a customer table when all their
  4391. transactions are deleted.
  4392.  
  4393. Foreign Keys
  4394. ............
  4395.  
  4396. In MySQL Server 3.23.44 and up, the `InnoDB' storage engine supports
  4397. checking of foreign key constraints, including `CASCADE', `ON DELETE',
  4398. and `ON UPDATE'. *Note InnoDB foreign key constraints::.
  4399.  
  4400. For storage engines other than `InnoDB', MySQL Server parses the
  4401. `FOREIGN KEY' syntax in `CREATE TABLE' statements, but does not use or
  4402. store it. In the future, the implementation will be extended to store
  4403. this information in the table specification file so that it may be
  4404. retrieved by `mysqldump' and ODBC.  At a later stage, foreign key
  4405. constraints will be implemented for `MyISAM' tables as well.
  4406.  
  4407. Foreign key enforcement offers several benefits to database developers:
  4408.  
  4409.    * Assuming proper design of the relationships, foreign key
  4410.      constraints make it more difficult for a programmer to introduce
  4411.      an inconsistency into the database.
  4412.  
  4413.    * Centralized checking of constraints by the database server makes it
  4414.      unnecessary to perform these checks on the application side. This
  4415.      eliminates the possibility that different applications may not all
  4416.      check the constraints in the same way.
  4417.  
  4418.    * Using cascading updates and deletes can simplify the application
  4419.      code.
  4420.  
  4421.    * Properly designed foreign key rules aid in documenting
  4422.      relationships between tables.
  4423.  
  4424. Do keep in mind that these benefits come at the cost of additional
  4425. overhead for the database server to perform the necessary checks.
  4426. Additional checking by the server affects performance, which for some
  4427. applications may be sufficiently undesirable as to be avoided if
  4428. possible.  (Some major commercial applications have coded the
  4429. foreign-key logic at the application level for this reason.)
  4430.  
  4431. MySQL gives database developers the choice of which approach to use. If
  4432. you don't need foreign keys and want to avoid the overhead associated
  4433. with enforcing referential integrity, you can choose another table type
  4434. instead, such as `MyISAM'. (For example, the `MyISAM' storage engine
  4435. offers very fast performance for applications that perform only
  4436. `INSERT' and `SELECT' operations, because the inserts can be performed
  4437. concurrently with retrievals.  *Note Table locking::.)
  4438.  
  4439. If you choose not to take advantage of referential integrity checks,
  4440. keep the following considerations in mind:
  4441.  
  4442.    * In the absence of server-side foreign key relationship checking,
  4443.      the application itself must handle relationship issues.  For
  4444.      example, it must take care to insert rows into tables in the proper
  4445.      order, and to avoid creating orphaned child records. It must also
  4446.      be able to recover from errors that occur in the middle of
  4447.      multiple-record insert operations.
  4448.  
  4449.    * If `ON DELETE' is the only referential integrity capability an
  4450.      application needs, note that as of MySQL Server 4.0, you can use
  4451.      multiple-table `DELETE' statements to delete rows from many tables
  4452.      with a single statement. *Note `DELETE': DELETE.
  4453.  
  4454.    * A workaround for the lack of `ON DELETE' is to add the appropriate
  4455.      `DELETE' statement to your application when you delete records
  4456.      from a table that has a foreign key. In practice, this is often as
  4457.      quick as using foreign keys, and is more portable.
  4458.  
  4459.  
  4460. Be aware that the use of foreign keys can in some instances lead to
  4461. problems:
  4462.  
  4463.    * Foreign key support addresses many referential integrity issues,
  4464.      but it is still necessary to design key relationships carefully to
  4465.      avoid circular rules or incorrect combinations of cascading
  4466.      deletes.
  4467.  
  4468.    * It is not uncommon for a DBA to create a topology of relationships
  4469.      that makes it difficult to restore individual tables from a backup.
  4470.      (MySQL alleviates this difficulty by allowing you to temporarily
  4471.      disable foreign key checks when reloading a table that depends on
  4472.      other tables.  *Note InnoDB foreign key constraints::.  As of
  4473.      MySQL 4.1.1, `mysqldump' generates dump files that take advantage
  4474.      of this capability automatically when reloaded.)
  4475.  
  4476. Note that foreign keys in SQL are used to check and enforce referential
  4477. integrity, not to join tables.  If you want to get results from multiple
  4478. tables from a `SELECT' statement, you do this by performing a join
  4479. between them:
  4480.  
  4481.      SELECT * FROM t1, t2 WHERE t1.id = t2.id;
  4482.  
  4483. *Note `JOIN': JOIN. *Note example-Foreign keys::.
  4484.  
  4485. The `FOREIGN KEY' syntax without `ON DELETE ...' is often used by ODBC
  4486. applications to produce automatic `WHERE' clauses.
  4487.  
  4488. Views
  4489. .....
  4490.  
  4491. Views are being implemented in the 5.0 version of MySQL Server. While
  4492. still under development, they are already available in the 5.0 BitKeeper
  4493. tree and will be present in binary releases from 5.0.1.  Unnamed views
  4494. (_derived tables_, a subquery in the `FROM' clause of a `SELECT') are
  4495. already implemented in version 4.1.  Unqualified union views (`SELECT
  4496. ... UNION SELECT ...' are also available through the `MERGE' table
  4497. feature.  *Note MERGE::.
  4498.  
  4499. Historically, MySQL Server has been most used in applications and on Web
  4500. systems where the application writer has full control over database
  4501. usage. Usage has shifted over time, and so we find that an increasing
  4502. number of users now regard views as an important feature.
  4503.  
  4504. Views are useful for allowing users to access a set of relations
  4505. (tables) as if it were a single table, and limiting their access to
  4506. just that.  Views can also be used to restrict access to rows (a subset
  4507. of a particular table).  For access control to columns, you can also
  4508. use the sophisticated privilege system in MySQL Server.  *Note
  4509. Privilege system::.
  4510.  
  4511. Many DBMS don't allow updates to a view. Instead, you have to perform
  4512. the updates on the individual tables.  In designing an implementation
  4513. of views, our goal, as much as is possible within the confines of SQL,
  4514. is full compliance with "Codd's Rule #6" for relational database
  4515. systems: All views that are theoretically updatable, should in practice
  4516. also be updatable.
  4517.  
  4518. `--' as the Start of a Comment
  4519. ..............................
  4520.  
  4521. Some other SQL databases use `--' to start comments.  MySQL Server uses
  4522. `#' as the start comment character. You can also use the C comment
  4523. style `/* this is a comment */' with MySQL Server.  *Note Comments::.
  4524.  
  4525. MySQL Server 3.23.3 and above support the `--' comment style, provided
  4526. the comment is followed by a space (or by a control character such as a
  4527. newline). The requirement for a space is to prevent problems with
  4528. automatically generated SQL queries that have used something like the
  4529. following code, where we automatically insert the value of the payment
  4530. for `!payment!':
  4531.  
  4532.      UPDATE account SET credit=credit-!payment!
  4533.  
  4534. Think about what happens if the value of `payment' is a negative value
  4535. such as `-1':
  4536.  
  4537.      UPDATE account SET credit=credit--1
  4538.  
  4539. `credit--1' is a legal expression in SQL, but if `--' is interpreted as
  4540. the start of a comment, part of the expression is discarded. The result
  4541. is a statement that has a completely different meaning than intended:
  4542.  
  4543.      UPDATE account SET credit=credit
  4544.  
  4545. The statement produces no change in value at all!  This illustrates that
  4546. allowing comments to start with `--' can have serious consequences.
  4547.  
  4548. Using our implementation of this method of commenting in MySQL Server
  4549. 3.23.3 and up, `credit--1' is actually safe.
  4550.  
  4551. Another safe feature is that the `mysql' command-line client removes
  4552. all lines that start with `--'.
  4553.  
  4554. The following information is relevant only if you are running a MySQL
  4555. version earlier than 3.23.3:
  4556.  
  4557. If you have an SQL program in a text file that contains `--' comments,
  4558. you should use the `replace' utility as follows to convert the comments
  4559. to use `#' characters:
  4560.  
  4561.      shell> replace " --" " #" < text-file-with-funny-comments.sql \
  4562.               | mysql DB_NAME
  4563.  
  4564. instead of the usual:
  4565.  
  4566.      shell> mysql DB_NAME < text-file-with-funny-comments.sql
  4567.  
  4568. You can also edit the command file "in place" to change the `--'
  4569. comments to `#' comments:
  4570.  
  4571.      shell> replace " --" " #" -- text-file-with-funny-comments.sql
  4572.  
  4573. Change them back with this command:
  4574.  
  4575.      shell> replace " #" " --" -- text-file-with-funny-comments.sql
  4576.  
  4577. How MySQL Deals with Constraints
  4578. --------------------------------
  4579.  
  4580. MySQL allows you to work with both transactional tables that allow
  4581. rollback and non-transactional tables that do not, so constraint
  4582. handling is a bit different in MySQL than in other databases.
  4583.  
  4584. We have to handle the case when you have updated a lot of rows in a
  4585. non-transactional table that cannot roll back when an error occurs.
  4586.  
  4587. The basic philosophy is to try to give an error for anything that we can
  4588. detect at compile time but try to recover from any errors we get at
  4589. runtime.  We do this in most cases, but not yet for all. *Note TODO
  4590. future::.
  4591.  
  4592. The options MySQL has when an error occurs are to stop the statement in
  4593. the middle or to recover as well as possible from the problem and
  4594. continue.
  4595.  
  4596. The following sections describe what happens for the different types of
  4597. constraints.
  4598.  
  4599. Constraint `PRIMARY KEY' / `UNIQUE'
  4600. ...................................
  4601.  
  4602. Normally you will get an error when you try to `INSERT' or `UPDATE' a
  4603. row that causes a primary key, unique key, or foreign key violation.
  4604. If you are using a transactional storage engine such as `InnoDB', MySQL
  4605. will automatically roll back the transaction.  If you are using a
  4606. non-transactional storage engine, MySQL will stop at the incorrect row
  4607. and leave any remaining rows unprocessed.
  4608.  
  4609. To make life easier, MySQL supports an `IGNORE' keyword for most
  4610. commands that can cause a key violation (such as `INSERT IGNORE' and
  4611. `UPDATE IGNORE'). In this case, MySQL will ignore any key violation and
  4612. continue with processing the next row.  You can get information about
  4613. what MySQL did with the `mysql_info()' C API function.  *Note
  4614. `mysql_info()': mysql_info.  In MySQL 4.1 and up, you also can use the
  4615. `SHOW WARNINGS' statement.  *Note SHOW WARNINGS::.
  4616.  
  4617. Note that, for the moment, only `InnoDB' tables support foreign keys.
  4618. *Note InnoDB foreign key constraints::.  Foreign key support in
  4619. `MyISAM' tables is scheduled for implementation in MySQL 5.1.
  4620.  
  4621. Constraint `NOT NULL' and `DEFAULT' Values
  4622. ..........................................
  4623.  
  4624. To be able to support easy handling of non-transactional tables, all
  4625. columns in MySQL have default values.
  4626.  
  4627. If you insert an "incorrect" value into a column, such as a `NULL' into
  4628. a `NOT NULL' column or a too-large numerical value into a numerical
  4629. column, MySQL sets the column to the "best possible value" instead of
  4630. producing an error:
  4631.  
  4632.    * If you try to store a value outside the range in a numerical
  4633.      column, MySQL Server instead stores zero, the smallest possible
  4634.      value, or the largest possible value in the column.
  4635.  
  4636.    * For strings, MySQL stores either the empty string or the longest
  4637.      possible string that can be in the column.
  4638.  
  4639.    * If you try to store a string that doesn't start with a number into
  4640.      a numerical column, MySQL Server stores 0.
  4641.  
  4642.    * If you try to store `NULL' into a column that doesn't take `NULL'
  4643.      values, MySQL Server stores 0 or `''' (the empty string) instead.
  4644.      This last behavior can, for single-row inserts, be changed when
  4645.      MySQL is built by using the `-DDONT_USE_DEFAULT_FIELDS' compile
  4646.      option.) *Note `configure' options: configure options.  This
  4647.      causes `INSERT' statements to generate an error unless you
  4648.      explicitly specify values for all columns that require a
  4649.      non-`NULL' value.
  4650.  
  4651.    * MySQL allows you to store some incorrect date values into `DATE'
  4652.      and `DATETIME' columns (like `'2000-02-31'' or `'2000-02-00'').
  4653.      The idea is that it's not the job of the SQL server to validate
  4654.      dates. If MySQL can store a date value and retrieve exactly the
  4655.      same value, MySQL stores it as given.  If the date is totally
  4656.      wrong (outside the server's ability to store it), the special date
  4657.      value `'0000-00-00'' is stored in the column instead.
  4658.  
  4659.  
  4660. The reason for the preceding rules is that we can't check these
  4661. conditions until the query has begun executing.  We can't just roll
  4662. back if we encounter a problem after updating a few rows, because the
  4663. table type may not support rollback.  The option of terminating the
  4664. statement is not that good; in this case, the update would be "half
  4665. done," which is probably the worst possible scenario.  In this case,
  4666. it's better to "do the best you can" and then continue as if nothing
  4667. happened.
  4668.  
  4669. This means that you should generally not use MySQL to check column
  4670. content.  Instead, the application should ensure that it passes only
  4671. legal values to MySQL.
  4672.  
  4673. In MySQL 5.0, we plan to improve this by providing warnings when
  4674. automatic column conversions occur, plus an option to let you roll back
  4675. statements that attempt to perform a disallowed column value
  4676. assignment, as long as the statement uses only transactional tables.
  4677.  
  4678. Constraint `ENUM' and `SET'
  4679. ...........................
  4680.  
  4681. In MySQL 4.x, `ENUM' is not a real constraint, but is a more efficient
  4682. way to define columns that can contain only a given set of values.
  4683. This is for the same reasons that `NOT NULL' is not honored.  *Note
  4684. constraint NOT NULL::.
  4685.  
  4686. If you insert an incorrect value into an `ENUM' column, it is set to
  4687. the reserved enumeration value of `0', which is displayed as an empty
  4688. string in string context. *Note ENUM::.
  4689.  
  4690. If you insert an incorrect value into a `SET' column, the incorrect
  4691. value is ignored. For example, if the column can contain the values
  4692. `'a'', `'b'', and `'c'', an attempt to assign `'a,x,b,y'' results in a
  4693. value of `'a,b''.  *Note SET::.
  4694.  
  4695. Known Errors and Design Deficiencies in MySQL
  4696. ---------------------------------------------
  4697.  
  4698. Errors in 3.23 Fixed in a Later MySQL Version
  4699. .............................................
  4700.  
  4701. The following known errors or bugs are not fixed in MySQL 3.23 because
  4702. fixing them would involve changing a lot of code that could introduce
  4703. other even worse bugs. The bugs are also classified as "not fatal" or
  4704. "bearable."
  4705.  
  4706.    * One should avoid having space at end of field names as this can
  4707.      cause weird behaviour. (Fixed in MySQL 4.0). (Bug #4196)
  4708.  
  4709.    * You can get a deadlock (hung thread) if you use `LOCK TABLE' to
  4710.      lock multiple tables and then in the same connection use `DROP
  4711.      TABLE' to drop one of them while another thread is trying to lock
  4712.      it.  (To break the deadlock, you can use `KILL' to terminate any
  4713.      of the threads involved.)  This issue is resolved as of MySQL
  4714.      4.0.12.
  4715.  
  4716.    * `SELECT MAX(key_column) FROM t1,t2,t3...' where one of the tables
  4717.      are empty doesn't return `NULL' but instead returns the maximum
  4718.      value for the column.  This issue is resolved as of MySQL 4.0.11.
  4719.  
  4720.    * `DELETE FROM heap_table' without a `WHERE' clause doesn't work on
  4721.      a locked `HEAP' table.
  4722.  
  4723. Errors in 4.0 Fixed in a Later MySQL Version
  4724. ............................................
  4725.  
  4726. The following known errors or bugs are not fixed in MySQL 4.0 because
  4727. fixing them would involve changing a lot of code that could introduce
  4728. other even worse bugs. The bugs are also classified as "not fatal" or
  4729. "bearable."
  4730.  
  4731.    * In a `UNION', the first `SELECT' determines the type,
  4732.      `max_length', and `NULL' properties for the resulting columns.
  4733.      This issue is resolved as of MySQL 4.1.1; the property values are
  4734.      based on the rows from all `UNION' parts.
  4735.  
  4736.    * In `DELETE' with many tables, you can't refer to tables to be
  4737.      deleted through an alias. This is fixed as of MySQL 4.1.
  4738.  
  4739.    * You cannot mix `UNION ALL' and `UNION DISTINCT' in the same query.
  4740.      If you use `ALL' for one `UNION', it is used for all of them.
  4741.      This is fixed as of MySQL 4.1.2. The rules for mixed `UNION' types
  4742.      are given in *Note `UNION': UNION.
  4743.  
  4744. Open Bugs and Design Deficiencies in MySQL
  4745. ..........................................
  4746.  
  4747. The following problems are known and fixing them is a high priority:
  4748.  
  4749.    * Even if you are using `lower_case_table_names=2' (which enables
  4750.      MySQL to remember the used case for databases and table names)
  4751.      MySQL will not on case insensitive systems remember the used case
  4752.      for database names for the function `DATABASE()' or in various
  4753.      logs.
  4754.  
  4755.    * Dropping a `FOREIGN KEY' constraint doesn't work in replication
  4756.      because the constraint may have another name on the slave.
  4757.  
  4758.    * `REPLACE' (and `LOAD DATA' with the `REPLACE' option) does not
  4759.      trigger `ON DELETE CASCADE'.
  4760.  
  4761.    * `DISTINCT' with `ORDER BY' doesn't work inside `GROUP_CONCAT()' if
  4762.      you don't use all and only those columns that are in the
  4763.      `DISTINCT' list.
  4764.  
  4765.    * `GROUP_CONCAT()' doesn't work with `BLOB'/`TEXT' columns when you
  4766.      use `DISTINCT' or `ORDER BY' inside `GROUP_CONCAT()'. To work
  4767.      around this limitation, use `MID(EXPR,1,255)' instead.
  4768.  
  4769.    * If one user has a long-running transaction and another user drops a
  4770.      table that is updated in the transaction, there is small chance
  4771.      that the binary log may contain the `DROP TABLE' command before
  4772.      the table is used in the transaction itself.  We plan to fix this
  4773.      in 5.0 by having the `DROP TABLE' wait until the table is not used
  4774.      in any transaction.
  4775.  
  4776.    * When inserting a big integer value (between 2^63 and 2^64-1) into a
  4777.      decimal/string column, it is inserted as a negative value because
  4778.      the number is evaluated in a signed integer context. We plan to
  4779.      fix this in MySQL 4.1.
  4780.  
  4781.    * `FLUSH TABLES WITH READ LOCK' does not block `CREATE TABLE' or
  4782.      `COMMIT', which may cause a problem with the binary log position
  4783.      when doing a full backup of tables and the binary log.
  4784.  
  4785.    * `ANALYZE TABLE' on a `BDB' table may in some cases make the table
  4786.      unusable until you restart `mysqld'.  If this happens, you will
  4787.      see errors of the following form in the MySQL error file:
  4788.  
  4789.           001207 22:07:56  bdb:  log_flush: LSN past current end-of-log
  4790.  
  4791.    * MySQL accepts parentheses in the `FROM' clause of a `SELECT'
  4792.      statement, but silently ignores them.  The reason for not giving
  4793.      an error is that many clients that automatically generate queries
  4794.      add parentheses in the `FROM' clause even where they are not
  4795.      needed.
  4796.  
  4797.    * Concatenating many `RIGHT JOINS' or combining `LEFT' and `RIGHT'
  4798.      join in the same query may not give a correct answer because MySQL
  4799.      only generates `NULL' rows for the table preceding a `LEFT' or
  4800.      before a `RIGHT' join.  This will be fixed in 5.0 at the same time
  4801.      we add support for parentheses in the `FROM' clause.
  4802.  
  4803.    * Don't execute `ALTER TABLE' on a `BDB' table on which you are
  4804.      running multiple-statement transactions until all those
  4805.      transactions complete.  (The transaction will probably be ignored.)
  4806.  
  4807.    * `ANALYZE TABLE', `OPTIMIZE TABLE', and `REPAIR TABLE' may cause
  4808.      problems on tables for which you are using `INSERT DELAYED'.
  4809.  
  4810.    * Doing a `LOCK TABLE ...' and `FLUSH TABLES ...' doesn't guarantee
  4811.      that there isn't a half-finished transaction in progress on the
  4812.      table.
  4813.  
  4814.    * `BDB' tables are a bit slow to open. If you have many `BDB' tables
  4815.      in a database, it will take a long time to use the `mysql' client
  4816.      on the database if you are not using the `-A' option or if you are
  4817.      using `rehash'. This is especially notable when you have a large
  4818.      table cache.
  4819.  
  4820.    * Replication uses query-level logging: The master writes the
  4821.      executed queries to the binary log. This is a very fast, compact,
  4822.      and efficient logging method that works perfectly in most cases.
  4823.      Although we have never heard of it actually occurring, it is
  4824.      theoretically possible for the data on the master and slave to
  4825.      become different if a query is designed in such a way that the
  4826.      data modification is non-deterministic; that is, left to the will
  4827.      of the query optimizer. (That generally is not a good practice
  4828.      anyway, even outside of replication!)  For example:
  4829.  
  4830.         - `CREATE ... SELECT' or `INSERT ... SELECT'  statements that
  4831.           insert zero or `NULL' values into an `AUTO_INCREMENT' column.
  4832.  
  4833.         - `DELETE' if you are deleting rows from a table that has
  4834.           foreign keys with `ON DELETE CASCADE' properties.
  4835.  
  4836.         - `REPLACE ... SELECT', `INSERT IGNORE ... SELECT' if you have
  4837.           duplicate key values in the inserted data.
  4838.      *If and only if all these queries have no `ORDER BY' clause
  4839.      guaranteeing a deterministic order*.
  4840.  
  4841.      For example, for `INSERT ... SELECT' with no `ORDER BY', the
  4842.      `SELECT' may return rows in a different order (which will result
  4843.      in a row having different ranks, hence getting a different number
  4844.      in the `AUTO_INCREMENT' column), depending on the choices made by
  4845.      the optimizers on the master and slave. A query will be optimized
  4846.      differently on the master and slave only if:
  4847.  
  4848.         - The files used by the two queries are not exactly the same;
  4849.           for example, `OPTIMIZE TABLE' was run on the master tables
  4850.           and not on the slave tables. (To fix this, `OPTIMIZE TABLE',
  4851.           `ANALYZE TABLE', and `REPAIR TABLE' are written to the binary
  4852.           log as of MySQL 4.1.1).
  4853.  
  4854.         - The table is stored using a different storage engine on the
  4855.           master than on the slave. (It is possible to use different
  4856.           storage engines on the master and slave. For example, you can
  4857.           use `InnoDB' on the master, but `MyISAM' on the slave if the
  4858.           slave has less available disk space.)
  4859.  
  4860.         - MySQL buffer sizes (`key_buffer_size', and so on) are
  4861.           different on the master and slave.
  4862.  
  4863.         - The master and slave run different MySQL versions, and the
  4864.           optimizer code differs between these versions.
  4865.  
  4866.      This problem may also affect database restoration using
  4867.      `mysqlbinlog|mysql'.
  4868.  
  4869.      The easiest way to avoid this problem in all cases is to add an
  4870.      `ORDER BY' clause to such non-deterministic queries to ensure that
  4871.      the rows are always stored or modified in the same order.  In
  4872.      future MySQL versions, we will automatically add an `ORDER BY'
  4873.      clause when needed.
  4874.  
  4875.  
  4876. The following problems are known and will be fixed in due time:
  4877.  
  4878.    * Log filenames are based on the server hostname (if you don't
  4879.      specify a filename with the startup option). For now you have to
  4880.      use options like `--log-bin=OLD_HOST_NAME-bin' if you change your
  4881.      hostname to something else. Another option is to just rename the
  4882.      old files to reflect your hostname change. *Note Server options::.
  4883.  
  4884.    * `mysqlbinlog' will not delete temporary files left after a `LOAD
  4885.      DATA INFILE' command. *Note `mysqlbinlog': mysqlbinlog.
  4886.  
  4887.    * `RENAME' doesn't work with `TEMPORARY' tables or tables used in a
  4888.      `MERGE' table.
  4889.  
  4890.    * When using the `RPAD()' function in a query that has to be
  4891.      resolved by using a temporary table, all resulting strings will
  4892.      have rightmost spaces removed. This is an example of such a query:
  4893.  
  4894.           SELECT RPAD(t1.column1, 50, ' ') AS f2, RPAD(t2.column2, 50, ' ') AS f1
  4895.           FROM table1 as t1 LEFT JOIN table2 AS t2 ON t1.record=t2.joinID
  4896.           ORDER BY t2.record;
  4897.  
  4898.      The final result of this bug is that you will not be able to get
  4899.      spaces on the right side of the resulting values. The problem also
  4900.      occurs for any other string function that adds spaces to the right.
  4901.  
  4902.      The reason for this is due to the fact that `HEAP' tables, which
  4903.      are used first for temporary tables, are not capable of handling
  4904.      `VARCHAR' columns.
  4905.  
  4906.      This behavior exists in all versions of MySQL.  It will be fixed
  4907.      in one of the 4.1 series releases.
  4908.  
  4909.    * Due to the way table definition files are stored, you cannot use
  4910.      character 255 (`CHAR(255)') in table names, column names, or
  4911.      enumerations.  This is scheduled to be fixed in version 5.1 when
  4912.      we have new table definition format files.
  4913.  
  4914.    * When using `SET CHARACTER SET', you can't use translated
  4915.      characters in database, table, and column names.
  4916.  
  4917.    * You can't use `_' or `%' with `ESCAPE' in `LIKE ... ESCAPE'.
  4918.  
  4919.    * If you have a `DECIMAL' column in which the same number is stored
  4920.      in different formats (for example, `+01.00', `1.00', `01.00'),
  4921.      `GROUP BY' may regard each value as a different value.
  4922.  
  4923.    * You cannot build the server in another directory when using
  4924.      MIT-pthreads. Because this requires changes to MIT-pthreads, we
  4925.      are not likely to fix this. *Note MIT-pthreads::.
  4926.  
  4927.    * `BLOB' values can't "reliably" be used in `GROUP BY' or `ORDER BY'
  4928.      or `DISTINCT'. Only the first `max_sort_length' bytes are used
  4929.      when comparing `BLOB' values in these cases.  The default value of
  4930.      `max_sort_length' value is 1024. It can be changed at server
  4931.      startup time.  A workaround for most cases is to use a substring.
  4932.      For example: `SELECT DISTINCT LEFT(blob_col,2048) FROM TBL_NAME'.
  4933.  
  4934.    * Numeric calculations are done with `BIGINT' or `DOUBLE' (both are
  4935.      normally 64 bits long). Which precision you get depends on the
  4936.      function.  The general rule is that bit functions are done with
  4937.      `BIGINT' precision, `IF' and `ELT()' with `BIGINT' or `DOUBLE'
  4938.      precision, and the rest with `DOUBLE' precision.  You should try to
  4939.      avoid using unsigned long long values if they resolve to be bigger
  4940.      than 63 bits (9223372036854775807) for anything other than bit
  4941.      fields.  MySQL Server 4.0 has better `BIGINT' handling than 3.23.
  4942.  
  4943.    * All string columns, except `BLOB' and `TEXT' columns, automatically
  4944.      have all trailing spaces removed when retrieved. For `CHAR' types,
  4945.      this is okay. The bug is that in MySQL Server, `VARCHAR' columns
  4946.      are treated the same way.
  4947.  
  4948.    * You can have only up to 255 `ENUM' and `SET' columns in one table.
  4949.  
  4950.    * In `MIN()', `MAX()', and other aggregate functions, MySQL
  4951.      currently compares `ENUM' and `SET' columns by their string value
  4952.      rather than by the string's relative position in the set.
  4953.  
  4954.    * `mysqld_safe' redirects all messages from `mysqld' to the `mysqld'
  4955.      log.  One problem with this is that if you execute `mysqladmin
  4956.      refresh' to close and reopen the log, `stdout' and `stderr' are
  4957.      still redirected to the old log.  If you use `--log' extensively,
  4958.      you should edit `mysqld_safe' to log to `HOST_NAME.err' instead of
  4959.      `HOST_NAME.log' so that you can easily reclaim the space for the
  4960.      old log by deleting the old one and executing `mysqladmin refresh'.
  4961.  
  4962.    * In the `UPDATE' statement, columns are updated from left to right.
  4963.      If you refer to an updated column, you get the updated value
  4964.      instead of the original value. For example, the following
  4965.      statement increments `KEY' by `2', not `1':
  4966.  
  4967.           mysql> UPDATE TBL_NAME SET KEY=KEY+1,KEY=KEY+1;
  4968.  
  4969.    * You can refer to multiple temporary tables in the same query, but
  4970.      you cannot refer to any given temporary table more than once.  For
  4971.      example, the following doesn't work:
  4972.  
  4973.           mysql> SELECT * FROM temp_table, temp_table AS t2;
  4974.           ERROR 1137: Can't reopen table: 'temp_table'
  4975.  
  4976.    * The optimizer may handle `DISTINCT' differently when you are using
  4977.      "hidden" columns in a join than when you are not.  In a join,
  4978.      hidden columns are counted as part of the result (even if they are
  4979.      not shown), whereas in normal queries, hidden columns don't
  4980.      participate in the `DISTINCT' comparison.  We will probably change
  4981.      this in the future to never compare the hidden columns when
  4982.      executing `DISTINCT'.
  4983.  
  4984.      An example of this is:
  4985.  
  4986.           SELECT DISTINCT mp3id FROM band_downloads
  4987.                  WHERE userid = 9 ORDER BY id DESC;
  4988.  
  4989.      and
  4990.  
  4991.           SELECT DISTINCT band_downloads.mp3id
  4992.                  FROM band_downloads,band_mp3
  4993.                  WHERE band_downloads.userid = 9
  4994.                  AND band_mp3.id = band_downloads.mp3id
  4995.                  ORDER BY band_downloads.id DESC;
  4996.  
  4997.      In the second case, you might in MySQL Server 3.23.x get two
  4998.      identical rows in the result set (because the values in the hidden
  4999.      `id' column may differ).
  5000.  
  5001.      Note that this happens only for queries where you don't have the
  5002.      `ORDER BY' columns in the result.
  5003.  
  5004.    * Because MySQL Server allows you to work with table types that don't
  5005.      support transactions, and thus can't roll back data, some things
  5006.      behave a little differently in MySQL Server than in other SQL
  5007.      servers.  This is just to ensure that MySQL Server never needs to
  5008.      do a rollback for an SQL statement.  This may be a little awkward
  5009.      at times because column values must be checked in the application,
  5010.      but this will actually give you a nice speed increase because it
  5011.      allows MySQL Server to do some optimizations that otherwise would
  5012.      be very hard to do.
  5013.  
  5014.      If you set a column to an incorrect value, MySQL Server will,
  5015.      instead of doing a rollback, store the "best possible value" in
  5016.      the column. For information about how this occurs, see *Note
  5017.      Constraints::.
  5018.  
  5019.    * If you execute a `PROCEDURE' on a query that returns an empty set,
  5020.      in some cases the `PROCEDURE' will not transform the columns.
  5021.  
  5022.    * Creation of a table of type `MERGE' doesn't check whether the
  5023.      underlying tables are of compatible types.
  5024.  
  5025.    * If you use `ALTER TABLE' first to add a `UNIQUE' index to a table
  5026.      used in a `MERGE' table and then to add a normal index on the
  5027.      `MERGE' table, the key order will be different for the tables if
  5028.      there was an old key that was not unique in the table. This is
  5029.      because `ALTER TABLE' puts `UNIQUE' indexes before normal indexes
  5030.      to be able to detect duplicate keys as early as possible.
  5031.  
  5032. The following are known bugs in earlier versions of MySQL:
  5033.  
  5034.    * In the following case you can get a core dump:
  5035.  
  5036.         - Delayed insert handler has pending inserts to a table.
  5037.  
  5038.         - `LOCK TABLE' with `WRITE'.
  5039.  
  5040.         - `FLUSH TABLES'.
  5041.  
  5042.    * Before MySQL Server 3.23.2, an `UPDATE' that updated a key with a
  5043.      `WHERE' on the same key may have failed because the key was used to
  5044.      search for records and the same row may have been found multiple
  5045.      times:
  5046.  
  5047.           UPDATE TBL_NAME SET KEY=KEY+1 WHERE KEY > 100;
  5048.  
  5049.      A workaround is to use:
  5050.  
  5051.           UPDATE TBL_NAME SET KEY=KEY+1 WHERE KEY+0 > 100;
  5052.  
  5053.      This will work because MySQL Server will not use an index on
  5054.      expressions in the `WHERE' clause.
  5055.  
  5056.    * Before MySQL Server 3.23, all numeric types were treated as
  5057.      fixed-point fields. That means that you had to specify how many
  5058.      decimals a floating-point field should have. All results were
  5059.      returned with the correct number of decimals.
  5060.  
  5061. For information about platform-specific bugs, see the installation and
  5062. porting instructions in *Note Operating System Specific Notes:: and
  5063. *Note Porting::.
  5064.  
  5065. Installing MySQL
  5066. ****************
  5067.  
  5068. This chapter describes how to obtain and install MySQL:
  5069.  
  5070.   1. *Determine whether your platform is supported.*  Please note that
  5071.      not all supported systems are equally good for running MySQL on
  5072.      them.  On some it is much more robust and efficient than others.
  5073.      See *Note Which OS:: for details.
  5074.  
  5075.   2. *Choose which distribution to install.*  Several versions of MySQL
  5076.      are available, and most are available in several distribution
  5077.      formats.  You can choose from pre-packaged distributions
  5078.      containing binary (precompiled) programs or source code.  When in
  5079.      doubt, use a binary distribution.  We also provide public access
  5080.      to our current source tree for those who want to see our most
  5081.      recent developments and help us test new code.  To determine which
  5082.      version and type of distribution you should use, see *Note Which
  5083.      version::.
  5084.  
  5085.   3. *Download the distribution that you want to install.* For a list
  5086.      of sites from which you can obtain MySQL, see *Note Getting MySQL:
  5087.      Getting MySQL.  You can verify the integrity of the distribution
  5088.      using the instructions in *Note Verifying Package Integrity::.
  5089.  
  5090.   4. *Install the distribution.*  To install MySQL from a binary
  5091.      distribution, use the instructions in *Note Quick Standard
  5092.      Installation::.  To install MySQL from a source distribution or
  5093.      from the current development source tree, use the instructions in
  5094.      *Note Installing source::.
  5095.  
  5096.      *Note*: If you plan to upgrade an existing version of MySQL to a
  5097.      newer version rather than installing MySQL for the first time, see
  5098.      *Note Upgrade:: for information about upgrade procedures and about
  5099.      issues that you should consider before upgrading.
  5100.  
  5101.      If you encounter installation difficulties, see *Note Operating
  5102.      System Specific Notes:: for information on solving problems for
  5103.      particular platforms.
  5104.  
  5105.   5. *Perform any necessary post-installation setup.* After installing
  5106.      MySQL, read *Note Post-installation::.  This section contains
  5107.      important information about making sure the MySQL server is
  5108.      working properly. It also describes how to secure the initial
  5109.      MySQL user accounts, _which have no passwords_ until you assign
  5110.      passwords.  The section applies whether you install MySQL using a
  5111.      binary or source distribution.
  5112.  
  5113.   6. If you want to run the MySQL benchmark scripts, Perl support for
  5114.      MySQL must be available.  *Note Perl support::.
  5115.  
  5116.  
  5117. General Installation Issues
  5118. ===========================
  5119.  
  5120. Before installing MySQL, you should do the following:
  5121.  
  5122.   1. Determine whether or not MySQL runs on your platform.
  5123.  
  5124.   2. Choose a distribution to install.
  5125.  
  5126.   3. Download the distribution and verify its integrity.
  5127.  
  5128.  
  5129. This section contains the information necessary to carry out these
  5130. steps.  After doing so, you can use the instructions in later sections
  5131. of the chapter to install the distribution that you choose.
  5132.  
  5133. Operating Systems Supported by MySQL
  5134. ------------------------------------
  5135.  
  5136. This section lists the operating systems on which you can expect to be
  5137. able to run MySQL.
  5138.  
  5139. We use GNU Autoconf, so it is possible to port MySQL to all modern
  5140. systems that have a C++ compiler and a working implementation of POSIX
  5141. threads.  (Thread support is needed for the server. To compile only the
  5142. client code, the only requirement is a C++ compiler.) We use and
  5143. develop the software ourselves primarily on Linux (SuSE and Red Hat),
  5144. FreeBSD, and Sun Solaris (Versions 8 and 9).
  5145.  
  5146. MySQL has been reported to compile successfully on the following
  5147. combinations of operating system and thread package.  Note that for many
  5148. operating systems, native thread support works only in the latest
  5149. versions.
  5150.  
  5151.    * AIX 4.x, 5.x with native threads.  *Note IBM-AIX::.
  5152.  
  5153.    * Amiga.
  5154.  
  5155.    * BSDI 2.x with the MIT-pthreads package.  *Note BSDI::.
  5156.  
  5157.    * BSDI 3.0, 3.1 and 4.x with native threads.  *Note BSDI::.
  5158.  
  5159.    * DEC UNIX 4.x with native threads.  *Note Alpha-DEC-UNIX::.
  5160.  
  5161.    * FreeBSD 2.x with the MIT-pthreads package.  *Note FreeBSD::.
  5162.  
  5163.    * FreeBSD 3.x and 4.x with native threads.  *Note FreeBSD::.
  5164.  
  5165.    * FreeBSD 4.x with LinuxThreads.  *Note FreeBSD::.
  5166.  
  5167.    * HP-UX 10.20 with the DCE threads or the MIT-pthreads package.
  5168.      *Note HP-UX 10.20::.
  5169.  
  5170.    * HP-UX 11.x with the native threads.  *Note HP-UX 11.x::.
  5171.  
  5172.    * Linux 2.0+ with LinuxThreads 0.7.1+ or `glibc' 2.0.7+.  *Note
  5173.      Linux::.
  5174.  
  5175.    * Mac OS X.  *Note Mac OS X::.
  5176.  
  5177.    * NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (requires GNU make).
  5178.      *Note NetBSD::.
  5179.  
  5180.    * Novell NetWare 6.0.  *Note NetWare installation::.
  5181.  
  5182.    * OpenBSD > 2.5 with native threads. OpenBSD < 2.5 with the
  5183.      MIT-pthreads package.  *Note OpenBSD::.
  5184.  
  5185.    * OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4.  *Note OS/2::.
  5186.  
  5187.    * SCO OpenServer with a recent port of the FSU Pthreads package.
  5188.      *Note SCO::.
  5189.  
  5190.    * SCO UnixWare 7.1.x.  *Note SCO UnixWare::.
  5191.  
  5192.    * SGI Irix 6.x with native threads.  *Note SGI-Irix::.
  5193.  
  5194.    * Solaris 2.5 and above with native threads on SPARC and x86.  *Note
  5195.      Solaris::.
  5196.  
  5197.    * SunOS 4.x with the MIT-pthreads package.  *Note Solaris::.
  5198.  
  5199.    * Tru64 Unix
  5200.  
  5201.    * Windows 9x, Me, NT, 2000, and XP.  *Note Windows installation::.
  5202.  
  5203. Not all platforms are equally well-suited for running MySQL. How well a
  5204. certain platform is suited for a high-load mission-critical MySQL
  5205. server is determined by the following factors:
  5206.  
  5207.    * General stability of the thread library. A platform may have an
  5208.      excellent reputation otherwise, but MySQL will be only as stable
  5209.      as the thread library if that library is unstable in the code that
  5210.      is called by MySQL, even if everything else is perfect.
  5211.  
  5212.    * The capability of the kernel and the thread library to take
  5213.      advantage of symmetric multi-processor (SMP) systems. In other
  5214.      words, when a process creates a thread, it should be possible for
  5215.      that thread to run on a different CPU than the original process.
  5216.  
  5217.    * The capability of the kernel and the thread library to run many
  5218.      threads that acquire and release a mutex over a short critical
  5219.      region frequently without excessive context switches. If the
  5220.      implementation of `pthread_mutex_lock()' is too anxious to yield
  5221.      CPU time, this will hurt MySQL tremendously. If this issue is not
  5222.      taken care of, adding extra CPUs will actually make MySQL slower.
  5223.  
  5224.    * General filesystem stability and performance.
  5225.  
  5226.    * If your tables are big, the ability of the filesystem to deal with
  5227.      large files at all and to deal with them efficiently.
  5228.  
  5229.    * Our level of expertise here at MySQL AB with the platform. If we
  5230.      know a platform well, we enable platform-specific optimizations
  5231.      and fixes at compile time. We can also provide advice on
  5232.      configuring your system optimally for MySQL.
  5233.  
  5234.    * The amount of testing we have done internally for similar
  5235.      configurations.
  5236.  
  5237.    * The number of users that have successfully run MySQL on the
  5238.      platform in similar configurations. If this number is high, the
  5239.      chances of encountering platform-specific surprises are much
  5240.      smaller.
  5241.  
  5242. Based on the preceding criteria, the best platforms for running MySQL
  5243. at this point are x86 with SuSE Linux using a 2.4 kernel, and ReiserFS
  5244. (or any similar Linux distribution) and SPARC with Solaris (2.7-9).
  5245. FreeBSD comes third, but we really hope it will join the top club once
  5246. the thread library is improved. We also hope that at some point we will
  5247. be able to include into the top category all other platforms on which
  5248. MySQL currently compiles and runs okay, but not quite with the same
  5249. level of stability and performance.  This will require some effort on
  5250. our part in cooperation with the developers of the operating system and
  5251. library components that MySQL depends on. If you are interested in
  5252. improving one of those components, are in a position to influence its
  5253. development, and need more detailed instructions on what MySQL needs to
  5254. run better, send an email message to the MySQL `internals' mailing list.
  5255. *Note Mailing-list::.
  5256.  
  5257. Please note that the purpose of the preceding comparison is not to say
  5258. that one operating system is better or worse than another in general.
  5259. We are talking only about choosing an OS for the specific purpose of
  5260. running MySQL.  With this in mind, the result of this comparison would
  5261. be different if we considered more factors. In some cases, the reason
  5262. one OS is better than the other could simply be that we have been able
  5263. to put more effort into testing and optimizing for a particular
  5264. platform.  We are just stating our observations to help you decide
  5265. which platform to use for running MySQL.
  5266.  
  5267. Choosing Which MySQL Distribution to Install
  5268. --------------------------------------------
  5269.  
  5270. When preparing to install MySQL, you should decide which version to
  5271. use.  MySQL development occurs in several release series, and you can
  5272. pick the one that best fits your needs.  After deciding which version
  5273. to install, you can choose a distribution format.  Releases are
  5274. available in binary or source format.
  5275.  
  5276. Choosing Which Version of MySQL to Install
  5277. ..........................................
  5278.  
  5279. The first decision to make is whether you want to use a production
  5280. (stable) release or a development release.  In the MySQL development
  5281. process, multiple release series co-exist, each at a different stage of
  5282. maturity:
  5283.  
  5284.    * MySQL 5.0 is the newest development release series and is under
  5285.      very active development for new features. Until recently it was
  5286.      available only in preview form from the BitKeeper source
  5287.      repository. An early alpha release has now been issued to allow
  5288.      more widespread testing.
  5289.  
  5290.    * MySQL 4.1 is a development release series to which major new
  5291.      features have been added. It is still at beta status. Sources and
  5292.      binaries are available for use and testing on development systems.
  5293.  
  5294.    * MySQL 4.0 is the current stable (production-quality) release
  5295.      series.  New releases are issued for bugfixes. No new features are
  5296.      added that could diminish the code stability.
  5297.  
  5298.    * MySQL 3.23 is the old stable (production-quality) release series.
  5299.      This series is retired, so new releases are issued only to fix
  5300.      critical bugs.
  5301.  
  5302.  
  5303. We don't believe in a complete freeze, as this also leaves out bugfixes
  5304. and things that "must be done."  "Somewhat frozen" means that we may add
  5305. small things that "almost surely will not affect anything that's already
  5306. working." Naturally, relevant bugfixes from an earlier series propagate
  5307. to later series.
  5308.  
  5309. Normally, if you are beginning to use MySQL for the first time or trying
  5310. to port it to some system for which there is no binary distribution, we
  5311. recommend going with the production release series. Currently this is
  5312. MySQL 4.0.  All MySQL releases, even those from development series, are
  5313. checked with the MySQL benchmarks and an extensive test suite before
  5314. being issued.
  5315.  
  5316. If you are running an old system and want to upgrade, but don't want to
  5317. take the chance of having a non-seamless upgrade, you should upgrade to
  5318. the latest version in the same release series you are using (where only
  5319. the last part of the version number is newer than yours).  We have tried
  5320. to fix only fatal bugs and make small, relatively safe changes to that
  5321. version.
  5322.  
  5323. If you want to use new features not present in the production release
  5324. series, you can use a version from a development series. Note that
  5325. development releases are not as stable as production releases.
  5326.  
  5327. If you want to use the very latest sources containing all current
  5328. patches and bugfixes, you can use one of our BitKeeper repositories.
  5329. These are not "releases" as such, but are available as previews of the
  5330. code on which future releases will be based.
  5331.  
  5332. The MySQL naming scheme uses release names that consist of three
  5333. numbers and a suffix; for example, `mysql-4.1.2-alpha'.  The numbers
  5334. within the release name are interpreted like this:
  5335.  
  5336.    * The first number (`4') is the major version and also describes the
  5337.      file format.  All Version 4 releases have the same file format.
  5338.  
  5339.    * The second number (`1') is the release level.  Taken together, the
  5340.      major version and release level constitute the release series
  5341.      number.
  5342.  
  5343.    * The third number (`2') is the version number within the release
  5344.      series.  This is incremented for each new release.  Usually you
  5345.      want the latest version for the series you have chosen.
  5346.  
  5347.  
  5348. For each minor update, the last number in the version string is
  5349. incremented.  When there are major new features or minor
  5350. incompatibilities with previous versions, the second number in the
  5351. version string is incremented.  When the file format changes, the first
  5352. number is increased.
  5353.  
  5354. Release names also include a suffix to indicates the stability level of
  5355. the release.  Releases within a series progress through a set of
  5356. suffixes to indicate how the stability level improves.  The possible
  5357. suffixes are:
  5358.  
  5359.    * `alpha' indicates that the release contains some large section of
  5360.      new code that hasn't been 100% tested.  Known bugs (usually there
  5361.      are none) should be documented in the News section.  *Note News::.
  5362.      There are also new commands and extensions in most alpha
  5363.      releases.  Active development that may involve major code changes
  5364.      can occur in an alpha release, but everything will be tested
  5365.      before issuing a release.  For this reason, there should be no
  5366.      known bugs in any MySQL release.
  5367.  
  5368.    * `beta' means that all new code has been tested.  No major new
  5369.      features that could cause corruption in old code are added.  There
  5370.      should be no known bugs.  A version changes from alpha to beta
  5371.      when there haven't been any reported fatal bugs within an alpha
  5372.      version for at least a month and we have no plans to add any
  5373.      features that could make any old command unreliable.
  5374.  
  5375.    * `gamma' is a beta that has been around a while and seems to work
  5376.      fine.  Only minor fixes are added.  This is what many other
  5377.      companies call a release.
  5378.  
  5379.    * If there is no suffix, it means that the version has been run for a
  5380.      while at many different sites with no reports of bugs other than
  5381.      platform-specific bugs.  Only critical bugfixes are applied to the
  5382.      release. This is what we call a production (stable) release.
  5383.  
  5384. MySQL uses a naming scheme that is slightly different from most other
  5385. products.  In general, it's relatively safe to use any version that has
  5386. been out for a couple of weeks without being replaced with a new
  5387. version within the release series.
  5388.  
  5389. All releases of MySQL are run through our standard tests and benchmarks
  5390. to ensure that they are relatively safe to use.  Because the standard
  5391. tests are extended over time to check for all previously found bugs,
  5392. the test suite keeps getting better.
  5393.  
  5394. All releases have been tested at least with:
  5395.  
  5396. An internal test suite
  5397.      The `mysql-test' directory contains an extensive set of test cases.
  5398.      We run these tests for virtually every server binary.  See *Note
  5399.      MySQL test suite:: for more information about this test suite.
  5400.  
  5401. The MySQL benchmark suite
  5402.      This suite runs a range of common queries.  It is also a test to
  5403.      see whether the latest batch of optimizations actually made the
  5404.      code faster.  *Note MySQL Benchmarks::.
  5405.  
  5406. The `crash-me' test
  5407.      This test tries to determine what features the database supports
  5408.      and what its capabilities and limitations are.  *Note MySQL
  5409.      Benchmarks::.
  5410.  
  5411. Another test is that we use the newest MySQL version in our internal
  5412. production environment, on at least one machine.  We have more than
  5413. 100GB of data to work with.
  5414.  
  5415. Choosing a Distribution Format
  5416. ..............................
  5417.  
  5418. After choosing which version of MySQL to install, you should decide
  5419. whether to use a binary distribution or a source distribution.  In most
  5420. cases, you should probably use a binary distribution, if one exists for
  5421. your platform. Binary distributions are available in native format for
  5422. many platforms, such as RPM files for Linux or DMG package installers
  5423. for Mac OS X. Distributions also are available as Zip archives or
  5424. compressed `tar' files.
  5425.  
  5426. Reasons to choose a binary distribution include the following:
  5427.  
  5428.    * Binary distributions generally are easier to install than source
  5429.      distributions.
  5430.  
  5431.    * To satisfy different user requirements, we provide two different
  5432.      binary versions: one compiled with the non-transactional storage
  5433.      engines (a small, fast binary), and one configured with the most
  5434.      important extended options like transaction-safe tables.  Both
  5435.      versions are compiled from the same source distribution.  All
  5436.      native MySQL clients can connect to servers from either MySQL
  5437.      version.
  5438.  
  5439.      The extended MySQL binary distribution is marked with the `-max'
  5440.      suffix and is configured with the same options as `mysqld-max'.
  5441.      *Note `mysqld-max': mysqld-max.
  5442.  
  5443.      If you want to use the `MySQL-Max' RPM, you must first install the
  5444.      standard `MySQL-server' RPM.
  5445.  
  5446.  
  5447. Under some circumstances, you probably will be better off installing
  5448. MySQL from a source distribution:
  5449.  
  5450.    * You want to install MySQL at some explicit location.  The standard
  5451.      binary distributions are "ready to run" at any place, but you may
  5452.      want to have even more flexibility to place MySQL components where
  5453.      you want.
  5454.  
  5455.    * You want to configure `mysqld' with some extra features that are
  5456.      not included in the standard binary distributions.  Here is a list
  5457.      of the most common extra options that you may want to use:
  5458.  
  5459.         * `--with-innodb' (default for MySQL 4.0 and up)
  5460.  
  5461.         * `--with-berkeley-db' (not available on all platforms)
  5462.  
  5463.         * `--with-raid'
  5464.  
  5465.         * `--with-libwrap'
  5466.  
  5467.         * `--with-named-z-libs' (this is done for some of the binaries)
  5468.  
  5469.         * `--with-debug[=FULL]'
  5470.  
  5471.    * You want to configure `mysqld' without some features that are
  5472.      included in the standard binary distributions. For example,
  5473.      distributions normally are compiled with support for all character
  5474.      sets. If you want a smaller MySQL server, you can recompile it
  5475.      with support for only the character sets you need.
  5476.  
  5477.    * You have a special compiler (such as `pgcc') or want to use
  5478.      compiler options that are better optimized for your processor.
  5479.      Binary distributions are compiled with options that should work on
  5480.      a variety of processors from the same processor family.
  5481.  
  5482.    * You want to use the latest sources from one of the BitKeeper
  5483.      repositories to have access to all current bugfixes. For example,
  5484.      if you have found a bug and reported it to the MySQL development
  5485.      team, the bugfix will be committed to the source repository and you
  5486.      can access it there.  The bugfix will not appear in a release until
  5487.      a release actually is issued.
  5488.  
  5489.    * You want to read (or modify) the C and C++ code that makes up
  5490.      MySQL. For this purpose, you should get a source distribution,
  5491.      because the source code is always the ultimate manual.
  5492.  
  5493.    * Source distributions contain more tests and examples than binary
  5494.      distributions.
  5495.  
  5496.  
  5497. How and When Updates Are Released
  5498. .................................
  5499.  
  5500. MySQL is evolving quite rapidly here at MySQL AB and we want to share
  5501. new developments with other MySQL users.  We try to make a release when
  5502. we have very useful features that others seem to have a need for.
  5503.  
  5504. We also try to help out users who request features that are easy to
  5505. implement.  We take note of what our licensed users want to have, and
  5506. we especially take note of what our extended email-supported customers
  5507. want and try to help them out.
  5508.  
  5509. No one has to download a new release.  The News section will tell you if
  5510. the new release has something you really want.  *Note News::.
  5511.  
  5512. We use the following policy when updating MySQL:
  5513.  
  5514.    * Releases are issued within each series. For each release, the last
  5515.      number in the version is one more than the previous release within
  5516.      the same series.
  5517.  
  5518.    * Production (stable) releases are meant to appear about 1-2 times a
  5519.      year.  However, if small bugs are found, a release with only
  5520.      bugfixes will be issued.
  5521.  
  5522.    * Working releases/bugfixes to old releases are meant to appear about
  5523.      every 4-8 weeks.
  5524.  
  5525.    * Binary distributions for some platforms are made by us for major
  5526.      releases.  Other people may make binary distributions for other
  5527.      systems, but probably less frequently.
  5528.  
  5529.    * We make fixes available as soon as we have identified and corrected
  5530.      small or non-critical but annoying bugs. The fixes are available
  5531.      immediately from our public BitKeeper repositories, and will be
  5532.      included in the next release.
  5533.  
  5534.    * If by any chance a fatal bug is found in a release, we will make a
  5535.      new release as soon as possible.  (We would like other companies
  5536.      to do this, too!)
  5537.  
  5538. Release Philosophy--No Known Bugs in Releases
  5539. .............................................
  5540.  
  5541. We put a lot of time and effort into making our releases bug-free.  To
  5542. our knowledge, we have not released a single MySQL version with any
  5543. _known_ "fatal" repeatable bugs.  (A "fatal" bug is something that
  5544. crashes MySQL under normal usage, produces incorrect answers for normal
  5545. queries, or has a security problem.)
  5546.  
  5547. We have documented all open problems, bugs, and issues that are
  5548. dependent on design decisions.  *Note Bugs::.
  5549.  
  5550. Our aim is to fix everything that is fixable without risk of making a
  5551. stable MySQL version less stable. In certain cases, this means we can
  5552. fix an issue in the development versions, but not in the stable
  5553. (production) version. Naturally, we document such issues so that users
  5554. are aware of them.
  5555.  
  5556. Here is a description of how our build process works:
  5557.    * We monitor bugs from our customer support list, the bugs database
  5558.      at `http://bugs.mysql.com/', and the MySQL external mailing lists.
  5559.  
  5560.    * All reported bugs for live versions are entered into the bugs
  5561.      database.
  5562.  
  5563.    * When we fix a bug, we always try to make a test case for it and
  5564.      include it into our test system to ensure that the bug will never
  5565.      recur without being detected. (About 90% of all fixed bugs have a
  5566.      test case.)
  5567.  
  5568.    * We create test cases for all new features we add to MySQL.
  5569.  
  5570.    * Before we start to build a new MySQL release, we ensure that all
  5571.      reported repeatable bugs for the MySQL version (3.23.x, 4.0.x, etc)
  5572.      are fixed.  If something is impossible to fix (due to some internal
  5573.      design decision in MySQL), we document this in the manual.  *Note
  5574.      Bugs::.
  5575.  
  5576.    * We do a build on all platforms for which we support binaries (15+
  5577.      platforms) and run our test suite and benchmark suite on all of
  5578.      them.
  5579.  
  5580.    * We will not publish a binary for a platform for which the test or
  5581.      benchmark suite fails.  If the problem is due to a general error
  5582.      in the source, we fix it and do the build plus tests on all
  5583.      systems again from scratch.
  5584.  
  5585.    * The build and test process takes 2-3 days.  If we receive a report
  5586.      regarding a fatal bug during this process (for example, one that
  5587.      causes a core dump), we fix the problem and restart the build
  5588.      process.
  5589.  
  5590.    * After publishing the binaries on `http://dev.mysql.com/', we send
  5591.      out an announcement message to the `mysql' and `announce' mailing
  5592.      lists.  *Note Mailing-list::.  The announcement message contains a
  5593.      list of all changes to the release and any known problems with the
  5594.      release.  The Known Problems section in the release notes has been
  5595.      needed for only a handful of releases.
  5596.  
  5597.    * To quickly give our users access to the latest MySQL features, we
  5598.      do a new MySQL release every 4-8 weeks.  Source code snapshots are
  5599.      built daily and are available at
  5600.      `http://downloads.mysql.com/snapshots.php'.
  5601.  
  5602.    * If, despite our best efforts, we get any bug reports after the
  5603.      release is done that there was something critically wrong with the
  5604.      build on a specific platform, we will fix it at once and build a
  5605.      new `'a'' release for that platform. Thanks to our large user
  5606.      base, problems are found quickly.
  5607.  
  5608.    * Our track record for making good releases is quite good.  In the
  5609.      last 150 releases, we had to do a new build for fewer than 10
  5610.      releases. In three of these cases, the bug was a faulty `glibc'
  5611.      library on one of our build machines that took us a long time to
  5612.      track down.
  5613.  
  5614. MySQL Binaries Compiled by MySQL AB
  5615. ...................................
  5616.  
  5617. As a service of MySQL AB, we provide a set of binary distributions of
  5618. MySQL that are compiled on systems at our site or on systems where
  5619. supporters of MySQL kindly have given us access to their machines.
  5620.  
  5621. In addition to the binaries provided in platform-specific package
  5622. formats, we offer binary distributions for a number of platforms in the
  5623. form of compressed `tar' files (`.tar.gz' files).  *Note Quick Standard
  5624. Installation::.
  5625.  
  5626. For Windows distributions, see *Note Windows installation::.
  5627.  
  5628. These distributions are generated using the script
  5629. `Build-tools/Do-compile', which compiles the source code and creates
  5630. the binary `tar.gz' archive using `scripts/make_binary_distribution'.
  5631.  
  5632. These binaries are configured and built with the following compilers and
  5633. options. This information can also be obtained by looking at the
  5634. variables `COMP_ENV_INFO' and `CONFIGURE_LINE' inside the script
  5635. `bin/mysqlbug' of every binary `tar' file distribution.
  5636.  
  5637. The following binaries are built on MySQL AB development systems:
  5638.  
  5639. Linux 2.4.xx x86 with `gcc' 2.95.3:
  5640.      `CFLAGS="-O2 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O2
  5641.      -mcpu=pentiumpro -felide-constructors" ./configure
  5642.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5643.      --enable-thread-safe-client --enable-local-infile
  5644.      --enable-assembler --disable-shared
  5645.      --with-client-ldflags=-all-static
  5646.      --with-mysqld-ldflags=-all-static'
  5647.  
  5648. Linux 2.4.x x86 with `icc' (Intel C++ Compiler 8.0):
  5649.      `CC=icc CXX=icc CFLAGS="-O3 -unroll2 -ip -mp -no-gcc -restrict"
  5650.      CXXFLAGS="-O3 -unroll2 -ip -mp -no-gcc -restrict" ./configure
  5651.      --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data
  5652.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5653.      --enable-thread-safe-client --enable-local-infile
  5654.      --enable-assembler --disable-shared
  5655.      --with-client-ldflags=-all-static
  5656.      --with-mysqld-ldflags=-all-static --with-embedded-server
  5657.      --with-innodb'
  5658.  
  5659. Linux 2.4.xx Intel Itanium 2 with `ecc' (Intel C++ Itanium Compiler 7.0):
  5660.      `CC=ecc CFLAGS="-O2 -tpp2 -ip -nolib_inline" CXX=ecc CXXFLAGS="-O2
  5661.      -tpp2 -ip -nolib_inline" ./configure --prefix=/usr/local/mysql
  5662.      --with-extra-charsets=complex --enable-thread-safe-client
  5663.      --enable-local-infile'
  5664.  
  5665. Linux 2.4.xx Intel Itanium with `ecc' (Intel C++ Itanium Compiler 7.0):
  5666.      `CC=ecc CFLAGS=-tpp1 CXX=ecc CXXFLAGS=-tpp1 ./configure
  5667.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5668.      --enable-thread-safe-client --enable-local-infile'
  5669.  
  5670. Linux 2.4.xx alpha with `ccc' (Compaq C V6.2-505 / Compaq C++ V6.3-006):
  5671.      `CC=ccc CFLAGS="-fast -arch generic" CXX=cxx CXXFLAGS="-fast -arch
  5672.      generic -noexceptions -nortti" ./configure
  5673.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5674.      --enable-thread-safe-client --enable-local-infile
  5675.      --with-mysqld-ldflags=-non_shared
  5676.      --with-client-ldflags=-non_shared --disable-shared'
  5677.  
  5678. Linux 2.x.xx ppc with `gcc' 2.95.4:
  5679.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5680.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5681.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5682.      --localstatedir=/usr/local/mysql/data
  5683.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5684.      --enable-thread-safe-client --enable-local-infile
  5685.      --disable-shared --with-embedded-server --with-innodb'
  5686.  
  5687. Linux 2.4.xx s390 with `gcc' 2.95.3:
  5688.      `CFLAGS="-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors"
  5689.      ./configure --prefix=/usr/local/mysql
  5690.      --with-extra-charsets=complex --enable-thread-safe-client
  5691.      --enable-local-infile --disable-shared
  5692.      --with-client-ldflags=-all-static
  5693.      --with-mysqld-ldflags=-all-static'
  5694.  
  5695. Linux 2.4.xx x86_64 (AMD64) with `gcc' 3.2.1:
  5696.      `CXX=gcc ./configure --prefix=/usr/local/mysql
  5697.      --with-extra-charsets=complex --enable-thread-safe-client
  5698.      --enable-local-infile  --disable-shared'
  5699.  
  5700. Sun Solaris 8 x86 with `gcc' 3.2.3:
  5701.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5702.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5703.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5704.      --localstatedir=/usr/local/mysql/data
  5705.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5706.      --enable-thread-safe-client --enable-local-infile
  5707.      --disable-shared --with-innodb'
  5708.  
  5709. Sun Solaris 8 SPARC with `gcc' 3.2:
  5710.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5711.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5712.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5713.      --with-extra-charsets=complex --enable-thread-safe-client
  5714.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  5715.      --with-named-curses-libs=-lcurses --disable-shared'
  5716.  
  5717. Sun Solaris 8 SPARC 64-bit with `gcc' 3.2:
  5718.      `CC=gcc CFLAGS="-O3 -m64 -fno-omit-frame-pointer" CXX=gcc
  5719.      CXXFLAGS="-O3 -m64 -fno-omit-frame-pointer -felide-constructors
  5720.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  5721.      --with-extra-charsets=complex --enable-thread-safe-client
  5722.      --enable-local-infile --with-named-z-libs=no
  5723.      --with-named-curses-libs=-lcurses --disable-shared'
  5724.  
  5725. Sun Solaris 9 SPARC with `gcc' 2.95.3:
  5726.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5727.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5728.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5729.      --with-extra-charsets=complex --enable-thread-safe-client
  5730.      --enable-local-infile --enable-assembler
  5731.      --with-named-curses-libs=-lcurses --disable-shared'
  5732.  
  5733. Sun Solaris 9 SPARC with `cc-5.0' (Sun Forte 5.0):
  5734.      `CC=cc-5.0 CXX=CC ASFLAGS="-xarch=v9" CFLAGS="-Xa -xstrconst -mt
  5735.      -D_FORTEC_ -xarch=v9" CXXFLAGS="-noex -mt -D_FORTEC_ -xarch=v9"
  5736.      ./configure --prefix=/usr/local/mysql
  5737.      --with-extra-charsets=complex --enable-thread-safe-client
  5738.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  5739.      --enable-thread-safe-client --disable-shared'
  5740.  
  5741. IBM AIX 4.3.2 ppc with `gcc' 3.2.3:
  5742.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many " CXX=gcc CXXFLAGS="-O2
  5743.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  5744.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5745.      --with-extra-charsets=complex --enable-thread-safe-client
  5746.      --enable-local-infile --with-named-z-libs=no --disable-shared'
  5747.  
  5748. IBM AIX 4.3.3 ppc with `xlC_r' (IBM Visual Age C/C++ 6.0):
  5749.      `CC=xlc_r CFLAGS="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  5750.      CXX=xlC_r CXXFLAGS ="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  5751.      ./configure --prefix=/usr/local/mysql
  5752.      --localstatedir=/usr/local/mysql/data
  5753.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5754.      --enable-thread-safe-client --enable-local-infile
  5755.      --with-named-z-libs=no --disable-shared --with-innodb'
  5756.  
  5757. IBM AIX 5.1.0 ppc with `gcc' 3.3:
  5758.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many" CXX=gcc CXXFLAGS="-O2
  5759.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  5760.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5761.      --with-extra-charsets=complex --enable-thread-safe-client
  5762.      --enable-local-infile --with-named-z-libs=no --disable-shared'
  5763.  
  5764. IBM AIX 5.2.0 ppc with `xlC_r' (IBM Visual Age C/C++ 6.0):
  5765.      `CC=xlc_r CFLAGS="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  5766.      CXX=xlC_r CXXFLAGS="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  5767.      ./configure --prefix=/usr/local/mysql
  5768.      --localstatedir=/usr/local/mysql/data
  5769.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5770.      --enable-thread-safe-client --enable-local-infile
  5771.      --with-named-z-libs=no --disable-shared --with-embedded-server
  5772.      --with-innodb'
  5773.  
  5774. HP-UX 10.20 pa-risc1.1 with `gcc' 3.1:
  5775.      `CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc
  5776.      CXXFLAGS="-DHPUX -I/opt/dce /include -felide-constructors
  5777.      -fno-exceptions -fno-rtti -O3 -fPIC" ./configure
  5778.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5779.      --enable-thread-safe-client --enable-local-infile  --with-pthread
  5780.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  5781.      --disable-shared'
  5782.  
  5783. HP-UX 11.00 pa-risc with `aCC' (HP ANSI C++ B3910B A.03.50):
  5784.      `CC=cc CXX=aCC CFLAGS=+DAportable CXXFLAGS=+DAportable ./configure
  5785.      --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data
  5786.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5787.      --enable-thread-safe-client --enable-local-infile --disable-shared
  5788.      --with-embedded-server --with-innodb'
  5789.  
  5790. HP-UX 11.11 pa-risc2.0 64bit with `aCC' (HP ANSI C++ B3910B A.03.33):
  5791.      `CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure
  5792.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5793.      --enable-thread-safe-client --enable-local-infile --disable-shared'
  5794.  
  5795. HP-UX 11.11 pa-risc2.0 32bit with `aCC' (HP ANSI C++ B3910B A.03.33):
  5796.      `CC=cc CXX=aCC CFLAGS="+DAportable" CXXFLAGS="+DAportable"
  5797.      ./configure --prefix=/usr/local/mysql
  5798.      --localstatedir=/usr/local/mysql/data
  5799.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5800.      --enable-thread-safe-client --enable-local-infile
  5801.      --disable-shared --with-innodb'
  5802.  
  5803. HP-UX 11.22 ia64 64bit with `aCC' (HP aC++/ANSI C B3910B A.05.50):
  5804.      `CC=cc CXX=aCC CFLAGS="+DD64 +DSitanium2" CXXFLAGS="+DD64
  5805.      +DSitanium2" ./configure --prefix=/usr/local/mysql
  5806.      --localstatedir=/usr/local/mysql/data
  5807.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5808.      --enable-thread-safe-client --enable-local-infile
  5809.      --disable-shared --with-embedded-server --with-innodb'
  5810.  
  5811. Apple Mac OS X 10.2 powerpc with `gcc' 3.1:
  5812.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5813.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5814.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5815.      --with-extra-charsets=complex --enable-thread-safe-client
  5816.      --enable-local-infile  --disable-shared'
  5817.  
  5818. FreeBSD 4.7 i386 with `gcc' 2.95.4:
  5819.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  5820.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5821.      --enable-thread-safe-client --enable-local-infile
  5822.      --enable-assembler --with-named-z-libs=not-used --disable-shared'
  5823.  
  5824. FreeBSD 4.7 i386 using LinuxThreads with `gcc' 2.95.4:
  5825.      `CFLAGS="-DHAVE_BROKEN_REALPATH -D__USE_UNIX98 -D_REENTRANT
  5826.      -D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads"
  5827.      CXXFLAGS="-DHAVE_BROKEN_REALPATH -D__USE_UNIX98 -D_REENTRANT
  5828.      -D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads"
  5829.      ./configure --prefix=/usr/local/mysql
  5830.      --localstatedir=/usr/local/mysql/data
  5831.      --libexecdir=/usr/local/mysql/bin --enable-thread-safe-client
  5832.      --enable-local-infile --enable-assembler
  5833.      --with-named-thread-libs="-DHAVE_GLIBC2_STYLE_GETHOSTBYNAME_R
  5834.      -D_THREAD_SAFE -I /usr/local/include/pthread/linuxthreads
  5835.      -L/usr/local/lib -llthread -llgcc_r" --disable-shared
  5836.      --with-embedded-server --with-innodb'
  5837.  
  5838. QNX Neutrino 6.2.1 i386 with `gcc' 2.95.3qnx-nto 20010315:
  5839.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5840.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5841.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5842.      --with-extra-charsets=complex --enable-thread-safe-client
  5843.      --enable-local-infile  --disable-shared'
  5844.  
  5845. The following binaries are built on third-party systems kindly provided
  5846. to MySQL AB by other users. These are provided only as a courtesy;
  5847. MySQL AB does not have full control over these systems, so we can
  5848. provide only limited support for the binaries built on them.
  5849.  
  5850. SCO Unix 3.2v5.0.6 i386 with `gcc' 2.95.3:
  5851.      `CFLAGS="-O3 -mpentium" LDFLAGS=-static CXX=gcc CXXFLAGS="-O3
  5852.      -mpentium -felide-constructors" ./configure
  5853.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5854.      --enable-thread-safe-client --enable-local-infile
  5855.      --with-named-z-libs=no --enable-thread-safe-client
  5856.      --disable-shared'
  5857.  
  5858. SCO OpenUnix 8.0.0 i386 with `CC' 3.2:
  5859.      `CC=cc CFLAGS="-O" CXX=CC ./configure --prefix=/usr/local/mysql
  5860.      --with-extra-charsets=complex --enable-thread-safe-client
  5861.      --enable-local-infile --with-named-z-libs=no
  5862.      --enable-thread-safe-client --disable-shared'
  5863.  
  5864. Compaq Tru64 OSF/1 V5.1 732 alpha with `cc/cxx' (Compaq C V6.3-029i / DIGITAL C++ V6.1-027):
  5865.      `CC="cc -pthread" CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline
  5866.      speed -speculate all" CXX="cxx -pthread" CXXFLAGS="-O4 -ansi_alias
  5867.      -fast -inline speed -speculate all -noexceptions -nortti"
  5868.      ./configure --prefix=/usr/local/mysql
  5869.      --with-extra-charsets=complex --enable-thread-safe-client
  5870.      --enable-local-infile --with-prefix=/usr/local/mysql
  5871.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  5872.      --disable-shared --with-mysqld-ldflags=-all-static'
  5873.  
  5874. SGI Irix 6.5 IP32 with `gcc' 3.0.1:
  5875.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXXFLAGS="-O3
  5876.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5877.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5878.      --with-extra-charsets=complex --enable-thread-safe-client
  5879.      --enable-local-infile  --disable-shared'
  5880.  
  5881. FreeBSD/sparc64 5.0 with `gcc' 3.2.1:
  5882.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  5883.      --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data
  5884.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5885.      --enable-thread-safe-client --enable-local-infile --disable-shared
  5886.      --with-innodb'
  5887.  
  5888. The following compile options have been used for binary packages that
  5889. MySQL AB provided in the past. These binaries no longer are being
  5890. updated, but the compile options are listed here for reference purposes.
  5891.  
  5892. Linux 2.2.xx SPARC with `egcs' 1.1.2:
  5893.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5894.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5895.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5896.      --with-extra-charsets=complex --enable-thread-safe-client
  5897.      --enable-local-infile --enable-assembler --disable-shared'
  5898.  
  5899. Linux 2.2.x with x686 with `gcc' 2.95.2:
  5900.      `CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  5901.      -felide-constructors -fno-exceptions -fno-rtti" ./configure
  5902.      --prefix=/usr/local/mysql --enable-assembler
  5903.      --with-mysqld-ldflags=-all-static --disable-shared
  5904.      --with-extra-charsets=complex'
  5905.  
  5906. SunOS 4.1.4 2 sun4c with `gcc' 2.7.2.1:
  5907.      `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors" ./configure
  5908.      --prefix=/usr/local/mysql --disable-shared
  5909.      --with-extra-charsets=complex --enable-assembler'
  5910.  
  5911. SunOS 5.5.1 (and above) sun4u with `egcs' 1.0.3a or 2.90.27 or
  5912.      `gcc' 2.95.2 and newer: `CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3
  5913.      -felide-constructors -fno-exceptions -fno-rtti" ./configure
  5914.      --prefix=/usr/local/mysql --with-low-memory
  5915.      --with-extra-charsets=complex --enable-assembler'
  5916.  
  5917. SunOS 5.6 i86pc with `gcc' 2.8.1:
  5918.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5919.      --with-low-memory --with-extra-charsets=complex'
  5920.  
  5921. BSDI BSD/OS 3.1 i386 with `gcc' 2.7.2.1:
  5922.      `CC=gcc CXX=gcc CXXFLAGS=-O ./configure --prefix=/usr/local/mysql
  5923.      --with-extra-charsets=complex'
  5924.  
  5925. BSDI BSD/OS 2.1 i386 with `gcc' 2.7.2:
  5926.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5927.      --with-extra-charsets=complex'
  5928.  
  5929. AIX 2 4 with `gcc' 2.7.2.2:
  5930.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5931.      --with-extra-charsets=complex'
  5932.  
  5933. Anyone who has more optimal options for any of the preceding
  5934. configurations listed can always mail them to the MySQL `internals'
  5935. mailing list.  *Note Mailing-list::.
  5936.  
  5937. RPM distributions prior to MySQL 3.22 are user-contributed.  Beginning
  5938. with MySQL 3.22, RPM distributions are generated by MySQL AB.
  5939.  
  5940. If you want to compile a debug version of MySQL, you should add
  5941. `--with-debug' or `--with-debug=full' to the preceding `configure'
  5942. commands and remove any `-fomit-frame-pointer' options.
  5943.  
  5944. How to Get MySQL
  5945. ----------------
  5946.  
  5947. Check the MySQL home page (`http://www.mysql.com/') for information
  5948. about the current version and for downloading instructions.
  5949.  
  5950. Our main mirror is located at `http://mirrors.sunsite.dk/mysql/'.
  5951.  
  5952. For a complete up-to-date list of MySQL download mirror sites, see
  5953. `http://dev.mysql.com/downloads/mirrors.html'.  There you will also
  5954. find information about becoming a MySQL mirror site and how to report a
  5955. bad or out-of-date mirror.
  5956.  
  5957. Verifying Package Integrity Using MD5 Checksums or `GnuPG'
  5958. ----------------------------------------------------------
  5959.  
  5960. After you have downloaded the MySQL package that suits your needs and
  5961. before you attempt to install it, you should make sure that it is
  5962. intact and has not been tampered with. MySQL AB offers three means of
  5963. integrity checking:
  5964.  
  5965.    * MD5 checksums
  5966.  
  5967.    * Cryptographic signatures using `GnuPG', the GNU Privacy Guard
  5968.  
  5969.    * For RPM packages, the built-in RPM integrity verification mechanism
  5970.  
  5971.  
  5972. The following sections describe how to use these methods.
  5973.  
  5974. If you notice that the MD5 checksum or GPG signatures do not match,
  5975. first try to download the respective package one more time, perhaps
  5976. from another mirror site. If you repeatedly cannot successfully verify
  5977. the integrity of the package, please notify us about such incidents,
  5978. including the full package name and the download site you have been
  5979. using, at <webmaster@mysql.com> or <build@mysql.com>.  Do not report
  5980. downloading problems using the bug-reporting system.
  5981.  
  5982. Verifying the MD5 Checksum
  5983. ..........................
  5984.  
  5985. After you have downloaded a MySQL package, you should make sure that
  5986. its MD5 checksum matches the one provided on the MySQL download pages.
  5987. Each package has an individual checksum that you can verify with the
  5988. following command, where `package_name' is the name of the package you
  5989. downloaded:
  5990.  
  5991.      shell> md5sum package_name
  5992.  
  5993. Example:
  5994.      shell> md5sum mysql-standard-4.0.17-pc-linux-i686.tar.gz
  5995.      60f5fe969d61c8f82e4f7f62657e1f06  mysql-standard-4.0.17-pc-linux-i686.tar.gz
  5996.  
  5997. You should verify that the resulting checksum (the string of hexadecimal
  5998. digits) matches the one displayed on the download page immediately
  5999. below the respective package.
  6000.  
  6001. Note that not all operating systems support the `md5sum' command. On
  6002. some, it is simply called `md5' and others do not ship it at all. On
  6003. Linux, it is part of the `GNU Text Utilities' package, which is
  6004. available for a wide range of platforms. You can download the source
  6005. code from `http://www.gnu.org/software/textutils/' as well. If you have
  6006. `OpenSSL' installed, you can also use the command `openssl md5
  6007. package_name' instead. A DOS/Windows implementation of the `md5'
  6008. command is available from `http://www.fourmilab.ch/md5/'.
  6009.  
  6010. Signature Checking Using `GnuPG'
  6011. ................................
  6012.  
  6013. Another method of verifying the integrity and authenticity of a package
  6014. is to use cryptographic signatures. This is more reliable than using MD5
  6015. checksums, but requires more work.
  6016.  
  6017. Beginning with MySQL 4.0.10 (February 2003), MySQL AB started signing
  6018. downloadable packages with `GnuPG' (`GNU Privacy Guard').  `GnuPG' is
  6019. an Open Source alternative to the very well-known `Pretty Good Privacy'
  6020. (`PGP') by Phil Zimmermann.  See `http://www.gnupg.org/' for more
  6021. information about `GnuPG' and how to obtain and install it on your
  6022. system. Most Linux distributions already ship with `GnuPG' installed by
  6023. default.  For more information about `OpenPGP', see
  6024. `http://www.openpgp.org/'.
  6025.  
  6026. To verify the signature for a specific package, you first need to
  6027. obtain a copy of MySQL AB's public GPG build key. You can download the
  6028. key from `http://www.keyserver.net/'.  The key that you want to obtain
  6029. is named `build@mysql.com'.  Alternatively, you can cut and paste the
  6030. key directly from the following text:
  6031.  
  6032.      Key ID:
  6033.      pub  1024D/5072E1F5 2003-02-03
  6034.           MySQL Package signing key (www.mysql.com) <build@mysql.com>
  6035.      Fingerprint: A4A9 4068 76FC BD3C 4567  70C8 8C71 8D3B 5072 E1F5
  6036.      
  6037.      Public Key (ASCII-armored):
  6038.      
  6039.      -----BEGIN PGP PUBLIC KEY BLOCK-----
  6040.      Version: GnuPG v1.0.6 (GNU/Linux)
  6041.      Comment: For info see http://www.gnupg.org
  6042.      
  6043.      mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3
  6044.      RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ
  6045.      fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3
  6046.      BqOxRznNCRCRxAuAuVztHRcEAJooQK1+iSiunZMYD1WufeXfshc57S/+yeJkegNW
  6047.      hxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo8gTxvxXNQc7fJYLV
  6048.      K2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7ITnE
  6049.      kYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDI
  6050.      QJEXM6FSbi0LLtZciNlYsafwAPEOMDKpMqAK6IyisNtPvaLd8lH0bPAnWqcyefep
  6051.      rv0sxxqUEMcM3o7wwgfN83POkDasDbs3pjwPhxvhz6//62zQJ7Q7TXlTUUwgUGFj
  6052.      a2FnZSBzaWduaW5nIGtleSAod3d3Lm15c3FsLmNvbSkgPGJ1aWxkQG15c3FsLmNv
  6053.      bT6IXQQTEQIAHQUCPj6jDAUJCWYBgAULBwoDBAMVAwIDFgIBAheAAAoJEIxxjTtQ
  6054.      cuH1cY4AnilUwTXn8MatQOiG0a/bPxrvK/gCAJ4oinSNZRYTnblChwFaazt7PF3q
  6055.      zIhMBBMRAgAMBQI+PqPRBYMJZgC7AAoJEElQ4SqycpHyJOEAn1mxHijft00bKXvu
  6056.      cSo/pECUmppiAJ41M9MRVj5VcdH/KN/KjRtW6tHFPYhMBBMRAgAMBQI+QoIDBYMJ
  6057.      YiKJAAoJELb1zU3GuiQ/lpEAoIhpp6BozKI8p6eaabzF5MlJH58pAKCu/ROofK8J
  6058.      Eg2aLos+5zEYrB/LsrkCDQQ+PqMdEAgA7+GJfxbMdY4wslPnjH9rF4N2qfWsEN/l
  6059.      xaZoJYc3a6M02WCnHl6ahT2/tBK2w1QI4YFteR47gCvtgb6O1JHffOo2HfLmRDRi
  6060.      Rjd1DTCHqeyX7CHhcghj/dNRlW2Z0l5QFEcmV9U0Vhp3aFfWC4Ujfs3LU+hkAWzE
  6061.      7zaD5cH9J7yv/6xuZVw411x0h4UqsTcWMu0iM1BzELqX1DY7LwoPEb/O9Rkbf4fm
  6062.      Le11EzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHbuE5p
  6063.      /1oIDznkg/p8kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+Lwqq
  6064.      a8CGrRfsOAJxim63CHfty5mUc5rUSnTslGYEIOCR1BeQauyPZbPDsDD9MZ1ZaSaf
  6065.      anFvwFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGoTbOW
  6066.      I39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev42Lmu
  6067.      QT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkKHt92
  6068.      6s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUOetdZ
  6069.      Whe70YGNPw1yjWJT1IhMBBgRAgAMBQI+PqMdBQkJZgGAAAoJEIxxjTtQcuH17p4A
  6070.      n3r1QpVC9yhnW2cSAjq+kr72GX0eAJ4295kl6NxYEuFApmr1+0uUq/SlsQ==
  6071.      =YJkx
  6072.      -----END PGP PUBLIC KEY BLOCK-----
  6073.  
  6074. You can import the build key into your personal public GPG keyring by
  6075. using `gpg --import'. For example, if you save the key in a file named
  6076. `mysql_pubkey.asc', the import command looks like this:
  6077.  
  6078.      shell> gpg --import mysql_pubkey.asc
  6079.  
  6080. See the GPG documentation for more information on how to work with
  6081. public keys.
  6082.  
  6083. After you have downloaded and imported the public build key, download
  6084. your desired MySQL package and the corresponding signature, which also
  6085. is available from the download page.  The signature file has the same
  6086. name as the distribution file with an `.asc' extension. For example:
  6087.  
  6088. Distribution file      `mysql-standard-4.0.17-pc-linux-i686.tar.gz'
  6089. Signature file         `mysql-standard-4.0.17-pc-linux-i686.tar.gz.asc'
  6090.  
  6091. Make sure that both files are stored in the same directory and then run
  6092. the following command to verify the signature for the distribution file:
  6093.  
  6094.      shell> gpg --verify package_name.asc
  6095.  
  6096. Example:
  6097.  
  6098.      shell> gpg --verify mysql-standard-4.0.17-pc-linux-i686.tar.gz.asc
  6099.      gpg: Warning: using insecure memory!
  6100.      gpg: Signature made Mon 03 Feb 2003 08:50:39 PM MET
  6101.      using DSA key ID 5072E1F5
  6102.      gpg: Good signature from
  6103.           "MySQL Package signing key (www.mysql.com) <build@mysql.com>"
  6104.  
  6105. The `Good signature' message indicates that everything is all right.
  6106. You can ignore the `insecure memory' warning.
  6107.  
  6108. Signature Checking Using `RPM'
  6109. ..............................
  6110.  
  6111. For RPM packages, there is no separate signature. RPM packages have a
  6112. built-in GPG signature and MD5 checksum. You can verify a package by
  6113. running the following command:
  6114.  
  6115.      shell> rpm --checksig package_name.rpm
  6116.  
  6117. Example:
  6118.  
  6119.      shell> rpm --checksig MySQL-server-4.0.10-0.i386.rpm
  6120.      MySQL-server-4.0.10-0.i386.rpm: md5 gpg OK
  6121.  
  6122. *Note*: If you are using RPM 4.1 and it complains about `(GPG) NOT OK
  6123. (MISSING KEYS: GPG#5072e1f5)', even though you have imported the MySQL
  6124. public build key into your own GPG keyring, you need to import the key
  6125. into the RPM keyring first. RPM 4.1 no longer uses your personal GPG
  6126. keyring (or GPG itself). Rather, it maintains its own keyring because
  6127. it is a system-wide application and a user's GPG public keyring is a
  6128. user-specific file. To import the MySQL public key into the RPM
  6129. keyring, first obtain the key as described in the previous section.
  6130. Then use `rpm --import' to import the key.  For example, if you have
  6131. the public key stored in a file named `mysql_pubkey.asc', import it
  6132. using this command:
  6133.  
  6134.      shell> rpm --import mysql_pubkey.asc
  6135.  
  6136. Installation Layouts
  6137. --------------------
  6138.  
  6139. This section describes the default layout of the directories created by
  6140. installing binary or source distributions provided by MySQL AB. If you
  6141. install a distribution provided by another vendor, some other layout
  6142. might be used.
  6143.  
  6144. On Windows, the default installation directory is `C:\mysql', which has
  6145. the following subdirectories:
  6146.  
  6147. *Directory*               *Contents of Directory*
  6148. `bin'                     Client programs and the
  6149.                           `mysqld' server
  6150. `data'                    Log files, databases
  6151. `Docs'                    Documentation
  6152. `examples'                Example programs and scripts
  6153. `include'                 Include (header) files
  6154. `lib'                     Libraries
  6155. `scripts'                 Utility scripts
  6156. `share'                   Error message files
  6157.  
  6158. Installations created from Linux RPM distributions result in files under
  6159. the following system directories:
  6160.  
  6161. *Directory*               *Contents of Directory*
  6162. `/usr/bin'                Client programs and scripts
  6163. `/usr/sbin'               The `mysqld' server
  6164. `/var/lib/mysql'          Log files, databases
  6165. `/usr/share/doc/packages' Documentation
  6166. `/usr/include/mysql'      Include (header) files
  6167. `/usr/lib/mysql'          Libraries
  6168. `/usr/share/mysql'        Error message and character set
  6169.                           files
  6170. `/usr/share/sql-bench'    Benchmarks
  6171.  
  6172. On Unix, a `tar' file binary distribution is installed by unpacking it
  6173. at the installation location you choose (typically `/usr/local/mysql')
  6174. and creates the following directories in that location:
  6175.  
  6176. *Directory*               *Contents of Directory*
  6177. `bin'                     Client programs and the
  6178.                           `mysqld' server
  6179. `data'                    Log files, databases
  6180. `docs'                    Documentation, ChangeLog
  6181. `include'                 Include (header) files
  6182. `lib'                     Libraries
  6183. `scripts'                 `mysql_install_db'
  6184. `share/mysql'             Error message files
  6185. `sql-bench'               Benchmarks
  6186.  
  6187. A source distribution is installed after you configure and compile it.
  6188. By default, the installation step installs files under `/usr/local', in
  6189. the following subdirectories:
  6190.  
  6191. *Directory*               *Contents of Directory*
  6192. `bin'                     Client programs and scripts
  6193. `include/mysql'           Include (header) files
  6194. `info'                    Documentation in Info format
  6195. `lib/mysql'               Libraries
  6196. `libexec'                 The `mysqld' server
  6197. `share/mysql'             Error message files
  6198. `sql-bench'               Benchmarks and `crash-me' test
  6199. `var'                     Databases and log files
  6200.  
  6201. Within an installation directory, the layout of a source installation
  6202. differs from that of a binary installation in the following ways:
  6203.  
  6204.    * The `mysqld' server is installed in the `libexec' directory rather
  6205.      than in the `bin' directory.
  6206.  
  6207.    * The data directory is `var' rather than `data'.
  6208.  
  6209.    * `mysql_install_db' is installed in the `bin' directory rather than
  6210.      in the `scripts' directory.
  6211.  
  6212.    * The header file and library directories are `include/mysql' and
  6213.      `lib/mysql' rather than `include' and `lib'.
  6214.  
  6215. You can create your own binary installation from a compiled source
  6216. distribution by executing the `scripts/make_binary_distribution' script
  6217. from the top directory of the source distribution.
  6218.  
  6219. Standard MySQL Installation Using a Binary Distribution
  6220. =======================================================
  6221.  
  6222. This section covers the installation of MySQL on platforms where we
  6223. offer packages using the native packaging format of the respective
  6224. platform. (This is also known as performing a "binary install.")
  6225. However, binary distributions of MySQL are available for many other
  6226. platforms as well. See *Note Installing binary:: for generic
  6227. installation instructions for these packages that apply to all
  6228. platforms.
  6229.  
  6230. See *Note General Installation Issues:: for more information on what
  6231. other binary distributions are available and how to obtain them.
  6232.  
  6233. Installing MySQL on Windows
  6234. ---------------------------
  6235.  
  6236. The installation process for MySQL on Windows has the following steps:
  6237.  
  6238.   1. Obtain and install the distribution.
  6239.  
  6240.   2. Set up an option file if necessary.
  6241.  
  6242.   3. Select the server you want to use.
  6243.  
  6244.   4. Start the server.
  6245.  
  6246.   5. Assign passwords to the initial MySQL accounts.
  6247.  
  6248.  
  6249. MySQL for Windows is available in two distribution formats:
  6250.  
  6251.    * The binary distribution contains a setup program that installs
  6252.      everything you need so that you can start the server immediately.
  6253.  
  6254.    * The source distribution contains all the code and support files
  6255.      for building the executables using the VC++ 6.0 compiler.
  6256.  
  6257.  
  6258. Generally speaking, you should use the binary distribution. It's
  6259. simpler, and you need no additional tools to get MySQL up and running.
  6260.  
  6261. This section describes how to install MySQL on Windows using a binary
  6262. distribution.  To install using a source distribution, see *Note
  6263. Windows source build::.
  6264.  
  6265. Windows System Requirements
  6266. ...........................
  6267.  
  6268. To run MySQL on Windows, you need the following:
  6269.  
  6270.    * A 32-bit Windows operating system such as 9x, Me, NT, 2000, or XP.
  6271.      The NT family (Windows NT, 2000, and XP) permits you to run the
  6272.      MySQL server as a service. *Note NT start::.
  6273.  
  6274.    * TCP/IP protocol support.
  6275.  
  6276.    * A copy of the MySQL binary distribution for Windows, which can be
  6277.      downloaded from `http://dev.mysql.com/downloads/'.  *Note Getting
  6278.      MySQL::.
  6279.  
  6280.      Note: If you download the distribution via FTP, we recommend the
  6281.      use of an adequate FTP client with a resume feature to avoid
  6282.      corruption of files during the download process.
  6283.  
  6284.    * `WinZip' or other Windows tool that can read `.zip' files, to
  6285.      unpack the distribution file.
  6286.  
  6287.    * Enough space on the hard drive to unpack, install, and create the
  6288.      databases in accordance with your requirements.
  6289.  
  6290.    * If you plan to connect to the MySQL server via ODBC, you also need
  6291.      the `MyODBC' driver. *Note ODBC::.
  6292.  
  6293.    * If you need tables with a size larger than 4GB, install MySQL on
  6294.      an NTFS or newer filesystem. Don't forget to use `MAX_ROWS' and
  6295.      `AVG_ROW_LENGTH' when you create tables.  *Note `CREATE TABLE':
  6296.      CREATE TABLE.
  6297.  
  6298.  
  6299. Installing a Windows Binary Distribution
  6300. ........................................
  6301.  
  6302. To install MySQL on Windows using a binary distribution, follow this
  6303. procedure:
  6304.  
  6305.   1. If you are working on a Windows NT, 2000, or XP machine, make sure
  6306.      that you have logged in as a user with administrator privileges.
  6307.  
  6308.   2. If you are doing an upgrade of an earlier MySQL installation, it
  6309.      is necessary to stop the current server.  On Windows NT, 2000, or
  6310.      XP machines, if you are running the server as a Windows service,
  6311.      stop it as follows from the command prompt:
  6312.  
  6313.           C:\> NET STOP MySQL
  6314.  
  6315.      If you plan to use a different server after the upgrade (for
  6316.      example, if you want to run `mysqld-max' rather than `mysqld'),
  6317.      remove the existing service:
  6318.  
  6319.           C:\> C:\mysql\bin\mysqld --remove
  6320.  
  6321.      You can reinstall the service to use the proper server after
  6322.      upgrading.
  6323.  
  6324.      If you are not running the MySQL server as a service, stop it like
  6325.      this:
  6326.  
  6327.           C:\> C:\mysql\bin\mysqladmin -u root shutdown
  6328.  
  6329.   3. Exit the `WinMySQLAdmin' program if it is running.
  6330.  
  6331.   4. Unzip the distribution file to a temporary directory.
  6332.  
  6333.   5. Run the `setup.exe' program to begin the installation process.  If
  6334.      you want to install MySQL into a location other than the default
  6335.      directory (`C:\mysql'), use the `Browse' button to specify your
  6336.      preferred directory. If you do not install MySQL into the default
  6337.      location, you will need to specify the location whenever you start
  6338.      the server. The easiest way to do this is to use an option file,
  6339.      as described in *Note Windows prepare environment::.
  6340.  
  6341.   6. Finish the install process.
  6342.  
  6343.  
  6344. *Important note:* Early alpha Windows distributions for MySQL 4.1 do
  6345. not contain an installer program.  A 4.1 distribution is a Zip file
  6346. that you just unzip in the location where you want to install MySQL.
  6347. For example, to install `mysql-4.1.1-alpha-win.zip' as `C:\mysql', unzip
  6348. the distribution file on the `C:' drive, then rename the resulting
  6349. `mysql-4.1.1-alpha' directory to `mysql'.
  6350.  
  6351. If you are upgrading to MySQL 4.1 from an earlier version, you will
  6352. want to preserve your existing `data' directory that contains the grant
  6353. tables in the `mysql' database and your own databases.  Before
  6354. installing 4.1, stop the server if it is running, and save your `data'
  6355. directory to another location. Then either rename the existing
  6356. `C:\mysql' directory or remove it.  Install 4.1 as described in the
  6357. preceding paragraph, and then replace its `data' directory with your
  6358. old `data' directory.  This will avoid the loss of your current
  6359. databases.  Start the new server and update the grant tables.  *Note
  6360. Upgrading-grant-tables::.
  6361.  
  6362. Please see *Note Windows troubleshooting:: if you encounter
  6363. difficulties during installation.
  6364.  
  6365. Preparing the Windows MySQL Environment
  6366. .......................................
  6367.  
  6368. If you need to specify startup options when you run the server, you can
  6369. indicate them on the command line or place them in an option file. For
  6370. options that will be used every time the server starts, you will find
  6371. it most convenient to use an option file to specify your MySQL
  6372. configuration. This is true particularly under the following
  6373. circumstances:
  6374.  
  6375.    * The installation or data directory locations are different from
  6376.      the default locations (`C:\mysql' and `C:\mysql\data').
  6377.  
  6378.    * You need to tune the server settings.  For example, to use the
  6379.      `InnoDB' transactional tables in MySQL 3.23, you must manually add
  6380.      some extra lines to the option file, as described in *Note
  6381.      `InnoDB' configuration: InnoDB configuration.  (As of MySQL 4.0,
  6382.      `InnoDB' creates its data files and log files in the data
  6383.      directory by default. This means you need not configure `InnoDB'
  6384.      explicitly.  You may still do so if you wish, and an option file
  6385.      will be useful in this case, too.)
  6386.  
  6387.  
  6388. On Windows, the MySQL installer places the data directory directly under
  6389. the directory where you install MySQL.  If you would like to use a data
  6390. directory in a different location, you should copy the entire contents
  6391. of the `data' directory to the new location. For example, by default,
  6392. the installer places MySQL in `C:\mysql' and the data directory in
  6393. `C:\mysql\data'. If you want to use a data directory of `E:\mydata',
  6394. you must do two things:
  6395.  
  6396.    * Move the data directory from `C:\mysql\data' to `E:\mydata'.
  6397.  
  6398.    * Use a `--datadir' option to specify the new data directory location
  6399.      each time you start the server.
  6400.  
  6401.  
  6402. When the MySQL server starts on Windows, it looks for options in two
  6403. files:  the `my.ini' file in the Windows directory, and the `C:\my.cnf'
  6404. file.  The Windows directory typically is named something like
  6405. `C:\WINDOWS' or `C:\WinNT'.  You can determine its exact location from
  6406. the value of the `WINDIR' environment variable using the following
  6407. command:
  6408.  
  6409.      C:\> echo %WINDIR%
  6410.  
  6411. MySQL looks for options first in the `my.ini' file, then in the
  6412. `my.cnf' file.  However, to avoid confusion, it's best if you use only
  6413. one file.  If your PC uses a boot loader where the `C:' drive isn't the
  6414. boot drive, your only option is to use the `my.ini' file.  Whichever
  6415. option file you use, it must be a plain text file.
  6416.  
  6417. An option file can be created and modified with any text editor, such
  6418. as the `Notepad' program.  For example, if MySQL is installed at
  6419. `E:\mysql' and the data directory is located at `E:\mydata\data', you
  6420. can create the option file and set up a `[mysqld]' section to specify
  6421. values for the `basedir' and `datadir' parameters:
  6422.  
  6423.      [mysqld]
  6424.      # set basedir to your installation path
  6425.      basedir=E:/mysql
  6426.      # set datadir to the location of your data directory
  6427.      datadir=E:/mydata/data
  6428.  
  6429. Note that Windows pathnames are specified in option files using forward
  6430. slashes rather than backslashes.  If you do use backslashes, you must
  6431. double them.
  6432.  
  6433. Another way to manage an option file is to use the `WinMySQLAdmin'
  6434. tool. You can find `WinMySQLAdmin' in the `bin' directory of your MySQL
  6435. installation, as well as a help file containing instructions for using
  6436. it. `WinMySQLAdmin' has the capability of editing your option file, but
  6437. note these points:
  6438.  
  6439.    * `WinMySQLAdmin' uses only the `my.ini' file.
  6440.  
  6441.    * If `WinMySQLAdmin' finds a `C:\my.cnf' file, it will in fact rename
  6442.      it to `C:\my_cnf.bak' to disable it.
  6443.  
  6444.  
  6445. Now you are ready to start the server.
  6446.  
  6447. Selecting a Windows Server
  6448. ..........................
  6449.  
  6450. Starting with MySQL 3.23.38, the Windows distribution includes both the
  6451. normal and the MySQL-Max server binaries.  Here is a list of the
  6452. different MySQL servers from which you can choose:
  6453.  
  6454. *Binary*       *Description*
  6455. `mysqld'       Compiled with full debugging and automatic memory
  6456.                allocation checking, symbolic links, and `InnoDB' and
  6457.                `BDB' tables.
  6458. `mysqld-opt'   Optimized binary.  From version 4.0 on, `InnoDB' is
  6459.                enabled.  Before 4.0, this server includes no
  6460.                transactional table support.
  6461. `mysqld-nt'    Optimized binary for Windows NT, 2000, and XP with
  6462.                support for named pipes.
  6463. `mysqld-max'   Optimized binary with support for symbolic links, and
  6464.                `InnoDB' and `BDB' tables.
  6465. `mysqld-max-nt'Like `mysqld-max', but compiled with support for named
  6466.                pipes.
  6467.  
  6468. All of the preceding binaries are optimized for modern Intel processors,
  6469. but should work on any Intel i386-class or higher processor.
  6470.  
  6471. MySQL supports TCP/IP on all Windows platforms. The `mysqld-nt' and
  6472. `mysql-max-nt' servers support named pipes on NT, 2000, and XP.
  6473. However, the default is to use TCP/IP regardless of the platform.
  6474. (Named pipes are slower than TCP/IP in many Windows configurations.)
  6475. Named pipe use is subject to these conditions:
  6476.  
  6477.    * Starting from MySQL 3.23.50, named pipes are enabled only if you
  6478.      start the server with the `--enable-named-pipe' option.  It is now
  6479.      necessary to use this option explicitly because some users have
  6480.      experienced problems shutting down the MySQL server when named
  6481.      pipes were used.
  6482.  
  6483.    * Named pipe connections are allowed only by the `mysqld-nt' or
  6484.      `mysqld-max-nt' servers, and only if the server is run on a
  6485.      version of Windows that supports named pipes (NT, 2000, XP).
  6486.  
  6487.    * These servers can be run on Windows 98 or Me, but only if TCP/IP
  6488.      is installed; named pipe connections cannot be used.
  6489.  
  6490.    * On Windows 95, these servers cannot be used.
  6491.  
  6492.  
  6493. *Note*: Most of the examples in the following sections use `mysqld' as
  6494. the server name. If you choose to use a different server, such as
  6495. `mysqld-opt', make the appropriate substitutions in the commands that
  6496. are shown in the examples. One good reason to choose a different server
  6497. is that because `mysqld' contains full debugging support, it uses more
  6498. memory and runs slower than the other Windows servers.
  6499.  
  6500. Starting the Server for the First Time
  6501. ......................................
  6502.  
  6503. On Windows 95, 98, or Me, MySQL clients always connect to the server
  6504. using TCP/IP.  (This will allow any machine on your network to connect
  6505. to your MySQL server.)  Because of this, you must make sure that TCP/IP
  6506. support is installed on your machine before starting MySQL.  You can
  6507. find TCP/IP on your Windows CD-ROM.
  6508.  
  6509. Note that if you are using an old Windows 95 release (for example,
  6510. OSR2), it's likely that you have an old Winsock package; MySQL requires
  6511. Winsock 2! You can get the newest Winsock from
  6512. `http://www.microsoft.com/'.  Windows 98 has the new Winsock 2 library,
  6513. so it is unnecessary to update the library.
  6514.  
  6515. On NT-based systems such as Windows NT, 2000, or XP, clients have two
  6516. options. They can use TCP/IP, or they can use a named pipe if the server
  6517. supports named pipe connections.
  6518.  
  6519. For information about which server binary to run, see *Note Windows
  6520. select server::.
  6521.  
  6522. This section gives a general overview of starting the MySQL server.
  6523. The following sections provide more specific information for particular
  6524. versions of Windows.
  6525.  
  6526. The examples in these sections assume that MySQL is installed under the
  6527. default location of `C:\mysql'. Adjust the pathnames shown in the
  6528. examples if you have MySQL installed in a different location.
  6529.  
  6530. Testing is best done from a command prompt in a console window (a "DOS
  6531. window"). This way you can have the server display status messages in
  6532. the window where they are easy to see.  If something is wrong with your
  6533. configuration, these messages will make it easier for you to identify
  6534. and fix any problems.
  6535.  
  6536. To start the server, enter this command:
  6537.  
  6538.      C:\> C:\mysql\bin\mysqld --console
  6539.  
  6540. For servers that include `InnoDB' support, you should see the following
  6541. messages as the server starts:
  6542.  
  6543.      InnoDB: The first specified datafile c:\ibdata\ibdata1 did not exist:
  6544.      InnoDB: a new database to be created!
  6545.      InnoDB: Setting file c:\ibdata\ibdata1 size to 209715200
  6546.      InnoDB: Database physically writes the file full: wait...
  6547.      InnoDB: Log file c:\iblogs\ib_logfile0 did not exist: new to be created
  6548.      InnoDB: Setting log file c:\iblogs\ib_logfile0 size to 31457280
  6549.      InnoDB: Log file c:\iblogs\ib_logfile1 did not exist: new to be created
  6550.      InnoDB: Setting log file c:\iblogs\ib_logfile1 size to 31457280
  6551.      InnoDB: Log file c:\iblogs\ib_logfile2 did not exist: new to be created
  6552.      InnoDB: Setting log file c:\iblogs\ib_logfile2 size to 31457280
  6553.      InnoDB: Doublewrite buffer not found: creating new
  6554.      InnoDB: Doublewrite buffer created
  6555.      InnoDB: creating foreign key constraint system tables
  6556.      InnoDB: foreign key constraint system tables created
  6557.      011024 10:58:25  InnoDB: Started
  6558.  
  6559. When the server finishes its startup sequence, you should see something
  6560. like this, which indicates that the server is ready to service client
  6561. connections:
  6562.  
  6563.      mysqld: ready for connections
  6564.      Version: '4.0.14-log'  socket: ''  port: 3306
  6565.  
  6566. The server will continue to write to the console any further diagnostic
  6567. output it produces.  You can open a new console window in which to run
  6568. client programs.
  6569.  
  6570. If you omit the `--console' option, the server writes diagnostic output
  6571. to the error log in the data directory (`C:\mysql\data' by default).
  6572. The error log is the file with the `.err' extension.
  6573.  
  6574. *Note*: The accounts that are listed in the MySQL grant tables
  6575. initially have no passwords.  After starting the server, you should set
  6576. up passwords for them using the instructions in *Note
  6577. Post-installation::.
  6578.  
  6579. Starting MySQL from the Windows Command Line
  6580. ............................................
  6581.  
  6582. The MySQL server can be started manually from the command line.  This
  6583. can be done on any version of Windows.
  6584.  
  6585. To start the `mysqld' server from the command line, you should start a
  6586. console window (a "DOS window") and enter this command:
  6587.  
  6588.      C:\> C:\mysql\bin\mysqld
  6589.  
  6590. On non-NT versions of Windows, this will start `mysqld' in the
  6591. background. That is, after the server starts, you should see another
  6592. command prompt. If you start the server this way on Windows NT, 2000,
  6593. or XP, the server will run in the foreground and no command prompt will
  6594. appear until the server exits.  Because of this, you should open
  6595. another console window to run client programs while the server is
  6596. running.
  6597.  
  6598. You can stop the MySQL server by executing this command:
  6599.  
  6600.      C:\> C:\mysql\bin\mysqladmin -u root shutdown
  6601.  
  6602. This invokes the MySQL administrative utility `mysqladmin' to connect
  6603. to the server and tell it to shut down. The command connects as `root',
  6604. which is the default administrative account in the MySQL grant system.
  6605. Note that users in the MySQL grant system are wholly independent from
  6606. any login users under Windows.
  6607.  
  6608. If `mysqld' doesn't start, check the error log to see whether the
  6609. server wrote any messages there to indicate the cause of the problem.
  6610. The error log is located in the `C:\mysql\data' directory. It is the
  6611. file with a suffix of `.err'. You can also try to start the server as
  6612. `mysqld --console'; in this case, you may get some useful information
  6613. on the screen that may help solve the problem.
  6614.  
  6615. The last option is to start `mysqld' with `--standalone --debug'.  In
  6616. this case, `mysqld' will write a log file `C:\mysqld.trace' that should
  6617. contain the reason why `mysqld' doesn't start. *Note Making trace
  6618. files::.
  6619.  
  6620. Use `mysqld --help' to display all the options that `mysqld'
  6621. understands!
  6622.  
  6623. Starting MySQL as a Windows Service
  6624. ...................................
  6625.  
  6626. On the NT family (Windows NT, 2000, or XP), the recommended way to run
  6627. MySQL is to install it as a Windows service. Then Windows starts and
  6628. stops the MySQL server automatically when Windows starts and stops. A
  6629. server installed as a service can also be controlled from the command
  6630. line using `NET' commands, or with the graphical `Services' utility.
  6631.  
  6632. The `Services' utility (the Windows `Service Control Manager') can be
  6633. found in the Windows `Control Panel' (under `Administrative Tools' on
  6634. Windows 2000 or XP). It is advisable to close the `Services' utility
  6635. while performing server installation or removal operations from this
  6636. command line.  This prevents some odd errors.
  6637.  
  6638. To get MySQL to work with TCP/IP on Windows NT 4, you must install
  6639. service pack 3 (or newer).
  6640.  
  6641. Before installing MySQL as a Windows service, you should first stop the
  6642. current server if it is running by using the following command:
  6643.  
  6644.      C:\> C:\mysql\bin\mysqladmin -u root shutdown
  6645.  
  6646. This invokes the MySQL administrative utility `mysqladmin' to connect
  6647. to the server and tell it to shut down. The command connects as `root',
  6648. which is the default administrative account in the MySQL grant system.
  6649. Note that users in the MySQL grant system are wholly independent from
  6650. any login users under Windows.
  6651.  
  6652. Now install the server as a service:
  6653.  
  6654.      C:\> mysqld --install
  6655.  
  6656. If you have problems installing `mysqld' as a service using just the
  6657. server name, try installing it using its full pathname:
  6658.  
  6659.      C:\> C:\mysql\bin\mysqld --install
  6660.  
  6661. As of MySQL 4.0.2, you can specify a specific service name after the
  6662. `--install' option.  As of MySQL 4.0.3, you can in addition specify a
  6663. `--defaults-file' option after the service name to indicate where the
  6664. server should obtain options when it starts. The rules that determine
  6665. the service name and option files the server uses are as follows:
  6666.  
  6667.    * If you specify no service name, the server uses the default
  6668.      service name of `MySQL' and the server reads options from the
  6669.      `[mysqld]' group in the standard option files.
  6670.  
  6671.    * If you specify a service name after the `--install' option, the
  6672.      server ignores the `[mysqld]' option group and instead reads
  6673.      options from the group that has the same name as the service. The
  6674.      server reads options from the standard option files.
  6675.  
  6676.    * If you specify a `--defaults-file' option after the service name,
  6677.      the server ignores the standard option files and reads options
  6678.      only from the `[mysqld]' group of the named file.
  6679.  
  6680.  
  6681. *Note*: Prior to MySQL 4.0.17, a server installed as a Windows service
  6682. has problems starting if its pathname or the service name contains
  6683. spaces. For this reason, avoid installing MySQL in a directory such as
  6684. `C:\Program Files' or using a service name containing spaces.
  6685.  
  6686. In the usual case that you install the server with `--install' but no
  6687. service name, the server is installed with a service name of `MySQL'.
  6688.  
  6689. As a more complex example, consider the following command:
  6690.  
  6691.      C:\> C:\mysql\bin\mysqld --install mysql --defaults-file=C:\my-opts.cnf
  6692.  
  6693. Here, a service name is given after the `--install' option. If no
  6694. `--defaults-file' option had been given, this command would have the
  6695. effect of causing the server to read the `[mysql]' group from the
  6696. standard option files. (This would be a bad idea, because that option
  6697. group is for use by the `mysql' client program.) However, because the
  6698. `--defaults-file' option is present, the server reads options only from
  6699. the named file, and only from the `[mysqld]' option group.
  6700.  
  6701. You can also specify options as "`Start parameters'" in the Windows
  6702. `Services' utility before you start the MySQL service.
  6703.  
  6704. Once a MySQL server is installed as a service, Windows will start the
  6705. service automatically whenever Windows starts.  The service also can be
  6706. started immediately from the `Services' utility, or by using the
  6707. command `NET START MySQL'.  The `NET' command is not case sensitive.
  6708.  
  6709. When run as a service, `mysqld' has no access to a console window, so
  6710. no messages can be seen there.  If `mysqld' doesn't start, check the
  6711. error log to see whether the server wrote any messages there to
  6712. indicate the cause of the problem.  The error log is located in the
  6713. `C:\mysql\data' directory. It is the file with a suffix of `.err'.
  6714.  
  6715. When `mysqld' is running as a service, it can be stopped by using the
  6716. `Services' utility, the command `NET STOP MySQL', or the command
  6717. `mysqladmin shutdown'. If the service is running when Windows shuts
  6718. down, Windows will stop the server automatically.
  6719.  
  6720. From MySQL 3.23.44 on, you have the choice of installing the server as
  6721. a `Manual' service if you don't wish the service to be started
  6722. automatically during the boot process. To do this, use the
  6723. `--install-manual' option rather than the `--install' option:
  6724.  
  6725.      C:\> C:\mysql\bin\mysqld --install-manual
  6726.  
  6727. To remove a server that is installed as a service, first stop it if it
  6728. is running. Then use the `--remove' option to remove it:
  6729.  
  6730.      C:\> C:\mysql\bin\mysqld --remove
  6731.  
  6732. For MySQL versions older than 3.23.49, one problem with automatic MySQL
  6733. service shutdown is that Windows waited only for a few seconds for the
  6734. shutdown to complete, then killed the database server process if the
  6735. time limit was exceeded. This had the potential to cause problems.
  6736. (For example, the `InnoDB' storage engine had to perform crash recovery
  6737. at the next startup.) Starting from MySQL 3.23.49, Windows waits longer
  6738. for the MySQL server shutdown to complete. If you notice this still is
  6739. not enough for your installation, it is safest not to run the MySQL
  6740. server as a service. Instead, start it from the command-line prompt,
  6741. and stop it with `mysqladmin shutdown'.
  6742.  
  6743. This change to tell Windows to wait longer when stopping the MySQL
  6744. server works for Windows 2000 and XP. It does not work for Windows NT,
  6745. where Windows waits only 20 seconds for a service to shut down, and
  6746. after that kills the service process. You can increase this default by
  6747. opening the Registry Editor `\winnt\system32\regedt32.exe' and editing
  6748. the value of `WaitToKillServiceTimeout' at
  6749. `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' in the Registry
  6750. tree. Specify the new larger value in milliseconds.  For example, the
  6751. value 120000 tells Windows NT to wait up to 120 seconds.
  6752.  
  6753. If you don't want to start `mysqld' as a service, you can start it from
  6754. the command line.  For instructions, see *Note Win95 start::.
  6755.  
  6756. Please see *Note Windows troubleshooting:: if you encounter
  6757. difficulties during installation.
  6758.  
  6759. Troubleshooting a MySQL Installation Under Windows
  6760. ..................................................
  6761.  
  6762. When installing and running MySQL for the first time, you may encounter
  6763. certain errors that prevent the MySQL server from starting.  The
  6764. purpose of this section is to help you diagnose and correct some of
  6765. these errors.
  6766.  
  6767. Your first resource when troubleshooting server issues is the error log.
  6768. The MySQL server uses the error log to record information relevant to
  6769. the error that is preventing the server from starting. The error log is
  6770. located in the data directory specified in your `my.ini' file.  The
  6771. default data directory location is `C:\mysql\data'.  *Note Error log::.
  6772.  
  6773. Another source of information regarding possible errors is the console
  6774. messages displayed when the MySQL service is starting. Use the `NET
  6775. START mysql' command from the command line after installing `mysqld' as
  6776. a service to see any error messages regarding the starting of the MySQL
  6777. server as a service.  *Note NT start::.
  6778.  
  6779. The following are examples of some of the more common error messages
  6780. you may encounter when installing MySQL and starting the server for the
  6781. first time:
  6782.  
  6783.      System error 1067 has occurred.
  6784.      Fatal error: Can't open privilege tables: Table 'mysql.host' doesn't exist
  6785.  
  6786. These messages occur when the MySQL server cannot find the `mysql'
  6787. privileges database or other critical files. This error is often
  6788. encountered when the MySQL base or data directories are installed in
  6789. different locations than the default locations (`C:\mysql' and
  6790. `C:\mysql\data', respectively).
  6791.  
  6792. If you have installed MySQL to a directory other than `C:\mysql' you
  6793. will need to ensure that the MySQL server is aware of this through the
  6794. use of a configuration (`my.ini') file. The `my.ini' file needs to be
  6795. located in your Windows directory, typically located at `C:\WinNT' or
  6796. `C:\WINDOWS'. You can determine its exact location from the value of
  6797. the `WINDIR' environment variable by issuing the following command from
  6798. the command prompt:
  6799.  
  6800.      C:\> echo %WINDIR%
  6801.  
  6802. An option file can be created and modified with any text editor, such
  6803. as the Notepad program. For example, if MySQL is installed at
  6804. `E:\mysql' and the data directory is located at `D:\MySQLdata', you can
  6805. create the option file and set up a `[mysqld]' section to specify
  6806. values for the basedir and datadir parameters:
  6807.  
  6808.      [mysqld]
  6809.      # set basedir to your installation path
  6810.      basedir=E:/mysql
  6811.      # set datadir to the location of your data directory
  6812.      datadir=D:/MySQLdata
  6813.  
  6814. Note that Windows pathnames are specified in option files using forward
  6815. slashes rather than backslashes. If you do use backslashes, you must
  6816. double them:
  6817.  
  6818.      [mysqld]
  6819.      # set basedir to your installation path
  6820.      basedir=C:\\Program Files\\mysql
  6821.      # set datadir to the location of your data directory
  6822.      datadir=D:\\MySQLdata
  6823. *Note Windows prepare environment::.
  6824.  
  6825. Running MySQL Client Programs on Windows
  6826. ........................................
  6827.  
  6828. You can test whether the MySQL server is working by executing any of the
  6829. following commands:
  6830.  
  6831.      C:\> C:\mysql\bin\mysqlshow
  6832.      C:\> C:\mysql\bin\mysqlshow -u root mysql
  6833.      C:\> C:\mysql\bin\mysqladmin version status proc
  6834.      C:\> C:\mysql\bin\mysql test
  6835.  
  6836. If `mysqld' is slow to respond to TCP/IP connections from client
  6837. programs on Windows 9x/Me, there is probably a problem with your DNS.
  6838. In this case, start `mysqld' with the `--skip-name-resolve' option and
  6839. use only `localhost' and IP numbers in the `Host' column of the MySQL
  6840. grant tables.
  6841.  
  6842. You can force a MySQL client to use a named pipe connection rather than
  6843. TCP/IP  by specifying the `--pipe' option or by specifying `.' (period)
  6844. as the host name.  Use the `--socket' option to specify the name of the
  6845. pipe.  As of MySQL 4.1, you should use the `--protocol=PIPE' option.
  6846.  
  6847. There are two versions of the MySQL command-line tool:
  6848. *Binary*       *Description*
  6849. `mysql'        Compiled on native Windows, offering limited text editing
  6850.                capabilities.
  6851. `mysqlc'       Compiled with the Cygnus GNU compiler and libraries,
  6852.                which offers `readline' editing.
  6853.  
  6854. If you want to use `mysqlc', you must have a copy of the
  6855. `cygwinb19.dll' library installed somewhere that `mysqlc' can find it.
  6856. Current distributions of MySQL include this library in the same
  6857. directory as `mysqlc' (the `bin' directory under the base directory of
  6858. your MySQL installation). If your distribution does not have the
  6859. `cygwinb19.dll' library in the `bin' directory, look for it in the
  6860. `lib' directory and copy it to your Windows system directory
  6861. (`\Windows\system' or a similar place).
  6862.  
  6863. MySQL on Windows Compared to MySQL on Unix
  6864. ..........................................
  6865.  
  6866. MySQL for Windows has by now proven itself to be very stable. The
  6867. Windows version of MySQL has the same features as the corresponding
  6868. Unix version, with the following exceptions:
  6869.  
  6870. *Windows 95 and threads*
  6871.      Windows 95 leaks about 200 bytes of main memory for each thread
  6872.      creation.  Each connection in MySQL creates a new thread, so you
  6873.      shouldn't run `mysqld' for an extended time on Windows 95 if your
  6874.      server handles many connections!  Other versions of Windows don't
  6875.      suffer from this bug.
  6876.  
  6877. *Limited number of ports*
  6878.      Windows systems have about 4,000 ports available for client
  6879.      connections, and after a connection on a port closes, it takes two
  6880.      to four minutes before the port can be reused.  In situations
  6881.      where clients connect to and disconnect from the server at a high
  6882.      rate, it is possible for all available ports to be used up before
  6883.      closed ports become available again. If this happens, the MySQL
  6884.      server will appear to have become unresponsive even though it is
  6885.      running.  Note that ports may be used by other applications
  6886.      running on the machine as well, in which case the number of ports
  6887.      available to MySQL is lower.
  6888.  
  6889.      For more information, see
  6890.      `http://support.microsoft.com/default.aspx?scid=kb;en-us;196271'.
  6891.  
  6892. *Concurrent reads*
  6893.      MySQL depends on the `pread()' and `pwrite()' calls to be able to
  6894.      mix `INSERT' and `SELECT'.  Currently we use mutexes to emulate
  6895.      `pread()'/`pwrite()'.  We will, in the long run, replace the file
  6896.      level interface with a virtual interface so that we can use the
  6897.      `readfile()'/`writefile()' interface on NT, 2000, and XP to get
  6898.      more speed.  The current implementation limits the number of open
  6899.      files MySQL can use to 2,048 (1,024 before MySQL 4.0.19), which
  6900.      means that you will not be able to run as many concurrent threads
  6901.      on NT, 2000, and XP as on Unix.
  6902.  
  6903. *Blocking read*
  6904.      MySQL uses a blocking read for each connection, which has the
  6905.      following implications if named pipe connections are enabled:
  6906.  
  6907.         * A connection will not be disconnected automatically after
  6908.           eight hours, as happens with the Unix version of MySQL.
  6909.  
  6910.         * If a connection hangs, it's impossible to break it without
  6911.           killing MySQL.
  6912.  
  6913.         * `mysqladmin kill' will not work on a sleeping connection.
  6914.  
  6915.         * `mysqladmin shutdown' can't abort as long as there are
  6916.           sleeping connections.
  6917.  
  6918.      We plan to fix this problem when our Windows developers have
  6919.      figured out a nice workaround.
  6920.  
  6921. *`ALTER TABLE'*
  6922.      While you are executing an `ALTER TABLE' statement, the table is
  6923.      locked from being used by other threads.  This has to do with the
  6924.      fact that on Windows, you can't delete a file that is in use by
  6925.      another thread.  In the future, we may find some way to work
  6926.      around this problem.
  6927.  
  6928. *`DROP TABLE'*
  6929.      `DROP TABLE' on a table that is in use by a `MERGE' table will not
  6930.      work on Windows because the `MERGE' handler does the table mapping
  6931.      hidden from the upper layer of MySQL.  Because Windows doesn't
  6932.      allow you to drop files that are open, you first must flush all
  6933.      `MERGE' tables (with `FLUSH TABLES') or drop the `MERGE' table
  6934.      before dropping the table.  We will fix this at the same time we
  6935.      introduce views.
  6936.  
  6937. *`DATA DIRECTORY' and `INDEX DIRECTORY'*
  6938.      The `DATA DIRECTORY' and `INDEX DIRECTORY' options for `CREATE
  6939.      TABLE' are ignored on Windows, because Windows doesn't support
  6940.      symbolic links.  These options also are ignored on systems that
  6941.      have a non-functional `realpath()' call.
  6942.  
  6943. *`DROP DATABASE'*
  6944.      You cannot drop a database that is in use by some thread.
  6945.  
  6946. *Killing MySQL from the Task Manager*
  6947.      You cannot kill MySQL from the Task Manager or with the shutdown
  6948.      utility in Windows 95.  You must take it down with `mysqladmin
  6949.      shutdown'.
  6950.  
  6951. *Case-insensitive names*
  6952.      Filenames are not case sensitive on Windows, so MySQL database and
  6953.      table names are also not case sensitive on Windows.  The only
  6954.      restriction is that database and table names must be specified
  6955.      using the same case throughout a given statement.  *Note Name case
  6956.      sensitivity::.
  6957.  
  6958. *The `\' pathname separator character*
  6959.      Pathname components in Windows 95 are separated by the `\'
  6960.      character, which is also the escape character in MySQL.  If you
  6961.      are using `LOAD DATA INFILE' or `SELECT ... INTO OUTFILE', use
  6962.      Unix-style filenames with `/' characters:
  6963.  
  6964.           mysql> LOAD DATA INFILE 'C:/tmp/skr.txt' INTO TABLE skr;
  6965.           mysql> SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr;
  6966.  
  6967.      Alternatively, you must double the `\' character:
  6968.  
  6969.           mysql> LOAD DATA INFILE 'C:\\tmp\\skr.txt' INTO TABLE skr;
  6970.           mysql> SELECT * INTO OUTFILE 'C:\\tmp\\skr.txt' FROM skr;
  6971.  
  6972. *Problems with pipes.*
  6973.      Pipes do not work reliably from the Windows command-line prompt.
  6974.      If the pipe includes the character `^Z' / `CHAR(24)', Windows will
  6975.      think it has encountered end-of-file and abort the program.
  6976.  
  6977.      This is mainly a problem when you try to apply a binary log as
  6978.      follows:
  6979.  
  6980.           C:\> mysqlbinlog binary-log-name | mysql --user=root
  6981.  
  6982.      If you have a problem applying the log and suspect that it is
  6983.      because of a `^Z' / `CHAR(24)' character, you can use the
  6984.      following workaround:
  6985.  
  6986.           C:\> mysqlbinlog binary-log-file --result-file=/tmp/bin.sql
  6987.           C:\> mysql --user=root --execute "source /tmp/bin.sql"
  6988.  
  6989.      The latter command also can be used to reliably read in any SQL
  6990.      file that may contain binary data.
  6991.  
  6992. *`Can't open named pipe' error*
  6993.      If you use a MySQL 3.22 server on Windows NT with the newest MySQL
  6994.      client programs, you will get the following error:
  6995.  
  6996.           error 2017: can't open named pipe to host: . pipe...
  6997.  
  6998.      This happens because the release version of MySQL uses named pipes
  6999.      on NT by default.  You can avoid this error by using the
  7000.      `--host=localhost' option to the new MySQL clients or by creating
  7001.      an option file `C:\my.cnf' that contains the following information:
  7002.  
  7003.           [client]
  7004.           host = localhost
  7005.  
  7006.      Starting from 3.23.50, named pipes are enabled only if `mysqld-nt'
  7007.      or `mysqld-max-nt' is started with `--enable-named-pipe'.
  7008.  
  7009. *`Access denied for user' error*
  7010.      If you attempt to run a MySQL client program to connect to a server
  7011.      running on the same machine, but get the error `Access denied for
  7012.      user 'SOME-USER'@'unknown' to database 'mysql'', this means that
  7013.      MySQL cannot resolve your hostname properly.
  7014.  
  7015.      To fix this, you should create a file named `\windows\hosts'
  7016.      containing the following information:
  7017.  
  7018.           127.0.0.1       localhost
  7019.  
  7020. Here are some open issues for anyone who might want to help us improve
  7021. MySQL on Windows:
  7022.  
  7023.    * Add some nice start and shutdown icons to the MySQL installation.
  7024.  
  7025.    * It would be really nice to be able to kill `mysqld' from the Task
  7026.      Manager in Windows 95.  For the moment, you must use `mysqladmin
  7027.      shutdown'.
  7028.  
  7029.    * Port `readline' to Windows for use in the `mysql' command-line
  7030.      tool.
  7031.  
  7032.    * GUI versions of the standard MySQL clients (`mysql', `mysqlshow',
  7033.      `mysqladmin', and `mysqldump') would be nice.
  7034.  
  7035.    * It would be nice if the socket read and write functions in `net.c'
  7036.      were interruptible. This would make it possible to kill open
  7037.      threads with `mysqladmin kill' on Windows.
  7038.  
  7039.    * Add macros to use the faster thread-safe increment/decrement
  7040.      methods provided by Windows.
  7041.  
  7042. Installing MySQL on Linux
  7043. -------------------------
  7044.  
  7045. The recommended way to install MySQL on Linux is by using the RPM
  7046. packages. The MySQL RPMs are currently built on a SuSE Linux 7.3
  7047. system, but should work on most versions of Linux that support `rpm'
  7048. and use `glibc'.  To obtain RPM packages, see *Note Getting MySQL::.
  7049.  
  7050. *Note*: RPM distributions of MySQL often are provided by other vendors.
  7051. Be aware that they may differ in features and capabilities from those
  7052. built by MySQL AB, and that the instructions in this manual do not
  7053. necessarily apply to installing them. The vendor's instructions should
  7054. be consulted instead.
  7055.  
  7056. If you have problems with an RPM file (for example, if you receive the
  7057. error "`Sorry, the host 'XXXX' could not be looked up'"), see *Note
  7058. Binary notes-Linux::.
  7059.  
  7060. In most cases, you only need to install the `MySQL-server' and
  7061. `MySQL-client' packages to get a functional MySQL installation. The
  7062. other packages are not required for a standard installation.  If you
  7063. want to run a MySQL-Max server that has additional capabilities, you
  7064. should also install the `MySQL-Max' RPM. However, you should do so only
  7065. _ after_ installing the `MySQL-server' RPM.  *Note `mysqld-max':
  7066. mysqld-max.
  7067.  
  7068. If you get a dependency failure when trying to install the MySQL 4.0
  7069. packages (for example, "`error: removing these packages would break
  7070. dependencies: libmysqlclient.so.10 is needed by ...'"), you should also
  7071. install the package `MySQL-shared-compat', which includes both the
  7072. shared libraries for backward compatibility (`libmysqlclient.so.12' for
  7073. MySQL 4.0 and `libmysqlclient.so.10' for MySQL 3.23).
  7074.  
  7075. Many Linux distributions still ship with MySQL 3.23 and they usually
  7076. link applications dynamically to save disk space. If these shared
  7077. libraries are in a separate package (for example, `MySQL-shared'), it is
  7078. sufficient to simply leave this package installed and just upgrade the
  7079. MySQL server and client packages (which are statically linked and do
  7080. not depend on the shared libraries). For distributions that include the
  7081. shared libraries in the same package as the MySQL server (for example,
  7082. Red Hat Linux), you could either install our 3.23 `MySQL-shared' RPM,
  7083. or use the `MySQL-shared-compat' package instead.
  7084.  
  7085. The following RPM packages are available:
  7086.  
  7087.    * `MySQL-server-VERSION.i386.rpm'
  7088.  
  7089.      The MySQL server.  You will need this unless you only want to
  7090.      connect to a MySQL server running on another machine. Note: Server
  7091.      RPM files were called `MySQL-VERSION.i386.rpm' before MySQL
  7092.      4.0.10. That is, they did not have `-server' in the name.
  7093.  
  7094.    * `MySQL-Max-VERSION.i386.rpm'
  7095.  
  7096.      The MySQL-Max server. This server has additional capabilities that
  7097.      the one provided in the `MySQL-server' RPM does not.  You must
  7098.      install the `MySQL-server' RPM first, because the `MySQL-Max' RPM
  7099.      depends on it.
  7100.  
  7101.    * `MySQL-client-VERSION.i386.rpm'
  7102.  
  7103.      The standard MySQL client programs. You probably always want to
  7104.      install this package.
  7105.  
  7106.    * `MySQL-bench-VERSION.i386.rpm'
  7107.  
  7108.      Tests and benchmarks. Requires Perl and the `DBD::mysql' module.
  7109.  
  7110.    * `MySQL-devel-VERSION.i386.rpm'
  7111.  
  7112.      The libraries and include files that are needed if you want to
  7113.      compile other MySQL clients, such as the Perl modules.
  7114.  
  7115.    * `MySQL-shared-VERSION.i386.rpm'
  7116.  
  7117.      This package contains the shared libraries (`libmysqlclient.so*')
  7118.      that certain languages and applications need to dynamically load
  7119.      and use MySQL.
  7120.  
  7121.    * `MySQL-shared-compat-VERSION.i386.rpm'
  7122.  
  7123.      This package includes the shared libraries for both MySQL 3.23 and
  7124.      MySQL 4.0. Install this package instead of `MySQL-shared' if you
  7125.      have applications installed that are dynamically linked against
  7126.      MySQL 3.23 but you want to upgrade to MySQL 4.0 without breaking
  7127.      the library dependencies. This package has been available since
  7128.      MySQL 4.0.13.
  7129.  
  7130.    * `MySQL-embedded-VERSION.i386.rpm'
  7131.  
  7132.      The embedded MySQL server library (from MySQL 4.0).
  7133.  
  7134.    * `MySQL-VERSION.src.rpm'
  7135.  
  7136.      This contains the source code for all of the previous packages. It
  7137.      can also be used to rebuild the RPMs on other architectures (for
  7138.      example, Alpha or SPARC).
  7139.  
  7140. To see all files in an RPM package (for example, a `MySQL-server' RPM),
  7141. run:
  7142.  
  7143.      shell> rpm -qpl MySQL-server-VERSION.i386.rpm
  7144.  
  7145. To perform a standard minimal installation, run:
  7146.  
  7147.      shell> rpm -i MySQL-server-VERSION.i386.rpm
  7148.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  7149.  
  7150. To install just the client package, run:
  7151.  
  7152.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  7153.  
  7154. RPM provides a feature to verify the integrity and authenticity of
  7155. packages before installing them. If you would like to learn more about
  7156. this feature, see *Note Verifying Package Integrity::.
  7157.  
  7158. The server RPM places data under the `/var/lib/mysql' directory. The
  7159. RPM also creates a login account for a user named `mysql' (if one does
  7160. not already exist) to use for running the MySQL server, and creates the
  7161. appropriate entries in `/etc/init.d/' to start the server automatically
  7162. at boot time. (This means that if you have performed a previous
  7163. installation and have made changes to its startup script, you may want
  7164. to make a copy of the script so that you don't lose it when you install
  7165. a newer RPM.) See *Note Automatic start:: for more information on how
  7166. MySQL can be started automatically on system startup.
  7167.  
  7168. If you want to install the MySQL RPM on older Linux distributions that
  7169. do not support initialization scripts in `/etc/init.d' (directly or via
  7170. a symlink), you should create a symbolic link that points to the
  7171. location where your initialization scripts actually are installed. For
  7172. example, if that location is `/etc/rc.d/init.d', use these commands
  7173. before installing the RPM to create `/etc/init.d' as a symbolic link
  7174. that points there:
  7175.  
  7176.      shell> cd /etc
  7177.      shell> ln -s rc.d/init.d .
  7178.  
  7179. However, all current major Linux distributions should already support
  7180. the new directory layout that uses `/etc/init.d', because it is
  7181. required for LSB (Linux Standard Base) compliance.
  7182.  
  7183. If the RPM files that you install include `MySQL-server', the `mysqld'
  7184. server should be up and running after installation.  You should now be
  7185. able to start using MySQL.
  7186.  
  7187. If something goes wrong, you can find more information in the binary
  7188. installation section. *Note Installing binary::.
  7189.  
  7190. *Note*: The accounts that are listed in the MySQL grant tables
  7191. initially have no passwords.  After starting the server, you should set
  7192. up passwords for them using the instructions in *Note
  7193. Post-installation::.
  7194.  
  7195. Installing MySQL on Mac OS X
  7196. ----------------------------
  7197.  
  7198. Beginning with MySQL 4.0.11, you can install MySQL on Mac OS X 10.2.x
  7199. ("Jaguar") and up using a Mac OS X binary package in PKG format instead
  7200. of the binary tarball distribution. Please note that older versions of
  7201. Mac OS X (for example, 10.1.x) are not supported by this package.
  7202.  
  7203. The package is located inside a disk image (`.dmg') file that you first
  7204. need to mount by double-clicking its icon in the Finder. It should then
  7205. mount the image and display its contents.
  7206.  
  7207. To obtain MySQL, see *Note Getting MySQL::.
  7208.  
  7209. *Note*: Before proceeding with the installation, be sure to shut down
  7210. all running MySQL server instances by either using the MySQL Manager
  7211. Application (on Mac OS X Server) or via `mysqladmin shutdown' on the
  7212. command line.
  7213.  
  7214. To actually install the MySQL PKG file, double-click on the package
  7215. icon. This launches the Mac OS X Package Installer, which will guide
  7216. you through the installation of MySQL.
  7217.  
  7218. Due to a bug in the Mac OS X package installer, you may see this error
  7219. message in the destination disk selection dialog:
  7220.  
  7221.      You cannot install this software on this disk. (null)
  7222.  
  7223. If this error occurs, simply click the `Go Back' button once to return
  7224. to the previous screen. Then click `Continue' to advance to the
  7225. destination disk selection again, and you should be able to choose the
  7226. destination disk correctly. We have reported this bug to Apple and it is
  7227. investigating this problem.
  7228.  
  7229. The Mac OS X PKG of MySQL will install itself into
  7230. `/usr/local/mysql-VERSION' and will also install a symbolic link,
  7231. `/usr/local/mysql', pointing to the new location. If a directory named
  7232. `/usr/local/mysql' already exists, it will be renamed to
  7233. `/usr/local/mysql.bak' first. Additionally, the installer will create
  7234. the grant tables in the `mysql' database by executing `mysql_install_db'
  7235. after the installation.
  7236.  
  7237. The installation layout is similar to that of a `tar' file binary
  7238. distribution; all MySQL binaries are located in the directory
  7239. `/usr/local/mysql/bin'.  The MySQL socket file is created as
  7240. `/tmp/mysql.sock' by default.  *Note Installation layouts::.
  7241.  
  7242. MySQL installation requires a Mac OS X user account named `mysql'.  A
  7243. user account with this name should exist by default on Mac OS X 10.2
  7244. and up.
  7245.  
  7246. If you are running Mac OS X Server, you already have a version of MySQL
  7247. installed.  The versions of MySQL that ship with Mac OS X Server
  7248. versions are shown in the following table:
  7249.  
  7250. *Mac OS X Server       *MySQL Version*
  7251. Version*               
  7252. 10.2-10.2.2            3.23.51
  7253. 10.2.3-10.2.6          3.23.53
  7254. 10.3                   4.0.14
  7255. 10.3.2                 4.0.16
  7256.  
  7257. This manual section covers the installation of the official MySQL Mac
  7258. OS X PKG only.  Make sure to read Apple's help information about
  7259. installing MySQL: Run the "Help View" application, select "Mac OS X
  7260. Server" help, do a search for "MySQL," and read the item entitled
  7261. "Installing MySQL."
  7262.  
  7263. For pre-installed versions of MySQL on Mac OS X Server, note especially
  7264. that you should start `mysqld' with `safe_mysqld' instead of
  7265. `mysqld_safe' if MySQL is older than version 4.0.
  7266.  
  7267. If you previously used Marc Liyanage's MySQL packages for Mac OS X from
  7268. `http://www.entropy.ch', you can simply follow the update instructions
  7269. for packages using the binary installation layout as given on his pages.
  7270.  
  7271. If you are upgrading from Marc's 3.23.xx versions or from the Mac OS X
  7272. Server version of MySQL to the official MySQL PKG, you also need to
  7273. convert the existing MySQL privilege tables to the current format,
  7274. because some new security privileges have been added.  *Note
  7275. Upgrading-grant-tables::.
  7276.  
  7277. If you would like to automatically start up MySQL during system
  7278. startup, you also need to install the MySQL Startup Item. Starting with
  7279. MySQL 4.0.15, it is part of the Mac OS X installation disk images as a
  7280. separate installation package. Simply double-click the
  7281. `MySQLStartupItem.pkg' icon and follow the instructions to install it.
  7282.  
  7283. Note that the Startup Item need be installed only once! There is no
  7284. need to install it each time you upgrade the MySQL package later.
  7285.  
  7286. The Startup Item will be installed into
  7287. `/Library/StartupItems/MySQLCOM'.  (Before MySQL 4.1.2, the location
  7288. was `/Library/StartupItems/MySQL', but that collided with the MySQL
  7289. Startup Item installed by Mac OS X Server.)  Startup Item installation
  7290. adds a variable `MYSQLCOM=-YES-' to the system configuration file
  7291. `/etc/hostconfig'. If you would like to disable the automatic startup
  7292. of MySQL, simply change this variable to `MYSQLCOM=-NO-'.
  7293.  
  7294. On Mac OS X Server, the default MySQL installation uses the variable
  7295. `MYSQL' in the `/etc/hostconfig' file.  The MySQL AB Startup Item
  7296. installer disables this variable by setting it to `MYSQL=-NO-'. This
  7297. avoids boot time conflicts with the `MYSQLCOM' variable used by the
  7298. MySQL AB Startup Item.  However, it does not shut down an already
  7299. running MySQL server. You should do that yourself.
  7300.  
  7301. After the installation, you can start up MySQL by running the following
  7302. commands in a terminal window. You must have administrator privileges to
  7303. perform this task.
  7304.  
  7305. If you have installed the Startup Item:
  7306.  
  7307.      shell> sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
  7308.      (Enter your password, if necessary)
  7309.      (Press Control-D or enter "exit" to exit the shell)
  7310.  
  7311. For versions of MySQL older than 4.1.3, substitute
  7312. `/Library/StartupItems/MySQLCOM/MySQLCOM' with
  7313. `/Library/StartupItems/MySQL/MySQL' above.
  7314.  
  7315. If you don't use the Startup Item, enter the following command sequence:
  7316.  
  7317.      shell> cd /usr/local/mysql
  7318.      shell> sudo ./bin/mysqld_safe
  7319.      (Enter your password, if necessary)
  7320.      (Press Control-Z)
  7321.      shell> bg
  7322.      (Press Control-D or enter "exit" to exit the shell)
  7323.  
  7324. You should now be able to connect to the MySQL server, for example, by
  7325. running `/usr/local/mysql/bin/mysql'.
  7326.  
  7327. *Note*: The accounts that are listed in the MySQL grant tables
  7328. initially have no passwords.  After starting the server, you should set
  7329. up passwords for them using the instructions in *Note
  7330. Post-installation::.
  7331.  
  7332. You might want to add aliases to your shell's resource file to make it
  7333. easier to access commonly used programs such as `mysql' and `mysqladmin'
  7334. from the command line. The syntax for `tcsh' is:
  7335.  
  7336.      alias mysql /usr/local/mysql/bin/mysql
  7337.      alias mysqladmin /usr/local/mysql/bin/mysqladmin
  7338.  
  7339. For `bash', use:
  7340.  
  7341.      alias mysql=/usr/local/mysql/bin/mysql
  7342.      alias mysqladmin=/usr/local/mysql/bin/mysqladmin
  7343.  
  7344. Even better, add `/usr/local/mysql/bin' to your `PATH' environment
  7345. variable. For example, add the following line to your `$HOME/.tcshrc'
  7346. file if your shell is `tcsh':
  7347.  
  7348.      setenv PATH ${PATH}:/usr/local/mysql/bin
  7349.  
  7350. If no `.tcshrc' file exists in your home directory, create it with a
  7351. text editor.
  7352.  
  7353. If you are upgrading an existing installation, please note that
  7354. installing a new MySQL PKG does not remove the directory of an older
  7355. installation. Unfortunately, the Mac OS X Installer does not yet offer
  7356. the functionality required to properly upgrade previously installed
  7357. packages.
  7358.  
  7359. To use your existing databases with the new installation, you'll need
  7360. to copy the contents of the old data directory to the new data
  7361. directory. Make sure that neither the old server nor the new one is
  7362. running when you do this.  After you have copied over the MySQL
  7363. database files from the previous installation and have successfully
  7364. started the new server, you should consider removing the old
  7365. installation files to save disk space.  Additionally, you should also
  7366. remove older versions of the Package Receipt directories located in
  7367. `/Library/Receipts/mysql-VERSION.pkg'.
  7368.  
  7369. Installing MySQL on NetWare
  7370. ---------------------------
  7371.  
  7372. Porting MySQL to NetWare was an effort spearheaded by Novell. Novell
  7373. customers will be pleased to note that NetWare 6.5 ships with bundled
  7374. MySQL binaries, complete with an automatic commercial use license for
  7375. all servers running that version of NetWare.
  7376.  
  7377. MySQL for NetWare is compiled using a combination of `Metrowerks
  7378. CodeWarrior for NetWare' and special cross-compilation versions of the
  7379. GNU autotools.
  7380.  
  7381. The latest binary packages for NetWare can be obtained at
  7382. `http://dev.mysql.com/downloads/'.  *Note Getting MySQL::.
  7383.  
  7384. In order to host MySQL, the NetWare server must meet these requirements:
  7385.  
  7386.    * NetWare version 6.5 Support Pack 2 (you can find this and other
  7387.      updates at
  7388.      `http://support.novell.com/filefinder/18197/index.html') Updated
  7389.      with the latest LibC
  7390.      (`http://developer.novell.com/ndk/doc/libc/index.html?page=/ndk/doc/libc/libc_enu/data/ajjl0r0.html')
  7391.      or NetWare 6.0 with Support Pack 4 installed (you can obtain this
  7392.      at `http://support.novell.com/filefinder/13659/index.html') updated
  7393.      with the latest LibC
  7394.      (`http://developer.novell.com/ndk/doc/libc/index.html?page=/ndk/doc/libc/libc_enu/data/ajjl0r0.html')
  7395.  
  7396.    * The system must meet Novell's minimum requirements to run the
  7397.      respective version of NetWare.
  7398.  
  7399.    * MySQL data, as well as the binaries themselves, must be installed
  7400.      on an NSS volume; traditional volumes are not supported.
  7401.  
  7402. To install MySQL for NetWare, use the following procedure:
  7403.  
  7404.   1. If you are upgrading from a prior installation, stop the MySQL
  7405.      server.  This is done from the server console, using the following
  7406.      command:
  7407.  
  7408.           SERVER:  mysqladmin -u root shutdown
  7409.  
  7410.   2. Log on to the target server from a client machine with access to
  7411.      the location where you will install MySQL.
  7412.  
  7413.   3. Extract the binary package Zip file onto the server. Be sure to
  7414.      allow the paths in the Zip file to be used. It is safe to simply
  7415.      extract the file to `SYS:\'.
  7416.  
  7417.      If you are upgrading from a prior installation, you may need to
  7418.      copy the data directory (for example, `SYS:MYSQL\DATA') now, as
  7419.      well as `my.cnf', if you have customized it. You can then delete
  7420.      the old copy of MySQL.
  7421.  
  7422.   4. You might want to rename the directory to something more
  7423.      consistent and easy to use. We recommend using `SYS:MYSQL';
  7424.      examples in this manual use this name to refer to the installation
  7425.      directory in general.
  7426.  
  7427.   5. At the server console, add a search path for the directory
  7428.      containing the MySQL NLMs. For example:
  7429.  
  7430.           SERVER:  SEARCH ADD SYS:MYSQL\BIN
  7431.  
  7432.   6. Initialize the data directory and the grant tables, if needed, by
  7433.      executing `mysql_install_db' at the server console.
  7434.  
  7435.   7. Start the MySQL server using `mysqld_safe' at the server console.
  7436.  
  7437.   8. To finish the installation, you should also add the following
  7438.      commands to `autoexec.ncf'. For example, if your MySQL
  7439.      installation is in `SYS:MYSQL' and you want MySQL to start
  7440.      automatically, you could add these lines:
  7441.  
  7442.           #Starts the MySQL 4.0.x database server
  7443.           SEARCH ADD SYS:MYSQL\BIN
  7444.           MYSQLD_SAFE
  7445.  
  7446.      If you are running MySQL on NetWare 6.0, we strongly suggest that
  7447.      you use the `--skip-external-locking' option on the command line:
  7448.  
  7449.           #Starts the MySQL 4.0.x database server
  7450.           SEARCH ADD SYS:MYSQL\BIN
  7451.           MYSQLD_SAFE --skip-external-locking
  7452.  
  7453.      It will also be necessary to use `CHECK TABLE' and `REPAIR TABLE'
  7454.      instead of `myisamchk', because `myisamchk' makes use of external
  7455.      locking.  External locking is known to have problems on NetWare
  7456.      6.0; the problem has been eliminated in NetWare 6.5.
  7457.  
  7458.      `mysqld_safe' on NetWare provides a screen presence. When you
  7459.      unload (shut down) the `mysqld_safe' NLM, the screen does not by
  7460.      default go away.  Instead, it prompts for user input:
  7461.  
  7462.           *<NLM has terminated; Press any key to close the screen>*
  7463.  
  7464.      If you want NetWare to close the screen automatically instead, use
  7465.      the `--autoclose' option to `mysqld_safe'. For example:
  7466.  
  7467.           #Starts the MySQL 4.0.x database server
  7468.           SEARCH ADD SYS:MYSQL\BIN
  7469.           MYSQLD_SAFE --autoclose
  7470.  
  7471.   9. The latest Netware Perl and PHP modules for MySQL can be
  7472.      downloaded from `http://developer.novell.com/ndk/perl5.htm' and
  7473.      `http://developer.novell.com/ndk/php2.htm' respectively.
  7474.  
  7475.  
  7476. The behavior of `mysqld_safe' on NetWare is described further in *Note
  7477. `mysqld_safe': mysqld_safe.
  7478.  
  7479. If there was an existing installation of MySQL on the server, be sure
  7480. to check for existing MySQL startup commands in `autoexec.ncf', and
  7481. edit or delete them as necessary.
  7482.  
  7483. *Note*: The accounts that are listed in the MySQL grant tables
  7484. initially have no passwords.  After starting the server, you should set
  7485. up passwords for them using the instructions in *Note
  7486. Post-installation::.
  7487.  
  7488. Installing MySQL on Other Unix-Like Systems
  7489. -------------------------------------------
  7490.  
  7491. This section covers the installation of MySQL binary distributions that
  7492. are provided for various platforms in the form of compressed `tar' files
  7493. (files with a `.tar.gz' extension).  See *Note MySQL binaries:: for a
  7494. detailed list.
  7495.  
  7496. To obtain MySQL, see *Note Getting MySQL::.
  7497.  
  7498. MySQL `tar' file binary distributions have names of the form
  7499. `mysql-VERSION-OS.tar.gz', where `VERSION' is a number (for example,
  7500. `4.0.17'), and OS indicates the type of operating system for which the
  7501. distribution is intended (for example, `pc-linux-i686').
  7502.  
  7503. In addition to these generic packages, we also offer binaries in
  7504. platform-specific package formats for selected platforms.  See *Note
  7505. Quick Standard Installation:: for more information on how to install
  7506. these.
  7507.  
  7508. You need the following tools to install a MySQL `tar' file binary
  7509. distribution:
  7510.  
  7511.    * GNU `gunzip' to uncompress the distribution.
  7512.  
  7513.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  7514.      to work. Some operating systems come with a pre-installed version
  7515.      of `tar' that is known to have problems.  For example, Mac OS X
  7516.      `tar' and Sun `tar' are known to have problems with long
  7517.      filenames.  On Mac OS X, you can use the pre-installed `gnutar'
  7518.      program.  On other systems with a deficient `tar', you should
  7519.      install GNU `tar' first.
  7520.  
  7521. If you run into problems, _please always use `mysqlbug'_ when posting
  7522. questions to a MySQL mailing list.  Even if the problem isn't a bug,
  7523. `mysqlbug' gathers system information that will help others solve your
  7524. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  7525. a solution to your problem.  You will find `mysqlbug' in the `bin'
  7526. directory after you unpack the distribution.  *Note Bug reports::.
  7527.  
  7528. The basic commands you must execute to install and use a MySQL binary
  7529. distribution are:
  7530.  
  7531.      shell> groupadd mysql
  7532.      shell> useradd -g mysql mysql
  7533.      shell> cd /usr/local
  7534.      shell> gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz | tar xvf -
  7535.      shell> ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql
  7536.      shell> cd mysql
  7537.      shell> scripts/mysql_install_db --user=mysql
  7538.      shell> chown -R root  .
  7539.      shell> chown -R mysql data
  7540.      shell> chgrp -R mysql .
  7541.      shell> bin/mysqld_safe --user=mysql &
  7542.  
  7543. For versions of MySQL older than 4.0, substitute `bin/safe_mysqld' for
  7544. `bin/mysqld_safe' in the final command.
  7545.  
  7546. *Note*: This procedure does not set up any passwords for MySQL
  7547. accounts.  After following the procedure, proceed to *Note
  7548. Post-installation::.
  7549.  
  7550. A more detailed version of the preceding description for installing a
  7551. binary distribution follows:
  7552.  
  7553.   1. Add a login user and group for `mysqld' to run as:
  7554.  
  7555.           shell> groupadd mysql
  7556.           shell> useradd -g mysql mysql
  7557.  
  7558.      These commands add the `mysql' group and the `mysql' user.  The
  7559.      syntax for `useradd' and `groupadd' may differ slightly on
  7560.      different versions of Unix.  They may also be called `adduser' and
  7561.      `addgroup'.
  7562.  
  7563.      You might want to call the user and group something else instead
  7564.      of `mysql'.  If so, substitute the appropriate name in the
  7565.      following steps.
  7566.  
  7567.   2. Pick the directory under which you want to unpack the
  7568.      distribution, and change location into it. In the following
  7569.      example, we unpack the distribution under `/usr/local'. (The
  7570.      instructions, therefore, assume that you have permission to create
  7571.      files and directories in `/usr/local'.  If that directory is
  7572.      protected, you will need to perform the installation as `root'.)
  7573.  
  7574.           shell> cd /usr/local
  7575.  
  7576.   3. Obtain a distribution file from one of the sites listed in *Note
  7577.      Getting MySQL: Getting MySQL.  For a given release, binary
  7578.      distributions for all platforms are built from the same MySQL
  7579.      source distribution.
  7580.  
  7581.   4. Unpack the distribution, which will create the installation
  7582.      directory.  Then create a symbolic link to that directory:
  7583.  
  7584.           shell> gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz | tar xvf -
  7585.           shell> ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql
  7586.  
  7587.      The `tar' command creates a directory named `mysql-VERSION-OS'.
  7588.      The `ln' command makes a symbolic link to that directory.  This
  7589.      lets you refer more easily to the installation directory as
  7590.      `/usr/local/mysql'.
  7591.  
  7592.      With GNU `tar', no separate invocation of `gunzip' is necessary.
  7593.      You can replace the first line with the following alternative
  7594.      command to uncompress and extract the distribution:
  7595.  
  7596.           shell> tar zxvf /PATH/TO/MYSQL-VERSION-OS.tar.gz
  7597.  
  7598.   5. Change location into the installation directory:
  7599.  
  7600.           shell> cd mysql
  7601.  
  7602.      You will find several files and subdirectories in the `mysql'
  7603.      directory.  The most important for installation purposes are the
  7604.      `bin' and `scripts' subdirectories.
  7605.  
  7606.     `bin'
  7607.           This directory contains client programs and the server.  You
  7608.           should add the full pathname of this directory to your `PATH'
  7609.           environment variable so that your shell finds the MySQL
  7610.           programs properly. *Note Environment variables::.
  7611.  
  7612.     `scripts'
  7613.           This directory contains the `mysql_install_db' script used to
  7614.           initialize the `mysql' database containing the grant tables
  7615.           that store the server access permissions.
  7616.  
  7617.   6. If you haven't installed MySQL before, you must create the MySQL
  7618.      grant tables:
  7619.  
  7620.           shell> scripts/mysql_install_db --user=mysql
  7621.  
  7622.      If you run the command as `root', you should use the `--user'
  7623.      option as shown.  The value of the option should be the name of
  7624.      the login account that you created in the first step to use for
  7625.      running the server.  If you run the command while logged in as
  7626.      that user, you can omit the `--user' option.
  7627.  
  7628.      Note that for MySQL versions older than 3.22.10,
  7629.      `mysql_install_db' left the server running after creating the grant
  7630.      tables.  This is no longer true; you will need to restart the
  7631.      server after performing the remaining steps in this procedure.
  7632.  
  7633.   7. Change the ownership of program binaries to `root' and ownership
  7634.      of the data directory to the user that you will run `mysqld' as.
  7635.      Assuming that you are located in the installation directory
  7636.      (`/usr/local/mysql'), the commands look like this:
  7637.  
  7638.           shell> chown -R root  .
  7639.           shell> chown -R mysql data
  7640.           shell> chgrp -R mysql .
  7641.  
  7642.      The first command changes the owner attribute of the files to the
  7643.      `root' user. The second changes the owner attribute of the data
  7644.      directory to the `mysql' user. The third changes the group
  7645.      attribute to the `mysql' group.
  7646.  
  7647.   8. If you would like MySQL to start automatically when you boot your
  7648.      machine, you can copy `support-files/mysql.server' to the location
  7649.      where your system has its startup files.  More information can be
  7650.      found in the `support-files/mysql.server' script itself and in
  7651.      *Note Automatic start::.
  7652.  
  7653.   9. You can set up new accounts using the `bin/mysql_setpermission'
  7654.      script if you install the `DBI' and `DBD::mysql' Perl modules.
  7655.      For instructions, see *Note Perl support::.
  7656.  
  7657.  10. If you would like to use `mysqlaccess' and have the MySQL
  7658.      distribution in some non-standard place, you must change the
  7659.      location where `mysqlaccess' expects to find the `mysql' client.
  7660.      Edit the `bin/mysqlaccess' script at approximately line 18.
  7661.      Search for a line that looks like this:
  7662.  
  7663.           $MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable
  7664.  
  7665.      Change the path to reflect the location where `mysql' actually is
  7666.      stored on your system.  If you do not do this, you will get a
  7667.      `Broken pipe' error when you run `mysqlaccess'.
  7668.  
  7669.  
  7670. After everything has been unpacked and installed, you should test your
  7671. distribution.
  7672.  
  7673. You can start the MySQL server with the following command:
  7674.  
  7675.      shell> bin/mysqld_safe --user=mysql &
  7676.  
  7677. For versions of MySQL older than 4.0, substitute `bin/safe_mysqld' for
  7678. `bin/mysqld_safe' in the command.
  7679.  
  7680. More information about `mysqld_safe' is given in *Note `mysqld_safe':
  7681. mysqld_safe.
  7682.  
  7683. *Note*: The accounts that are listed in the MySQL grant tables
  7684. initially have no passwords.  After starting the server, you should set
  7685. up passwords for them using the instructions in *Note
  7686. Post-installation::.
  7687.  
  7688. MySQL Installation Using a Source Distribution
  7689. ==============================================
  7690.  
  7691. Before you proceed with the source installation, check first to see
  7692. whether our binary is available for your platform and whether it will
  7693. work for you. We put a lot of effort into making sure that our binaries
  7694. are built with the best possible options.
  7695.  
  7696. To obtain a source distribution for MySQL, *Note Getting MySQL::.
  7697.  
  7698. MySQL source distributions are provided as compressed `tar' archives
  7699. and have names of the form `mysql-VERSION.tar.gz', where VERSION is a
  7700. number like `5.0.1-alpha'.
  7701.  
  7702. You need the following tools to build and install MySQL from source:
  7703.  
  7704.    * GNU `gunzip' to uncompress the distribution.
  7705.  
  7706.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  7707.      to work. Some operating systems come with a pre-installed version
  7708.      of `tar' that is known to have problems.  For example, Mac OS X
  7709.      `tar' and Sun `tar' are known to have problems with long
  7710.      filenames.  On Mac OS X, you can use the pre-installed `gnutar'
  7711.      program.  On other systems with a deficient `tar', you should
  7712.      install GNU `tar' first.
  7713.  
  7714.    * A working ANSI C++ compiler.  `gcc' 2.95.2 or later, `egcs' 1.0.2
  7715.      or later or `egcs 2.91.66', SGI C++, and SunPro C++ are some of the
  7716.      compilers that are known to work.  `libg++' is not needed when
  7717.      using `gcc'.  `gcc' 2.7.x has a bug that makes it impossible to
  7718.      compile some perfectly legal C++ files, such as `sql/sql_base.cc'.
  7719.      If you have only `gcc' 2.7.x, you must upgrade your `gcc' to be
  7720.      able to compile MySQL. `gcc' 2.8.1 is also known to have problems
  7721.      on some platforms, so it should be avoided if a new compiler
  7722.      exists for the platform.
  7723.  
  7724.      `gcc' 2.95.2 or later is recommended when compiling MySQL 3.23.x.
  7725.  
  7726.    * A good `make' program.  GNU `make' is always recommended and is
  7727.      sometimes required.  If you have problems, we recommend trying GNU
  7728.      `make' 3.75 or newer.
  7729.  
  7730. If you are using a version of `gcc' recent enough to understand the
  7731. `-fno-exceptions' option, it is _very important_ that you use this
  7732. option. Otherwise, you may compile a binary that crashes randomly. We
  7733. also recommend that you use `-felide-constructors' and `-fno-rtti' along
  7734. with `-fno-exceptions'. When in doubt, do the following:
  7735.  
  7736.      CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
  7737.             -fno-exceptions -fno-rtti" ./configure \
  7738.             --prefix=/usr/local/mysql --enable-assembler \
  7739.             --with-mysqld-ldflags=-all-static
  7740.  
  7741. On most systems, this will give you a fast and stable binary.
  7742.  
  7743. If you run into problems, _please always use `mysqlbug'_ when posting
  7744. questions to a MySQL mailing list.  Even if the problem isn't a bug,
  7745. `mysqlbug' gathers system information that will help others solve your
  7746. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  7747. a solution to your problem.  You will find `mysqlbug' in the `scripts'
  7748. directory after you unpack the distribution.  *Note Bug reports::.
  7749.  
  7750. Source Installation Overview
  7751. ----------------------------
  7752.  
  7753. The basic commands you must execute to install a MySQL source
  7754. distribution are:
  7755.  
  7756.      shell> groupadd mysql
  7757.      shell> useradd -g mysql mysql
  7758.      shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
  7759.      shell> cd mysql-VERSION
  7760.      shell> ./configure --prefix=/usr/local/mysql
  7761.      shell> make
  7762.      shell> make install
  7763.      shell> cp support-files/my-medium.cnf /etc/my.cnf
  7764.      shell> cd /usr/local/mysql
  7765.      shell> bin/mysql_install_db --user=mysql
  7766.      shell> chown -R root  .
  7767.      shell> chown -R mysql var
  7768.      shell> chgrp -R mysql .
  7769.      shell> bin/mysqld_safe --user=mysql &
  7770.  
  7771. For versions of MySQL older than 4.0, substitute `bin/safe_mysqld' for
  7772. `bin/mysqld_safe' in the final command.
  7773.  
  7774. If you start from a source RPM, do the following:
  7775.  
  7776.      shell> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm
  7777.  
  7778. This will make a binary RPM that you can install. For older versions of
  7779. RPM, you may have to replace the command `rpmbuild' with `rpm' instead.
  7780.  
  7781. *Note*: This procedure does not set up any passwords for MySQL
  7782. accounts.  After following the procedure, proceed to *Note
  7783. Post-installation::, for post-installation setup and testing.
  7784.  
  7785. A more detailed version of the preceding description for installing
  7786. MySQL from a source distribution follows:
  7787.  
  7788.   1. Add a login user and group for `mysqld' to run as:
  7789.  
  7790.           shell> groupadd mysql
  7791.           shell> useradd -g mysql mysql
  7792.  
  7793.      These commands add the `mysql' group and the `mysql' user.  The
  7794.      syntax for `useradd' and `groupadd' may differ slightly on
  7795.      different versions of Unix.  They may also be called `adduser' and
  7796.      `addgroup'.
  7797.  
  7798.      You might want to call the user and group something else instead
  7799.      of `mysql'.  If so, substitute the appropriate name in the
  7800.      following steps.
  7801.  
  7802.   2. Pick the directory under which you want to unpack the
  7803.      distribution, and change location into it.
  7804.  
  7805.   3. Obtain a distribution file from one of the sites listed in *Note
  7806.      Getting MySQL: Getting MySQL.
  7807.  
  7808.   4. Unpack the distribution into the current directory:
  7809.           shell> gunzip < /PATH/TO/MYSQL-VERSION.tar.gz | tar xvf -
  7810.  
  7811.      This command creates a directory named `mysql-VERSION'.
  7812.  
  7813.      With GNU `tar', no separate invocation of `gunzip' is necessary.
  7814.      You can use the following alternative command to uncompress and
  7815.      extract the distribution:
  7816.  
  7817.           shell> tar zxvf /PATH/TO/MYSQL-VERSION-OS.tar.gz
  7818.  
  7819.   5. Change location into the top-level directory of the unpacked
  7820.      distribution:
  7821.  
  7822.           shell> cd mysql-VERSION
  7823.  
  7824.      Note that currently you must configure and build MySQL from this
  7825.      top-level directory.  You cannot build it in a different directory.
  7826.  
  7827.   6. Configure the release and compile everything:
  7828.  
  7829.           shell> ./configure --prefix=/usr/local/mysql
  7830.           shell> make
  7831.  
  7832.      When you run `configure', you might want to specify some options.
  7833.      Run `./configure --help' for a list of options.  *Note `configure'
  7834.      options: configure options, discusses some of the more useful
  7835.      options.
  7836.  
  7837.      If `configure' fails and you are going to send mail to a MySQL
  7838.      mailing list to ask for assistance, please include any lines from
  7839.      `config.log' that you think can help solve the problem.  Also
  7840.      include the last couple of lines of output from `configure'.  Post
  7841.      the bug report using the `mysqlbug' script.  *Note Bug reports::.
  7842.  
  7843.      If the compile fails, see *Note Compilation problems:: for help.
  7844.  
  7845.   7. Install the distribution:
  7846.  
  7847.           shell> make install
  7848.  
  7849.      If you want to set up an option file, use one of those present in
  7850.      the `support-files' directory as a template. For example:
  7851.  
  7852.           shell> cp support-files/my-medium.cnf /etc/my.cnf
  7853.  
  7854.      You might need to run these commands as `root'.
  7855.  
  7856.      If you want to configure support for `InnoDB' tables, you should
  7857.      edit the `/etc/my.cnf' file, remove the `#' character before the
  7858.      option lines that start with `innodb_...', and modify the option
  7859.      values to be what you want.  See *Note Option files:: and *Note
  7860.      `InnoDB' configuration: InnoDB configuration.
  7861.  
  7862.   8. Change location into the installation directory:
  7863.  
  7864.           shell> cd /usr/local/mysql
  7865.  
  7866.   9. If you haven't installed MySQL before, you must create the MySQL
  7867.      grant tables:
  7868.  
  7869.           shell> bin/mysql_install_db --user=mysql
  7870.  
  7871.      If you run the command as `root', you should use the `--user'
  7872.      option as shown.  The value of the option should be the name of
  7873.      the login account that you created in the first step to use for
  7874.      running the server.  If you run the command while logged in as
  7875.      that user, you can omit the `--user' option.
  7876.  
  7877.      Note that for MySQL versions older than 3.22.10,
  7878.      `mysql_install_db' left the server running after creating the grant
  7879.      tables.  This is no longer true; you will need to restart the
  7880.      server after performing the remaining steps in this procedure.
  7881.  
  7882.  10. Change the ownership of program binaries to `root' and ownership
  7883.      of the data directory to the user that you will run `mysqld' as.
  7884.      Assuming that you are located in the installation directory
  7885.      (`/usr/local/mysql'), the commands look like this:
  7886.  
  7887.           shell> chown -R root  .
  7888.           shell> chown -R mysql var
  7889.           shell> chgrp -R mysql .
  7890.  
  7891.      The first command changes the owner attribute of the files to the
  7892.      `root' user. The second changes the owner attribute of the data
  7893.      directory to the `mysql' user. The third changes the group
  7894.      attribute to the `mysql' group.
  7895.  
  7896.  11. If you would like MySQL to start automatically when you boot your
  7897.      machine, you can copy `support-files/mysql.server' to the location
  7898.      where your system has its startup files.  More information can be
  7899.      found in the `support-files/mysql.server' script itself and in
  7900.      *Note Automatic start::.
  7901.  
  7902.  12. You can set up new accounts using the `bin/mysql_setpermission'
  7903.      script if you install the `DBI' and `DBD::mysql' Perl modules.
  7904.      For instructions, see *Note Perl support::.
  7905.  
  7906.  
  7907. After everything has been installed, you should initialize and test your
  7908. distribution using this command:
  7909.  
  7910.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  7911.  
  7912. For versions of MySQL older than 4.0, substitute `safe_mysqld' for
  7913. `mysqld_safe' in the command.
  7914.  
  7915. If that command fails immediately and prints `mysqld ended', you can
  7916. find some information in the `HOST_NAME.err' file in the data directory.
  7917.  
  7918. More information about `mysqld_safe' is given in *Note `mysqld_safe':
  7919. mysqld_safe.
  7920.  
  7921. *Note*: The accounts that are listed in the MySQL grant tables
  7922. initially have no passwords.  After starting the server, you should set
  7923. up passwords for them using the instructions in *Note
  7924. Post-installation::.
  7925.  
  7926. Typical `configure' Options
  7927. ---------------------------
  7928.  
  7929. The `configure' script gives you a great deal of control over how you
  7930. configure a MySQL source distribution.  Typically you do this using
  7931. options on the `configure' command line.  You can also affect
  7932. `configure' using certain environment variables.  *Note Environment
  7933. variables::.  For a list of options supported by `configure', run this
  7934. command:
  7935.  
  7936.      shell> ./configure --help
  7937.  
  7938. Some of the more commonly used `configure' options are described here:
  7939.  
  7940.    * To compile just the MySQL client libraries and client programs and
  7941.      not the server, use the `--without-server' option:
  7942.  
  7943.           shell> ./configure --without-server
  7944.  
  7945.      If you don't have a C++ compiler, `mysql' will not compile (it is
  7946.      the one client program that requires C++).  In this case, you can
  7947.      remove the code in `configure' that tests for the C++ compiler and
  7948.      then run `./configure' with the `--without-server' option. The
  7949.      compile step will still try to build `mysql', but you can ignore
  7950.      any warnings about `mysql.cc'.  (If `make' stops, try `make -k' to
  7951.      tell it to continue with the rest of the build even if errors
  7952.      occur.)
  7953.  
  7954.    * If you want to build the embedded MySQL library (`libmysqld.a')
  7955.      you should use the `--with-embedded-server' option.
  7956.  
  7957.    * If you don't want your log files and database directories located
  7958.      under `/usr/local/var', use a `configure' command something like
  7959.      one of these:
  7960.  
  7961.           shell> ./configure --prefix=/usr/local/mysql
  7962.           shell> ./configure --prefix=/usr/local \
  7963.                      --localstatedir=/usr/local/mysql/data
  7964.  
  7965.      The first command changes the installation prefix so that
  7966.      everything is installed under `/usr/local/mysql' rather than the
  7967.      default of `/usr/local'.  The second command preserves the default
  7968.      installation prefix, but overrides the default location for
  7969.      database directories (normally `/usr/local/var') and changes it to
  7970.      `/usr/local/mysql/data'.  After you have compiled MySQL, you can
  7971.      change these options with option files. *Note Option files::.
  7972.  
  7973.    * If you are using Unix and you want the MySQL socket located
  7974.      somewhere other than the default location (normally in the
  7975.      directory `/tmp' or `/var/run'), use a `configure' command like
  7976.      this:
  7977.  
  7978.           shell> ./configure \
  7979.                      --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
  7980.  
  7981.      The socket filename must be an absolute pathname.  You can also
  7982.      change the location of `mysql.sock' later by using a MySQL option
  7983.      file. *Note Problems with `mysql.sock': Problems with mysql.sock.
  7984.  
  7985.    * If you want to compile statically linked programs (for example, to
  7986.      make a binary distribution, to get more speed, or to work around
  7987.      problems with some Red Hat Linux distributions), run `configure'
  7988.      like this:
  7989.  
  7990.           shell> ./configure --with-client-ldflags=-all-static \
  7991.                      --with-mysqld-ldflags=-all-static
  7992.  
  7993.    * If you are using `gcc' and don't have `libg++' or `libstdc++'
  7994.      installed, you can tell `configure' to use `gcc' as your C++
  7995.      compiler:
  7996.  
  7997.           shell> CC=gcc CXX=gcc ./configure
  7998.  
  7999.      When you use `gcc' as your C++ compiler, it will not attempt to
  8000.      link in `libg++' or `libstdc++'.  This may be a good idea to do
  8001.      even if you have these libraries installed, because some versions
  8002.      of them have caused strange problems for MySQL users in the past.
  8003.  
  8004.      The following list indicates some compilers and environment
  8005.      variable settings that are commonly used with each one.
  8006.  
  8007.     `gcc' 2.7.2:
  8008.                CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"
  8009.  
  8010.     `egcs' 1.0.3a:
  8011.                CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors \
  8012.                -fno-exceptions -fno-rtti"
  8013.  
  8014.     `gcc' 2.95.2:
  8015.                CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
  8016.                -felide-constructors -fno-exceptions -fno-rtti"
  8017.  
  8018.     `pgcc' 2.90.29 or newer:
  8019.                CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \
  8020.                CXXFLAGS="-O3 -mpentiumpro -mstack-align-double \
  8021.                -felide-constructors -fno-exceptions -fno-rtti"
  8022.  
  8023.      In most cases, you can get a reasonably optimized MySQL binary by
  8024.      using the options from the preceding list and adding the following
  8025.      options to the `configure' line:
  8026.  
  8027.           --prefix=/usr/local/mysql --enable-assembler \
  8028.           --with-mysqld-ldflags=-all-static
  8029.  
  8030.      The full `configure' line would, in other words, be something like
  8031.      the following for all recent `gcc' versions:
  8032.  
  8033.           CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
  8034.           -felide-constructors -fno-exceptions -fno-rtti" ./configure \
  8035.           --prefix=/usr/local/mysql --enable-assembler \
  8036.           --with-mysqld-ldflags=-all-static
  8037.  
  8038.      The binaries we provide on the MySQL Web site at
  8039.      `http://www.mysql.com/' are all compiled with full optimization and
  8040.      should be perfect for most users.  *Note MySQL binaries::.  There
  8041.      are some configuration settings you can tweak to make an even
  8042.      faster binary, but these are only for advanced users.  *Note
  8043.      Compile and link options::.
  8044.  
  8045.      If the build fails and produces errors about your compiler or
  8046.      linker not being able to create the shared library
  8047.      `libmysqlclient.so.#' (where `#' is a version number), you can
  8048.      work around this problem by giving the `--disable-shared' option
  8049.      to `configure'.  In this case, `configure' will not build a shared
  8050.      `libmysqlclient.so.#' library.
  8051.  
  8052.    * You can configure MySQL not to use `DEFAULT' column values for
  8053.      non-`NULL' columns (that is, columns that are not allowed to be
  8054.      `NULL'). *Note constraint NOT NULL::.
  8055.  
  8056.           shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure
  8057.  
  8058.      The effect of this flag is to cause any `INSERT' statement to fail
  8059.      unless it includes explicit values for all columns that require a
  8060.      non-`NULL' value.
  8061.  
  8062.    * By default, MySQL uses the `latin1' (ISO-8859-1) character set. To
  8063.      change the default set, use the `--with-charset' option:
  8064.           shell> ./configure --with-charset=CHARSET
  8065.      CHARSET may be one of `big5', `cp1251', `cp1257', `czech',
  8066.      `danish', `dec8', `dos', `euc_kr', `gb2312', `gbk', `german1',
  8067.      `hebrew', `hp8', `hungarian', `koi8_ru', `koi8_ukr', `latin1',
  8068.      `latin2', `sjis', `swe7', `tis620', `ujis', `usa7', or
  8069.      `win1251ukr'.  *Note Character sets::.
  8070.  
  8071.      As of MySQL 4.1.1, the default collation may also be specified.
  8072.      MySQL uses the `latin1_swedish_ci' collation. To change this, use
  8073.      the `--with-collation' option:
  8074.  
  8075.           shell> ./configure --with-collation=COLLATION
  8076.  
  8077.      To change both the character set and the collation, use both the
  8078.      `--with-charset' and `--with-collation' options.  The collation
  8079.      must be a legal collation for the character set.  (Use the `SHOW
  8080.      COLLATION' statement to determine which collations are available
  8081.      for each character set.)
  8082.  
  8083.      If you want to convert characters between the server and the
  8084.      client, you should take a look at the `SET CHARACTER SET'
  8085.      statement.  *Note `SET': SET OPTION.
  8086.  
  8087.      *Warning:* If you change character sets after having created any
  8088.      tables, you will have to run `myisamchk -r -q
  8089.      --set-character-set=CHARSET' on every table. Your indexes may be
  8090.      sorted incorrectly otherwise.  (This can happen if you install
  8091.      MySQL, create some tables, then reconfigure MySQL to use a
  8092.      different character set and reinstall it.)
  8093.  
  8094.      With the `configure' option `--with-extra-charsets=LIST', you can
  8095.      define which additional character sets should be compiled into the
  8096.      server.  LIST is either a list of character set names separated by
  8097.      spaces, `complex' to include all character sets that can't be
  8098.      dynamically loaded, or `all' to include all character sets into
  8099.      the binaries.
  8100.  
  8101.    * To configure MySQL with debugging code, use the `--with-debug'
  8102.      option:
  8103.           shell> ./configure --with-debug
  8104.      This causes a safe memory allocator to be included that can find
  8105.      some errors and that provides output about what is happening.
  8106.      *Note Debugging server::.
  8107.  
  8108.    * If your client programs are using threads, you also must compile a
  8109.      thread-safe version of the MySQL client library with the
  8110.      `--enable-thread-safe-client' configure option. This will create a
  8111.      `libmysqlclient_r' library with which you should link your threaded
  8112.      applications.  *Note Threaded clients::.
  8113.  
  8114.    * Options that pertain to particular systems can be found in the
  8115.      system-specific section of this manual.  *Note Operating System
  8116.      Specific Notes::.
  8117.  
  8118. Installing from the Development Source Tree
  8119. -------------------------------------------
  8120.  
  8121. *Caution*: You should read this section only if you are interested in
  8122. helping us test our new code. If you just want to get MySQL up and
  8123. running on your system, you should use a standard release distribution
  8124. (either a binary or source distribution will do).
  8125.  
  8126. To obtain our most recent development source tree, use these
  8127. instructions:
  8128.  
  8129.   1. Download BitKeeper from
  8130.      `http://www.bitmover.com/cgi-bin/download.cgi'.  You will need
  8131.      Bitkeeper 3.0 or newer to access our repository.
  8132.  
  8133.   2. Follow the instructions to install it.
  8134.  
  8135.   3. After BitKeeper has been installed, first go to the directory you
  8136.      want to work from, and then use one of the following commands to
  8137.      clone the MySQL version branch of your choice:
  8138.  
  8139.      To clone the old 3.23 branch, use this command:
  8140.  
  8141.           shell> bk clone bk://mysql.bkbits.net/mysql-3.23 mysql-3.23
  8142.  
  8143.      To clone the 4.0 stable (production) branch, use this command:
  8144.  
  8145.           shell> bk clone bk://mysql.bkbits.net/mysql-4.0 mysql-4.0
  8146.  
  8147.      To clone the 4.1 beta branch, use this command:
  8148.  
  8149.           shell> bk clone bk://mysql.bkbits.net/mysql-4.1 mysql-4.1
  8150.  
  8151.      To clone the 5.0 development branch, use this command:
  8152.  
  8153.           shell> bk clone bk://mysql.bkbits.net/mysql-5.0 mysql-5.0
  8154.  
  8155.      In the preceding examples, the source tree will be set up in the
  8156.      `mysql-3.23/', `mysql-4.0/', `mysql-4.1/', or `mysql-5.0/'
  8157.      subdirectory of your current directory.
  8158.  
  8159.      If you are behind a firewall and can only initiate HTTP
  8160.      connections, you can also use BitKeeper via HTTP.
  8161.  
  8162.      If you are required to use a proxy server, set the environment
  8163.      variable `http_proxy' to point to your proxy:
  8164.  
  8165.           shell> export http_proxy="http://your.proxy.server:8080/"
  8166.  
  8167.      Now, simply replace the `bk://' with `http://' when doing a clone.
  8168.      Example:
  8169.  
  8170.           shell> bk clone http://mysql.bkbits.net/mysql-4.1 mysql-4.1
  8171.  
  8172.      The initial download of the source tree may take a while,
  8173.      depending on the speed of your connection. Please be patient.
  8174.  
  8175.   4. You will need GNU `make', `autoconf' 2.53 (or newer), `automake'
  8176.      1.5, `libtool' 1.5, and `m4' to run the next set of commands. Even
  8177.      though many operating systems already come with their own
  8178.      implementation of `make', chances are high that the compilation
  8179.      will fail with strange error messages. Therefore, it is highly
  8180.      recommended that you use GNU `make' (sometimes named `gmake')
  8181.      instead.
  8182.  
  8183.      Fortunately, a large number of operating systems already ship with
  8184.      the GNU toolchain preinstalled or supply installable packages of
  8185.      these. In any case, they can also be downloaded from the following
  8186.      locations:
  8187.  
  8188.         * `http://www.gnu.org/software/autoconf/'
  8189.  
  8190.         * `http://www.gnu.org/software/automake/'
  8191.  
  8192.         * `http://www.gnu.org/software/libtool/'
  8193.  
  8194.         * `http://www.gnu.org/software/m4/'
  8195.  
  8196.         * `http://www.gnu.org/software/make/'
  8197.  
  8198.      If you are trying to configure MySQL 4.1 or later, you will also
  8199.      need GNU `bison' 1.75 or later.  Older versions of `bison' may
  8200.      report this error:
  8201.  
  8202.           sql_yacc.yy:#####: fatal error: maximum table size (32767) exceeded
  8203.  
  8204.      Note: The maximum table size is not actually exceeded; the error
  8205.      is caused by bugs in older versions of `bison'.
  8206.  
  8207.      Versions of MySQL before version 4.1 may also compile with other
  8208.      `yacc' implementations (for example, BSD `yacc' 91.7.30). For later
  8209.      versions, GNU `bison' is required.
  8210.  
  8211.      The following example shows the typical commands required to
  8212.      configure a source tree. The first `cd' command changes location
  8213.      into the top-level directory of the tree; replace `mysql-4.0' with
  8214.      the appropriate directory name.
  8215.  
  8216.           shell> cd mysql-4.0
  8217.           shell> bk -r edit
  8218.           shell> aclocal; autoheader; autoconf; automake
  8219.           shell> (cd innobase; aclocal; autoheader; autoconf; automake)
  8220.           shell> (cd bdb/dist; sh s_all)
  8221.           shell> ./configure  # Add your favorite options here
  8222.           make
  8223.  
  8224.      The command lines that change directory into the `innobase' and
  8225.      `bdb/dist' directories are used to configure the `InnoDB' and
  8226.      Berkeley DB (`BDB') storage engines.  You can omit these command
  8227.      lines if you to not require `InnoDB' or `BDB' support.
  8228.  
  8229.      If you get some strange errors during this stage, verify that you
  8230.      really have `libtool' installed.
  8231.  
  8232.      A collection of our standard configuration scripts is located in
  8233.      the `BUILD/' subdirectory.  You may find it more convenient to use
  8234.      the `BUILD/compile-pentium-debug' script than the preceding set of
  8235.      shell commands. To compile on a different architecture, modify the
  8236.      script by removing flags that are Pentium-specific.
  8237.  
  8238.   5. When the build is done, run `make install'.  Be careful with this
  8239.      on a production machine; the command may overwrite your live
  8240.      release installation.  If you have another installation of MySQL,
  8241.      we recommend that you run `./configure' with different values for
  8242.      the `--prefix', `--with-tcp-port', and `--unix-socket-path' options
  8243.      than those used for your production server.
  8244.  
  8245.   6. Play hard with your new installation and try to make the new
  8246.      features crash.  Start by running `make test'.  *Note MySQL test
  8247.      suite::.
  8248.  
  8249.   7. If you have gotten to the `make' stage and the distribution does
  8250.      not compile, please report it in our bugs database at
  8251.      `http://bugs.mysql.com/'.  If you have installed the latest
  8252.      versions of the required GNU tools, and they crash trying to
  8253.      process our configuration files, please report that also.
  8254.      However, if you execute `aclocal' and get a `command not found'
  8255.      error or a similar problem, do not report it.  Instead, make sure
  8256.      that all the necessary tools are installed and that your `PATH'
  8257.      variable is set correctly so that your shell can find them.
  8258.  
  8259.   8. After the initial `bk clone' operation to obtain the source tree,
  8260.      you should run `bk pull' periodically to get updates.
  8261.  
  8262.   9. You can examine the change history for the tree with all the diffs
  8263.      by using `bk revtool'.  If you see some funny diffs or code that
  8264.      you have a question about, do not hesitate to send email to the
  8265.      MySQL `internals' mailing list.  *Note Mailing-list::.  Also, if
  8266.      you think you have a better idea on how to do something, send an
  8267.      email message to the same address with a patch.  `bk diffs' will
  8268.      produce a patch for you after you have made changes to the source.
  8269.      If you do not have the time to code your idea, just send a
  8270.      description.
  8271.  
  8272.  10. BitKeeper has a nice help utility that you can access via `bk
  8273.      helptool'.
  8274.  
  8275.  11. Please note that any commits (made via `bk ci' or `bk citool') will
  8276.      trigger the posting of a message with the changeset to our
  8277.      internals mailing list, as well as the usual openlogging.org
  8278.      submission with just the changeset comments.  Generally, you
  8279.      wouldn't need to use commit (since the public tree will not allow
  8280.      `bk push'), but rather use the `bk diffs' method described
  8281.      previously.
  8282.  
  8283.  
  8284. You can also browse changesets, comments, and source code online. For
  8285. example, to browse this information for MySQL 4.1, go to
  8286. `http://mysql.bkbits.net:8080/mysql-4.1'.
  8287.  
  8288. The manual is in a separate tree that can be cloned with:
  8289.  
  8290.      shell> bk clone bk://mysql.bkbits.net/mysqldoc mysqldoc
  8291.  
  8292. There are also public BitKeeper trees for MySQL Control Center and
  8293. Connector/ODBC. They can be cloned respectively as follows.
  8294.  
  8295. To clone MySQL Control center, use this command:
  8296.  
  8297.      shell> bk clone http://mysql.bkbits.net/mysqlcc mysqlcc
  8298.  
  8299. To clone Connector/ODBC, use this command:
  8300.  
  8301.      shell> bk clone http://mysql.bkbits.net/myodbc3 myodbc3
  8302.  
  8303. Dealing with Problems Compiling MySQL
  8304. -------------------------------------
  8305.  
  8306. All MySQL programs compile cleanly for us with no warnings on Solaris
  8307. or Linux using `gcc'.  On other systems, warnings may occur due to
  8308. differences in system include files.  See *Note MIT-pthreads:: for
  8309. warnings that may occur when using MIT-pthreads.  For other problems,
  8310. check the following list.
  8311.  
  8312. The solution to many problems involves reconfiguring.  If you do need to
  8313. reconfigure, take note of the following:
  8314.  
  8315.    * If `configure' is run after it already has been run, it may use
  8316.      information that was gathered during its previous invocation.  This
  8317.      information is stored in `config.cache'.  When `configure' starts
  8318.      up, it looks for that file and reads its contents if it exists, on
  8319.      the assumption that the information is still correct.  That
  8320.      assumption is invalid when you reconfigure.
  8321.  
  8322.    * Each time you run `configure', you must run `make' again to
  8323.      recompile.  However, you may want to remove old object files from
  8324.      previous builds first because they were compiled using different
  8325.      configuration options.
  8326.  
  8327. To prevent old configuration information or object files from being
  8328. used, run these commands before re-running `configure':
  8329.  
  8330.      shell> rm config.cache
  8331.      shell> make clean
  8332.  
  8333. Alternatively, you can run `make distclean'.
  8334.  
  8335. The following list describes some of the problems when compiling MySQL
  8336. that have been found to occur most often:
  8337.  
  8338.    * If you get errors such as the ones shown here when compiling
  8339.      `sql_yacc.cc', you probably have run out of memory or swap space:
  8340.  
  8341.           Internal compiler error: program cc1plus got fatal signal 11
  8342.           Out of virtual memory
  8343.           Virtual memory exhausted
  8344.  
  8345.      The problem is that `gcc' requires a huge amount of memory to
  8346.      compile `sql_yacc.cc' with inline functions.  Try running
  8347.      `configure' with the `--with-low-memory' option:
  8348.  
  8349.           shell> ./configure --with-low-memory
  8350.  
  8351.      This option causes `-fno-inline' to be added to the compile line
  8352.      if you are using `gcc' and `-O0' if you are using something else.
  8353.      You should try the `--with-low-memory' option even if you have so
  8354.      much memory and swap space that you think you can't possibly have
  8355.      run out.  This problem has been observed to occur even on systems
  8356.      with generous hardware configurations and the `--with-low-memory'
  8357.      option usually fixes it.
  8358.  
  8359.    * By default, `configure' picks `c++' as the compiler name and GNU
  8360.      `c++' links with `-lg++'.  If you are using `gcc', that behavior
  8361.      can cause problems during configuration such as this:
  8362.  
  8363.           configure: error: installation or configuration problem:
  8364.           C++ compiler cannot create executables.
  8365.  
  8366.      You might also observe problems during compilation related to
  8367.      `g++', `libg++', or `libstdc++'.
  8368.  
  8369.      One cause of these problems is that you may not have `g++', or you
  8370.      may have `g++' but not `libg++', or `libstdc++'.  Take a look at
  8371.      the `config.log' file.  It should contain the exact reason why
  8372.      your C++ compiler didn't work.  To work around these problems, you
  8373.      can use `gcc' as your C++ compiler.  Try setting the environment
  8374.      variable `CXX' to `"gcc -O3"'.  For example:
  8375.  
  8376.           shell> CXX="gcc -O3" ./configure
  8377.  
  8378.      This works because `gcc' compiles C++ sources as well as `g++'
  8379.      does, but does not link in `libg++' or `libstdc++' by default.
  8380.  
  8381.      Another way to fix these problems is to install `g++', `libg++',
  8382.      and `libstdc++'.  We would, however, like to recommend that you
  8383.      not use `libg++' or `libstdc++' with MySQL because this will only
  8384.      increase the binary size of `mysqld' without giving you any
  8385.      benefits.  Some versions of these libraries have also caused
  8386.      strange problems for MySQL users in the past.
  8387.  
  8388.      Using `gcc' as the C++ compiler is also required if you want to
  8389.      compile MySQL with RAID functionality (see *Note CREATE TABLE::
  8390.      for more info on RAID table type) and you are using GNU `gcc'
  8391.      version 3 and above. If you get errors like those following during
  8392.      the linking stage when you configure MySQL to compile with the
  8393.      option `--with-raid', try to use `gcc' as your C++ compiler by
  8394.      defining the `CXX' environment variable:
  8395.  
  8396.           gcc -O3 -DDBUG_OFF -rdynamic -o isamchk isamchk.o sort.o  libnisam.a
  8397.           ../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a
  8398.            -lpthread -lz -lcrypt -lnsl -lm -lpthread
  8399.           ../mysys/libmysys.a(raid.o)(.text+0x79): In function
  8400.           `my_raid_create':: undefined reference to `operator new(unsigned)'
  8401.           ../mysys/libmysys.a(raid.o)(.text+0xdd): In function
  8402.           `my_raid_create':: undefined reference to `operator delete(void*)'
  8403.           ../mysys/libmysys.a(raid.o)(.text+0x129): In function
  8404.           `my_raid_open':: undefined reference to `operator new(unsigned)'
  8405.           ../mysys/libmysys.a(raid.o)(.text+0x189): In function
  8406.           `my_raid_open':: undefined reference to `operator delete(void*)'
  8407.           ../mysys/libmysys.a(raid.o)(.text+0x64b): In function
  8408.           `my_raid_close':: undefined reference to `operator delete(void*)'
  8409.           collect2: ld returned 1 exit status
  8410.  
  8411.    * If your compile fails with errors such as any of the following,
  8412.      you must upgrade your version of `make' to GNU `make':
  8413.  
  8414.           making all in mit-pthreads
  8415.           make: Fatal error in reader: Makefile, line 18:
  8416.           Badly formed macro assignment
  8417.      Or:
  8418.           make: file `Makefile' line 18: Must be a separator (:
  8419.      Or:
  8420.           pthread.h: No such file or directory
  8421.  
  8422.      Solaris and FreeBSD are known to have troublesome `make' programs.
  8423.  
  8424.      GNU `make' Version 3.75 is known to work.
  8425.  
  8426.    * If you want to define flags to be used by your C or C++ compilers,
  8427.      do so by adding the flags to the `CFLAGS' and `CXXFLAGS'
  8428.      environment variables.  You can also specify the compiler names
  8429.      this way using `CC' and `CXX'.  For example:
  8430.  
  8431.           shell> CC=gcc
  8432.           shell> CFLAGS=-O3
  8433.           shell> CXX=gcc
  8434.           shell> CXXFLAGS=-O3
  8435.           shell> export CC CFLAGS CXX CXXFLAGS
  8436.  
  8437.      See *Note MySQL binaries::, for a list of flag definitions that
  8438.      have been found to be useful on various systems.
  8439.  
  8440.    * If you get an error message like this, you need to upgrade your
  8441.      `gcc' compiler:
  8442.  
  8443.           client/libmysql.c:273: parse error before `__attribute__'
  8444.  
  8445.      `gcc' 2.8.1 is known to work, but we recommend using `gcc' 2.95.2
  8446.      or `egcs' 1.0.3a instead.
  8447.  
  8448.    * If you get errors such as those shown here when compiling `mysqld',
  8449.      `configure' didn't correctly detect the type of the last argument
  8450.      to `accept()', `getsockname()', or `getpeername()':
  8451.  
  8452.           cxx: Error: mysqld.cc, line 645: In this statement, the referenced
  8453.                type of the pointer value ''length'' is ''unsigned long'',
  8454.                which is not compatible with ''int''.
  8455.           new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
  8456.  
  8457.      To fix this, edit the `config.h' file (which is generated by
  8458.      `configure').  Look for these lines:
  8459.  
  8460.           /* Define as the base type of the last arg to accept */
  8461.           #define SOCKET_SIZE_TYPE XXX
  8462.  
  8463.      Change `XXX' to `size_t' or `int', depending on your operating
  8464.      system.  (Note that you will have to do this each time you run
  8465.      `configure' because `configure' regenerates `config.h'.)
  8466.  
  8467.    * The `sql_yacc.cc' file is generated from `sql_yacc.yy'.  Normally
  8468.      the build process doesn't need to create `sql_yacc.cc', because
  8469.      MySQL comes with an already generated copy.  However, if you do
  8470.      need to re-create it, you might encounter this error:
  8471.  
  8472.           "sql_yacc.yy", line XXX fatal: default action causes potential...
  8473.  
  8474.      This is a sign that your version of `yacc' is deficient.  You
  8475.      probably need to install `bison' (the GNU version of `yacc') and
  8476.      use that instead.
  8477.  
  8478.    * On Debian Linux 3.0, you need to install `gawk' instead of the
  8479.      default `mawk' if you want to compile MySQL 4.1 or higher with
  8480.      Berkeley DB support.
  8481.  
  8482.    * If you need to debug `mysqld' or a MySQL client, run `configure'
  8483.      with the `--with-debug' option, then recompile and link your
  8484.      clients with the new client library.  *Note Debugging client::.
  8485.  
  8486.    * If you get a compilation error on Linux (for example, SuSE Linux
  8487.      8.1 or Red Hat Linux 7.3) similar to the following one:
  8488.  
  8489.           libmysql.c:1329: warning: passing arg 5 of `gethostbyname_r' from
  8490.           incompatible pointer type
  8491.           libmysql.c:1329: too few arguments to function `gethostbyname_r'
  8492.           libmysql.c:1329: warning: assignment makes pointer from integer
  8493.           without a cast
  8494.           make[2]: *** [libmysql.lo] Error 1
  8495.  
  8496.      By default, the `configure' script attempts to determine the
  8497.      correct number of arguments by using `g++' the GNU C++ compiler.
  8498.      This test yields wrong results if `g++' is not installed. There
  8499.      are two ways to work around this problem:
  8500.  
  8501.         * Make sure that the GNU C++ `g++' is installed. On some Linux
  8502.           distributions, the required package is called `gpp'; on
  8503.           others, it is named `gcc-c++'.
  8504.  
  8505.         * Use `gcc' as your C++ compiler by setting the `CXX'
  8506.           environment variable to `gcc':
  8507.                export CXX="gcc"
  8508.  
  8509.      Please note that you need to run `configure' again afterward.
  8510.  
  8511.  
  8512. MIT-pthreads Notes
  8513. ------------------
  8514.  
  8515. This section describes some of the issues involved in using
  8516. MIT-pthreads.
  8517.  
  8518. On Linux, you should _not_ use MIT-pthreads. Use the installed
  8519. LinuxThreads implementation instead.  *Note Linux::.
  8520.  
  8521. If your system does not provide native thread support, you will need to
  8522. build MySQL using the MIT-pthreads package.  This includes older
  8523. FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others.
  8524. *Note Which OS::.
  8525.  
  8526. Beginning with MySQL 4.0.2, MIT-pthreads is no longer part of the
  8527. source distribution. If you require this package, you need to download
  8528. it separately from
  8529. `http://www.mysql.com/Downloads/Contrib/pthreads-1_60_beta6-mysql.tar.gz'
  8530.  
  8531. After downloading, extract this source archive into the top level of the
  8532. MySQL source directory. It will create a new subdirectory named
  8533. `mit-pthreads'.
  8534.  
  8535.    * On most systems, you can force MIT-pthreads to be used by running
  8536.      `configure' with the `--with-mit-threads' option:
  8537.  
  8538.           shell> ./configure --with-mit-threads
  8539.  
  8540.      Building in a non-source directory is not supported when using
  8541.      MIT-pthreads because we want to minimize our changes to this code.
  8542.  
  8543.    * The checks that determine whether to use MIT-pthreads occur only
  8544.      during the part of the configuration process that deals with the
  8545.      server code.  If you have configured the distribution using
  8546.      `--without-server' to build only the client code, clients will not
  8547.      know whether MIT-pthreads is being used and will use Unix socket
  8548.      connections by default.  Because Unix socket files do not work
  8549.      under MIT-pthreads on some platforms, this means you will need to
  8550.      use `-h' or `--host' when you run client programs.
  8551.  
  8552.    * When MySQL is compiled using MIT-pthreads, system locking is
  8553.      disabled by default for performance reasons.  You can tell the
  8554.      server to use system locking with the `--external-locking' option.
  8555.      This is needed only if you want to be able to run two MySQL
  8556.      servers against the same data files, which is not recommended.
  8557.  
  8558.    * Sometimes the pthread `bind()' command fails to bind to a socket
  8559.      without any error message (at least on Solaris).  The result is
  8560.      that all connections to the server fail.  For example:
  8561.  
  8562.           shell> mysqladmin version
  8563.           mysqladmin: connect to server at '' failed;
  8564.           error: 'Can't connect to mysql server on localhost (146)'
  8565.  
  8566.      The solution to this is to kill the `mysqld' server and restart it.
  8567.      This has only happened to us when we have forced down the server
  8568.      and done a restart immediately.
  8569.  
  8570.    * With MIT-pthreads, the `sleep()' system call isn't interruptible
  8571.      with `SIGINT' (break).  This is only noticeable when you run
  8572.      `mysqladmin --sleep'.  You must wait for the `sleep()' call to
  8573.      terminate before the interrupt is served and the process stops.
  8574.  
  8575.    * When linking, you may receive warning messages like these (at
  8576.      least on Solaris); they can be ignored:
  8577.  
  8578.           ld: warning: symbol `_iob' has differing sizes:
  8579.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  8580.           file /usr/lib/libc.so value=0x140);
  8581.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  8582.           ld: warning: symbol `__iob' has differing sizes:
  8583.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  8584.           file /usr/lib/libc.so value=0x140);
  8585.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  8586.  
  8587.    * Some other warnings also can be ignored:
  8588.  
  8589.           implicit declaration of function `int strtoll(...)'
  8590.           implicit declaration of function `int strtoul(...)'
  8591.  
  8592.    * We haven't gotten `readline' to work with MIT-pthreads.  (This
  8593.      isn't needed, but may be interesting for someone.)
  8594.  
  8595. Installing MySQL from Source on Windows
  8596. ---------------------------------------
  8597.  
  8598. These instructions describe how to build MySQL binaries from source for
  8599. versions 4.1 and above on Windows. Instructions are provided for
  8600. building binaries from a standard source distribution or from the
  8601. BitKeeper tree that contains the latest development source.
  8602.  
  8603. *Note*: The instructions in this document are strictly for users who
  8604. want to test MySQL on Windows from the latest source distribution or
  8605. from the BitKeeper tree.  For production use, MySQL AB does not advise
  8606. using a MySQL server built by yourself from source.  Normally, it is
  8607. best to use precompiled binary distributions of MySQL that are built
  8608. specifically for optimal performance on Windows by MySQL AB.
  8609. Instructions for installing a binary distributions are available at
  8610. *Note Windows installation::.
  8611.  
  8612. To build MySQL on Windows from source, you need the following compiler
  8613. and resources available on your Windows system:
  8614.  
  8615.    * VC++ 6.0 compiler (updated with 4 or 5 SP and pre-processor
  8616.      package).  The pre-processor package is necessary for the macro
  8617.      assembler.  More details can be found at
  8618.      `http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/faq.aspx'.
  8619.  
  8620.    * Approximately 45MB disk space.
  8621.  
  8622.    * 64MB RAM.
  8623.  
  8624.  
  8625. You'll also need a MySQL source distribution for Windows.  There are
  8626. two ways you can get a source distribution for MySQL version 4.1 and
  8627. above:
  8628.  
  8629.   1. Obtain a source distribution packaged by MySQL AB for the
  8630.      particular version of MySQL in which you are interested.
  8631.      Prepackaged source distributions are available for released
  8632.      versions of MySQL and can be obtained from
  8633.      `http://dev.mysql.com/downloads/'.
  8634.  
  8635.   2. You can package a source distribution yourself from the latest
  8636.      BitKeeper developer source tree. If you plan to do this, you must
  8637.      create the package on a Unix system and then transfer it to your
  8638.      Windows system.  (The reason for this is that some of the
  8639.      configuration and build steps require tools that work only on
  8640.      Unix.)  The BitKeeper approach thus requires:
  8641.  
  8642.         * A system running Unix, or a Unix-like system such as Linux.
  8643.  
  8644.         * BitKeeper 3.0 installed on that system. You can obtain
  8645.           BitKeeper from `http://www.bitkeeper.com/'.
  8646.  
  8647.  
  8648.  
  8649. If you are using a Windows source distribution, you can go directly to
  8650. *Note Windows VC++ Build::. To build from the BitKeeper tree, proceed to
  8651. *Note Windows BitKeeper Build::.
  8652.  
  8653. If you find something not working as expected, or you have suggestions
  8654. about ways to improve the current build process on Windows, please send
  8655. a message to the `win32' mailing list.  *Note Mailing-list::.
  8656.  
  8657. Building MySQL Using VC++
  8658. .........................
  8659.  
  8660. *Note*: VC++ workspace files for MySQL 4.1 and above are compatible with
  8661. Microsoft Visual Studio 6.0 and above (7.0/.NET) editions and tested by
  8662. MySQL AB staff before each release.
  8663.  
  8664. Follow this procedure to build MySQL:
  8665.  
  8666.   1. Create a work directory (for example, `C:\workdir').
  8667.  
  8668.   2. Unpack the source distribution in the aforementioned directory
  8669.      using `WinZip' or other Windows tool that can read `.zip' files.
  8670.  
  8671.   3. Start the VC++ 6.0 compiler.
  8672.  
  8673.   4. In the `File' menu, select `Open Workspace'.
  8674.  
  8675.   5. Open the `mysql.dsw' workspace you find in the work directory.
  8676.  
  8677.   6. From the `Build' menu, select the `Set Active Configuration' menu.
  8678.  
  8679.   7. Click over the screen selecting `mysqld - Win32 Debug' and click
  8680.      OK.
  8681.  
  8682.   8. Press `F7' to begin the build of the debug server, libraries, and
  8683.      some client applications.
  8684.  
  8685.   9. Compile the release versions that you want in the same way.
  8686.  
  8687.  10. Debug versions of the programs and libraries are placed in the
  8688.      `client_debug' and `lib_debug' directories.  Release versions of
  8689.      the programs and libraries are placed in the `client_release' and
  8690.      `lib_release' directories.  Note that if you want to build both
  8691.      debug and release versions, you can select the `Build All' option
  8692.      from the `Build' menu.
  8693.  
  8694.  11. Test the server.  The server built using the preceding instructions
  8695.      will expect that the MySQL base directory and data directory are
  8696.      `C:\mysql' and `C:\mysql\data' by default. If you want to test
  8697.      your server using the source tree root directory and its data
  8698.      directory as the base directory and data directory, you will need
  8699.      to tell the server their pathnames. You can either do this on the
  8700.      command line with the `--basedir' and `--datadir' options, or
  8701.      place appropriate options in an option file (the `my.ini' file in
  8702.      your Windows directory or `C:\my.cnf').  If you have an existing
  8703.      data directory elsewhere that you want to use, you can specify its
  8704.      pathname instead.
  8705.  
  8706.  12. Start your server from the `client_release' or `client_debug'
  8707.      directory, depending on which server you want to use. The general
  8708.      server startup instructions are at *Note Windows installation::.
  8709.      You'll need to adapt the instructions appropriately if you want to
  8710.      use a different base directory or data directory.
  8711.  
  8712.  13. When the server is running in standalone fashion or as a service
  8713.      based on your configuration, try to connect to it from the `mysql'
  8714.      interactive command-line utility that exists in your
  8715.      `client_release' or `client_debug' directory.
  8716.  
  8717.  
  8718. When you are satisfied that the programs you have built are working
  8719. correctly, stop the server. Then install MySQL as follows:
  8720.  
  8721.   1. Create the directories where you want to install MySQL.  For
  8722.      example, to install into `C:\mysql', use these commands:
  8723.  
  8724.           C:\> mkdir C:\mysql
  8725.           C:\> mkdir C:\mysql\bin
  8726.           C:\> mkdir C:\mysql\data
  8727.           C:\> mkdir C:\mysql\share
  8728.           C:\> mkdir C:\mysql\scripts
  8729.  
  8730.      If you want to compile other clients and link them to MySQL, you
  8731.      should also create several additional directories:
  8732.  
  8733.           C:\> mkdir C:\mysql\include
  8734.           C:\> mkdir C:\mysql\lib
  8735.           C:\> mkdir C:\mysql\lib\debug
  8736.           C:\> mkdir C:\mysql\lib\opt
  8737.  
  8738.      If you want to benchmark MySQL, create this directory:
  8739.  
  8740.           C:\> mkdir C:\mysql\sql-bench
  8741.  
  8742.      Benchmarking requires Perl support.
  8743.  
  8744.   2. From the `workdir' directory, copy into the `C:\mysql' directory
  8745.      the following directories:
  8746.  
  8747.           C:\> cd \workdir
  8748.           C:\workdir> copy client_release\*.exe C:\mysql\bin
  8749.           C:\workdir> copy client_debug\mysqld.exe C:\mysql\bin\mysqld-debug.exe
  8750.           C:\workdir> xcopy scripts\*.* C:\mysql\scripts /E
  8751.           C:\workdir> xcopy share\*.* C:\mysql\share /E
  8752.  
  8753.      If you want to compile other clients and link them to MySQL, you
  8754.      should also copy several libraries and header files:
  8755.  
  8756.           C:\workdir> copy lib_debug\mysqlclient.lib C:\mysql\lib\debug
  8757.           C:\workdir> copy lib_debug\libmysql.* C:\mysql\lib\debug
  8758.           C:\workdir> copy lib_debug\zlib.* C:\mysql\lib\debug
  8759.           C:\workdir> copy lib_release\mysqlclient.lib C:\mysql\lib\opt
  8760.           C:\workdir> copy lib_release\libmysql.* C:\mysql\lib\opt
  8761.           C:\workdir> copy lib_release\zlib.* C:\mysql\lib\opt
  8762.           C:\workdir> copy include\*.h C:\mysql\include
  8763.           C:\workdir> copy libmysql\libmysql.def C:\mysql\include
  8764.  
  8765.      If you want to benchmark MySQL, you should also do this:
  8766.  
  8767.           C:\workdir> xcopy sql-bench\*.* C:\mysql\bench /E
  8768.  
  8769.  
  8770. Set up and start the server in the same way as for the binary Windows
  8771. distribution.  *Note Windows installation::.
  8772.  
  8773. Creating a Windows Source Package from the Latest Development Source
  8774. ....................................................................
  8775.  
  8776. To create a Windows source package from the current BitKeeper source
  8777. tree, use the following instructions. Please note that this procedure
  8778. must be performed on a system running a Unix or Unix-like operating
  8779. system.  For example, the procedure is known to work well on Linux.
  8780.  
  8781.   1. Clone the BitKeeper source tree for MySQL (version 4.1 or above,
  8782.      as desired).  For more information on how to clone the source tree,
  8783.      see the instructions at *Note Installing source tree::.
  8784.  
  8785.   2. Configure and build the distribution so that you have a server
  8786.      binary to work with.  One way to do this is to run the following
  8787.      command in the top-level directory of your source tree:
  8788.  
  8789.           shell> ./BUILD/compile-pentium-max
  8790.  
  8791.   3. After making sure that the build process completed successfully,
  8792.      run the following utility script from top-level directory of your
  8793.      source tree:
  8794.  
  8795.           shell> ./scripts/make_win_src_distribution
  8796.  
  8797.      This script creates a Windows source package to be used on your
  8798.      Windows system.  You can supply different options to the script
  8799.      based on your needs. It accepts the following options:
  8800.  
  8801.     `--help'
  8802.           Display a help message.
  8803.  
  8804.     `--debug'
  8805.           Print information about script operations, do not create
  8806.           package.
  8807.  
  8808.     `--tmp'
  8809.           Specify the temporary location.
  8810.  
  8811.     `--suffix'
  8812.           Suffix name for the package.
  8813.  
  8814.     `--dirname'
  8815.           Directory name to copy files (intermediate).
  8816.  
  8817.     `--silent'
  8818.           Do not print verbose list of files processed.
  8819.  
  8820.     `--tar'
  8821.           Create `tar.gz' package instead of `.zip' package.
  8822.  
  8823.      By default, `make_win_src_distribution' creates a Zip-format
  8824.      archive with the name `mysql-VERSION-win-src.zip', where VERSION
  8825.      represents the version of your MySQL source tree.
  8826.  
  8827.   4. Copy or upload to your Windows machine the Windows source package
  8828.      that you have just created. To compile it, use the instructions in
  8829.      *Note Windows VC++ Build::.
  8830.  
  8831.  
  8832. Compiling MySQL Clients on Windows
  8833. ----------------------------------
  8834.  
  8835. In your source files, you should include `my_global.h' before `mysql.h':
  8836.  
  8837.      #include <my_global.h>
  8838.      #include <mysql.h>
  8839.  
  8840. `my_global.h' includes any other files needed for Windows compatibility
  8841. (such as `windows.h') if you compile your program on Windows.
  8842.  
  8843. You can either link your code with the dynamic `libmysql.lib' library,
  8844. which is just a wrapper to load in `libmysql.dll' on demand, or link
  8845. with the static `mysqlclient.lib' library.
  8846.  
  8847. The MySQL client libraries are compiled as threaded libraries, so you
  8848. should also compile your code to be multi-threaded.
  8849.  
  8850. Post-Installation Setup and Testing
  8851. ===================================
  8852.  
  8853. After installing MySQL, there are some issues you should address.  For
  8854. example, on Unix, you should initialize the data directory and create
  8855. the MySQL grant tables.  On all platforms, an important security
  8856. concern is that the initial accounts in the grant tables have no
  8857. passwords.  You should assign passwords to prevent unauthorized access
  8858. to the MySQL server.  For MySQL 4.1.3 and up, you can create time zone
  8859. tables to enable recognition of named time zones. (Currently, these
  8860. tables can be populated only on Unix. This problem will be addressed
  8861. soon for Windows.)
  8862.  
  8863. The following sections include post-installation procedures that are
  8864. specific to Windows systems and to Unix systems. Another section, *Note
  8865. Starting server::, applies to all platforms; it describes what to do if
  8866. you have trouble getting the server to start.  *Note Default
  8867. privileges:: also applies to all platforms. You should follow its
  8868. instructions to make sure that you have properly protected your MySQL
  8869. accounts by assigning passwords to them.
  8870.  
  8871. When you are ready to create additional user accounts, you can find
  8872. information on the MySQL access control system and account management in
  8873. *Note Privilege system:: and *Note User Account Management::.
  8874.  
  8875. Windows Post-Installation Procedures
  8876. ------------------------------------
  8877.  
  8878. On Windows, the data directory and the grant tables do not have to be
  8879. created. MySQL Windows distributions include the grant tables already
  8880. set up with a set of preinitialized accounts in the `mysql' database
  8881. under the data directory.  However, you should assign passwords to the
  8882. accounts.  The procedure for this is given in *Note Default
  8883. privileges::.
  8884.  
  8885. Before setting up passwords, you might want to try running some client
  8886. programs to make sure that you can connect to the server and that it is
  8887. operating properly.  Make sure the server is running (*note Windows
  8888. server first start::), then issue the following commands to verify that
  8889. you can retrieve information from the server.  The output should be
  8890. similar to what is shown here:
  8891.  
  8892.      C:\> C:\mysql\bin\mysqlshow
  8893.      +-----------+
  8894.      | Databases |
  8895.      +-----------+
  8896.      | mysql     |
  8897.      | test      |
  8898.      +-----------+
  8899.      
  8900.      C:\> C:\mysql\bin\mysqlshow mysql
  8901.      Database: mysql
  8902.      +--------------+
  8903.      |    Tables    |
  8904.      +--------------+
  8905.      | columns_priv |
  8906.      | db           |
  8907.      | func         |
  8908.      | host         |
  8909.      | tables_priv  |
  8910.      | user         |
  8911.      +--------------+
  8912.      
  8913.      C:\> C:\mysql\bin\mysql -e "SELECT Host,Db,User FROM db" mysql
  8914.      +------+-------+------+
  8915.      | host | db    | user |
  8916.      +------+-------+------+
  8917.      | %    | test% |      |
  8918.      +------+-------+------+
  8919.  
  8920. If you are running a version of Windows that supports services and you
  8921. want the MySQL server to run automatically when Windows starts, see
  8922. *Note NT start::.
  8923.  
  8924. Unix Post-Installation Procedures
  8925. ---------------------------------
  8926.  
  8927. After installing MySQL on Unix, you need to initialize the grant tables,
  8928. start the server, and make sure that the server works okay.  You may
  8929. also wish to arrange for the server to be started and stopped
  8930. automatically when your system starts and stops.  You should also
  8931. assign passwords to the accounts in the grant tables.
  8932.  
  8933. On Unix, the grant tables are set up by the `mysql_install_db' program.
  8934. For some installation methods, this program is run for you
  8935. automatically:
  8936.  
  8937.    * If you install MySQL on Linux using RPM distributions, the server
  8938.      RPM runs `mysql_install_db'.
  8939.  
  8940.    * If you install MySQL on Mac OS X using a PKG distribution, the
  8941.      installer runs `mysql_install_db'.
  8942.  
  8943. Otherwise, you'll need to run `mysql_install_db' yourself.
  8944.  
  8945. The following procedure describes how to initialize the grant tables (if
  8946. that has not already been done) and then start the server. It also
  8947. suggests some commands that you can use to test whether the server is
  8948. accessible and working properly.  For information about starting and
  8949. stopping the server automatically, see *Note Automatic start::.
  8950.  
  8951. After you complete the procedure and have the server running, you should
  8952. assign passwords to the accounts created by `mysql_install_db'.
  8953. Instructions for doing so are given in *Note Default privileges::.
  8954.  
  8955. In the examples shown here, the server runs under the user ID of the
  8956. `mysql' login account. This assumes that such an account exists.
  8957. Either create the account if it does not exist, or substitute the name
  8958. of a different existing login account that you plan to use for running
  8959. the server.
  8960.  
  8961.   1. Change location into the top-level directory of your MySQL
  8962.      installation, represented here by BASEDIR:
  8963.  
  8964.           shell> cd BASEDIR
  8965.  
  8966.      BASEDIR is likely to be something like `/usr/local/mysql' or
  8967.      `/usr/local'.  The following steps assume that you are located in
  8968.      this directory.
  8969.  
  8970.   2. If necessary, run the `mysql_install_db' program to set up the
  8971.      initial MySQL grant tables containing the privileges that
  8972.      determine how users are allowed to connect to the server. You'll
  8973.      need to do this if you used a distribution type that doesn't run
  8974.      the program for you.
  8975.  
  8976.      Typically, `mysql_install_db' needs to be run only the first time
  8977.      you install MySQL, so you can skip this step if you are upgrading
  8978.      an existing installation, However, `mysql_install_db' does not
  8979.      overwrite any existing privilege tables, so it should be safe to
  8980.      run in any circumstances.
  8981.  
  8982.      To initialize the grant tables, use one of the following commands,
  8983.      depending on whether `mysql_install_db' is located in the `bin' or
  8984.      `scripts' directory:
  8985.  
  8986.           shell> bin/mysql_install_db --user=mysql
  8987.           shell> scripts/mysql_install_db --user=mysql
  8988.  
  8989.      The `mysql_install_db' script creates the data directory, the
  8990.      `mysql' database that holds all database privileges, and the `test'
  8991.      database that you can use to test MySQL. The script also creates
  8992.      privilege table entries for `root' accounts and anonymous-user
  8993.      accounts.  The accounts have no passwords initially.  A
  8994.      description of their initial privileges is given in *Note Default
  8995.      privileges::.  Briefly, these privileges allow the MySQL `root'
  8996.      user to do anything, and allow anybody to create or use databases
  8997.      with a name of `test' or starting with `test_'.
  8998.  
  8999.      It is important to make sure that the database directories and
  9000.      files are owned by the `mysql' login account so that the server
  9001.      has read and write access to them when you run it later. To ensure
  9002.      this, the `--user' option should be used as shown if you run
  9003.      `mysql_install_db' as `root'. Otherwise, you should execute the
  9004.      script while logged in as `mysql', in which case you can omit the
  9005.      `--user' option from the command.
  9006.  
  9007.      `mysql_install_db' creates several tables in the `mysql' database:
  9008.      `user', `db', `host', `tables_priv', `columns_priv', `func', and
  9009.      possibly others depending on your version of MySQL.
  9010.  
  9011.      If you don't want to have the `test' database, you can remove it
  9012.      with `mysqladmin -u root drop test' after starting the server.
  9013.  
  9014.      If you have problems with `mysql_install_db', see *Note
  9015.      `mysql_install_db': mysql_install_db.
  9016.  
  9017.      There are some alternatives to running the `mysql_install_db'
  9018.      script as it is provided in the MySQL distribution:
  9019.  
  9020.         * If you want the initial privileges to be different from the
  9021.           standard defaults, you can modify `mysql_install_db' before
  9022.           you run it.  However, a preferable technique is to use
  9023.           `GRANT' and `REVOKE' to change the privileges after the grant
  9024.           tables have been set up.  In other words, you can run
  9025.           `mysql_install_db', and then use `mysql -u root mysql' to
  9026.           connect to the server as the MySQL `root' user so that you
  9027.           can issue the `GRANT' and `REVOKE' statements.
  9028.  
  9029.           If you want to install MySQL on a lot of machines with the
  9030.           same privileges, you can put the `GRANT' and `REVOKE'
  9031.           statements in a file and execute the file as a script using
  9032.           `mysql' after running `mysql_install_db'. For example:
  9033.  
  9034.                shell> bin/mysql_install_db --user=mysql
  9035.                shell> bin/mysql -u root < your_script_file
  9036.  
  9037.           By doing this, you can avoid having to issue the statements
  9038.           manually on each machine.
  9039.  
  9040.         * It is possible to re-create the grant tables completely after
  9041.           they have already been created.  You might want to do this if
  9042.           you're just learning how to use `GRANT' and `REVOKE' and have
  9043.           made so many modifications after running `mysql_install_db'
  9044.           that you want to wipe out the tables and start over.
  9045.  
  9046.           To re-create the grant tables, remove all the `.frm', `.MYI',
  9047.           and `.MYD' files in the directory containing the `mysql'
  9048.           database.  (This is the directory named `mysql' under the
  9049.           data directory, which is listed as the `datadir' value when
  9050.           you run `mysqld --help'.) Then run the `mysql_install_db'
  9051.           script again.
  9052.  
  9053.           *Note*: For MySQL versions older than 3.22.10, you should not
  9054.           delete the `.frm' files.  If you accidentally do this, you
  9055.           should copy them back into the `mysql' directory from your
  9056.           MySQL distribution before running `mysql_install_db'.
  9057.  
  9058.         * You can start `mysqld' manually using the
  9059.           `--skip-grant-tables' option and add the privilege
  9060.           information yourself using `mysql':
  9061.  
  9062.                shell> bin/mysqld_safe --user=mysql --skip-grant-tables &
  9063.                shell> bin/mysql mysql
  9064.  
  9065.           From `mysql', manually execute the SQL commands contained in
  9066.           `mysql_install_db'.  Make sure that you run `mysqladmin
  9067.           flush-privileges' or `mysqladmin reload' afterward to tell
  9068.           the server to reload the grant tables.
  9069.  
  9070.           Note that by not using `mysql_install_db', you not only have
  9071.           to populate the grant tables manually, you also have to
  9072.           create them first.
  9073.  
  9074.   3. Start the MySQL server:
  9075.  
  9076.           shell> bin/mysqld_safe --user=mysql &
  9077.  
  9078.      For versions of MySQL older than 4.0, substitute `bin/safe_mysqld'
  9079.      for `bin/mysqld_safe' in this command.
  9080.  
  9081.      It is important that the MySQL server be run using an unprivileged
  9082.      (non-`root') login account.  To ensure this, the `--user' option
  9083.      should be used as shown if you run `mysql_safe' as `root'.
  9084.      Otherwise, you should execute the script while logged in as
  9085.      `mysql', in which case you can omit the `--user' option from the
  9086.      command.
  9087.  
  9088.      Further instructions for running MySQL as an unprivileged user are
  9089.      given in *Note Changing MySQL user::.
  9090.  
  9091.      If you neglected to create the grant tables before proceeding to
  9092.      this step, the following message will appear in the error log file
  9093.      when you start the server:
  9094.  
  9095.           mysqld: Can't find file: 'host.frm'
  9096.  
  9097.      If you have other problems starting the server, see *Note Starting
  9098.      server::.
  9099.  
  9100.   4. Use `mysqladmin' to verify that the server is running.  The
  9101.      following commands provide simple tests to check whether the
  9102.      server is up and responding to connections:
  9103.  
  9104.           shell> bin/mysqladmin version
  9105.           shell> bin/mysqladmin variables
  9106.  
  9107.      The output from `mysqladmin version' varies slightly depending on
  9108.      your platform and version of MySQL, but should be similar to that
  9109.      shown here:
  9110.  
  9111.           shell> bin/mysqladmin version
  9112.           mysqladmin  Ver 8.40 Distrib 4.0.18, for linux on i586
  9113.           Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  9114.           This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  9115.           and you are welcome to modify and redistribute it under the GPL license
  9116.           
  9117.           Server version          4.0.18-log
  9118.           Protocol version        10
  9119.           Connection              Localhost via Unix socket
  9120.           TCP port                3306
  9121.           UNIX socket             /tmp/mysql.sock
  9122.           Uptime:                 16 sec
  9123.           
  9124.           Threads: 1  Questions: 9  Slow queries: 0
  9125.           Opens: 7  Flush tables: 2  Open tables: 0
  9126.           Queries per second avg: 0.000
  9127.           Memory in use: 132K  Max memory used: 16773K
  9128.  
  9129.      To see what else you can do with `mysqladmin', invoke it with the
  9130.      `--help' option.
  9131.  
  9132.   5. Verify that you can shut down the server:
  9133.  
  9134.           shell> bin/mysqladmin -u root shutdown
  9135.  
  9136.   6. Verify that you can restart the server.  Do this by using
  9137.      `mysqld_safe' or by invoking `mysqld' directly.  For example:
  9138.  
  9139.           shell> bin/mysqld_safe --user=mysql --log &
  9140.  
  9141.      If `mysqld_safe' fails, see *Note Starting server::.
  9142.  
  9143.   7. Run some simple tests to verify that you can retrieve information
  9144.      from the server.  The output should be similar to what is shown
  9145.      here:
  9146.  
  9147.           shell> bin/mysqlshow
  9148.           +-----------+
  9149.           | Databases |
  9150.           +-----------+
  9151.           | mysql     |
  9152.           | test      |
  9153.           +-----------+
  9154.           
  9155.           shell> bin/mysqlshow mysql
  9156.           Database: mysql
  9157.           +--------------+
  9158.           |    Tables    |
  9159.           +--------------+
  9160.           | columns_priv |
  9161.           | db           |
  9162.           | func         |
  9163.           | host         |
  9164.           | tables_priv  |
  9165.           | user         |
  9166.           +--------------+
  9167.           
  9168.           shell> bin/mysql -e "SELECT Host,Db,User FROM db" mysql
  9169.           +------+--------+------+
  9170.           | host | db     | user |
  9171.           +------+--------+------+
  9172.           | %    | test   |      |
  9173.           | %    | test_% |      |
  9174.           +------+--------+------+
  9175.  
  9176.   8. There is a benchmark suite in the `sql-bench' directory (under the
  9177.      MySQL installation directory) that you can use to compare how
  9178.      MySQL performs on different platforms. The benchmark suite is
  9179.      written in Perl. It uses the Perl DBI module to provide a
  9180.      database-independent interface to the various databases, and some
  9181.      other additional Perl modules are required to run the benchmark
  9182.      suite. You must have the following modules installed:
  9183.  
  9184.           DBI
  9185.           DBD::mysql
  9186.           Data::Dumper
  9187.           Data::ShowTable
  9188.  
  9189.      These modules can be obtained from CPAN (`http://www.cpan.org/').
  9190.      *Note Perl installation::.
  9191.  
  9192.      The `sql-bench/Results' directory contains the results from many
  9193.      runs against different databases and platforms.  To run all tests,
  9194.      execute these commands:
  9195.  
  9196.           shell> cd sql-bench
  9197.           shell> perl run-all-tests
  9198.  
  9199.      If you don't have the `sql-bench' directory, you probably
  9200.      installed MySQL using RPM files other than the source RPM.  (The
  9201.      source RPM includes the `sql-bench' benchmark directory.)  In this
  9202.      case, you must first install the benchmark suite before you can
  9203.      use it.  Beginning with MySQL 3.22, there are separate benchmark
  9204.      RPM files named `mysql-bench-VERSION-i386.rpm' that contain
  9205.      benchmark code and data.
  9206.  
  9207.      If you have a source distribution, there are also tests in its
  9208.      `tests' subdirectory that you can run. For example, to run
  9209.      `auto_increment.tst', execute this command from the top-level
  9210.      directory of your source distribution:
  9211.  
  9212.           shell> mysql -vvf test < ./tests/auto_increment.tst
  9213.  
  9214.      The expected result of the test can be found in the
  9215.      `./tests/auto_increment.res' file.
  9216.  
  9217.   9. At this point, you should have the server running. However, none
  9218.      of the initial MySQL accounts have a password, so you should
  9219.      assign passwords using the instructions in *Note Default
  9220.      privileges::.
  9221.  
  9222. As of MySQL 4.1.3, the installation procedure creates time zone tables
  9223. in the `mysql' database. However, you must populate the tables manually.
  9224. Instructions to do this are given in *Note Time zone support::.
  9225.  
  9226. Problems Running `mysql_install_db'
  9227. ...................................
  9228.  
  9229. The purpose of the `mysql_install_db' script is to generate new MySQL
  9230. privilege tables.  It will not overwrite existing MySQL privilege
  9231. tables, and it will not affect any other data.
  9232.  
  9233. If you want to re-create your privilege tables, first stop the `mysqld'
  9234. server if it's running. Then rename the `mysql' directory under the
  9235. data directory to save it, and then run `mysql_install_db'.  For
  9236. example:
  9237.  
  9238.      shell> mv mysql-data-directory/mysql mysql-data-directory/mysql-old
  9239.      shell> mysql_install_db --user=mysql
  9240.  
  9241. This section lists problems you might encounter when you run
  9242. `mysql_install_db':
  9243.  
  9244. *`mysql_install_db' doesn't install the grant tables*
  9245.      You may find that `mysql_install_db' fails to install the grant
  9246.      tables and terminates after displaying the following messages:
  9247.  
  9248.           Starting mysqld daemon with databases from XXXXXX
  9249.           mysqld ended
  9250.  
  9251.      In this case, you should examine the error log file very
  9252.      carefully.  The log should be located in the directory `XXXXXX'
  9253.      named by the error message, and should indicate why `mysqld'
  9254.      didn't start.  If you don't understand what happened, include the
  9255.      log when you post a bug report.  *Note Bug reports::.
  9256.  
  9257. *There is already a `mysqld' process running*
  9258.      This indicates that the server is already running, in which case
  9259.      the grant tables probably have already been created. If so, you
  9260.      don't have to run `mysql_install_db' at all because it need be run
  9261.      only once (when you install MySQL the first time).
  9262.  
  9263. *Installing a second `mysqld' server doesn't work when one server is running*
  9264.      This can happen when you already have an existing MySQL
  9265.      installation, but want to put a new installation in a different
  9266.      location.  For example, you might have a production installation
  9267.      already, but you want to create a second installation for testing
  9268.      purposes.  Generally the problem that occurs when you try to run a
  9269.      second server is that it tries to use a network interface that is
  9270.      already in use by the first server.  In this case, you will see
  9271.      one of the following error messages:
  9272.  
  9273.           Can't start server: Bind on TCP/IP port:
  9274.           Address already in use
  9275.           Can't start server: Bind on unix socket...
  9276.  
  9277.      For instructions on setting up multiple servers, see *Note
  9278.      Multiple servers::.
  9279.  
  9280. *You don't have write access to `/tmp'*
  9281.      If you don't have write access to create temporary files or a Unix
  9282.      socket file in the default location (the `/tmp' directory), an
  9283.      error will occur when you run `mysql_install_db' or the `mysqld'
  9284.      server.
  9285.  
  9286.      You can specify different temporary directory and Unix socket file
  9287.      locations by executing these commands prior to starting
  9288.      `mysql_install_db' or `mysqld':
  9289.  
  9290.           shell> TMPDIR=/some_tmp_dir/
  9291.           shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysql.sock
  9292.           shell> export TMPDIR MYSQL_UNIX_PORT
  9293.  
  9294.      `some_tmp_dir' should be the full pathname to some directory for
  9295.      which you have write permission.
  9296.  
  9297.      After this, you should be able to run `mysql_install_db' and start
  9298.      the server with these commands:
  9299.  
  9300.           shell> bin/mysql_install_db --user=mysql
  9301.           shell> bin/mysqld_safe --user=mysql &
  9302.  
  9303.      If `mysql_install_db' is located in the `scripts' directory,
  9304.      modify the first command to use `scripts/mysql_install_db'.
  9305.  
  9306.      See *Note Problems with `mysql.sock': Problems with mysql.sock.
  9307.      *Note Environment variables::.
  9308.  
  9309. Starting and Stopping MySQL Automatically
  9310. .........................................
  9311.  
  9312. Generally, you start the `mysqld' server in one of these ways:
  9313.  
  9314.    * By invoking `mysqld' directly. This works on any platform.
  9315.  
  9316.    * By running the MySQL server as a Windows service.  This can be
  9317.      done on versions of Windows that support services (such as NT,
  9318.      2000, and XP). The service can be set to start the server
  9319.      automatically when Windows starts, or as a manual service that you
  9320.      start on request.  For instructions, see *Note NT start::.
  9321.  
  9322.    * By invoking `mysqld_safe', which tries to determine the proper
  9323.      options for `mysqld' and then runs it with those options.  This
  9324.      script is used on systems based on BSD Unix.  *Note `mysqld_safe':
  9325.      mysqld_safe.
  9326.  
  9327.    * By invoking `mysql.server'.  This script is used primarily at
  9328.      system startup and shutdown on systems that use System V-style run
  9329.      directories, where it usually is installed under the name `mysql'.
  9330.      The `mysql.server' script starts the server by invoking
  9331.      `mysqld_safe'.  *Note `mysql.server': mysql.server.
  9332.  
  9333.    * On Mac OS X, you can install a separate MySQL Startup Item package
  9334.      to enable the automatic startup of MySQL on system startup.  The
  9335.      Startup Item starts the server by invoking `mysql.server'.  See
  9336.      *Note Mac OS X installation:: for details.
  9337.  
  9338.  
  9339. The `mysql.server' and `mysqld_safe' scripts and the Mac OS X Startup
  9340. Item can be used to start the server manually, or automatically at
  9341. system startup time. `mysql.server' and the Startup Item also can be
  9342. used to stop the server.
  9343.  
  9344. To start or stop the server manually using the `mysql.server' script,
  9345. invoke it with `start' or `stop' arguments:
  9346.  
  9347.      shell> mysql.server start
  9348.      shell> mysql.server stop
  9349.  
  9350. Before `mysql.server' starts the server, it changes location to the
  9351. MySQL installation directory, and then invokes `mysqld_safe'.  If you
  9352. want the server to run as some specific user, add an appropriate `user'
  9353. option to the `[mysqld]' group of the `/etc/my.cnf' option file, as
  9354. shown later in this section.  (It is possible that you'll need to edit
  9355. `mysql.server' if you've installed a binary distribution of MySQL in a
  9356. non-standard location.  Modify it to `cd' into the proper directory
  9357. before it runs `mysqld_safe'.  If you do this, your modified version of
  9358. `mysql.server' may be overwritten if you upgrade MySQL in the future,
  9359. so you should make a copy of your edited version that you can
  9360. reinstall.)
  9361.  
  9362. `mysql.server stop' brings down the server by sending a signal to it.
  9363. You can also stop the server manually by executing `mysqladmin
  9364. shutdown'.
  9365.  
  9366. To start and stop MySQL automatically on your server, you need to add
  9367. start and stop commands to the appropriate places in your `/etc/rc*'
  9368. files.
  9369.  
  9370. If you use the Linux server RPM package (`MySQL-server-VERSION.rpm'),
  9371. the `mysql.server' script will already have been installed in the
  9372. `/etc/init.d' directory with the name `mysql'. You need not install it
  9373. manually. See *Note Linux-RPM:: for more information on the Linux RPM
  9374. packages.
  9375.  
  9376. Some vendors provide RPM packages that install a startup script under a
  9377. different name such as `mysqld'.
  9378.  
  9379. If you install MySQL from a source distribution or using a binary
  9380. distribution format that does not install `mysql.server' automatically,
  9381. you can install it manually. The script can be found in the
  9382. `support-files' directory under the MySQL installation directory or in
  9383. a MySQL source tree.
  9384.  
  9385. To install `mysql.server' manually, copy it to the `/etc/init.d'
  9386. directory with the name `mysql', and then make it executable.  Do this
  9387. by changing location into the appropriate directory where
  9388. `mysql.server' is located and executing these commands:
  9389.  
  9390.      shell> cp mysql.server /etc/init.d/mysql
  9391.      shell> chmod +x /etc/init.d/mysql
  9392.  
  9393. Older Red Hat systems use the `/etc/rc.d/init.d' directory rather than
  9394. `/etc/init.d'. Adjust the preceding commands accordingly. Alternatively,
  9395. first create `/etc/init.d' as a symbolic link that points to
  9396. `/etc/rc.d/init.d':
  9397.  
  9398.      shell> cd /etc
  9399.      shell> ln -s rc.d/init.d .
  9400.  
  9401. After installing the script, the commands needed to activate it to run
  9402. at system startup depend on your operating system.  On Linux, you can
  9403. use `chkconfig':
  9404.  
  9405.      shell> chkconfig --add mysql
  9406.  
  9407. On some Linux systems, the following command also seems to be necessary
  9408. to fully enable the `mysql' script:
  9409.  
  9410.      shell> chkconfig --level 345 mysql on
  9411.  
  9412. On FreeBSD, startup scripts generally should go in
  9413. `/usr/local/etc/rc.d/'. The `rc(8)' manual page states that scripts in
  9414. this directory are executed only if their basename matches the `*.sh'
  9415. shell filename pattern.  Any other files or directories present within
  9416. the directory are silently ignored. In other words, on FreeBSD, you
  9417. should install the `mysql.server' script as
  9418. `/usr/local/etc/rc.d/mysql.server.sh' to enable automatic startup.
  9419.  
  9420. As an alternative to the preceding setup, some operating systems also
  9421. use `/etc/rc.local' or `/etc/init.d/boot.local' to start additional
  9422. services on startup. To start up MySQL using this method, you could
  9423. append a command like the one following to the appropriate startup file:
  9424.  
  9425.      /bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'
  9426.  
  9427. For other systems, consult your operating system documentation to see
  9428. how to install startup scripts.
  9429.  
  9430. You can add options for `mysql.server' in a global `/etc/my.cnf' file.
  9431. A typical `/etc/my.cnf' file might look like this:
  9432.  
  9433.      [mysqld]
  9434.      datadir=/usr/local/mysql/var
  9435.      socket=/var/tmp/mysql.sock
  9436.      port=3306
  9437.      user=mysql
  9438.      
  9439.      [mysql.server]
  9440.      basedir=/usr/local/mysql
  9441.  
  9442. The `mysql.server' script understands the following options: `basedir',
  9443. `datadir', and `pid-file'.  If specified, they _must_ be placed in an
  9444. option file, not on the command line.  `mysql.server' understands only
  9445. `start' and `stop' as command-line arguments.
  9446.  
  9447. The following table shows which option groups the server and each
  9448. startup script read from option files:
  9449.  
  9450. *Script*       *Option Groups*
  9451. `mysqld'       `[mysqld]', `[server]', `[mysqld-major-version]'
  9452. `mysql.server' `[mysqld]', `[mysql.server]'
  9453. `mysqld_safe'  `[mysqld]', `[server]', `[mysqld_safe]'
  9454.  
  9455. `[mysqld-major-version]' means that groups with names like
  9456. `[mysqld-4.0]', `[mysqld-4.1]', and `[mysqld-5.0]' will be read by
  9457. servers having versions 4.0.x, 4.1.x, 5.0.x, and so forth.  This
  9458. feature was added in MySQL 4.0.14. It can be used to specify options
  9459. that will be read only by servers within a given release series.
  9460.  
  9461. For backward compatibility, `mysql.server' also reads the
  9462. `[mysql_server]' group and `mysqld_safe' also reads the `[safe_mysqld]'
  9463. group. However, you should update your option files to use the
  9464. `[mysql.server]' and `[mysqld_safe]' groups instead when you begin
  9465. using MySQL 4.0 or later.
  9466.  
  9467. *Note Option files::.
  9468.  
  9469. Starting and Troubleshooting the MySQL Server
  9470. .............................................
  9471.  
  9472. If you have problems starting the server, here are some things you can
  9473. try:
  9474.  
  9475.    * Specify any special options needed by the storage engines you are
  9476.      using.
  9477.  
  9478.    * Make sure that the server knows where to find the data directory.
  9479.  
  9480.    * Make sure the server can use the data directory.  The ownership and
  9481.      permissions of the data directory and its contents must be set
  9482.      such that the server can access and modify them.
  9483.  
  9484.    * Check the error log to see why the server doesn't start.
  9485.  
  9486.    * Verify that the network interfaces the server wants to use are
  9487.      available.
  9488.  
  9489.  
  9490. Some storage engines have options that control their behavior.  You can
  9491. create a `my.cnf' file and set startup options for the engines you plan
  9492. to use.  If you are going to use storage engines that support
  9493. transactional tables (`InnoDB', `BDB'), be sure that you have them
  9494. configured the way you want before starting the server:
  9495.  
  9496.    * If you are using `InnoDB' tables, refer to the `InnoDB'-specific
  9497.      startup options.  In MySQL 3.23, you must configure `InnoDB'
  9498.      explicitly or the server will fail to start.  From MySQL 4.0 on,
  9499.      `InnoDB' uses default values for its configuration options if you
  9500.      specify none.  *Note `InnoDB' configuration: InnoDB configuration.
  9501.  
  9502.    * If you are using `BDB' (Berkeley DB) tables, you should familiarize
  9503.      yourself with the different `BDB'-specific startup options.  *Note
  9504.      BDB start::.
  9505.  
  9506.  
  9507. When the `mysqld' server starts, it changes location to the data
  9508. directory.  This is where it expects to find databases and where it
  9509. expects to write log files. On Unix, the server also writes the pid
  9510. (process ID) file in the data directory.
  9511.  
  9512. The data directory location is hardwired in when the server is compiled.
  9513. This is where the server looks for the data directory by default. If
  9514. the data directory is located somewhere else on your system, the server
  9515. will not work properly.  You can find out what the default path
  9516. settings are by invoking `mysqld' with the `--verbose' and `--help'
  9517. options.  (Prior to MySQL 4.1, omit the `--verbose' option.)
  9518.  
  9519. If the defaults don't match the MySQL installation layout on your
  9520. system, you can override them by specifying options on the command line
  9521. to `mysqld' or `mysqld_safe'. You can also list the options in an
  9522. option file.
  9523.  
  9524. To specify the location of the data directory explicitly, use the
  9525. `--datadir' option. However, normally you can tell `mysqld' the
  9526. location of the base directory under which MySQL is installed and it
  9527. will look for the data directory there.  You can do this with the
  9528. `--basedir' option.
  9529.  
  9530. To check the effect of specifying path options, invoke `mysqld' with
  9531. those options followed by the `--verbose' and `--help' options.  For
  9532. example, if you change location into the directory where `mysqld' is
  9533. installed, and then run the following command, it will show the effect
  9534. of starting the server with a base directory of `/usr/local':
  9535.  
  9536.      shell> ./mysqld --basedir=/usr/local --verbose --help
  9537.  
  9538. You can specify other options such as `--datadir' as well, but note
  9539. that `--verbose' and `--help' must be the last options.  (Prior to
  9540. MySQL 4.1, omit the `--verbose' option.)
  9541.  
  9542. Once you determine the path settings you want, start the server without
  9543. `--verbose' and `--help'.
  9544.  
  9545. If `mysqld' is currently running, you can find out what path settings
  9546. it is using by executing this command:
  9547.  
  9548.      shell> mysqladmin variables
  9549.  
  9550. Or:
  9551.  
  9552.      shell> mysqladmin -h HOST_NAME variables
  9553.  
  9554. HOST_NAME is the name of the MySQL server host.
  9555.  
  9556. If you get `Errcode 13' (which means `Permission denied') when starting
  9557. `mysqld', this means that the access privileges of the data directory
  9558. or its contents do not allow the server access.  In this case, you
  9559. change the permissions for the involved files and directories so that
  9560. the server has the right to use them.  You can also start the server as
  9561. `root', but this can raise security issues and should be avoided.
  9562.  
  9563. On Unix, change location into the data directory and check the
  9564. ownership of the data directory and its contents to make sure the
  9565. server has access. For example, if the data directory is
  9566. `/usr/local/mysql/var', use this command:
  9567.  
  9568.      shell> ls -la /usr/local/mysql/var
  9569.  
  9570. If the data directory or its files or subdirectories are not owned by
  9571. the account that you use for running the server, change their ownership
  9572. to that account:
  9573.  
  9574.      shell> chown -R mysql /usr/local/mysql/var
  9575.      shell> chgrp -R mysql /usr/local/mysql/var
  9576.  
  9577. If the server fails to start up correctly, check the error log file to
  9578. see if you can find out why.  Log files are located in the data
  9579. directory (typically `C:\mysql\data' on Windows, `/usr/local/mysql/data'
  9580. for a Unix binary distribution, and `/usr/local/var' for a Unix source
  9581. distribution).  Look in the data directory for files with names of the
  9582. form `HOST_NAME.err' and `HOST_NAME.log', where HOST_NAME is the name
  9583. of your server host. (Older servers on Windows use `mysql.err' as the
  9584. error log name.)  Then check the last few lines of these files.  On
  9585. Unix, you can use `tail' to display the last few lines:
  9586.  
  9587.      shell> tail HOST_NAME.err
  9588.      shell> tail HOST_NAME.log
  9589.  
  9590. The error log contains information that indicates why the server
  9591. couldn't start.  For example, you might see something like this in the
  9592. log:
  9593.  
  9594.      000729 14:50:10  bdb:  Recovery function for LSN 1 27595 failed
  9595.      000729 14:50:10  bdb:  warning: ./test/t1.db: No such file or directory
  9596.      000729 14:50:10  Can't init databases
  9597.  
  9598. This means that you didn't start `mysqld' with the `--bdb-no-recover'
  9599. option and Berkeley DB found something wrong with its own log files
  9600. when it tried to recover your databases.  To be able to continue, you
  9601. should move away the old Berkeley DB log files from the database
  9602. directory to some other place, where you can later examine them.  The
  9603. `BDB' log files are named in sequence beginning with `log.0000000001',
  9604. where the number increases over time.
  9605.  
  9606. If you are running `mysqld' with `BDB' table support and `mysqld' dumps
  9607. core at startup, this could be due to problems with the `BDB' recovery
  9608. log.  In this case, you can try starting `mysqld' with
  9609. `--bdb-no-recover'.  If that helps, then you should remove all `BDB'
  9610. log files from the data directory and try starting `mysqld' again
  9611. without the `--bdb-no-recover' option.
  9612.  
  9613. If either of the following errors occur, it means that some other
  9614. program (perhaps another `mysqld' server) is already using the TCP/IP
  9615. port or Unix socket file that `mysqld' is trying to use:
  9616.  
  9617.      Can't start server: Bind on TCP/IP port: Address already in use
  9618.      Can't start server: Bind on unix socket...
  9619.  
  9620. Use `ps' to determine whether you have another `mysqld' server running.
  9621. If so, shut down the server before starting `mysqld' again.  (If
  9622. another server is running, and you really want to run multiple servers,
  9623. you can find information about how to do so in *Note Multiple
  9624. servers::.)
  9625.  
  9626. If no other server is running, try to execute the command `telnet
  9627. your-host-name tcp-ip-port-number'.  (The default MySQL port number is
  9628. 3306.) Then press Enter a couple of times.  If you don't get an error
  9629. message like `telnet: Unable to connect to remote host: Connection
  9630. refused', some other program is using the TCP/IP port that `mysqld' is
  9631. trying to use.  You'll need to track down what program this is and
  9632. disable it, or else tell `mysqld' to listen to a different port with the
  9633. `--port' option.  In this case, you'll also need to specify the port
  9634. number for client programs when connecting to the server via TCP/IP.
  9635.  
  9636. Another reason the port might be inaccessible is that you have a
  9637. firewall running that blocks connections to it. If so, modify the
  9638. firewall settings to allow access to the port.
  9639.  
  9640. If the server starts but you can't connect to it, you should make sure
  9641. that you have an entry in `/etc/hosts' that looks like this:
  9642.  
  9643.      127.0.0.1       localhost
  9644.  
  9645. This problem occurs only on systems that don't have a working thread
  9646. library and for which MySQL must be configured to use MIT-pthreads.
  9647.  
  9648. If you can't get `mysqld' to start, you can try to make a trace file to
  9649. find the problem by using the `--debug' option.  *Note Making trace
  9650. files::.
  9651.  
  9652. Securing the Initial MySQL Accounts
  9653. -----------------------------------
  9654.  
  9655. Part of the MySQL installation process is to set up the `mysql' database
  9656. containing the grant tables:
  9657.  
  9658.    * Windows distributions contain preinitialized grant tables that are
  9659.      installed automatically.
  9660.  
  9661.    * On Unix, the grant tables are populated by the `mysql_install_db'
  9662.      program. Some installation methods run this program for you.
  9663.      Others require that you execute it manually. For details, see
  9664.      *Note Unix post-installation::.
  9665.  
  9666. The grant tables define the initial MySQL user accounts and their access
  9667. privileges.  These accounts are set up as follows:
  9668.  
  9669.    * Two accounts are created with a username of `root'.  These are
  9670.      superuser accounts that can do anything.  The initial `root'
  9671.      account passwords are empty, so anyone can connect to the MySQL
  9672.      server as `root' _without a password_ and be granted all
  9673.      privileges.
  9674.  
  9675.         * On Windows, one `root' account is for connecting from the
  9676.           local host and the other allows connections from any host.
  9677.  
  9678.         * On Unix, both `root' accounts are for connections from the
  9679.           local host.  Connections must be made from the local host by
  9680.           specifying a hostname of `localhost' for one account, or the
  9681.           actual hostname or IP number for the other.
  9682.  
  9683.  
  9684.    * Two anonymous-user accounts are created, each with an empty
  9685.      username.  The anonymous accounts have no passwords, so anyone can
  9686.      use them to connect to the MySQL server.
  9687.  
  9688.         * On Windows, one anonymous account is for connections from the
  9689.           local host.  It has all privileges, just like the `root'
  9690.           accounts.  The other is for connections from any host and has
  9691.           all privileges for the `test' database or other databases
  9692.           with names that start with `test'.
  9693.  
  9694.         * On Unix, both anonymous accounts are for connections from the
  9695.           local host.  Connections must be made from the local host by
  9696.           specifying a hostname of `localhost' for one account, or the
  9697.           actual hostname or IP number for the other.  These accounts
  9698.           have all privileges for the `test' database or other
  9699.           databases with names that start with `test_'.
  9700.  
  9701.  
  9702.  
  9703. As noted, none of the initial accounts have passwords.  This means that
  9704. your MySQL installation is unprotected until you do something about it:
  9705.  
  9706.    * If you want to prevent clients from connecting as anonymous users
  9707.      without a password, you should either assign passwords to the
  9708.      anonymous accounts or else remove them.
  9709.  
  9710.    * You should assign passwords to the MySQL `root' accounts.
  9711.  
  9712.  
  9713. The following instructions describe how to set up passwords for the
  9714. initial MySQL accounts, first for the anonymous accounts and then for
  9715. the `root' accounts.  Replace "NEWPWD" in the examples with the actual
  9716. password that you want to use.  The instructions also cover how to
  9717. remove the anonymous accounts, should you prefer not to allow anonymous
  9718. access at all.
  9719.  
  9720. You might want to defer setting the passwords until later, so that you
  9721. don't need to specify them while you perform additional setup or
  9722. testing.  However, be sure to set them before using your installation
  9723. for any real production work.
  9724.  
  9725. To assign passwords to the anonymous accounts, you can use either `SET
  9726. PASSWORD' or `UPDATE'.  In both cases, be sure to encrypt the password
  9727. using the `PASSWORD()' function.
  9728.  
  9729. To use `SET PASSWORD' on Windows, do this:
  9730.  
  9731.      shell> mysql -u root
  9732.      mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('NEWPWD');
  9733.      mysql> SET PASSWORD FOR ''@'%' = PASSWORD('NEWPWD');
  9734.  
  9735. To use `SET PASSWORD' on Unix, do this:
  9736.  
  9737.      shell> mysql -u root
  9738.      mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('NEWPWD');
  9739.      mysql> SET PASSWORD FOR ''@'HOST_NAME' = PASSWORD('NEWPWD');
  9740.  
  9741. In the second `SET PASSWORD' statement, replace HOST_NAME with the name
  9742. of the server host.  This is the name that is specified in the `Host'
  9743. column of the non-`localhost' record for `root' in the `user' table.
  9744. If you don't know what hostname this is, issue the following statement
  9745. before using `SET PASSWORD':
  9746.  
  9747.      mysql> SELECT Host, User FROM mysql.user;
  9748.  
  9749. Look for the record that has `root' in the `User' column and something
  9750. other than `localhost' in the `Host' column. Then use that `Host' value
  9751. in the second `SET PASSWORD' statement.
  9752.  
  9753. The other way to assign passwords to the anonymous accounts is by using
  9754. `UPDATE' to modify the `user' table directly.  Connect to the server as
  9755. `root' and issue an `UPDATE' statement that assigns a value to the
  9756. `Password' column of the appropriate `user' table records.  The
  9757. procedure is the same for Windows and Unix.  The following `UPDATE'
  9758. statement assigns a password to both anonymous accounts at once:
  9759.  
  9760.      shell> mysql -u root
  9761.      mysql> UPDATE mysql.user SET Password = PASSWORD('NEWPWD')
  9762.          ->     WHERE User = '';
  9763.      mysql> FLUSH PRIVILEGES;
  9764.  
  9765. After you update the passwords in the `user' table directly using
  9766. `UPDATE', you must tell the server to re-read the grant tables with
  9767. `FLUSH PRIVILEGES'. Otherwise, the change will go unnoticed until you
  9768. restart the server.
  9769.  
  9770. If you prefer to remove the anonymous accounts instead, do so as
  9771. follows:
  9772.  
  9773.      shell> mysql -u root
  9774.      mysql> DELETE FROM mysql.user WHERE User = '';
  9775.      mysql> FLUSH PRIVILEGES;
  9776.  
  9777. The `DELETE' statement applies both to Windows and to Unix.  On
  9778. Windows, if you want to remove only the anonymous account that has the
  9779. same privileges as `root', do this instead:
  9780.  
  9781.      shell> mysql -u root
  9782.      mysql> DELETE FROM mysql.user WHERE Host='localhost' AND User='';
  9783.      mysql> FLUSH PRIVILEGES;
  9784.  
  9785. This account allows anonymous access but has full privileges, so
  9786. removing it improves security.
  9787.  
  9788. You can assign passwords to the `root' accounts in several ways. The
  9789. following discussion demonstrates three methods:
  9790.  
  9791.    * Use the `SET PASSWORD' statement
  9792.  
  9793.    * Use the `mysqladmin' command-line client program
  9794.  
  9795.    * Use the `UPDATE' statement
  9796.  
  9797. To assign passwords using `SET PASSWORD', connect to the server as
  9798. `root' and issue two `SET PASSWORD' statements.  Be sure to encrypt the
  9799. password using the `PASSWORD()' function.
  9800.  
  9801. For Windows, do this:
  9802.  
  9803.      shell> mysql -u root
  9804.      mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NEWPWD');
  9805.      mysql> SET PASSWORD FOR 'root'@'%' = PASSWORD('NEWPWD');
  9806.  
  9807. For Unix, do this:
  9808.  
  9809.      shell> mysql -u root
  9810.      mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NEWPWD');
  9811.      mysql> SET PASSWORD FOR 'root'@'HOST_NAME' = PASSWORD('NEWPWD');
  9812.  
  9813. In the second `SET PASSWORD' statement, replace HOST_NAME with the name
  9814. of the server host.  This is the same hostname that you used when you
  9815. assigned the anonymous account passwords.
  9816.  
  9817. To assign passwords to the `root' accounts using `mysqladmin', execute
  9818. the following commands:
  9819.  
  9820.      shell> mysqladmin -u root password "NEWPWD"
  9821.      shell> mysqladmin -u root -h HOST_NAME password "NEWPWD"
  9822.  
  9823. These commands apply both to Windows and to Unix.  In the second
  9824. command, replace HOST_NAME with the name of the server host.  The double
  9825. quotes around the password are not always necessary, but you should use
  9826. them if the password contains spaces or other characters that are
  9827. special to your command interpreter.
  9828.  
  9829. If you are using a server from a _very_ old version of MySQL, the
  9830. `mysqladmin' commands to set the password will fail with the message
  9831. `parse error near 'SET password''.  The solution to this problem is to
  9832. upgrade the server to a newer version of MySQL.
  9833.  
  9834. You can also use `UPDATE' to modify the `user' table directly.  The
  9835. following `UPDATE' statement assigns a password to both `root' accounts
  9836. at once:
  9837.  
  9838.      shell> mysql -u root
  9839.      mysql> UPDATE mysql.user SET Password = PASSWORD('NEWPWD')
  9840.          ->     WHERE User = 'root';
  9841.      mysql> FLUSH PRIVILEGES;
  9842.  
  9843. The `UPDATE' statement applies both to Windows and to Unix.
  9844.  
  9845. After the passwords have been set, you must supply the appropriate
  9846. password whenever you connect to the server.  For example, if you want
  9847. to use `mysqladmin' to shut down the server, you can do so using this
  9848. command:
  9849.  
  9850.      shell> mysqladmin -u root -p shutdown
  9851.      Enter password: (enter root password here)
  9852.  
  9853. *Note*: If you forget your `root' password after setting it up, the
  9854. procedure for resetting it is covered in *Note Resetting permissions::.
  9855.  
  9856. To set up new accounts, you can use the `GRANT' statement. For
  9857. instructions, see *Note Adding users::.
  9858.  
  9859. Upgrading/Downgrading MySQL
  9860. ===========================
  9861.  
  9862. As a general rule, we recommend that when upgrading from one release
  9863. series to another, you should go to the next series rather than
  9864. skipping a series. For example, if you currently are running MySQL 3.23
  9865. and wish to upgrade to a newer series, upgrade to MySQL 4.0 rather than
  9866. to 4.1 or 5.0.
  9867.  
  9868. The following items form a checklist of things you should do whenever
  9869. you perform an upgrade:
  9870.  
  9871.    * Read the change log for the release series to which you are
  9872.      upgrading to see what new features you can use. For example,
  9873.      before upgrading from MySQL 4.1 to 5.0, read the 5.0 news items.
  9874.      *Note News::.
  9875.  
  9876.    * Before you do an upgrade, back up your databases.
  9877.  
  9878.    * If you are running MySQL Server on Windows, see *Note Windows
  9879.      upgrading::.
  9880.  
  9881.    * An upgrade may involve changes to the grant tables that are stored
  9882.      in the `mysql' database.) Occasionally new columns or tables are
  9883.      added to support new features.  To take advantage of these
  9884.      features, be sure that your grant tables are up to date.  The
  9885.      upgrade procedure is described in *Note Upgrading-grant-tables::.
  9886.  
  9887.    * If you are using replication, see *Note Replication Upgrade:: for
  9888.      information on upgrading your replication setup.
  9889.  
  9890.    * If you install a MySQL-Max distribution that includes a server
  9891.      named `mysqld-max', then upgrade later to a non-Max version of
  9892.      MySQL, `mysqld_safe' will still attempt to run the old `mysqld-max'
  9893.      server.  If you perform such an upgrade, you should manually
  9894.      remove the old `mysqld-max' server to ensure that `mysqld_safe'
  9895.      runs the new `mysqld' server.
  9896.  
  9897.  
  9898. You can always move the MySQL format files and data files between
  9899. different versions on the same architecture as long as you stay within
  9900. versions for the same release series of MySQL. The current production
  9901. release series is 4.0. If you change the character set when running
  9902. MySQL, you must run `myisamchk -r -q --set-character-set=CHARSET' on
  9903. all `MyISAM' tables.  Otherwise, your indexes may not be ordered
  9904. correctly, because changing the character set may also change the sort
  9905. order.
  9906.  
  9907. If you upgrade or downgrade from one release series to another, there
  9908. may be incompatibilities in table storage formats. In this case, you
  9909. can use `mysqldump' to dump your tables before upgrading. After
  9910. upgrading, reload the dump file using `mysql' to re-create your tables.
  9911.  
  9912. If you are cautious about using new versions, you can always rename
  9913. your old `mysqld' before installing a newer one. For example, if you
  9914. are using MySQL 4.0.18 and want to upgrade to 4.1.1, rename your
  9915. current server from `mysqld' to `mysqld-4.0.18'.  If your new `mysqld'
  9916. then does something unexpected, you can simply shut it down and restart
  9917. with your old `mysqld'.
  9918.  
  9919. If, after an upgrade, you experience problems with recompiled client
  9920. programs, such as `Commands out of sync' or unexpected core dumps, you
  9921. probably have used old header or library files when compiling your
  9922. programs.  In this case, you should check the date for your `mysql.h'
  9923. file and `libmysqlclient.a' library to verify that they are from the new
  9924. MySQL distribution.  If not, recompile your programs with the new
  9925. headers and libraries.
  9926.  
  9927. If problems occur, such as that the new `mysqld' server doesn't want to
  9928. start or that you can't connect without a password, verify that you
  9929. don't have some old `my.cnf' file from your previous installation.  You
  9930. can check this with the `--print-defaults' option (for example, `mysqld
  9931. --print-defaults').  If this displays anything other than the program
  9932. name, you have an active `my.cnf' file that affects server or client
  9933. operation.
  9934.  
  9935. It is a good idea to rebuild and reinstall the Perl `DBD::mysql' module
  9936. whenever you install a new release of MySQL. The same applies to other
  9937. MySQL interfaces as well, such as the Python `MySQLdb' module.
  9938.  
  9939. Upgrading from Version 4.1 to 5.0
  9940. ---------------------------------
  9941.  
  9942. In general, you should do the following when upgrading to MySQL 5.0
  9943. from 4.1:
  9944.  
  9945.    * Read the 5.0 news items to see what significant new features you
  9946.      can use in 5.0.  *Note News-5.0.x::.
  9947.  
  9948.    * If you are running MySQL Server on Windows, see *Note Windows
  9949.      upgrading::.
  9950.  
  9951.    * MySQL 5.0 adds support for stored procedures. This support
  9952.      requires the `proc' table in the `mysql' database.  To create this
  9953.      file, you should run the `mysql_fix_privilege_tables' script as
  9954.      described in *Note Upgrading-grant-tables::.
  9955.  
  9956.    * If you are using replication, see *Note Replication Upgrade:: for
  9957.      information on upgrading your replication setup.
  9958.  
  9959.  
  9960. Upgrading from Version 4.0 to 4.1
  9961. ---------------------------------
  9962.  
  9963. In general, you should do the following when upgrading to MySQL 4.1
  9964. from 4.0:
  9965.  
  9966.    * Check the items in the change lists found later in this section to
  9967.      see whether any of them might affect your applications.
  9968.  
  9969.    * Read the 4.1 news items to see what significant new features you
  9970.      can use in 4.1.  *Note News-4.1.x::.
  9971.  
  9972.    * If you are running MySQL Server on Windows, see *Note Windows
  9973.      upgrading::.
  9974.  
  9975.      *Important note:* Early alpha Windows distributions for MySQL 4.1
  9976.      do not contain an installer program.  See *Note Windows binary
  9977.      installation:: for instructions on how to install such a
  9978.      distribution.
  9979.  
  9980.    * After upgrading, update the grant tables to have the new longer
  9981.      `Password' column that is needed for secure handling of passwords.
  9982.      The procedure uses `mysql_fix_privilege_tables' and is described
  9983.      in *Note Upgrading-grant-tables::.  Implications of the
  9984.      password-handling change for applications are given later in this
  9985.      section.  If you don't do this, MySQL will not us the new more
  9986.      secure protocol to authenticate.
  9987.  
  9988.    * If you are using replication, see *Note Replication Upgrade:: for
  9989.      information on upgrading your replication setup.
  9990.  
  9991.    * The Berkeley DB table handler is updated to DB 4.1 (from 3.2)
  9992.      which has a new log format. If you have to downgrade back to 4.0
  9993.      you must use `mysqldump' to dump your `BDB' tables in text format
  9994.      and delete all `log.XXXXXXXXXX' files before you start MySQL 4.0
  9995.      and reload the data.
  9996.  
  9997.    * Character set support has been improved.  If you have table
  9998.      columns that store character data represented in a character set
  9999.      that the 4.1 server now supports directly, you can convert the
  10000.      columns to the proper character set using the instructions in
  10001.      *Note Charset-conversion::.  Also, database, table, and column
  10002.      identifiers now are stored internally using Unicode (UTF8)
  10003.      regardless of the default character set.  *Note Legal names::.
  10004.  
  10005.    * Starting from MySQL 4.1.3, `InnoDB' uses the same character set
  10006.      comparison functions as MySQL for non-`latin1_swedish_ci'
  10007.      character strings that are not `BINARY'.  This changes the sorting
  10008.      order of space and characters with a code < ASCII(32) in those
  10009.      character sets.  For `latin1_swedish_ci' character strings and
  10010.      `BINARY' strings, `InnoDB' uses its own pad-spaces-at-end
  10011.      comparison method, which stays unchanged.  If you have an `InnoDB'
  10012.      table created with MySQL 4.1.2 or earlier, with an index on a
  10013.      non-`latin1' character set (in the case of 4.1.0 and 4.1.1 with
  10014.      any character set) `CHAR'/`VARCHAR'/or `TEXT' column that is not
  10015.      `BINARY' but may contain characters with a code < ASCII(32), then
  10016.      you should do `ALTER TABLE' or `OPTIMIZE' table on it to
  10017.      *regenerate the index, after upgrading to MySQL 4.1.3 or later*.
  10018.  
  10019.    * MySQL 4.1.3 introduces support for per-connection time zones.
  10020.      *Note Time zone support::. To enable recognition of named time
  10021.      zones, you should create the time zone tables in the `mysql'
  10022.      database.  For instructions, see *Note Post-installation::.
  10023.  
  10024.    * `mysql_shutdown()' has starting from 4.1.3 an extra parameter:
  10025.      `SHUTDOWN'-level. You should convert any `mysql_shutdown(X)' call
  10026.      you have in your application to
  10027.      `mysql_shutdown(X,SHUTDOWN_DEFAULT)'.
  10028.  
  10029.    * If you are using an old `DBD-mysql' module (`Msql-MySQL-modules')
  10030.      you have to upgrade to use the newer `DBD-mysql' module. Anything
  10031.      above `DBD-mysql' 2.xx should be fine.
  10032.  
  10033.      If you don't upgrade, some methods (such as `DBI->do()') will not
  10034.      notice error conditions correctly.
  10035.  
  10036.    * Option `--defaults-file=option-file-name' will now give an error if
  10037.      the option file doesn't exists.
  10038.  
  10039.    * Some notes about upgrading from MySQL 4.0 to MySQL 4.1 on Netware:
  10040.      Make sure to upgrade Perl and PHP versions. Download and install
  10041.      Perl module for MySQL 4.1 from
  10042.      `http://forge.novell.com/modules/xfmod/project/showfiles.php?group_id=1126'
  10043.      and PHP Extension for MySQL 4.1 from
  10044.      `http://forge.novell.com/modules/xfmod/project/showfiles.php?group_id=1078'.
  10045.  
  10046.  
  10047. Several visible behaviors have changed between MySQL 4.0 and MySQL 4.1
  10048. to fix some critical bugs and make MySQL more compatible with standard
  10049. SQL.  These changes may affect your applications.
  10050.  
  10051. Some of the 4.1 behaviors can be tested in 4.0 before performing a full
  10052. upgrade to 4.1. We have added to later MySQL 4.0 releases (from 4.0.12
  10053. on) a `--new' startup option for `mysqld'.  *Note Server options::.
  10054.  
  10055. This option gives you the 4.1 behavior for the most critical changes.
  10056. You can also enable these behaviors for a given client connection with
  10057. the `SET @@new=1' command, or turn them off if they are on with `SET
  10058. @@new=0'.
  10059.  
  10060. If you believe that some of the 4.1 changes will affect you, we
  10061. recommend that before upgrading to 4.1, you download the latest MySQL
  10062. 4.0 version and run it with the `--new' option by adding the following
  10063. to your config file:
  10064.  
  10065.      [mysqld-4.0]
  10066.      new
  10067.  
  10068. That way you can test the new behaviors in 4.0 to make sure that your
  10069. applications work with them. This will help you have a smooth, painless
  10070. transition when you perform a full upgrade to 4.1 later. Putting the
  10071. `--new' option in the `[mysqld-4.0]' option group ensures that you
  10072. don't accidentally later run the 4.1 version with the `--new' option.
  10073.  
  10074. The following lists describe changes that may affect applications and
  10075. that you should watch out for when upgrading to version 4.1:
  10076.  
  10077. *Server Changes:*
  10078.  
  10079.    * All tables and string columns now have a character set.  *Note
  10080.      Charset::.  Character set information is displayed by `SHOW CREATE
  10081.      TABLE' and `mysqldump'.  (MySQL versions 4.0.6 and above can read
  10082.      the new dump files; older versions cannot.)  This change should
  10083.      not affect applications that use only one character set.
  10084.  
  10085.    * MySQL now interprets length specifications in character column
  10086.      definitions in characters. (Earlier versions interpret them in
  10087.      bytes.)  For example, `CHAR(N)' now means N characters, not N
  10088.      bytes.
  10089.  
  10090.    * The table definition format used in `.frm' files has changed
  10091.      slightly in 4.1.  MySQL 4.0 versions from 4.0.11 on can read the
  10092.      new `.frm' format directly, but older versions cannot.  If you
  10093.      need to move tables from 4.1 to a version earlier than 4.0.11, you
  10094.      should use `mysqldump'.  *Note `mysqldump': mysqldump.
  10095.  
  10096.    * *Important note:* If you upgrade to MySQL 4.1.1 or higher, it is
  10097.      difficult to downgrade back to 4.0 or 4.1.0! That is because, for
  10098.      earlier versions, `InnoDB' is not aware of multiple tablespaces.
  10099.  
  10100.    * If you are running multiple servers on the same Windows machine,
  10101.      you should use a different `--shared-memory-base-name' option for
  10102.      each server.
  10103.  
  10104.    * The interface to aggregated UDF functions has changed a bit. You
  10105.      must now declare a `xxx_clear()' function for each aggregate
  10106.      function `XXX()'.
  10107.  
  10108.  
  10109. *Client Changes:*
  10110.  
  10111.    * `mysqldump' now has the `--opt' and `--quote-names' options
  10112.      enabled by default. You can turn them off with `--skip-opt' and
  10113.      `--skip-quote-names'.
  10114.  
  10115.  
  10116. *SQL Changes:*
  10117.  
  10118.    * String comparison now works according to SQL standard: Instead of
  10119.      stripping end spaces before comparison, we now extend the shorter
  10120.      string with spaces.  The problem with this is that now `'a' >
  10121.      'a\t'', which it wasn't before.  If you have any tables where you
  10122.      have a `CHAR' or `VARCHAR' column in which the last character in
  10123.      the column may be less than `ASCII(32)', you should use `REPAIR
  10124.      TABLE' or `myisamchk' to ensure that the table is correct.
  10125.  
  10126.    * When using multiple-table `DELETE' statements, you should use the
  10127.      alias of the tables from which you want to delete, not the actual
  10128.      table name.  For example, instead of doing this:
  10129.  
  10130.           DELETE test FROM test AS t1, test2 WHERE ...
  10131.  
  10132.      Do this:
  10133.  
  10134.           DELETE t1 FROM test AS t1, test2 WHERE ...
  10135.  
  10136.    * `TIMESTAMP' is now returned as a string in `'YYYY-MM-DD HH:MM:SS''
  10137.      format (from 4.0.12 the `--new' option can be used to make a 4.0
  10138.      server behave as 4.1 in this respect).  *Note `TIMESTAMP' 4.1:
  10139.      TIMESTAMP 4.1.
  10140.  
  10141.      If you want to have the value returned as a number (as MySQL 4.0
  10142.      does) you should add `+0' to `TIMESTAMP' columns when you retrieve
  10143.      them:
  10144.  
  10145.           mysql> SELECT ts_col + 0 FROM TBL_NAME;
  10146.  
  10147.      Display widths for `TIMESTAMP' columns are no longer supported.
  10148.      For example, if you declare a column as `TIMESTAMP(10)', the `(10)'
  10149.      is ignored.
  10150.  
  10151.      These changes were necessary for SQL standards compliance. In a
  10152.      future version, a further change will be made (backward compatible
  10153.      with this change), allowing the timestamp length to indicate the
  10154.      desired number of digits for fractions of a second.
  10155.  
  10156.    * Binary values such as `0xFFDF' now are assumed to be strings
  10157.      instead of numbers.  This fixes some problems with character sets
  10158.      where it's convenient to input a string as a binary value.  With
  10159.      this change, you should use `CAST()' if you want to compare binary
  10160.      values numerically as integers:
  10161.  
  10162.           mysql> SELECT CAST(0xFEFF AS UNSIGNED INTEGER)
  10163.               ->        < CAST(0xFF AS UNSIGNED INTEGER);
  10164.                   -> 0
  10165.  
  10166.      If you don't use `CAST()', a lexical string comparison will be
  10167.      done:
  10168.  
  10169.           mysql> SELECT 0xFEFF < 0xFF;
  10170.                   -> 1
  10171.  
  10172.      Using binary items in a numeric context or comparing them using the
  10173.      `=' operator should work as before.  (The `--new' option can be
  10174.      used from 4.0.13 on to make a 4.0 server behave as 4.1 in this
  10175.      respect.)
  10176.  
  10177.    * For functions that produce a `DATE', `DATETIME', or `TIME' value,
  10178.      the result returned to the client now is fixed up to have a
  10179.      temporal type. For example, in MySQL 4.1, you get this result:
  10180.  
  10181.           mysql> SELECT CAST('2001-1-1' AS DATETIME);
  10182.                  -> '2001-01-01 00:00:00'
  10183.  
  10184.      In MySQL 4.0, the result is different:
  10185.  
  10186.           mysql> SELECT CAST('2001-1-1' AS DATETIME);
  10187.                  -> '2001-01-01'
  10188.  
  10189.    * `DEFAULT' values no longer can be specified for `AUTO_INCREMENT'
  10190.      columns. (In 4.0, a `DEFAULT' value is silently ignored; in 4.1,
  10191.      an error occurs.)
  10192.  
  10193.    * `LIMIT' no longer accepts negative arguments.  Use some large
  10194.      number (maximum 18446744073709551615) instead of -1.
  10195.  
  10196.    * `SERIALIZE' is no longer a valid mode value for the `sql_mode'
  10197.      variable.  You should use `SET TRANSACTION ISOLATION LEVEL
  10198.      SERIALIZABLE' instead. `SERIALIZE' is no longer valid for the
  10199.      `--sql-mode' option for `mysqld', either. Use
  10200.      `--transaction-isolation=SERIALIZABLE' instead.
  10201.  
  10202.  
  10203. *C API Changes:*
  10204.  
  10205.    * Some C API calls such as `mysql_real_query()' now return `1' on
  10206.      error, not `-1'.  You may have to change some old applications if
  10207.      they use constructs like this:
  10208.  
  10209.           if (mysql_real_query(mysql_object, query, query_length) == -1)
  10210.           {
  10211.             printf("Got error");
  10212.           }
  10213.  
  10214.      Change the call to test for a non-zero value instead:
  10215.  
  10216.           if (mysql_real_query(mysql_object, query, query_length) != 0)
  10217.           {
  10218.             printf("Got error");
  10219.           }
  10220.  
  10221.  
  10222. *Password-Handling Changes:*
  10223.  
  10224. The password hashing mechanism has changed in 4.1 to provide better
  10225. security, but this may cause compatibility problems if you still have
  10226. clients that use the client library from 4.0 or earlier.  (It is very
  10227. likely that you will have 4.0 clients in situations where clients
  10228. connect from remote hosts that have not yet upgraded to 4.1.)  The
  10229. following list indicates some possible upgrade strategies.  They
  10230. represent various tradeoffs between the goal of compatibility with old
  10231. clients and the goal of security.
  10232.  
  10233.    * Only upgrade the client to use 4.1 client libraries (not the
  10234.      server). No behavior will change (except the return value of some
  10235.      API calls), but you cannot use any of the new features provided by
  10236.      the 4.1 client/server protocol, either.  (MySQL 4.1 has an
  10237.      extended client/server protocol that offers such features as
  10238.      prepared statements and multiple result sets.)  *Note C API
  10239.      Prepared statements::.
  10240.  
  10241.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  10242.      widen the `Password' column in the `user' table so that it can
  10243.      hold long password hashes.  But run the server with the
  10244.      `--old-passwords' option to provide backward compatibility that
  10245.      allows pre-4.1 clients to continue to connect to their short-hash
  10246.      accounts.  Eventually, when all your clients are upgraded to 4.1,
  10247.      you can stop using the `--old-passwords' server option. You can
  10248.      also change the passwords for your MySQL accounts to use the new
  10249.      more secure format.
  10250.  
  10251.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  10252.      widen the `Password' column in the `user' table.  If you know that
  10253.      all clients also have been upgraded to 4.1, don't run the server
  10254.      with the `--old-passwords' option.  Instead, change the passwords
  10255.      on all existing accounts so that they have the new format.  A
  10256.      pure-4.1 installation is the most secure.
  10257.  
  10258.    * Some notes about upgrading from MySQL 4.0 to MySQL 4.1 on Netware:
  10259.      Make sure to upgrade Perl and PHP versions. Download Perl 5 for
  10260.      Netware from http://forge.novell.com/modules/xfmod/project/?perl5)
  10261.      and PHP from http://forge.novell.com/modules/xfmod/project/?php.
  10262.  
  10263.  
  10264. Further background on password hashing with respect to client
  10265. authentication and password-changing operations may be found in *Note
  10266. Password hashing:: and *Note Old client::.
  10267.  
  10268. Upgrading from Version 3.23 to 4.0
  10269. ----------------------------------
  10270.  
  10271. In general, you should do the following when upgrading to MySQL 4.0
  10272. from 3.23:
  10273.  
  10274.    * Check the items in the change lists found later in this section to
  10275.      see whether any of them might affect your applications.
  10276.  
  10277.    * Read the 4.0 news items to see what significant new features you
  10278.      can use in 4.0.  *Note News-4.0.x::.
  10279.  
  10280.    * If you are running MySQL Server on Windows, see *Note Windows
  10281.      upgrading::.
  10282.  
  10283.    * After upgrading, update the grant tables to add new privileges and
  10284.      features.  The procedure uses the `mysql_fix_privilege_tables'
  10285.      script and is described in *Note Upgrading-grant-tables::.
  10286.  
  10287.    * If you are using replication, see *Note Replication Upgrade:: for
  10288.      information on upgrading your replication setup.
  10289.  
  10290.    * Edit any MySQL startup scripts or option files to not use any of
  10291.      the deprecated options described later in this section.
  10292.  
  10293.    * Convert your old `ISAM' files to `MyISAM' files. One way to do this
  10294.      is with the `mysql_convert_table_format' script. (This is a Perl
  10295.      script; it requires that DBI be installed.) To convert the tables
  10296.      in a given database, use this command:
  10297.  
  10298.           shell> mysql_convert_table_format database DB_NAME
  10299.  
  10300.      Note that this should be used only if all tables in the given
  10301.      database are `ISAM' or `MyISAM' tables. To avoid converting tables
  10302.      of other types to `MyISAM', you can explicitly list the names of
  10303.      your `ISAM' tables after the database name on the command line.
  10304.  
  10305.      Individual tables can be changed to `MyISAM' by using the following
  10306.      `ALTER TABLE' statement for each table to be converted:
  10307.  
  10308.           mysql> ALTER TABLE TBL_NAME TYPE=MyISAM;
  10309.  
  10310.      If you are not sure of the table type for a given table, use this
  10311.      statement:
  10312.  
  10313.           mysql> SHOW TABLE STATUS LIKE 'TBL_NAME';
  10314.  
  10315.    * Ensure that you don't have any MySQL clients that use shared
  10316.      libraries (like the Perl `DBD::mysql' module). If you do, you
  10317.      should recompile them, because the data structures used in
  10318.      `libmysqlclient.so' have changed.  The same applies to other MySQL
  10319.      interfaces as well, such as the Python `MySQLdb' module.
  10320.  
  10321.  
  10322. MySQL 4.0 will work even if you don't perform the preceding actions,
  10323. but you will not be able to use the new security privileges in MySQL
  10324. 4.0 and you may run into problems when upgrading later to MySQL 4.1 or
  10325. newer.  The `ISAM' file format still works in MySQL 4.0, but is
  10326. deprecated and is not compiled in by default as of MySQL 4.1. `MyISAM'
  10327. tables should be used instead.
  10328.  
  10329. Old clients should work with a Version 4.0 server without any problems.
  10330.  
  10331. Even if you perform the preceding actions, you can still downgrade to
  10332. MySQL 3.23.52 or newer if you run into problems with the MySQL 4.0
  10333. series.  In this case, you must use `mysqldump' to dump any tables that
  10334. use full-text indexes and reload the dump file into the 3.23 server.
  10335. This is necessary because 4.0 uses a new format for full-text indexing.
  10336.  
  10337. The following lists describe changes that may affect applications and
  10338. that you should watch out for when upgrading to version 4.0:
  10339.  
  10340. *Server Changes:*
  10341.  
  10342.    * MySQL 4.0 has a lot of new privileges in the `mysql.user' table.
  10343.      *Note Privileges provided::.
  10344.  
  10345.      To get these new privileges to work, you must update the grant
  10346.      tables.  The procedure is described in *Note
  10347.      Upgrading-grant-tables::.  Until you do this, all accounts have
  10348.      the `SHOW DATABASES', `CREATE TEMPORARY TABLES', and `LOCK TABLES'
  10349.      privileges. `SUPER' and `EXECUTE' privileges take their value from
  10350.      `PROCESS'.  `REPLICATION SLAVE' and `REPLICATION CLIENT' take their
  10351.      values from `FILE'.
  10352.  
  10353.      If you have any scripts that create new MySQL user accounts, you
  10354.      may want to change them to use the new privileges.  If you are not
  10355.      using `GRANT' commands in the scripts, this is a good time to
  10356.      change your scripts to use `GRANT' instead of modifying the grant
  10357.      tables directly.
  10358.  
  10359.      From version 4.0.2 on, the option `--safe-show-database' is
  10360.      deprecated (and no longer does anything). *Note Privileges
  10361.      options::.
  10362.  
  10363.      If you get `Access denied' errors for new users in version 4.0.2
  10364.      and up, you should check whether you need some of the new grants
  10365.      that you didn't need before.  In particular, you will need
  10366.      `REPLICATION SLAVE' (instead of `FILE') for new slave servers.
  10367.  
  10368.    * `safe_mysqld' has been renamed to `mysqld_safe'.  For backward
  10369.      compatibility, binary distributions will for some time include
  10370.      `safe_mysqld' as a symlink to `mysqld_safe'.
  10371.  
  10372.    * `InnoDB' support is now included by default in binary
  10373.      distributions.  If you build MySQL from source, `InnoDB' is
  10374.      configured in by default.  If you do not use `InnoDB' and want to
  10375.      save memory when running a server that has `InnoDB' support
  10376.      enabled, use the `--skip-innodb' server startup option. To compile
  10377.      MySQL without `InnoDB' support, run `configure' with the
  10378.      `--without-innodb' option.
  10379.  
  10380.    * Values for the startup parameters
  10381.      `myisam_max_extra_sort_file_size' and
  10382.      `myisam_max_extra_sort_file_size' now are given in bytes (they
  10383.      were given in megabytes before 4.0.3).
  10384.  
  10385.    * `mysqld' now has the option `--temp-pool' enabled by default
  10386.      because this gives better performance with some operating systems
  10387.      (most notably Linux).
  10388.  
  10389.    * The `mysqld' startup options `--skip-locking' and
  10390.      `--enable-locking' were renamed to `--skip-external-locking' and
  10391.      `--external-locking'.
  10392.  
  10393.    * External system locking of `MyISAM'/`ISAM' files is now turned off
  10394.      by default.  You can turn this on with `--external-locking'.
  10395.      (However, this is never needed for most users.)
  10396.  
  10397.    * The following startup variables and options have been renamed:
  10398.  
  10399.      *Old Name*                         *New Name*
  10400.      `myisam_bulk_insert_tree_size'     `bulk_insert_buffer_size'
  10401.      `query_cache_startup_type'         `query_cache_type'
  10402.      `record_buffer'                    `read_buffer_size'
  10403.      `record_rnd_buffer'                `read_rnd_buffer_size'
  10404.      `sort_buffer'                      `sort_buffer_size'
  10405.      `warnings'                         `log-warnings'
  10406.      `--err-log'                        `--log-error' (for `mysqld_safe')
  10407.  
  10408.      The startup options `record_buffer', `sort_buffer', and `warnings'
  10409.      will still work in MySQL 4.0 but are deprecated.
  10410.  
  10411. *SQL Changes:*
  10412.  
  10413.    * The following SQL variables have been renamed:
  10414.  
  10415.      *Old Name*                         *New Name*
  10416.      `SQL_BIG_TABLES'                   `BIG_TABLES'
  10417.      `SQL_LOW_PRIORITY_UPDATES'         `LOW_PRIORITY_UPDATES'
  10418.      `SQL_MAX_JOIN_SIZE'                `MAX_JOIN_SIZE'
  10419.      `SQL_QUERY_CACHE_TYPE'             `QUERY_CACHE_TYPE'
  10420.      The old names still work in MySQL 4.0 but are deprecated.
  10421.  
  10422.    * You have to use `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=skip_count'
  10423.      instead of `SET SQL_SLAVE_SKIP_COUNTER=skip_count'.
  10424.  
  10425.    * `SHOW MASTER STATUS' now returns an empty set if binary logging is
  10426.      not enabled.
  10427.  
  10428.    * `SHOW SLAVE STATUS' now returns an empty set if the slave is not
  10429.      initialized.
  10430.  
  10431.    * `SHOW INDEX' has two more columns than it had in 3.23 (`Null' and
  10432.      `Index_type').
  10433.  
  10434.    * The format of `SHOW OPEN TABLES' has changed.
  10435.  
  10436.    * `ORDER BY col_name DESC' sorts `NULL' values last, as of MySQL
  10437.      4.0.11. In 3.23 and in earlier 4.0 versions, this was not always
  10438.      consistent.
  10439.  
  10440.    * `CHECK', `LOCALTIME', and `LOCALTIMESTAMP' now are reserved words.
  10441.  
  10442.    * `DOUBLE' and `FLOAT' columns now honor the `UNSIGNED' flag on
  10443.      storage (before, `UNSIGNED' was ignored for these columns).
  10444.  
  10445.    * The result of all bitwise operators (`|', `&', `<<', `>>', and
  10446.      `~') is now unsigned.  This may cause problems if you are using
  10447.      them in a context where you want a signed result.  *Note Cast
  10448.      Functions::.
  10449.  
  10450.      *Note*: When you use subtraction between integer values where one
  10451.      is of type `UNSIGNED', the result will be unsigned.  In other
  10452.      words, before upgrading to MySQL 4.0, you should check your
  10453.      application for cases in which you are subtracting a value from an
  10454.      unsigned entity and want a negative answer or subtracting an
  10455.      unsigned value from an integer column. You can disable this
  10456.      behavior by using the `--sql-mode=NO_UNSIGNED_SUBTRACTION' option
  10457.      when starting `mysqld'.  *Note Server SQL mode::.
  10458.  
  10459.    * You should use integers to store values in `BIGINT' columns
  10460.      (instead of using strings, as you did in MySQL 3.23).  Using
  10461.      strings will still work, but using integers is more efficient.
  10462.  
  10463.    * In MySQL 3.23, `INSERT INTO ... SELECT' always had `IGNORE'
  10464.      enabled.  As of 4.0.1, MySQL will stop (and possibly roll back) by
  10465.      default in case of an error unless you specify `IGNORE'.
  10466.  
  10467.    * You should use `TRUNCATE TABLE' when you want to delete all rows
  10468.      from a table and you don't need to obtain a count of the number of
  10469.      rows that were deleted.  (`DELETE FROM TBL_NAME' returns a row
  10470.      count in 4.0 and doesn't reset the `AUTO_INCREMENT' counter, and
  10471.      `TRUNCATE TABLE' is faster.)
  10472.  
  10473.    * You will get an error if you have an active transaction or `LOCK
  10474.      TABLES' statement when trying to execute `TRUNCATE TABLE' or `DROP
  10475.      DATABASE'.
  10476.  
  10477.    * To use `MATCH ... AGAINST (... IN BOOLEAN MODE)' full-text searches
  10478.      with your tables, you must rebuild their indexes with `REPAIR TABLE
  10479.      tbl_name USE_FRM'.  If you attempt a boolean full-text search
  10480.      without rebuilding the indexes this way, the search will return
  10481.      incorrect results.  *Note Fulltext Fine-tuning::.
  10482.  
  10483.    * `LOCATE()' and `INSTR()' are case sensitive if one of the
  10484.      arguments is a binary string. Otherwise they are case insensitive.
  10485.  
  10486.    * `STRCMP()' now uses the current character set when performing
  10487.      comparisons.  This makes the default comparison behavior not case
  10488.      sensitive unless one or both of the operands are binary strings.
  10489.  
  10490.    * `HEX(STR)' now returns the characters in STR converted to
  10491.      hexadecimal.  If you want to convert a number to hexadecimal, you
  10492.      should ensure that you call `HEX()' with a numeric argument.
  10493.  
  10494.    * `RAND(seed)' returns a different random number series in 4.0 than
  10495.      in 3.23; this was done to further differentiate `RAND(seed)' and
  10496.      `RAND(seed+1)'.
  10497.  
  10498.    * The default type returned by `IFNULL(A,B)' is now set to be the
  10499.      more "general" of the types of `A' and `B'. (The
  10500.      general-to-specific order is string, `REAL', `INTEGER').
  10501.  
  10502.  
  10503. *C API Changes:*
  10504.  
  10505.    * The old C API functions `mysql_drop_db()', `mysql_create_db()', and
  10506.      `mysql_connect()' are no longer supported unless you compile MySQL
  10507.      with `CFLAGS=-DUSE_OLD_FUNCTIONS'.  However, it is preferable to
  10508.      change client programs to use the new 4.0 API instead.
  10509.  
  10510.    * In the `MYSQL_FIELD' structure, `length' and `max_length' have
  10511.      changed from `unsigned int' to `unsigned long'. This should not
  10512.      cause any problems, except that they may generate warning messages
  10513.      when used as arguments in the `printf()' class of functions.
  10514.  
  10515.    * Multi-threaded clients should use `mysql_thread_init()' and
  10516.      `mysql_thread_end()'. *Note Threaded clients::.
  10517.  
  10518.  
  10519. *Other Changes:*
  10520.  
  10521.    * If you want to recompile the Perl `DBD::mysql' module, use a recent
  10522.      version.  Version 2.9003 is recommended. Versions older than
  10523.      1.2218 should not be used because they use the deprecated
  10524.      `mysql_drop_db()' call.
  10525.  
  10526.  
  10527. Upgrading from Version 3.22 to 3.23
  10528. -----------------------------------
  10529.  
  10530. MySQL 3.22 and 3.21 clients will work without any problems with a MySQL
  10531. 3.23 server.
  10532.  
  10533. When upgrading to MySQL 3.23 from an earlier version, note the following
  10534. changes:
  10535.  
  10536. *Table Changes:*
  10537.  
  10538.    * MySQL 3.23 supports tables of the new `MyISAM' type and the old
  10539.      `ISAM' type.  By default, all new tables are created with type
  10540.      `MyISAM' unless you start `mysqld' with the
  10541.      `--default-table-type=isam' option.  You don't have to convert
  10542.      your old `ISAM' tables to use them with MySQL 3.23.  You can
  10543.      convert an `ISAM' table to `MyISAM' format with `ALTER TABLE
  10544.      TBL_NAME TYPE=MyISAM' or the Perl script
  10545.      `mysql_convert_table_format'.
  10546.  
  10547.    * All tables that use the `tis620' character set must be fixed with
  10548.      `myisamchk -r' or `REPAIR TABLE'.
  10549.  
  10550.    * If you are using the `german' character sort order for `ISAM'
  10551.      tables, you must repair them with `isamchk -r', because we have
  10552.      made some changes in the sort order.
  10553.  
  10554.  
  10555. *Client Program Changes:*
  10556.  
  10557.    * The MySQL client `mysql' is now by default started with the
  10558.      `--no-named-commands (-g)' option. This option can be disabled with
  10559.      `--enable-named-commands (-G)'. This may cause incompatibility
  10560.      problems in some cases--for example, in SQL scripts that use named
  10561.      commands without a semicolon.  Long format commands still work
  10562.      from the first line.
  10563.  
  10564.    * If you want your `mysqldump' files to be compatible between MySQL
  10565.      3.22 and 3.23, you should not use the `--opt' or `--all' option to
  10566.      `mysqldump'.
  10567.  
  10568.  
  10569. *SQL Changes:*
  10570.  
  10571.    * If you do a `DROP DATABASE' on a symbolically linked database,
  10572.      both the link and the original database are deleted.  This didn't
  10573.      happen in MySQL 3.22 because `configure' didn't detect the
  10574.      availability of the `readlink()' system call.
  10575.  
  10576.    * `OPTIMIZE TABLE' now works only for `MyISAM' tables.  For other
  10577.      table types, you can use `ALTER TABLE' to optimize the table.
  10578.      During `OPTIMIZE TABLE', the table is now locked to prevent it
  10579.      from being used by other threads.
  10580.  
  10581.    * Date functions that work on parts of dates (such as `MONTH()')
  10582.      will now return 0 for `0000-00-00' dates. In MySQL 3.22, these
  10583.      functions returned `NULL'.
  10584.  
  10585.    * The default return type of `IF()' now depends on both arguments,
  10586.      not just the first one.
  10587.  
  10588.    * `AUTO_INCREMENT' columns should not be used to store negative
  10589.      numbers. The reason for this is that negative numbers caused
  10590.      problems when wrapping from -1 to 0.  You should not store 0 in
  10591.      `AUTO_INCREMENT' columns, either; `CHECK TABLE' will complain
  10592.      about 0 values because they may change if you dump and restore the
  10593.      table.  `AUTO_INCREMENT' for `MyISAM' tables is now handled at a
  10594.      lower level and is much faster than before. In addition, for
  10595.      `MyISAM' tables, old numbers are no longer reused, even if you
  10596.      delete rows from the table.
  10597.  
  10598.    * `CASE', `DELAYED', `ELSE', `END', `FULLTEXT', `INNER', `RIGHT',
  10599.      `THEN', and `WHEN' now are reserved words.
  10600.  
  10601.    * `FLOAT(p)' now is a true floating-point type and not a value with a
  10602.      fixed number of decimals.
  10603.  
  10604.    * When declaring columns using a `DECIMAL(length,dec)' type, the
  10605.      `length' argument no longer includes a place for the sign or the
  10606.      decimal point.
  10607.  
  10608.    * A `TIME' string must now be of one of the following formats:
  10609.      `[[[DAYS] [H]H:]MM:]SS[.fraction]' or
  10610.      `[[[[[H]H]H]H]MM]SS[.fraction]'.
  10611.  
  10612.    * `LIKE' now compares strings using the same character comparison
  10613.      rules as for the `=' operator.  If you require the old behavior,
  10614.      you can compile MySQL with the `CXXFLAGS=-DLIKE_CMP_TOUPPER' flag.
  10615.  
  10616.    * `REGEXP' now is case insensitive if neither of the strings is a
  10617.      binary string.
  10618.  
  10619.    * When you check or repair `MyISAM' (`.MYI') tables, you should use
  10620.      the `CHECK TABLE' statement or the `myisamchk' command. For `ISAM'
  10621.      (`.ISM') tables, use the `isamchk' command.
  10622.  
  10623.    * Check all your calls to `DATE_FORMAT()' to make sure that there is
  10624.      a `%' before each format character.  (MySQL 3.22 already allowed
  10625.      this syntax, but now `%' is required.)
  10626.  
  10627.    * In MySQL 3.22, the output of `SELECT DISTINCT ...' was almost
  10628.      always sorted.  In MySQL 3.23, you must use `GROUP BY' or `ORDER
  10629.      BY' to obtain sorted output.
  10630.  
  10631.    * `SUM()' now returns `NULL' instead of 0 if there are no matching
  10632.      rows. This is required by standard SQL.
  10633.  
  10634.    * An `AND' or `OR' with `NULL' values will now return `NULL' instead
  10635.      of 0. This mostly affects queries that use `NOT' on an `AND/OR'
  10636.      expression as `NOT NULL' = `NULL'.
  10637.  
  10638.    * `LPAD()' and `RPAD()' now shorten the result string if it's longer
  10639.      than the length argument.
  10640.  
  10641.  
  10642. *C API Changes:*
  10643.  
  10644.    * `mysql_fetch_fields_direct()' now is a function instead of a macro.
  10645.      It now returns a pointer to a `MYSQL_FIELD' instead of a
  10646.      `MYSQL_FIELD'.
  10647.  
  10648.    * `mysql_num_fields()' no longer can be used on a `MYSQL*' object
  10649.      (it's now a function that takes a `MYSQL_RES*' value as an
  10650.      argument). With a `MYSQL*' object, you now should use
  10651.      `mysql_field_count()' instead.
  10652.  
  10653.  
  10654. Upgrading from Version 3.21 to 3.22
  10655. -----------------------------------
  10656.  
  10657. Nothing that affects compatibility has changed between versions 3.21
  10658. and 3.22.  The only pitfall is that new tables that are created with
  10659. `DATE' type columns will use the new way to store the date. You can't
  10660. access these new columns from an old version of `mysqld'.
  10661.  
  10662. When upgrading to MySQL 3.23 from an earlier version, note the following
  10663. changes:
  10664.  
  10665.    * After installing MySQL Version 3.22, you should start the new
  10666.      server and then run the `mysql_fix_privilege_tables' script. This
  10667.      will add the new privileges that you need to use the `GRANT'
  10668.      command.  If you forget this, you will get `Access denied' when
  10669.      you try to use `ALTER TABLE', `CREATE INDEX', or `DROP INDEX'. The
  10670.      procedure for updating the grant tables is described in *Note
  10671.      Upgrading-grant-tables::.
  10672.  
  10673.    * The C API interface to `mysql_real_connect()' has changed.  If you
  10674.      have an old client program that calls this function, you must pass
  10675.      a `0' for the new `db' argument (or recode the client to send the
  10676.      `db' element for faster connections).  You must also call
  10677.      `mysql_init()' before calling `mysql_real_connect()'.  This change
  10678.      was done to allow the new `mysql_options()' function to save
  10679.      options in the `MYSQL' handler structure.
  10680.  
  10681.    * The `mysqld' variable `key_buffer' has been renamed to
  10682.      `key_buffer_size', but you can still use the old name in your
  10683.      startup files.
  10684.  
  10685.  
  10686. Upgrading from Version 3.20 to 3.21
  10687. -----------------------------------
  10688.  
  10689. If you are running a version older than Version 3.20.28 and want to
  10690. switch to Version 3.21, you need to do the following:
  10691.  
  10692. You can start the `mysqld' Version 3.21 server with the
  10693. `--old-protocol' option to use it with clients from a Version 3.20
  10694. distribution.  In this case, the server uses the old pre-3.21
  10695. `password()' checking rather than the new method. Also, the new client
  10696. function `mysql_errno()' will not return any server error, only
  10697. `CR_UNKNOWN_ERROR'. The function does work for client errors.
  10698.  
  10699. If you are _not_ using the `--old-protocol' option to `mysqld', you
  10700. will need to make the following changes:
  10701.  
  10702.    * All client code must be recompiled. If you are using ODBC, you
  10703.      must get the new `MyODBC' 2.x driver.
  10704.  
  10705.    * The `scripts/add_long_password' script must be run to convert the
  10706.      `Password' field in the `mysql.user' table to `CHAR(16)'.
  10707.  
  10708.    * All passwords must be reassigned in the `mysql.user' table to get
  10709.      62-bit rather than 31-bit passwords.
  10710.  
  10711.    * The table format hasn't changed, so you don't have to convert any
  10712.      tables.
  10713.  
  10714.  
  10715. MySQL 3.20.28 and above can handle the new `user' table format without
  10716. affecting clients. If you have a MySQL version earlier than 3.20.28,
  10717. passwords will no longer work with it if you convert the `user' table.
  10718. So to be safe, you should first upgrade to at least Version 3.20.28 and
  10719. then upgrade to Version 3.21.
  10720.  
  10721. The new client code works with a 3.20.x `mysqld' server, so if you
  10722. experience problems with 3.21.x, you can use the old 3.20.x server
  10723. without having to recompile the clients again.
  10724.  
  10725. If you are not using the `--old-protocol' option to `mysqld', old
  10726. clients will be unable to connect and will issue the following error
  10727. message:
  10728.  
  10729.      ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
  10730.  
  10731. The Perl DBI interface also supports the old `mysqlperl' interface.
  10732. The only change you have to make if you use `mysqlperl' is to change
  10733. the arguments to the `connect()' function.  The new arguments are:
  10734. `host', `database', `user', and `password' (note that the `user' and
  10735. `password' arguments have changed places).
  10736.  
  10737. The following changes may affect queries in old applications:
  10738.  
  10739.    * `HAVING' must now be specified before any `ORDER BY' clause.
  10740.  
  10741.    * The parameters to `LOCATE()' have been swapped.
  10742.  
  10743.    * There are some new reserved words. The most noticeable are `DATE',
  10744.      `TIME', and `TIMESTAMP'.
  10745.  
  10746.  
  10747. Upgrading MySQL Under Windows
  10748. -----------------------------
  10749.  
  10750. When upgrading MySQL under Windows, please follow these steps:
  10751.  
  10752.   1. Download the latest Windows distribution of MySQL.
  10753.  
  10754.   2. Choose a time of day with low usage, where a maintenance break is
  10755.      acceptable.
  10756.  
  10757.   3. Alert the users who still are active about the maintenance break.
  10758.  
  10759.   4. Stop the running MySQL Server (for example, with `NET STOP MySQL'
  10760.      or with the `Services' utility if you are running MySQL as a
  10761.      service, or with `mysqladmin shutdown' otherwise).
  10762.  
  10763.   5. Exit the `WinMySQLAdmin' program if it is running.
  10764.  
  10765.   6. Run the installation script of the Windows distribution by
  10766.      clicking the Install button in WinZip and following the
  10767.      installation steps of the script.
  10768.  
  10769.      *Important note:* Early alpha Windows distributions for MySQL 4.1
  10770.      do not contain an installer program.  See *Note Windows binary
  10771.      installation:: for instructions on how to install such a
  10772.      distribution.
  10773.  
  10774.   7. You may either overwrite your old MySQL installation (usually
  10775.      located at `C:\mysql'), or install it into a different directory,
  10776.      such as `C:\mysql4'. Overwriting the old installation is
  10777.      recommended.
  10778.  
  10779.   8. Restart the server. For example, use `NET START MySQL' if you run
  10780.      MySQL as a service, or invoke `mysqld' directly otherwise.
  10781.  
  10782.   9. Update the grant tables. The procedure is described in *Note
  10783.      Upgrading-grant-tables::.
  10784.  
  10785.  
  10786. Possible error situations:
  10787.      A system error has occurred.
  10788.      System error 1067 has occurred.
  10789.      The process terminated unexpectedly.
  10790.  
  10791. These errors mean that your option file (by default `C:\my.cnf')
  10792. contains an option that cannot be recognized by MySQL. You can verify
  10793. that this is the case by trying to restart MySQL with the option file
  10794. renamed to prevent the server from using it. (For example, rename
  10795. `C:\my.cnf' to `C:\my_cnf.old'.)  Once you have verified it, you need
  10796. to identify which option is the culprit. Create a new `my.cnf' file and
  10797. move parts of the old file to it (restarting the server after you move
  10798. each part) until you determine which option causes server startup to
  10799. fail.
  10800.  
  10801. Upgrading the Grant Tables
  10802. --------------------------
  10803.  
  10804. Some releases introduce changes to the structure of the grant tables
  10805. (the tables in the `mysql' database) to add new  privileges or
  10806. features. To make sure that your grant tables are current when you
  10807. update to a new version of MySQL, you should update your grant tables
  10808. as well.
  10809.  
  10810. On Unix or Unix-like systems, update the grant tables by running the
  10811. `mysql_fix_privilege_tables' script:
  10812.  
  10813.      shell> mysql_fix_privilege_tables
  10814.  
  10815. You must run this script while the server is running. It attempts to
  10816. connect to the server running on the local host as `root'.  If your
  10817. `root' account requires a password, indicate the password on the
  10818. command line.  For MySQL 4.1 and up, specify the password like this:
  10819.  
  10820.      shell> mysql_fix_privilege_tables --password=root_password
  10821.  
  10822. Prior to MySQL 4.1, specify the password like this:
  10823.  
  10824.      shell> mysql_fix_privilege_tables root_password
  10825.  
  10826. The `mysql_fix_privilege_tables' script performs any actions necessary
  10827. to convert your grant tables to the current format. You might see some
  10828. `Duplicate column name' warnings as it runs; you can ignore them.
  10829.  
  10830. After running the script, stop the server and restart it.
  10831.  
  10832. On Windows systems, there isn't an easy way to update the grant tables
  10833. until MySQL 4.0.15.  From version 4.0.15 on, MySQL distributions
  10834. include a `mysql_fix_privilege_tables.sql' SQL script that you can run
  10835. using the `mysql' client.  If your MySQL installation is located at
  10836. `C:\mysql', the commands look like this:
  10837.  
  10838.      C:\> C:\mysql\bin\mysql -u root -p mysql
  10839.      mysql> SOURCE C:\mysql\scripts\mysql_fix_privilege_tables.sql
  10840.  
  10841. If your installation is located in some other directory, adjust the
  10842. pathnames appropriately.
  10843.  
  10844. The `mysql' command will prompt you for the `root' password; enter it
  10845. when prompted.
  10846.  
  10847. As with the Unix procedure, you might see some `Duplicate column name'
  10848. warnings as `mysql' processes the statements in the
  10849. `mysql_fix_privilege_tables.sql' script; you can ignore them.
  10850.  
  10851. After running the script, stop the server and restart it.
  10852.  
  10853. Copying MySQL Databases to Another Machine
  10854. ------------------------------------------
  10855.  
  10856. If you are using MySQL 3.23 or later, you can copy the `.frm', `.MYI',
  10857. and `.MYD' files for `MyISAM' tables between different architectures
  10858. that support the same floating-point format.  (MySQL takes care of any
  10859. byte-swapping issues.)  *Note `MyISAM' Tables: MyISAM.
  10860.  
  10861. The MySQL `ISAM' data and index files (`.ISD' and `*.ISM',
  10862. respectively) are architecture dependent and in some cases operating
  10863. system dependent.  If you want to move your applications to another
  10864. machine that has a different architecture or operating system than your
  10865. current machine, you should not try to move a database by simply copying
  10866. the files to the other machine. Use `mysqldump' instead.
  10867.  
  10868. By default, `mysqldump' will create a file containing SQL statements.
  10869. You can then transfer the file to the other machine and feed it as input
  10870. to the `mysql' client.
  10871.  
  10872. Try `mysqldump --help' to see what options are available.  If you are
  10873. moving the data to a newer version of MySQL, you should use `mysqldump
  10874. --opt' to take advantage of any optimizations that result in a dump
  10875. file that is smaller and can be processed faster.
  10876.  
  10877. The easiest (although not the fastest) way to move a database between
  10878. two machines is to run the following commands on the machine on which
  10879. the database is located:
  10880.  
  10881.      shell> mysqladmin -h 'OTHER_HOSTNAME' create DB_NAME
  10882.      shell> mysqldump --opt DB_NAME | mysql -h 'OTHER_HOSTNAME' DB_NAME
  10883.  
  10884. If you want to copy a database from a remote machine over a slow
  10885. network, you can use:
  10886.  
  10887.      shell> mysqladmin create DB_NAME
  10888.      shell> mysqldump -h 'OTHER_HOSTNAME' --opt --compress DB_NAME | mysql DB_NAME
  10889.  
  10890. You can also store the result in a file, then transfer the file to the
  10891. target machine and load the file into the database there.  For example,
  10892. you can dump a database to a file on the source machine like this:
  10893.  
  10894.      shell> mysqldump --quick DB_NAME | gzip > DB_NAME.CONTENTS.gz
  10895.  
  10896. (The file created in this example is compressed.) Transfer the file
  10897. containing the database contents to the target machine and run these
  10898. commands there:
  10899.  
  10900.      shell> mysqladmin create DB_NAME
  10901.      shell> gunzip < DB_NAME.CONTENTS.gz | mysql DB_NAME
  10902.  
  10903. You can also use `mysqldump' and `mysqlimport' to transfer the database.
  10904. For big tables, this is much faster than simply using `mysqldump'.  In
  10905. the following commands, `DUMPDIR' represents the full pathname of the
  10906. directory you use to store the output from `mysqldump'.
  10907.  
  10908. First, create the directory for the output files and dump the database:
  10909.  
  10910.      shell> mkdir DUMPDIR
  10911.      shell> mysqldump --tab=DUMPDIR DB_NAME
  10912.  
  10913. Then transfer the files in the `DUMPDIR' directory to some corresponding
  10914. directory on the target machine and load the files into MySQL there:
  10915.  
  10916.      shell> mysqladmin create DB_NAME           # create database
  10917.      shell> cat DUMPDIR/*.sql | mysql DB_NAME   # create tables in database
  10918.      shell> mysqlimport DB_NAME DUMPDIR/*.txt   # load data into tables
  10919.  
  10920. Also, don't forget to copy the `mysql' database because that is where
  10921. the `user', `db', and `host' grant tables are stored.  You might have
  10922. to run commands as the MySQL `root' user on the new machine until you
  10923. have the `mysql' database in place.
  10924.  
  10925. After you import the `mysql' database on the new machine, execute
  10926. `mysqladmin flush-privileges' so that the server reloads the grant table
  10927. information.
  10928.  
  10929. Operating System-Specific Notes
  10930. ===============================
  10931.  
  10932. Linux Notes
  10933. -----------
  10934.  
  10935. This section discusses issues that have been found to occur on Linux.
  10936. The first few subsections describe general operating system-related
  10937. issues, problems that can occur when using binary or source
  10938. distributions, and post-installation issues. The remaining subsections
  10939. discuss problems that occur with Linux on specific platforms.
  10940.  
  10941. Note that most of these problems occur on older versions of Linux. If
  10942. you are running a recent version, you likely will see none of them.
  10943.  
  10944. Linux Operating System Notes
  10945. ............................
  10946.  
  10947. MySQL needs at least Linux Version 2.0.
  10948.  
  10949. *Warning:* We have seen some strange problems with Linux 2.2.14 and
  10950. MySQL on SMP systems.  We also have reports from some MySQL users that
  10951. they have encountered serious stability problems using MySQL with
  10952. kernel 2.2.14.  If you are using this kernel, you should upgrade to
  10953. 2.2.19 (or newer) or to a 2.4 kernel.  If you have a multiple-CPU box,
  10954. then you should seriously consider using 2.4 because it will give you a
  10955. significant speed boost.  Your system also will be more stable.
  10956.  
  10957. When using LinuxThreads, you will see a minimum of three `mysqld'
  10958. processes running.  These are in fact threads.  There will be one
  10959. thread for the LinuxThreads manager, one thread to handle connections,
  10960. and one thread to handle alarms and signals.
  10961.  
  10962. Linux Binary Distribution Notes
  10963. ...............................
  10964.  
  10965. The Linux-Intel binary and RPM releases of MySQL are configured for the
  10966. highest possible speed.  We are always trying to use the fastest stable
  10967. compiler available.
  10968.  
  10969. The binary release is linked with `-static', which means you do not
  10970. normally need to worry about which version of the system libraries you
  10971. have. You need not install LinuxThreads, either.  A program linked with
  10972. `-static' is slightly larger than a dynamically linked program, but
  10973. also slightly faster (3-5%).  However, one problem with a statically
  10974. linked program is that you can't use user-defined functions (UDFs).  If
  10975. you are going to write or use UDFs (this is something for C or C++
  10976. programmers only), you must compile MySQL yourself using dynamic
  10977. linking.
  10978.  
  10979. A known issue with binary distributions is that on older Linux systems
  10980. that use `libc' (such as Red Hat 4.x or Slackware), you will get some
  10981. non-fatal problems with hostname resolution. If your system uses `libc'
  10982. rather than `glibc2', you probably will encounter some difficulties
  10983. with hostname resolution and `getpwnam()'. This happens because `glibc'
  10984. unfortunately depends on some external libraries to implement hostname
  10985. resolution and `getpwent()', even when compiled with `-static'.  These
  10986. problems manifest themselves in two ways:
  10987.  
  10988.    * You probably will see  the following error message when you run
  10989.      `mysql_install_db':
  10990.  
  10991.           Sorry, the host 'XXXX' could not be looked up
  10992.  
  10993.      You can deal with this by executing `mysql_install_db --force',
  10994.      which will not execute the `resolveip' test in `mysql_install_db'.
  10995.      The downside is that you can't use hostnames in the grant tables:
  10996.      Except for `localhost', you must use IP numbers instead.  If you
  10997.      are using an old version of MySQL that doesn't support `--force',
  10998.      you must manually remove the `resolveip' test in `mysql_install'
  10999.      using an editor.
  11000.  
  11001.    * You also may see the following error when you try to run `mysqld'
  11002.      with the `--user' option:
  11003.  
  11004.           getpwnam: No such file or directory
  11005.  
  11006.      To work around this, start `mysqld' by using the `su' command
  11007.      rather than by specifying the `--user' option. This causes the
  11008.      system itself to change the user ID of the `mysqld' process so
  11009.      that `mysqld' need not do so.
  11010.  
  11011.  
  11012. Another solution, which solves both problems, is to not use a binary
  11013. distribution.  Get a MySQL source distribution (in RPM or `tar.gz'
  11014. format) and install that instead.
  11015.  
  11016. On some Linux 2.2 versions, you may get the error `Resource temporarily
  11017. unavailable' when clients make a lot of new connections to a `mysqld'
  11018. server over TCP/IP.  The problem is that Linux has a delay between the
  11019. time that you close a TCP/IP socket and the time that the system
  11020. actually frees it.  There is room for only a finite number of TCP/IP
  11021. slots, so you will encounter the resource-unavailable error if clients
  11022. attempt too many new TCP/IP connections during a short time. For
  11023. example, you may see the error when you run the MySQL `test-connect'
  11024. benchmark over TCP/IP.
  11025.  
  11026. We have inquired about this problem a few times on different Linux
  11027. mailing lists but have never been able to find a suitable resolution.
  11028. The only known "fix" is for the clients to use persistent connections,
  11029. or, if you are running the database server and clients on the same
  11030. machine, to use Unix socket file connections rather than TCP/IP
  11031. connections.
  11032.  
  11033. Linux Source Distribution Notes
  11034. ...............................
  11035.  
  11036. The following notes regarding `glibc' apply only to the situation when
  11037. you build MySQL yourself. If you are running Linux on an x86 machine,
  11038. in most cases it is much better for you to just use our binary. We link
  11039. our binaries against the best patched version of `glibc' we can come up
  11040. with and with the best compiler options, in an attempt to make it
  11041. suitable for a high-load server.  For a typical user, even for setups
  11042. with a lot of concurrent connections or tables exceeding the 2GB limit,
  11043. our binary is the best choice in most cases.  After reading the
  11044. following text, if you are in doubt about what to do, try our binary
  11045. first to see whether it meets your needs.  If you discover that it is
  11046. not good enough, then you may want to try your own build.  In that
  11047. case, we would appreciate a note about it so that we can build a better
  11048. binary next time.
  11049.  
  11050. MySQL uses LinuxThreads on Linux.  If you are using an old Linux
  11051. version that doesn't have `glibc2', you must install LinuxThreads
  11052. before trying to compile MySQL.   You can get LinuxThreads at
  11053. `http://dev.mysql.com/downloads/os-linux.html'.
  11054.  
  11055. Note that `glibc' versions before and including Version 2.1.1 have a
  11056. fatal bug in `pthread_mutex_timedwait()' handling, which is used when
  11057. you issue `INSERT DELAYED' statements.  We recommend that you not use
  11058. `INSERT DELAYED' before upgrading `glibc'.
  11059.  
  11060. Note that Linux kernel and the LinuxThread library can by default only
  11061. have 1,024 threads.  If you plan to have more than 1,000 concurrent
  11062. connections, you will need to make some changes to LinuxThreads:
  11063.  
  11064.    * Increase `PTHREAD_THREADS_MAX' in
  11065.      `sysdeps/unix/sysv/linux/bits/local_lim.h' to 4096 and decrease
  11066.      `STACK_SIZE' in `linuxthreads/internals.h' to 256KB. The paths are
  11067.      relative to the root of `glibc'. (Note that MySQL will not be
  11068.      stable with around 600-1000 connections if `STACK_SIZE' is the
  11069.      default of 2MB.)
  11070.  
  11071.    * Recompile LinuxThreads to produce a new `libpthread.a' library,
  11072.      and relink MySQL against it.
  11073.  
  11074.  
  11075. The page `http://www.volano.com/linuxnotes.html' contains additional
  11076. information about circumventing thread limits in LinuxThreads.
  11077.  
  11078. There is another issue that greatly hurts MySQL performance, especially
  11079. on SMP systems.  The mutex implementation in LinuxThreads in `glibc'
  11080. 2.1 is very bad for programs with many threads that hold the mutex only
  11081. for a short time.  This produces a paradoxical result: If you link
  11082. MySQL against an unmodified LinuxThreads, removing processors from an
  11083. SMP actually improves MySQL performance in many cases.  We have made a
  11084. patch available for `glibc' 2.1.3 to correct this behavior
  11085. (`http://www.mysql.com/Downloads/Linux/linuxthreads-2.1-patch').
  11086.  
  11087. With `glibc' 2.2.2, MySQL 3.23.36 will use the adaptive mutex, which is
  11088. much better than even the patched one in `glibc' 2.1.3. Be warned,
  11089. however, that under some conditions, the current mutex code in `glibc'
  11090. 2.2.2 overspins, which hurts MySQL performance. The likelihood that
  11091. this condition will occur can be reduced by renicing the `mysqld'
  11092. process to the highest priority. We have also been able to correct the
  11093. overspin behavior with a patch, available at
  11094. `http://www.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch'.  It
  11095. combines the correction of overspin, maximum number of threads, and
  11096. stack spacing all in one. You will need to apply it in the
  11097. `linuxthreads' directory with `patch -p0
  11098. </tmp/linuxthreads-2.2.2.patch'.  We hope it will be included in some
  11099. form in future releases of `glibc' 2.2. In any case, if you link
  11100. against `glibc' 2.2.2, you still need to correct `STACK_SIZE' and
  11101. `PTHREAD_THREADS_MAX'. We hope that the defaults will be corrected to
  11102. some more acceptable values for high-load MySQL setup in the future, so
  11103. that the commands needed to produce your own build can be reduced to
  11104. `./configure; make; make install'.
  11105.  
  11106. We recommend that you use these patches to build a special static
  11107. version of `libpthread.a' and use it only for statically linking
  11108. against MySQL. We know that the patches are safe for MySQL and
  11109. significantly improve its performance, but we cannot say anything about
  11110. other applications. If you link other applications that require
  11111. LinuxThreads against the patched static version of the library, or
  11112. build a patched shared version and install it on your system, you do so
  11113. at your own risk.
  11114.  
  11115. If you experience any strange problems during the installation of
  11116. MySQL, or with some common utilities hanging, it is very likely that
  11117. they are either library or compiler related. If this is the case, using
  11118. our binary will resolve them.
  11119.  
  11120. If you link your own MySQL client programs, you may see the following
  11121. error at runtime:
  11122.  
  11123.      ld.so.1: fatal: libmysqlclient.so.#:
  11124.      open failed: No such file or directory
  11125.  
  11126. This problem can be avoided by one of the following methods:
  11127.  
  11128.    * Link clients with the `-Wl,r/full/path/to/libmysqlclient.so' flag
  11129.      rather than with `-Lpath').
  11130.  
  11131.    * Copy `libmysqclient.so' to `/usr/lib'.
  11132.  
  11133.    * Add the pathname of the directory where `libmysqlclient.so' is
  11134.      located to the `LD_RUN_PATH' environment variable before running
  11135.      your client.
  11136.  
  11137. If you are using the Fujitsu compiler (`fcc/FCC'), you will have some
  11138. problems compiling MySQL because the Linux header files are very `gcc'
  11139. oriented.  The following `configure' line should work with `fcc/FCC':
  11140.  
  11141.      CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE \
  11142.          -DCONST=const -DNO_STRTOLL_PROTO" \
  11143.      CXX=FCC CXXFLAGS="-O -K fast -K lib \
  11144.          -K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE \
  11145.          -DCONST=const -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO \
  11146.          '-D_EXTERN_INLINE=static __inline'" \
  11147.      ./configure \
  11148.          --prefix=/usr/local/mysql --enable-assembler \
  11149.          --with-mysqld-ldflags=-all-static --disable-shared \
  11150.          --with-low-memory
  11151.  
  11152. Linux Post-Installation Notes
  11153. .............................
  11154.  
  11155. `mysql.server' can be found in the `support-files' directory under the
  11156. MySQL installation directory or in a MySQL source tree.  You can install
  11157. it as `/etc/init.d/mysql' for automatic MySQL startup and shutdown.
  11158. *Note Automatic start::.
  11159.  
  11160. If MySQL can't open enough files or connections, it may be that you
  11161. haven't configured Linux to handle enough files.
  11162.  
  11163. In Linux 2.2 and onward, you can check the number of allocated file
  11164. handles as follows:
  11165.  
  11166.      shell> cat /proc/sys/fs/file-max
  11167.      shell> cat /proc/sys/fs/dquot-max
  11168.      shell> cat /proc/sys/fs/super-max
  11169.  
  11170. If you have more than 16MB of memory, you should add something like the
  11171. following to your init scripts (for example, `/etc/init.d/boot.local'
  11172. on SuSE Linux):
  11173.  
  11174.      echo 65536 > /proc/sys/fs/file-max
  11175.      echo 8192 > /proc/sys/fs/dquot-max
  11176.      echo 1024 > /proc/sys/fs/super-max
  11177.  
  11178. You can also run the `echo' commands from the command line as `root',
  11179. but these settings will be lost the next time your computer restarts.
  11180.  
  11181. Alternatively, you can set these parameters on startup by using the
  11182. `sysctl' tool, which is used by many Linux distributions (SuSE has
  11183. added it as well, beginning with SuSE Linux 8.0). Just put the following
  11184. values into a file named `/etc/sysctl.conf':
  11185.  
  11186.      # Increase some values for MySQL
  11187.      fs.file-max = 65536
  11188.      fs.dquot-max = 8192
  11189.      fs.super-max = 1024
  11190.  
  11191. You should also add the following to `/etc/my.cnf':
  11192.  
  11193.      [mysqld_safe]
  11194.      open-files-limit=8192
  11195.  
  11196. This should allow the server a limit of 8,192 for the combined number of
  11197. connections and open files.
  11198.  
  11199. The `STACK_SIZE' constant in LinuxThreads controls the spacing of thread
  11200. stacks in the address space.  It needs to be large enough so that there
  11201. will be plenty of room for each individual thread stack, but small
  11202. enough to keep the stack of some threads from running into the global
  11203. `mysqld' data.  Unfortunately, as we have experimentally discovered,
  11204. the Linux implementation of `mmap()' will successfully unmap an already
  11205. mapped region if you ask it to map out an address already in use,
  11206. zeroing out the data on the entire page instead of returning an error.
  11207. So, the safety of `mysqld' or any other threaded application depends on
  11208. "gentlemanly" behavior of the code that creates threads.  The user must
  11209. take measures to make sure that the number of running threads at any
  11210. time is sufficiently low for thread stacks to stay away from the global
  11211. heap.  With `mysqld', you should enforce this behavior by setting a
  11212. reasonable value for the `max_connections' variable.
  11213.  
  11214. If you build MySQL yourself, you can patch LinuxThreads for better
  11215. stack use.  *Note Source notes-Linux::.  If you do not want to patch
  11216. LinuxThreads, you should set `max_connections' to a value no higher
  11217. than 500.  It should be even less if you have a large key buffer,  large
  11218. heap tables, or some other things that make `mysqld' allocate a lot of
  11219. memory, or if you are running a 2.2 kernel with a 2GB patch. If you are
  11220. using our binary or RPM version 3.23.25 or later, you can safely set
  11221. `max_connections' at 1500, assuming no large key buffer or heap tables
  11222. with lots of data.  The more you reduce `STACK_SIZE' in LinuxThreads
  11223. the more threads you can safely create.  We recommend values between
  11224. 128KB and 256KB.
  11225.  
  11226. If you use a lot of concurrent connections, you may suffer from a
  11227. "feature" in the 2.2 kernel that attempts to prevent fork bomb attacks
  11228. by penalizing a process for forking or cloning a child.  This causes
  11229. MySQL not to scale well as you increase the number of concurrent
  11230. clients.  On single-CPU systems, we have seen this manifested as very
  11231. slow thread creation: It may take a long time to connect to MySQL (as
  11232. long as one minute), and it may take just as long to shut it down.  On
  11233. multiple-CPU systems, we have observed a gradual drop in query speed as
  11234. the number of clients increases.  In the process of trying to find a
  11235. solution, we have received a kernel patch from one of our users who
  11236. claimed it made a lot of difference for his site.  The patch is
  11237. available at `http://www.mysql.com/Downloads/Patches/linux-fork.patch'.
  11238. We have now done rather extensive testing of this patch on both
  11239. development and production systems.  It has significantly improved
  11240. MySQL performance without causing any problems and we now recommend it
  11241. to our users who still run high-load servers on 2.2 kernels.
  11242.  
  11243. This issue has been fixed in the 2.4 kernel, so if you are not satisfied
  11244. with the current performance of your system, rather than patching your
  11245. 2.2 kernel, it might be easier to upgrade to 2.4. On SMP systems,
  11246. upgrading also will give you a nice SMP boost in addition to fixing the
  11247. fairness bug.
  11248.  
  11249. We have tested MySQL on the 2.4 kernel on a two-CPU machine and found
  11250. MySQL scales _much_ better. There was virtually no slowdown on query
  11251. throughput all the way up to 1,000 clients, and the MySQL scaling factor
  11252. (computed as the ratio of maximum throughput to the throughput for one
  11253. client) was 180%.  We have observed similar results on a four-CPU
  11254. system: Virtually no slowdown as the number of clients was increased up
  11255. to 1,000, and a 300% scaling factor. Based on these results, for a
  11256. high-load SMP server using a 2.2 kernel, we definitely recommend
  11257. upgrading to the 2.4 kernel at this point.
  11258.  
  11259. We have discovered that it is essential to run the `mysqld' process
  11260. with the highest possible priority on the 2.4 kernel to achieve maximum
  11261. performance.  This can be done by adding a `renice -20 $$' command to
  11262. `mysqld_safe'. In our testing on a four-CPU machine, increasing the
  11263. priority resulted in a 60% throughput increase with 400 clients.
  11264.  
  11265. We are currently also trying to collect more information on how well
  11266. MySQL performs with a 2.4 kernel on four-way and eight-way systems. If
  11267. you have access such a system and have done some benchmarks, please
  11268. send an email message to <benchmarks@mysql.com> with the results. We
  11269. will review them for inclusion in the manual.
  11270.  
  11271. If you see a dead `mysqld' server process with `ps', this usually means
  11272. that you have found a bug in MySQL or you have a corrupted table. *Note
  11273. Crashing::.
  11274.  
  11275. To get a core dump on Linux if `mysqld' dies with a `SIGSEGV' signal,
  11276. you can start `mysqld' with the `--core-file' option.  Note that you
  11277. also probably need to raise the core file size by adding `ulimit -c
  11278. 1000000' to `mysqld_safe' or starting `mysqld_safe' with
  11279. `--core-file-size=1000000'.  *Note `mysqld_safe': mysqld_safe.
  11280.  
  11281. Linux x86 Notes
  11282. ...............
  11283.  
  11284. MySQL requires `libc' Version 5.4.12 or newer. It's known to work with
  11285. `libc' 5.4.46.  `glibc' Version 2.0.6 and later should also work. There
  11286. have been some problems with the `glibc' RPMs from Red Hat, so if you
  11287. have problems, check whether there are any updates.  The `glibc'
  11288. 2.0.7-19 and 2.0.7-29 RPMs are known to work.
  11289.  
  11290. If you are using Red Hat 8.0 or a new `glibc' 2.2.x library, you may see
  11291. `mysqld' die in `gethostbyaddr()'. This happens because the new `glibc'
  11292. library requires a stack size greater than 128KB for this call.  To fix
  11293. the problem, start `mysqld' with the `--thread-stack=192K' option.
  11294. (Use `-O thread_stack=192K' before MySQL 4.)  This stack size is now
  11295. the default on MySQL 4.0.10 and above, so you should not see the
  11296. problem.
  11297.  
  11298. If you are using `gcc' 3.0 and above to compile MySQL, you must install
  11299. the `libstdc++v3' library before compiling MySQL; if you don't do this,
  11300. you will get an error about a missing `__cxa_pure_virtual' symbol
  11301. during linking.
  11302.  
  11303. On some older Linux distributions, `configure' may produce an error
  11304. like this:
  11305.  
  11306.      Syntax error in sched.h. Change _P to __P in the
  11307.      /usr/include/sched.h file.
  11308.      See the Installation chapter in the Reference Manual.
  11309.  
  11310. Just do what the error message says. Add an extra underscore to the
  11311. `_P' macro name that has only one underscore, then try again.
  11312.  
  11313. You may get some warnings when compiling. Those shown here can be
  11314. ignored:
  11315.  
  11316.      mysqld.cc -o objs-thread/mysqld.o
  11317.      mysqld.cc: In function `void init_signals()':
  11318.      mysqld.cc:315: warning: assignment of negative value `-1' to
  11319.      `long unsigned int'
  11320.      mysqld.cc: In function `void * signal_hand(void *)':
  11321.      mysqld.cc:346: warning: assignment of negative value `-1' to
  11322.      `long unsigned int'
  11323.  
  11324. If `mysqld' always dumps core when it starts, the problem may be that
  11325. you have an old `/lib/libc.a'.  Try renaming it, then remove
  11326. `sql/mysqld' and do a new `make install' and try again.  This problem
  11327. has been reported on some Slackware installations.
  11328.  
  11329. If you get the following error when linking `mysqld', it means that
  11330. your `libg++.a' is not installed correctly:
  11331.  
  11332.      /usr/lib/libc.a(putc.o): In function `_IO_putc':
  11333.      putc.o(.text+0x0): multiple definition of `_IO_putc'
  11334.  
  11335. You can avoid using `libg++.a' by running `configure' like this:
  11336.  
  11337.      shell> CXX=gcc ./configure
  11338.  
  11339. If `mysqld' crashes immediately and you are running Red Hat Version 5.0
  11340. with a version of `glibc' older than 2.0.7-5, you should make sure that
  11341. you have installed all `glibc' patches.  There is a lot of information
  11342. about this in the MySQL mail archives, available online at
  11343. `http://lists.mysql.com/'.
  11344.  
  11345. Linux SPARC Notes
  11346. .................
  11347.  
  11348. In some implementations, `readdir_r()' is broken.  The symptom is that
  11349. the `SHOW DATABASES' statement always returns an empty set.  This can
  11350. be fixed by removing `HAVE_READDIR_R' from `config.h' after configuring
  11351. and before compiling.
  11352.  
  11353. Linux Alpha Notes
  11354. .................
  11355.  
  11356. MySQL 3.23.12 is the first MySQL version that is tested on Linux-Alpha.
  11357. If you plan to use MySQL on Linux-Alpha, you should ensure that you
  11358. have this version or newer.
  11359.  
  11360. We have tested MySQL on Alpha with our benchmarks and test suite, and
  11361. it appears to work nicely.
  11362.  
  11363. We currently build the MySQL binary packages on SuSE Linux 7.0 for AXP,
  11364. kernel 2.4.4-SMP, Compaq C compiler (V6.2-505) and Compaq C++ compiler
  11365. (V6.3-006) on a Compaq DS20 machine with an Alpha EV6 processor.
  11366.  
  11367. You can find the preceding compilers at
  11368. `http://www.support.compaq.com/alpha-tools/'.  By using these compilers
  11369. rather than `gcc', we get about 9-14% better MySQL performance.
  11370.  
  11371. Note that until MySQL version 3.23.52 and 4.0.2, we optimized the
  11372. binary for the current CPU only (by using the `-fast' compile option).
  11373. This means that for older versions, you can use our Alpha binaries only
  11374. if you have an Alpha EV6 processor.
  11375.  
  11376. For all following releases, we added the `-arch generic' flag to our
  11377. compile options, which makes sure that the binary runs on all Alpha
  11378. processors. We also compile statically to avoid library problems.  The
  11379. `configure' command looks like this:
  11380.  
  11381.      CC=ccc CFLAGS="-fast -arch generic" CXX=cxx \
  11382.      CXXFLAGS="-fast -arch generic -noexceptions -nortti" \
  11383.      ./configure --prefix=/usr/local/mysql --disable-shared \
  11384.          --with-extra-charsets=complex --enable-thread-safe-client \
  11385.          --with-mysqld-ldflags=-non_shared --with-client-ldflags=-non_shared
  11386.  
  11387. If you want to use `egcs', the following `configure' line worked for us:
  11388.  
  11389.      CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc \
  11390.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
  11391.          -fno-exceptions -fno-rtti" \
  11392.      ./configure --prefix=/usr/local/mysql --disable-shared
  11393.  
  11394. Some known problems when running MySQL on Linux-Alpha:
  11395.  
  11396.    * Debugging threaded applications like MySQL will not work with `gdb
  11397.      4.18'.  You should use `gdb' 5.1 instead.
  11398.  
  11399.    * If you try linking `mysqld' statically when using `gcc', the
  11400.      resulting image will dump core at startup time.  In other words,
  11401.      _do not_ use `--with-mysqld-ldflags=-all-static' with `gcc'.
  11402.  
  11403. Linux PowerPC Notes
  11404. ...................
  11405.  
  11406. MySQL should work on MkLinux with the newest `glibc' package (tested
  11407. with `glibc' 2.0.7).
  11408.  
  11409. Linux MIPS Notes
  11410. ................
  11411.  
  11412. To get MySQL to work on Qube2 (Linux Mips), you need the newest `glibc'
  11413. libraries. `glibc-2.0.7-29C2' is known to work.  You must also use the
  11414. `egcs' C++ compiler (`egcs' 1.0.2-9, `gcc' 2.95.2 or newer).
  11415.  
  11416. Linux IA-64 Notes
  11417. .................
  11418.  
  11419. To get MySQL to compile on Linux IA-64, we use the following `configure'
  11420. command for building with `gcc' 2.96:
  11421.  
  11422.      CC=gcc \
  11423.      CFLAGS="-O3 -fno-omit-frame-pointer" \
  11424.      CXX=gcc \
  11425.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  11426.          -fno-exceptions -fno-rtti" \
  11427.          ./configure --prefix=/usr/local/mysql \
  11428.          "--with-comment=Official MySQL binary" \
  11429.          --with-extra-charsets=complex
  11430.  
  11431. On IA-64, the MySQL client binaries use shared libraries. This means
  11432. that if you install our binary distribution at a location other than
  11433. `/usr/local/mysql', you need to add the path of the directory where you
  11434. have `libmysqlclient.so' installed either to the `/etc/ld.so.conf' file
  11435. or to the value of your `LD_LIBRARY_PATH' environment variable.
  11436.  
  11437. *Note Link errors::.
  11438.  
  11439. Mac OS X Notes
  11440. --------------
  11441.  
  11442. On Mac OS X, `tar' cannot handle long filenames. If you need to unpack a
  11443. `.tar.gz' distribution, use `gnutar' instead.
  11444.  
  11445. Mac OS X 10.x (Darwin)
  11446. ......................
  11447.  
  11448. MySQL should work without any problems on Mac OS X 10.x (Darwin).
  11449.  
  11450. Our binary for Mac OS X is compiled on Darwin 6.3 with the following
  11451. `configure' line:
  11452.  
  11453.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  11454.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  11455.          -fno-exceptions -fno-rtti" \
  11456.          ./configure --prefix=/usr/local/mysql \
  11457.          --with-extra-charsets=complex --enable-thread-safe-client \
  11458.          --enable-local-infile --disable-shared
  11459.  
  11460. *Note Mac OS X installation::.
  11461.  
  11462. Mac OS X Server 1.2 (Rhapsody)
  11463. ..............................
  11464.  
  11465. For current versions of Mac OS X Server, no operating system changes are
  11466. necessary before compiling MySQL.  Compiling for the Server platform is
  11467. the same as for the client version of Mac OS X. (However, note that
  11468. MySQL comes preinstalled on Mac OS X Server, so you need not build it
  11469. yourself.)
  11470.  
  11471. For older versions (Mac OS X Server 1.2, a.k.a. Rhapsody), you must
  11472. first install a pthread package before trying to configure MySQL.
  11473.  
  11474. *Note Mac OS X installation::.
  11475.  
  11476. Solaris Notes
  11477. -------------
  11478.  
  11479. On Solaris, you may run into trouble even before you get the MySQL
  11480. distribution unpacked!  Solaris `tar' can't handle long filenames, so
  11481. you may see an error like this when you unpack MySQL:
  11482.  
  11483.      x mysql-3.22.12-beta/bench/Results/ATIS-mysql_odbc-NT_4.0-cmp-db2,
  11484.      informix,ms-sql,mysql,oracle,solid,sybase, 0 bytes, 0 tape blocks
  11485.      tar: directory checksum error
  11486.  
  11487. In this case, you must use GNU `tar' (`gtar') to unpack the
  11488. distribution.  You can find a precompiled copy for Solaris at
  11489. `http://dev.mysql.com/downloads/os-solaris.html'.
  11490.  
  11491. Sun native threads work only on Solaris 2.5 and higher.  For Version
  11492. 2.4 and earlier, MySQL automatically uses MIT-pthreads.  *Note
  11493. MIT-pthreads::.
  11494.  
  11495. If you get the following error from `configure', it means that you have
  11496. something wrong with your compiler installation:
  11497.  
  11498.      checking for restartable system calls... configure: error can not
  11499.      run test programs while cross compiling
  11500.  
  11501. In this case, you should upgrade your compiler to a newer version.  You
  11502. may also be able to solve this problem by inserting the following row
  11503. into the `config.cache' file:
  11504.  
  11505.      ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
  11506.  
  11507. If you are using Solaris on a SPARC, the recommended compiler is `gcc'
  11508. 2.95.2 or 3.2. You can find this at `http://gcc.gnu.org/'.  Note that
  11509. `egcs' 1.1.1 and `gcc' 2.8.1 don't work reliably on SPARC!
  11510.  
  11511. The recommended `configure' line when using `gcc' 2.95.2 is:
  11512.  
  11513.      CC=gcc CFLAGS="-O3" \
  11514.      CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" \
  11515.      ./configure --prefix=/usr/local/mysql --with-low-memory \
  11516.          --enable-assembler
  11517.  
  11518. If you have an UltraSPARC system, you can get 4% better performance by
  11519. adding `-mcpu=v8 -Wa,-xarch=v8plusa' to the `CFLAGS' and `CXXFLAGS'
  11520. environment variables.
  11521.  
  11522. If you have Sun's Forte 5.0 (or newer) compiler, you can run
  11523. `configure' like this:
  11524.  
  11525.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt" \
  11526.      CXX=CC CXXFLAGS="-noex -mt" \
  11527.      ./configure --prefix=/usr/local/mysql --enable-assembler
  11528.  
  11529. To create a 64-bit binary with Sun's Forte compiler, use the following
  11530. configuration options:
  11531.  
  11532.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt -xarch=v9" \
  11533.      CXX=CC CXXFLAGS="-noex -mt -xarch=v9" ASFLAGS="-xarch=v9" \
  11534.      ./configure --prefix=/usr/local/mysql --enable-assembler
  11535.  
  11536. To create a 64-bit Solaris binary using `gcc', add `-m64' to `CFLAGS'
  11537. and `CXXFLAGS' and remove `--enable-assembler' from the `configure'
  11538. line. This works only with MySQL 4.0 and up; MySQL 3.23 does not
  11539. include the required modifications to support this.
  11540.  
  11541. In the MySQL benchmarks, we got a 4% speedup on an UltraSPARC when using
  11542. Forte 5.0 in 32-bit mode compared to using `gcc' 3.2 with the `-mcpu'
  11543. flag.
  11544.  
  11545. If you create a 64-bit `mysqld' binary, it is 4% slower than the 32-bit
  11546. binary, but can handle more threads and memory.
  11547.  
  11548. If you get a problem with `fdatasync' or `sched_yield', you can fix
  11549. this by adding `LIBS=-lrt' to the `configure' line
  11550.  
  11551. For compilers older than WorkShop 5.3, you might have to edit the
  11552. `configure' script. Change this line:
  11553.  
  11554.      #if !defined(__STDC__) || __STDC__ != 1
  11555.  
  11556. To this:
  11557.  
  11558.      #if !defined(__STDC__)
  11559.  
  11560. If you turn on `__STDC__' with the `-Xc' option, the Sun compiler can't
  11561. compile with the Solaris `pthread.h' header file.  This is a Sun bug
  11562. (broken compiler or broken include file).
  11563.  
  11564. If `mysqld' issues the following error message when you run it, you have
  11565. tried to compile MySQL with the Sun compiler without enabling the `-mt'
  11566. multi-thread option:
  11567.  
  11568.      libc internal error: _rmutex_unlock: rmutex not held
  11569.  
  11570. Add `-mt' to `CFLAGS' and `CXXFLAGS' and recompile.
  11571.  
  11572. If you are using the SFW version of `gcc' (which comes with Solaris 8),
  11573. you must add `/opt/sfw/lib' to the environment variable
  11574. `LD_LIBRARY_PATH' before running `configure'.
  11575.  
  11576. If you are using the `gcc' available from `sunfreeware.com', you may
  11577. have many problems.  To avoid this, you should recompile `gcc' and GNU
  11578. `binutils' on the machine where you will be running them.
  11579.  
  11580. If you get the following error when compiling MySQL with `gcc', it
  11581. means that your `gcc' is not configured for your version of Solaris:
  11582.  
  11583.      shell> gcc -O3 -g -O2 -DDBUG_OFF  -o thr_alarm ...
  11584.      ./thr_alarm.c: In function `signal_hand':
  11585.      ./thr_alarm.c:556: too many arguments to function `sigwait'
  11586.  
  11587. The proper thing to do in this case is to get the newest version of
  11588. `gcc' and compile it with your current `gcc' compiler.  At least for
  11589. Solaris 2.5, almost all binary versions of `gcc' have old, unusable
  11590. include files that will break all programs that use threads, and
  11591. possibly other programs!
  11592.  
  11593. Solaris doesn't provide static versions of all system libraries
  11594. (`libpthreads' and `libdl'), so you can't compile MySQL with
  11595. `--static'.  If you try to do so, you will get one of the following
  11596. errors:
  11597.  
  11598.      ld: fatal: library -ldl: not found
  11599.      undefined reference to `dlopen'
  11600.      cannot find -lrt
  11601.  
  11602. If you link your own MySQL client programs, you may see the following
  11603. error at runtime:
  11604.  
  11605.      ld.so.1: fatal: libmysqlclient.so.#:
  11606.      open failed: No such file or directory
  11607.  
  11608. This problem can be avoided by one of the following methods:
  11609.  
  11610.    * Link clients with the `-Wl,r/full/path/to/libmysqlclient.so' flag
  11611.      rather than with `-Lpath').
  11612.  
  11613.    * Copy `libmysqclient.so' to `/usr/lib'.
  11614.  
  11615.    * Add the pathname of the directory where `libmysqlclient.so' is
  11616.      located to the `LD_RUN_PATH' environment variable before running
  11617.      your client.
  11618.  
  11619. If you have problems with `configure' trying to link with `-lz' when
  11620. you don't have `zlib' installed, you have two options:
  11621.  
  11622.    * If you want to be able to use the compressed communication
  11623.      protocol, you need to get and install `zlib' from `ftp.gnu.org'.
  11624.  
  11625.    * Run `configure' with the `--with-named-z-libs=no' option when
  11626.      building MySQL.
  11627.  
  11628. If you are using `gcc' and have problems with loading user-defined
  11629. functions (UDFs) into MySQL, try adding `-lgcc' to the link line for
  11630. the UDF.
  11631.  
  11632. If you would like MySQL to start automatically, you can copy
  11633. `support-files/mysql.server' to `/etc/init.d' and create a symbolic
  11634. link to it named `/etc/rc3.d/S99mysql.server'.
  11635.  
  11636. If too many processes try to connect very rapidly to `mysqld', you will
  11637. see this error in the MySQL log:
  11638.  
  11639.      Error in accept: Protocol error
  11640.  
  11641. You might try starting the server with the `--back_log=50' option as a
  11642. workaround for this.  (Use `-O back_log=50' before MySQL 4.)
  11643.  
  11644. Solaris doesn't support core files for `setuid()' applications, so you
  11645. can't get a core file from `mysqld' if you are using the `--user'
  11646. option.
  11647.  
  11648. Solaris 2.7/2.8 Notes
  11649. .....................
  11650.  
  11651. Normally, you can use a Solaris 2.6 binary on Solaris 2.7 and 2.8.  Most
  11652. of the Solaris 2.6 issues also apply for Solaris 2.7 and 2.8.
  11653.  
  11654. MySQL 3.23.4 and above should be able to detect new versions of Solaris
  11655. automatically and enable workarounds for the following problems.
  11656.  
  11657. Solaris 2.7 / 2.8 has some bugs in the include files.  You may see the
  11658. following error when you use `gcc':
  11659.  
  11660.      /usr/include/widec.h:42: warning: `getwc' redefined
  11661.      /usr/include/wchar.h:326: warning: this is the location of the previous
  11662.      definition
  11663.  
  11664. If this occurs, you can fix the problem by copying
  11665. `/usr/include/widec.h' to `.../lib/gcc-lib/os/gcc-version/include' and
  11666. changing line 41 from this:
  11667.  
  11668.      #if     !defined(lint) && !defined(__lint)
  11669.  
  11670. To this:
  11671.  
  11672.      #if     !defined(lint) && !defined(__lint) && !defined(getwc)
  11673.  
  11674. Alternatively, you can edit `/usr/include/widec.h' directly.  Either
  11675. way, after you make the fix, you should remove `config.cache' and run
  11676. `configure' again.
  11677.  
  11678. If you get the following errors when you run `make', it's because
  11679. `configure' didn't detect the `curses.h' file (probably because of the
  11680. error in `/usr/include/widec.h'):
  11681.  
  11682.      In file included from mysql.cc:50:
  11683.      /usr/include/term.h:1060: syntax error before `,'
  11684.      /usr/include/term.h:1081: syntax error before `;'
  11685.  
  11686. The solution to this problem is to do one of the following:
  11687.  
  11688.    * Configure with `CFLAGS=-DHAVE_CURSES_H CXXFLAGS=-DHAVE_CURSES_H
  11689.      ./configure'.
  11690.  
  11691.    * Edit `/usr/include/widec.h' as indicated in the preceding
  11692.      discussion and re-run `configure'.
  11693.  
  11694.    * Remove the `#define HAVE_TERM' line from the `config.h' file and
  11695.      run `make' again.
  11696.  
  11697. If your linker can't find `-lz' when linking client programs, the
  11698. problem is probably that your `libz.so' file is installed in
  11699. `/usr/local/lib'.  You can fix this problem by one of the following
  11700. methods:
  11701.  
  11702.    * Add `/usr/local/lib' to `LD_LIBRARY_PATH'.
  11703.  
  11704.    * Add a link to `libz.so' from `/lib'.
  11705.  
  11706.    * If you are using Solaris 8, you can install the optional `zlib'
  11707.      from your Solaris 8 CD distribution.
  11708.  
  11709.    * Run `configure' with the `--with-named-z-libs=no' option when
  11710.      building MySQL.
  11711.  
  11712. Solaris x86 Notes
  11713. .................
  11714.  
  11715. On Solaris 8 on x86, `mysqld' will dump core if you remove the debug
  11716. symbols using `strip'.
  11717.  
  11718. If you are using `gcc' or `egcs' on Solaris x86 and you experience
  11719. problems with core dumps under load, you should use the following
  11720. `configure' command:
  11721.  
  11722.      CC=gcc CFLAGS="-O3 -fomit-frame-pointer -DHAVE_CURSES_H" \
  11723.      CXX=gcc \
  11724.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
  11725.          -fno-exceptions -fno-rtti -DHAVE_CURSES_H" \
  11726.      ./configure --prefix=/usr/local/mysql
  11727.  
  11728. This will avoid problems with the `libstdc++' library and with C++
  11729. exceptions.
  11730.  
  11731. If this doesn't help, you should compile a debug version and run it
  11732. with a trace file or under `gdb'.  *Note Using `gdb' on `mysqld': Using
  11733. gdb on mysqld.
  11734.  
  11735. BSD Notes
  11736. ---------
  11737.  
  11738. This section provides information about using MySQL on variants of BSD
  11739. Unix.
  11740.  
  11741. FreeBSD Notes
  11742. .............
  11743.  
  11744. FreeBSD 4.x or newer is recommended for running MySQL, because the
  11745. thread package is much more integrated.  To get a secure and stable
  11746. system, you should use only FreeBSD kernels that are marked `-RELEASE'.
  11747.  
  11748. The easiest (and preferred) way to install MySQL is to use the
  11749. `mysql-server' and `mysql-client' ports available at
  11750. `http://www.freebsd.org/'.  Using these ports gives you the following
  11751. benefits:
  11752.  
  11753.    * A working MySQL with all optimizations enabled that are known to
  11754.      work on your version of FreeBSD.
  11755.  
  11756.    * Automatic configuration and build.
  11757.  
  11758.    * Startup scripts installed in `/usr/local/etc/rc.d'.
  11759.  
  11760.    * The ability to use `pkg_info -L' to see which files are installed.
  11761.  
  11762.    * The ability to use `pkg_delete' to remove MySQL if you no longer
  11763.      want it on your machine.
  11764.  
  11765. It is recommended you use MIT-pthreads on FreeBSD 2.x, and native
  11766. threads on Versions 3 and up. It is possible to run with native threads
  11767. on some late 2.2.x versions, but you may encounter problems shutting
  11768. down `mysqld'.
  11769.  
  11770. Unfortunately, certain function calls on FreeBSD are not yet fully
  11771. thread-safe.  Most notably, this includes the `gethostbyname()'
  11772. function, which is used by MySQL to convert hostnames into IP
  11773. addresses. Under certain circumstances, the `mysqld' process will
  11774. suddenly cause 100% CPU load and will be unresponsive. If you encounter
  11775. this problem, try to start MySQL using the `--skip-name-resolve' option.
  11776.  
  11777. Alternatively, you can link MySQL on FreeBSD 4.x against the
  11778. LinuxThreads library, which avoids a few of the problems that the
  11779. native FreeBSD thread implementation has. For a very good comparison of
  11780. LinuxThreads versus native threads, see Jeremy Zawodny's article
  11781. `FreeBSD or Linux for your MySQL Server?' at
  11782. `http://jeremy.zawodny.com/blog/archives/000697.html'.
  11783.  
  11784. A known problem when using LinuxThreads on FreeBSD is that the
  11785. `wait_timeout' value is not honored (probably a signal handling problem
  11786. in FreeBSD/LinuxThreads).  This is supposed to be fixed in FreeBSD 5.0.
  11787. The symptom is that persistent connections can hang for a very long
  11788. time without getting closed down.
  11789.  
  11790. The MySQL build process requires GNU make (`gmake') to work.  If GNU
  11791. `make' is not available, you must install it first before compiling
  11792. MySQL.
  11793.  
  11794. The recommended way to compile and install MySQL on FreeBSD with `gcc'
  11795. (2.95.2 and up) is:
  11796.  
  11797.      CC=gcc CFLAGS="-O2 -fno-strength-reduce" \
  11798.          CXX=gcc CXXFLAGS="-O2 -fno-rtti -fno-exceptions \
  11799.          -felide-constructors -fno-strength-reduce" \
  11800.          ./configure --prefix=/usr/local/mysql --enable-assembler
  11801.      gmake
  11802.      gmake install
  11803.      cd /usr/local/mysql
  11804.      bin/mysql_install_db --user=mysql
  11805.      bin/mysqld_safe &
  11806.  
  11807. If you notice that `configure' will use MIT-pthreads, you should read
  11808. the MIT-pthreads notes.  *Note MIT-pthreads::.
  11809.  
  11810. If you get an error from `make install' that it can't find
  11811. `/usr/include/pthreads', `configure' didn't detect that you need
  11812. MIT-pthreads. To fix this problem, remove `config.cache', then re-run
  11813. `configure' with the `--with-mit-threads' option.
  11814.  
  11815. Be sure that your name resolver setup is correct.  Otherwise, you may
  11816. experience resolver delays or failures when connecting to `mysqld'.
  11817. Also make sure that the `localhost' entry in the `/etc/hosts' file is
  11818. correct.  The file should start with a line similar to this:
  11819.  
  11820.      127.0.0.1       localhost localhost.your.domain
  11821.  
  11822. FreeBSD is known to have a very low default file handle limit.  *Note
  11823. Not enough file handles::.  Start the server by using the
  11824. `--open-files-limit' option for `mysqld_safe', or raise the limits for
  11825. the `mysqld' user in `/etc/login.conf' and rebuild it with `cap_mkdb
  11826. /etc/login.conf'.  Also be sure that you set the appropriate class for
  11827. this user in the password file if you are not using the default (use
  11828. `chpass mysqld-user-name').  *Note `mysqld_safe': mysqld_safe.
  11829.  
  11830. If you have a lot of memory, you should consider rebuilding the kernel
  11831. to allow MySQL to use more than 512MB of RAM.  Take a look at `option
  11832. MAXDSIZ' in the LINT config file for more information.
  11833.  
  11834. If you get problems with the current date in MySQL, setting the `TZ'
  11835. variable will probably help.  *Note Environment variables::.
  11836.  
  11837. NetBSD Notes
  11838. ............
  11839.  
  11840. To compile on NetBSD, you need GNU `make'. Otherwise, the build process
  11841. will fail when `make' tries to run `lint' on C++ files.
  11842.  
  11843. OpenBSD 2.5 Notes
  11844. .................
  11845.  
  11846. On OpenBSD Version 2.5, you can compile MySQL with native threads with
  11847. the following options:
  11848.  
  11849.      CFLAGS=-pthread CXXFLAGS=-pthread ./configure --with-mit-threads=no
  11850.  
  11851. OpenBSD 2.8 Notes
  11852. .................
  11853.  
  11854. Our users have reported that OpenBSD 2.8 has a threading bug that causes
  11855. problems with MySQL.  The OpenBSD Developers have fixed the problem,
  11856. but as of January 25, 2001, it's only available in the "-current"
  11857. branch.  The symptoms of this threading bug are slow response, high
  11858. load, high CPU usage, and crashes.
  11859.  
  11860. If you get an error like `Error in accept:: Bad file descriptor' or
  11861. error 9 when trying to open tables or directories, the problem is
  11862. probably that you have not allocated enough file descriptors for MySQL.
  11863.  
  11864. In this case, try starting `mysqld_safe' as `root' with the following
  11865. options:
  11866.  
  11867.      mysqld_safe --user=mysql --open-files-limit=2048 &
  11868.  
  11869. BSD/OS Version 2.x Notes
  11870. ........................
  11871.  
  11872. If you get the following error when compiling MySQL, your `ulimit'
  11873. value for virtual memory is too low:
  11874.  
  11875.      item_func.h: In method
  11876.      `Item_func_ge::Item_func_ge(const Item_func_ge &)':
  11877.      item_func.h:28: virtual memory exhausted
  11878.      make[2]: *** [item_func.o] Error 1
  11879.  
  11880. Try using `ulimit -v 80000' and run `make' again.  If this doesn't work
  11881. and you are using `bash', try switching to `csh' or `sh'; some BSDI
  11882. users have reported problems with `bash' and `ulimit'.
  11883.  
  11884. If you are using `gcc', you may also use have to use the
  11885. `--with-low-memory' flag for `configure' to be able to compile
  11886. `sql_yacc.cc'.
  11887.  
  11888. If you get problems with the current date in MySQL, setting the `TZ'
  11889. variable will probably help.  *Note Environment variables::.
  11890.  
  11891. BSD/OS Version 3.x Notes
  11892. ........................
  11893.  
  11894. Upgrade to BSD/OS Version 3.1.  If that is not possible, install
  11895. BSDIpatch M300-038.
  11896.  
  11897. Use the following command when configuring MySQL:
  11898.  
  11899.      env CXX=shlicc++ CC=shlicc2 \
  11900.      ./configure \
  11901.          --prefix=/usr/local/mysql \
  11902.          --localstatedir=/var/mysql \
  11903.          --without-perl \
  11904.          --with-unix-socket-path=/var/mysql/mysql.sock
  11905.  
  11906. The following is also known to work:
  11907.  
  11908.      env CC=gcc CXX=gcc CXXFLAGS=-O3 \
  11909.      ./configure \
  11910.          --prefix=/usr/local/mysql \
  11911.          --with-unix-socket-path=/var/mysql/mysql.sock
  11912.  
  11913. You can change the directory locations if you wish, or just use the
  11914. defaults by not specifying any locations.
  11915.  
  11916. If you have problems with performance under heavy load, try using the
  11917. `--skip-thread-priority' option to `mysqld'!  This will run all threads
  11918. with the same priority. On BSDI Version 3.1, this gives better
  11919. performance, at least until BSDI fixes its thread scheduler.
  11920.  
  11921. If you get the error `virtual memory exhausted' while compiling, you
  11922. should try using `ulimit -v 80000' and running `make' again.  If this
  11923. doesn't work and you are using `bash', try switching to `csh' or `sh';
  11924. some BSDI users have reported problems with `bash' and `ulimit'.
  11925.  
  11926. BSD/OS Version 4.x Notes
  11927. ........................
  11928.  
  11929. BSDI Version 4.x has some thread-related bugs.  If you want to use
  11930. MySQL on this, you should install all thread-related patches.  At least
  11931. M400-023 should be installed.
  11932.  
  11933. On some BSDI Version 4.x systems, you may get problems with shared
  11934. libraries.  The symptom is that you can't execute any client programs,
  11935. for example, `mysqladmin'.  In this case, you need to reconfigure not
  11936. to use shared libraries with the `--disable-shared' option to configure.
  11937.  
  11938. Some customers have had problems on BSDI 4.0.1 that the `mysqld' binary
  11939. after a while can't open tables.  This is because some
  11940. library/system-related bug causes `mysqld' to change current directory
  11941. without having asked for that to happen.
  11942.  
  11943. The fix is to either upgrade MySQL to at least version 3.23.34 or, after
  11944. running `configure', remove the line `#define HAVE_REALPATH' from
  11945. `config.h' before running `make'.
  11946.  
  11947. Note that this means that you can't symbolically link a database
  11948. directories to another database directory or symbolic link a table to
  11949. another database on BSDI.  (Making a symbolic link to another disk is
  11950. okay).
  11951.  
  11952. Other Unix Notes
  11953. ----------------
  11954.  
  11955. HP-UX Version 10.20 Notes
  11956. .........................
  11957.  
  11958. There are a couple of small problems when compiling MySQL on HP-UX.  We
  11959. recommend that you use `gcc' instead of the HP-UX native compiler,
  11960. because `gcc' produces better code.
  11961.  
  11962. We recommend using `gcc' 2.95 on HP-UX.  Don't use high optimization
  11963. flags (such as `-O6') because they may not be safe on HP-UX.
  11964.  
  11965. The following `configure' line should work with `gcc' 2.95:
  11966.  
  11967.      CFLAGS="-I/opt/dce/include -fpic" \
  11968.      CXXFLAGS="-I/opt/dce/include -felide-constructors -fno-exceptions \
  11969.      -fno-rtti" \
  11970.      CXX=gcc \
  11971.      ./configure --with-pthread \
  11972.          --with-named-thread-libs='-ldce' \
  11973.          --prefix=/usr/local/mysql --disable-shared
  11974.  
  11975. The following `configure' line should work with `gcc' 3.1:
  11976.  
  11977.      CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc \
  11978.      CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors \
  11979.          -fno-exceptions -fno-rtti -O3 -fPIC" \
  11980.      ./configure --prefix=/usr/local/mysql \
  11981.          --with-extra-charsets=complex --enable-thread-safe-client \
  11982.          --enable-local-infile  --with-pthread \
  11983.          --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  11984.          --disable-shared
  11985.  
  11986. HP-UX Version 11.x Notes
  11987. ........................
  11988.  
  11989. For HP-UX Version 11.x, we recommend MySQL 3.23.15 or later.
  11990.  
  11991. Because of some critical bugs in the standard HP-UX libraries, you
  11992. should install the following patches before trying to run MySQL on
  11993. HP-UX 11.0:
  11994.  
  11995.      PHKL_22840 Streams cumulative
  11996.      PHNE_22397 ARPA cumulative
  11997.  
  11998. This will solve the problem of getting `EWOULDBLOCK' from `recv()' and
  11999. `EBADF' from `accept()' in threaded applications.
  12000.  
  12001. If you are using `gcc' 2.95.1 on an unpatched HP-UX 11.x system, you
  12002. will get the error:
  12003.  
  12004.      In file included from /usr/include/unistd.h:11,
  12005.                       from ../include/global.h:125,
  12006.                       from mysql_priv.h:15,
  12007.                       from item.cc:19:
  12008.      /usr/include/sys/unistd.h:184: declaration of C function ...
  12009.      /usr/include/sys/pthread.h:440: previous declaration ...
  12010.      In file included from item.h:306,
  12011.                       from mysql_priv.h:158,
  12012.                       from item.cc:19:
  12013.  
  12014. The problem is that HP-UX doesn't define `pthreads_atfork()'
  12015. consistently.  It has conflicting prototypes in
  12016. `/usr/include/sys/unistd.h':184 and `/usr/include/sys/pthread.h':440.
  12017.  
  12018. One solution is to copy `/usr/include/sys/unistd.h' into
  12019. `mysql/include' and edit `unistd.h' and change it to match the
  12020. definition in `pthread.h'.  Look for this line:
  12021.  
  12022.      extern int pthread_atfork(void (*prepare)(), void (*parent)(),
  12023.                                                void (*child)());
  12024.  
  12025. Change it to look like this:
  12026.  
  12027.      extern int pthread_atfork(void (*prepare)(void), void (*parent)(void),
  12028.                                                void (*child)(void));
  12029.  
  12030. After making the change, the following `configure' line should work:
  12031.  
  12032.      CFLAGS="-fomit-frame-pointer -O3 -fpic" CXX=gcc \
  12033.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -O3" \
  12034.      ./configure --prefix=/usr/local/mysql --disable-shared
  12035.  
  12036. If you are using MySQL 4.0.5 with the HP-UX compiler, you can use the
  12037. following command (which has been tested with `cc' B.11.11.04):
  12038.  
  12039.      CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure \
  12040.          --with-extra-character-set=complex
  12041.  
  12042. You can ignore any errors of the following type:
  12043.  
  12044.      aCC: warning 901: unknown option: `-3': use +help for online
  12045.      documentation
  12046.  
  12047. If you get the following error from `configure', verify that you don't
  12048. have the path to the K&R compiler before the path to the HP-UX C and
  12049. C++ compiler:
  12050.  
  12051.      checking for cc option to accept ANSI C... no
  12052.      configure: error: MySQL requires an ANSI C compiler (and a C++ compiler).
  12053.      Try gcc. See the Installation chapter in the Reference Manual.
  12054.  
  12055. Another reason for not being able to compile is that you didn't define
  12056. the `+DD64' flags as just described.
  12057.  
  12058. Another possibility for HP-UX 11 is to use MySQL binaries for HP-UX
  12059. 10.20.  We have received reports from some users that these binaries
  12060. work fine on HP-UX 11.00. If you encounter problems, be sure to check
  12061. your HP-UX patch level.
  12062.  
  12063. IBM-AIX notes
  12064. .............
  12065.  
  12066. Automatic detection of `xlC' is missing from Autoconf, so a number of
  12067. variables need to be set before running `configure'. The following
  12068. example uses the IBM compiler:
  12069.  
  12070.      export CC="xlc_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192 "
  12071.      export CXX="xlC_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192"
  12072.      export CFLAGS="-I /usr/local/include"
  12073.      export LDFLAGS="-L /usr/local/lib"
  12074.      export CPPFLAGS=$CFLAGS
  12075.      export CXXFLAGS=$CFLAGS
  12076.      
  12077.      ./configure --prefix=/usr/local \
  12078.                      --localstatedir=/var/mysql \
  12079.                      --sysconfdir=/etc/mysql \
  12080.                      --sbindir='/usr/local/bin' \
  12081.                      --libexecdir='/usr/local/bin' \
  12082.                      --enable-thread-safe-client \
  12083.                      --enable-large-files
  12084.  
  12085. The preceding options are used to compile the MySQL distribution that
  12086. can be found at `http://www-frec.bull.com/'.
  12087.  
  12088. If you change the `-O3' to `-O2' in the preceding `configure' line, you
  12089. must also remove the `-qstrict' option. This is a limitation in the IBM
  12090. C compiler.
  12091.  
  12092. If you are using `gcc' or `egcs' to compile MySQL, you _must_ use the
  12093. `-fno-exceptions' flag, because the exception handling in `gcc'/`egcs'
  12094. is not thread-safe!  (This is tested with `egcs' 1.1.)  There are also
  12095. some known problems with IBM's assembler that may cause it to generate
  12096. bad code when used with `gcc'.
  12097.  
  12098. We recommend the following `configure' line with `egcs' and `gcc' 2.95
  12099. on AIX:
  12100.  
  12101.      CC="gcc -pipe -mcpu=power -Wa,-many" \
  12102.      CXX="gcc -pipe -mcpu=power -Wa,-many" \
  12103.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti" \
  12104.      ./configure --prefix=/usr/local/mysql --with-low-memory
  12105.  
  12106. The `-Wa,-many' option is necessary for the compile to be successful.
  12107. IBM is aware of this problem but is in no hurry to fix it because of the
  12108. workaround that is available.  We don't know if the `-fno-exceptions'
  12109. is required with `gcc' 2.95, but because MySQL doesn't use exceptions
  12110. and the option generates faster code, we recommend that you should
  12111. always use it with `egcs' / `gcc'.
  12112.  
  12113. If you get a problem with assembler code, try changing the `-mcpu=XXX'
  12114. option to match your CPU. Typically `power2', `power', or `powerpc' may
  12115. need to be used.  Alternatively, you might need to use `604' or `604e'.
  12116. We are not positive but suspect that `power' would likely be safe most
  12117. of the time, even on a power2 machine.
  12118.  
  12119. If you don't know what your CPU is, execute a `uname -m' command.  It
  12120. will produce a string that looks like `000514676700', with a format of
  12121. `xxyyyyyymmss' where `xx' and `ss' are always `00', `yyyyyy' is a
  12122. unique system ID and `mm' is the ID of the CPU Planar.  A chart of
  12123. these values can be found at
  12124. `http://publib.boulder.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/uname.htm'.
  12125. This will give you a machine type and a machine model you can use to
  12126. determine what type of CPU you have.
  12127.  
  12128. If you have problems with signals (MySQL dies unexpectedly under high
  12129. load), you may have found an OS bug with threads and signals.  In this
  12130. case, you can tell MySQL not to use signals by configuring as follows:
  12131.  
  12132.      CFLAGS=-DDONT_USE_THR_ALARM CXX=gcc \
  12133.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti \
  12134.      -DDONT_USE_THR_ALARM" \
  12135.      ./configure --prefix=/usr/local/mysql --with-debug \
  12136.          --with-low-memory
  12137.  
  12138. This doesn't affect the performance of MySQL, but has the side effect
  12139. that you can't kill clients that are "sleeping" on a connection with
  12140. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  12141. die when it issues its next command.
  12142.  
  12143. On some versions of AIX, linking with `libbind.a' makes
  12144. `getservbyname()' dump core.  This is an AIX bug and should be reported
  12145. to IBM.
  12146.  
  12147. For AIX 4.2.1 and `gcc', you have to make the following changes.
  12148.  
  12149. After configuring, edit `config.h' and `include/my_config.h' and change
  12150. the line that says this:
  12151.  
  12152.      #define HAVE_SNPRINTF 1
  12153.  
  12154. to this:
  12155.  
  12156.      #undef HAVE_SNPRINTF
  12157.  
  12158. And finally, in `mysqld.cc', you need to add a prototype for
  12159. `initgroups()'.
  12160.  
  12161.      #ifdef _AIX41
  12162.      extern "C" int initgroups(const char *,int);
  12163.      #endif
  12164.  
  12165. If you need to allocate a lot of memory to the `mysqld' process, it's
  12166. not enough to just use `ulimit -d unlimited'. You may also have to
  12167. modify `mysqld_safe' to add a line something like this:
  12168.  
  12169.      export LDR_CNTRL='MAXDATA=0x80000000'
  12170.  
  12171. You can find more information about using a lot of memory at
  12172. `http://publib16.boulder.ibm.com/pseries/en_US/aixprggd/genprogc/lrg_prg_support.htm'.
  12173.  
  12174. SunOS 4 Notes
  12175. .............
  12176.  
  12177. On SunOS 4, MIT-pthreads is needed to compile MySQL. This in turn means
  12178. you will need GNU `make'.
  12179.  
  12180. Some SunOS 4 systems have problems with dynamic libraries and `libtool'.
  12181. You can use the following `configure' line to avoid this problem:
  12182.  
  12183.      ./configure --disable-shared --with-mysqld-ldflags=-all-static
  12184.  
  12185. When compiling `readline', you may get warnings about duplicate defines.
  12186. These can be ignored.
  12187.  
  12188. When compiling `mysqld', there will be some `implicit declaration of
  12189. function' warnings. These can be ignored.
  12190.  
  12191. Alpha-DEC-UNIX Notes (Tru64)
  12192. ............................
  12193.  
  12194. If you are using `egcs' 1.1.2 on Digital Unix, you should upgrade to
  12195. `gcc' 2.95.2, because `egcs' on DEC has some serious bugs!
  12196.  
  12197. When compiling threaded programs under Digital Unix, the documentation
  12198. recommends using the `-pthread' option for `cc' and `cxx' and the
  12199. `-lmach -lexc' libraries (in addition to `-lpthread').  You should run
  12200. `configure' something like this:
  12201.  
  12202.      CC="cc -pthread" CXX="cxx -pthread -O" \
  12203.      ./configure --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  12204.  
  12205. When compiling `mysqld', you may see a couple of warnings like this:
  12206.  
  12207.      mysqld.cc: In function void handle_connections()':
  12208.      mysqld.cc:626: passing long unsigned int *' as argument 3 of
  12209.      accept(int,sockadddr *, int *)'
  12210.  
  12211. You can safely ignore these warnings.  They occur because `configure'
  12212. can detect only errors, not warnings.
  12213.  
  12214. If you start the server directly from the command line, you may have
  12215. problems with it dying when you log out.  (When you log out, your
  12216. outstanding processes receive a `SIGHUP' signal.)  If so, try starting
  12217. the server like this:
  12218.  
  12219.      nohup mysqld [OPTIONS] &
  12220.  
  12221. `nohup' causes the command following it to ignore any `SIGHUP' signal
  12222. sent from the terminal.  Alternatively, start the server by running
  12223. `mysqld_safe', which invokes `mysqld' using `nohup' for you.  *Note
  12224. `mysqld_safe': mysqld_safe.
  12225.  
  12226. If you get a problem when compiling `mysys/get_opt.c', just remove the
  12227. `#define _NO_PROTO' line from the start of that file.
  12228.  
  12229. If you are using Compaq's CC compiler, the following `configure' line
  12230. should work:
  12231.  
  12232.      CC="cc -pthread"
  12233.      CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
  12234.      CXX="cxx -pthread"
  12235.      CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all \
  12236.          -arch host -noexceptions -nortti"
  12237.      export CC CFLAGS CXX CXXFLAGS
  12238.      ./configure \
  12239.          --prefix=/usr/local/mysql \
  12240.          --with-low-memory \
  12241.          --enable-large-files \
  12242.          --enable-shared=yes \
  12243.          --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  12244.      gnumake
  12245.  
  12246. If you get a problem with `libtool' when compiling with shared libraries
  12247. as just shown, when linking `mysql', you should be able to get around
  12248. this by issuing these commands:
  12249.  
  12250.      cd mysql
  12251.      /bin/sh ../libtool --mode=link cxx -pthread  -O3 -DDBUG_OFF \
  12252.          -O4 -ansi_alias -ansi_args -fast -inline speed \
  12253.          -speculate all \ -arch host  -DUNDEF_HAVE_GETHOSTBYNAME_R \
  12254.          -o mysql  mysql.o readline.o sql_string.o completion_hash.o \
  12255.          ../readline/libreadline.a -lcurses \
  12256.          ../libmysql/.libs/libmysqlclient.so  -lm
  12257.      cd ..
  12258.      gnumake
  12259.      gnumake install
  12260.      scripts/mysql_install_db
  12261.  
  12262. Alpha-DEC-OSF/1 Notes
  12263. .....................
  12264.  
  12265. If you have problems compiling and have DEC `CC' and `gcc' installed,
  12266. try running `configure' like this:
  12267.  
  12268.      CC=cc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 \
  12269.      ./configure --prefix=/usr/local/mysql
  12270.  
  12271. If you get problems with the `c_asm.h' file, you can create and use a
  12272. 'dummy' `c_asm.h' file with:
  12273.  
  12274.      touch include/c_asm.h
  12275.      CC=gcc CFLAGS=-I./include \
  12276.      CXX=gcc CXXFLAGS=-O3 \
  12277.      ./configure --prefix=/usr/local/mysql
  12278.  
  12279. Note that the following problems with the `ld' program can be fixed by
  12280. downloading the latest DEC (Compaq) patch kit from:
  12281. `http://ftp.support.compaq.com/public/unix/'.
  12282.  
  12283. On OSF/1 V4.0D and compiler "DEC C V5.6-071 on Digital Unix V4.0 (Rev.
  12284. 878)," the compiler had some strange behavior (undefined `asm' symbols).
  12285. `/bin/ld' also appears to be broken (problems with `_exit undefined'
  12286. errors occurring while linking `mysqld').  On this system, we have
  12287. managed to compile MySQL with the following `configure' line, after
  12288. replacing `/bin/ld' with the version from OSF 4.0C:
  12289.  
  12290.      CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  12291.  
  12292. With the Digital compiler "C++ V6.1-029," the following should work:
  12293.  
  12294.      CC=cc -pthread
  12295.      CFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed \
  12296.             -speculate all -arch host
  12297.      CXX=cxx -pthread
  12298.      CXXFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed \
  12299.               -speculate all -arch host -noexceptions -nortti
  12300.      export CC CFLAGS CXX CXXFLAGS
  12301.      ./configure --prefix=/usr/mysql/mysql \
  12302.                  --with-mysqld-ldflags=-all-static --disable-shared \
  12303.                  --with-named-thread-libs="-lmach -lexc -lc"
  12304.  
  12305. In some versions of OSF/1, the `alloca()' function is broken. Fix this
  12306. by removing the line in `config.h' that defines `'HAVE_ALLOCA''.
  12307.  
  12308. The `alloca()' function also may have an incorrect prototype in
  12309. `/usr/include/alloca.h'.  This warning resulting from this can be
  12310. ignored.
  12311.  
  12312. `configure' will use the following thread libraries automatically:
  12313. `--with-named-thread-libs="-lpthread -lmach -lexc -lc"'.
  12314.  
  12315. When using `gcc', you can also try running `configure' like this:
  12316.  
  12317.      CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-O3 ./configure ...
  12318.  
  12319. If you have problems with signals (MySQL dies unexpectedly under high
  12320. load), you may have found an OS bug with threads and signals. In this
  12321. case, you can tell MySQL not to use signals by configuring with:
  12322.  
  12323.      CFLAGS=-DDONT_USE_THR_ALARM \
  12324.      CXXFLAGS=-DDONT_USE_THR_ALARM \
  12325.      ./configure ...
  12326.  
  12327. This doesn't affect the performance of MySQL, but has the side effect
  12328. that you can't kill clients that are "sleeping" on a connection with
  12329. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  12330. die when it issues its next command.
  12331.  
  12332. With `gcc' 2.95.2, you will probably run into the following compile
  12333. error:
  12334.  
  12335.      sql_acl.cc:1456: Internal compiler error in `scan_region',
  12336.      at except.c:2566
  12337.      Please submit a full bug report.
  12338.  
  12339. To fix this, you should change to the `sql' directory and do a
  12340. cut-and-paste of the last `gcc' line, but change `-O3' to `-O0' (or add
  12341. `-O0' immediately after `gcc' if you don't have any `-O' option on your
  12342. compile line).  After this is done, you can just change back to the
  12343. top-level directory and run `make' again.
  12344.  
  12345. SGI Irix Notes
  12346. ..............
  12347.  
  12348. If you are using Irix Version 6.5.3 or newer, `mysqld' will be able to
  12349. create threads only if you run it as a user that has `CAP_SCHED_MGT'
  12350. privileges (such as `root') or give the `mysqld' server this privilege
  12351. with the following shell command:
  12352.  
  12353.      chcap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld
  12354.  
  12355. You may have to undefine some symbols in `config.h' after running
  12356. `configure' and before compiling.
  12357.  
  12358. In some Irix implementations, the `alloca()' function is broken.  If the
  12359. `mysqld' server dies on some `SELECT' statements, remove the lines from
  12360. `config.h' that define `HAVE_ALLOC' and `HAVE_ALLOCA_H'.  If
  12361. `mysqladmin create' doesn't work, remove the line from `config.h' that
  12362. defines `HAVE_READDIR_R'.  You may have to remove the `HAVE_TERM_H'
  12363. line as well.
  12364.  
  12365. SGI recommends that you install all the patches on this page as a set:
  12366. `http://support.sgi.com/surfzone/patches/patchset/6.2_indigo.rps.html'
  12367.  
  12368. At the very minimum, you should install the latest kernel rollup, the
  12369. latest `rld' rollup, and the latest `libc' rollup.
  12370.  
  12371. You definitely need all the POSIX patches on this page, for pthreads
  12372. support:
  12373.  
  12374. `http://support.sgi.com/surfzone/patches/patchset/6.2_posix.rps.html'
  12375.  
  12376. If you get the something like the following error when compiling
  12377. `mysql.cc':
  12378.  
  12379.      "/usr/include/curses.h", line 82: error(1084):
  12380.      invalid combination of type
  12381.  
  12382. Type the following in the top-level directory of your MySQL source tree:
  12383.  
  12384.      extra/replace bool curses_bool < /usr/include/curses.h > include/curses.h
  12385.      make
  12386.  
  12387. There have also been reports of scheduling problems.  If only one
  12388. thread is running, performance is slow.  Avoid this by starting another
  12389. client.  This may lead to a two-to-tenfold increase in execution speed
  12390. thereafter for the other thread.  This is a poorly understood problem
  12391. with Irix threads; you may have to improvise to find solutions until
  12392. this can be fixed.
  12393.  
  12394. If you are compiling with `gcc', you can use the following `configure'
  12395. command:
  12396.  
  12397.      CC=gcc CXX=gcc CXXFLAGS=-O3 \
  12398.      ./configure --prefix=/usr/local/mysql --enable-thread-safe-client \
  12399.          --with-named-thread-libs=-lpthread
  12400.  
  12401. On Irix 6.5.11 with native Irix C and C++ compilers ver. 7.3.1.2, the
  12402. following is reported to work
  12403.  
  12404.      CC=cc CXX=CC CFLAGS='-O3 -n32 -TARG:platform=IP22 -I/usr/local/include \
  12405.      -L/usr/local/lib' CXXFLAGS='-O3 -n32 -TARG:platform=IP22 \
  12406.      -I/usr/local/include -L/usr/local/lib' \
  12407.      ./configure --prefix=/usr/local/mysql --with-innodb --with-berkeley-db \
  12408.          --with-libwrap=/usr/local \
  12409.          --with-named-curses-libs=/usr/local/lib/libncurses.a
  12410.  
  12411. SCO Notes
  12412. .........
  12413.  
  12414. The current port is tested only on "sco3.2v5.0.5," "sco3.2v5.0.6," and
  12415. "sco3.2v5.0.7" systems. There has also been a lot of progress on a port
  12416. to "sco 3.2v4.2."  Open Server 5.0.8(Legend) will have native threads
  12417. and allow files greater than 2GB.  The current maximum file size is 2GB.
  12418.  
  12419. We have been able to compile MySQL with the following `configure'
  12420. command on on OpenServer with `gcc' 2.95.3.
  12421.  
  12422.      CC=gcc CXX=gcc ./configure --prefix=/usr/local/mysql \
  12423.          --enable-thread-safe-client --with-innodb \
  12424.          --with-openssl --with-vio --with-extra-charsets=complex
  12425.  
  12426. `gcc' is available at
  12427. `ftp://ftp.sco.com/pub/openserver5/opensrc/gnutools-5.0.7Kj'.
  12428.  
  12429. This development system requires the OpenServer Execution Enviroment
  12430. Supplement oss646B on OpenServer 5.0.6 and oss656B and The OpenSource
  12431. libraries found in gwxlibs.  All OpenSource tools are in the `opensrc'
  12432. directory.  They are available at
  12433. `ftp://ftp.sco.com/pub/openserver5/opensrc/'.
  12434.  
  12435. We recommend using the latest production release of MySQL.  Currently
  12436. MySQL-4.0.x is the latest production release.  There were some problems
  12437. with MySQL 4.0.17 and MySQL 4.0.18, but they have now been fixed.
  12438.  
  12439. SCO provides operating system patches at
  12440. `ftp://ftp.sco.com/pub/openserver5' for OpenServer 5.0.[0-6] and
  12441. `ftp://ftp.sco.com/pub/openserverv5/507' for OpenServer 5.0.7.
  12442.  
  12443. SCO provides information about security fixes at
  12444. `ftp://ftp.sco.com/pub/security/OpenServer' for OpenServer 5.0.x.
  12445.  
  12446. The maximum file size on an OpenSever 5.0.x system is 2GB.
  12447.  
  12448. The total memory which could be allocated for streams buffers, clists
  12449. and lock records cannot exceed 60MB on OpenServer 5.0.x.
  12450.  
  12451. Streams buffers are allocated in units of 4096 byte pages, clists are 70
  12452. bytes each, and lock records are 64 bytes each, so:
  12453.  
  12454.      (NSTRPAGES * 4096) + (NCLIST * 70) + (MAX_FLCKREC * 64) <= 62914560
  12455.  
  12456. Follow this procedure to configure the Database Services option. If you
  12457. are unsure whether an application requires this, see the documentation
  12458. provided with the application.
  12459.  
  12460.   1. Log in as `root'.
  12461.  
  12462.   2. Enable the SUDS driver by editing the `/etc/conf/sdevice.d/suds'
  12463.      file.  Change the `N' in the second field to a `Y'.
  12464.  
  12465.   3. Use `mkdev aio' or the Hardware/Kernel Manager to enable support
  12466.      for asynchronous I/O and relink the kernel. To allow users to lock
  12467.      down memory for use with this type of I/O, update the
  12468.      aiomemlock(F) file. This file should be updated to include the
  12469.      names of users that can use AIO and the maximum amounts of memory
  12470.      they can lock down.
  12471.  
  12472.   4. Many applications use setuid binaries so that you need to specify
  12473.      only a single user. See the documentation provided with the
  12474.      application to see if this is the case for your application.
  12475.  
  12476. After you complete this process, reboot the system to create a new
  12477. kernel incorporating these changes.
  12478.  
  12479. By default, the entries in `/etc/conf/cf.d/mtune' are set as follows:
  12480.  
  12481.      Value           Default         Min             Max
  12482.      -----           -------         ---             ---
  12483.      NBUF            0               24              450000
  12484.      NHBUF           0               32              524288
  12485.      NMPBUF          0               12              512
  12486.      MAX_INODE       0               100             64000
  12487.      MAX_FILE        0               100             64000
  12488.      CTBUFSIZE       128             0               256
  12489.      MAX_PROC        0               50              16000
  12490.      MAX_REGION      0               500             160000
  12491.      NCLIST          170             120             16640
  12492.      MAXUP           100             15              16000
  12493.      NOFILES         110             60              11000
  12494.      NHINODE         128             64              8192
  12495.      NAUTOUP         10              0               60
  12496.      NGROUPS         8               0               128
  12497.      BDFLUSHR        30              1               300
  12498.      MAX_FLCKREC     0               50              16000
  12499.      PUTBUFSZ        8000            2000            20000
  12500.      MAXSLICE        100             25              100
  12501.      ULIMIT          4194303         2048            4194303
  12502.      * Streams Parameters
  12503.      NSTREAM         64              1               32768
  12504.      NSTRPUSH        9               9               9
  12505.      NMUXLINK        192             1               4096
  12506.      STRMSGSZ        16384           4096            524288
  12507.      STRCTLSZ        1024            1024            1024
  12508.      STRMAXBLK       524288          4096            524288
  12509.      NSTRPAGES       500             0               8000
  12510.      STRSPLITFRAC    80              50              100
  12511.      NLOG            3               3               3
  12512.      NUMSP           64              1               256
  12513.      NUMTIM          16              1               8192
  12514.      NUMTRW          16              1               8192
  12515.      * Semaphore Parameters
  12516.      SEMMAP          10              10              8192
  12517.      SEMMNI          10              10              8192
  12518.      SEMMNS          60              60              8192
  12519.      SEMMNU          30              10              8192
  12520.      SEMMSL          25              25              150
  12521.      SEMOPM          10              10              1024
  12522.      SEMUME          10              10              25
  12523.      SEMVMX          32767           32767           32767
  12524.      SEMAEM          16384           16384           16384
  12525.      * Shared Memory Parameters
  12526.      SHMMAX          524288          131072          2147483647
  12527.      SHMMIN          1               1               1
  12528.      SHMMNI          100             100             2000
  12529.      FILE            0               100             64000
  12530.      NMOUNT          0               4               256
  12531.      NPROC           0               50              16000
  12532.      NREGION         0               500             160000
  12533.  
  12534. We recommend setting these values as follows:
  12535.  
  12536. `NOFILES' should be 4096 or 2048.
  12537.  
  12538. `MAXUP' should be 2048.
  12539.  
  12540. To make changes to the kernel, `cd' to `/etc/conf/bin' and use
  12541. `./idtune' NAME PARAMETER to make the changes. For example, to change
  12542. `SEMMS' to `200', execute these commands as `root':
  12543.  
  12544.      # cd /etc/conf/bin
  12545.      # ./idtune SEMMNS 200
  12546.  
  12547. We recommend tuning the system, but the proper parameter values to use
  12548. depend on the number of users accessing the application or database and
  12549. size the of the database (that is, the used buffer pool). The following
  12550. will affect the following kernel parameters defined in
  12551. `/etc/conf/cf.d/stune':
  12552.  
  12553. `SHMMAX' (recommended setting: 128MB) and `SHMSEG' (recommended
  12554. setting: 15).  These parameters have influence on the MySQL database
  12555. engine to create user buffer pools.
  12556.  
  12557. `NOFILES' and `MAXUP' should be at to at least 2048.
  12558.  
  12559. `MAXPROC' should be set to at least 3000/4000 (depends on number of
  12560. users) or more.
  12561.  
  12562. Also is recommended to use following formula to count value for
  12563. `SEMMSL', `SEMMNS' and `SEMMNU':
  12564.  
  12565.      SEMMSL = 13
  12566.  
  12567. The 13 is what has been found to be the best for both Progress and
  12568. MySQL.
  12569.  
  12570. `SEMMNS' = `SEMMSL' * number of db servers to be run on the system.
  12571.  
  12572. Set `SEMMNS' to the value of `SEMMSL' multiplied by the number of db
  12573. servers (maximum) that you will be running on the system at one time.
  12574.  
  12575.      SEMMNU = SEMMNS
  12576.  
  12577. Set the value of `SEMMNU' to equal the value of `SEMMNS'. You could
  12578. probably set this to 75% of `SEMMNS', but this is a conservative
  12579. estimate.
  12580.  
  12581. You need to at least install the "SCO OpenServer Linker and Application
  12582. Development Libraries" or the OpenServer Development System to use
  12583. `gcc'.  You cannot just use the GCC Dev system without installing one
  12584. of these.
  12585.  
  12586. You should get the FSU Pthreads package and install it first. This can
  12587. be found at
  12588. `http://moss.csc.ncsu.edu/~mueller/ftp/pub/PART/pthreads.tar.gz'.  You
  12589. can also get a precompiled package from
  12590. `ftp://ftp.zenez.com/pub/zenez/prgms/FSU-threads-3.14.tar.gz'.
  12591.  
  12592. FSU Pthreads can be compiled with SCO Unix 4.2 with tcpip, or using
  12593. OpenServer 3.0 or Open Desktop 3.0 (OS 3.0 ODT 3.0) with the SCO
  12594. Development System installed using a good port of GCC 2.5.x. For ODT or
  12595. OS 3.0, you will need a good port of GCC 2.5.x. There are a lot of
  12596. problems without a good port. The port for this product requires the
  12597. SCO Unix Development system. Without it, you are missing the libraries
  12598. and the linker that is needed.  You will also need
  12599. `SCO-3.2v4.2-includes.tar.gz'. This file contains the changes to the
  12600. SCO Development include files that are needed to get MySQL to build.
  12601. You need to replace the existing system include files with these
  12602. modified header files.  They can be obtained from
  12603. `ftp://ftp.zenez.com/pub/zenez/prgms/SCO-3.2v4.2-includes.tar.gz'.
  12604.  
  12605. To build FSU Pthreads on your system, all you should need to do is run
  12606. GNU `make'.  The `Makefile' in FSU-threads-3.14.tar.gz is already set
  12607. up to make FSU-threads.
  12608.  
  12609. You can run `./configure' in the `threads/src' directory and select the
  12610. SCO OpenServer option. This command copies `Makefile.SCO5' to
  12611. `Makefile'.  Then run `make'.
  12612.  
  12613. To install in the default `/usr/include' directory, log in as `root',
  12614. then `cd' to the `thread/src' directory and run `make install'.
  12615.  
  12616. Remember that you must use GNU `make' when making MySQL.
  12617.  
  12618. *Note*: If you don't start `mysqld_safe' as `root', you probably will
  12619. get only the default 110 open files per process. `mysqld' will write a
  12620. note about this in the log file.
  12621.  
  12622. With SCO 3.2V4.2, you should use FSU Pthreads version 3.14 or newer.
  12623. The following `configure' command should work:
  12624.  
  12625.      CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
  12626.      ./configure \
  12627.          --prefix=/usr/local/mysql \
  12628.          --with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \
  12629.          --with-named-curses-libs="-lcurses"
  12630.  
  12631. You may get some problems with some include files. In this case, you can
  12632. find new SCO-specific include files at
  12633. `ftp://ftp.zenez.com/pub/zenez/prgms/SCO-3.2v4.2-includes.tar.gz'.
  12634.  
  12635. You should unpack this file in the `include' directory of your MySQL
  12636. source tree.
  12637.  
  12638. SCO development notes:
  12639.  
  12640.    bullet MySQL should automatically detect FSU Pthreads and link
  12641.      `mysqld' with `-lgthreads -lsocket -lgthreads'.
  12642.  
  12643.    bullet The SCO development libraries are re-entrant in FSU Pthreads.
  12644.      SCO claims that its library functions are re-entrant, so they must
  12645.      be re-entrant with FSU Pthreads. FSU Pthreads on OpenServer tries
  12646.      to use the SCO scheme to make re-entrant libraries.
  12647.  
  12648.    bullet FSU Pthreads (at least the version at `ftp::/ftp.zenez.com')
  12649.      comes linked with GNU `malloc'. If you encounter problems with
  12650.      memory usage, make sure that `gmalloc.o' is included in
  12651.      `libgthreads.a' and `libgthreads.so'.
  12652.  
  12653.    bullet In FSU Pthreads, the following system calls are
  12654.      pthreads-aware: `read()', `write()', `getmsg()', `connect()',
  12655.      `accept(),' `select()', and `wait()'.
  12656.  
  12657.    bullet The CSSA-2001-SCO.35.2 (the patch is listed in custom as
  12658.      erg711905-dscr_remap security patch (version 2.0.0)) breaks FSU
  12659.      threads and makes `mysqld' unstable. You have to remove this one
  12660.      if you want to run `mysqld' on an OpenServer 5.0.6 machine.
  12661.  
  12662.    bullet SCO provides operating system patches at
  12663.      `ftp://ftp.sco.com/pub/openserver5' for OpenServer 5.0.x.
  12664.  
  12665.    bullet SCO provides security fixes and `libsocket.so.2' at
  12666.      `ftp://ftp.sco.com/pub/security/OpenServer' and
  12667.      `ftp://ftp.sco.com/pub/security/sse' for OpenServer 5.0.x.
  12668.  
  12669.    bullet Pre-OSR506 security fixes. Also, the `telnetd' fix at
  12670.      `ftp://stage.caldera.com/pub/security/openserver/' or
  12671.      `ftp://stage.caldera.com/pub/security/openserver/CSSA-2001-SCO.10/'
  12672.      as both `libsocket.so.2' and `libresolv.so.1' with instructions for
  12673.      installing on pre-OSR506 systems.
  12674.  
  12675.      It's probably a good idea to install these patches before trying
  12676.      to compile/use MySQL.
  12677.  
  12678.  
  12679. Begining with Legend, OpenServer will have native threads and no 2GB
  12680. file size limit.
  12681.  
  12682. SCO UnixWare Version 7.1.x Notes
  12683. ................................
  12684.  
  12685. We recommend using the latest production release of MySQL.  Currently
  12686. this is MySQL 4.0.x.  Should you choose to use an older release of
  12687. MySQL on UnixWare 7.1.x, you must use a version of MySQL at least as
  12688. recent as 3.22.13 to get fixes for some portability and OS problems.
  12689.  
  12690. We have been able to compile MySQL with the following `configure'
  12691. command on UnixWare Version 7.1.x:
  12692.  
  12693.      CC="cc" CFLAGS="-I/usr/local/include" \
  12694.      CXX="CC" CXXFLAGS="-I/usr/local/include" \
  12695.      ./configure --prefix=/usr/local/mysql \
  12696.          --enable-thread-safe-client --with-berkeley-db=./bdb \
  12697.          --with-innodb --with-openssl --with-extra-charsets=complex
  12698.  
  12699. If you want to use `gcc', you must use `gcc' 2.95.3 or newer.
  12700.  
  12701.      CC=gcc CXX=g++ ./configure --prefix=/usr/local/mysql
  12702.  
  12703. SCO provides operating system patches at
  12704. `ftp://ftp.sco.com/pub/unixware7' for UnixWare 7.1.1,
  12705. `ftp://ftp.sco.com/pub/unixware7/713/' for UnixWare 7.1.3,
  12706. `ftp://ftp.sco.com/pub/unixware7/714/' for UnixWare 7.1.4, and
  12707. `ftp://ftp.sco.com/pub/openunix8' for OpenUNIX 8.0.0.
  12708.  
  12709. SCO provides information about security fixes at
  12710. `ftp://ftp.sco.com/pub/security/OpenUNIX' for OpenUNIX and
  12711. `ftp://ftp.sco.com/pub/security/UnixWare' for UnixWare.
  12712.  
  12713. By default, the maximum file size on a UnixWare 7 system is 1GB.  Many
  12714. OS utilities have a limitation of 2GB.  The maximum possible file size
  12715. on UnixWare 7 is 1TB with VXFS.
  12716.  
  12717. To enable large file support on UnixWare 7.1.x, run `fsadm'.
  12718.  
  12719.      # fsadm -Fvxfs -o largefiles /
  12720.      # fsadm /                    * Note
  12721.      # ulimit unlimited
  12722.      # cd /etc/conf/bin
  12723.      # ./idtune SFSZLIM 0x7FFFFFFF            ** Note
  12724.      # ./idtune HFSZLIM 0x7FFFFFFF            ** Note
  12725.      # ./idbuild -B
  12726.      
  12727.      * This should report "largefiles".
  12728.      ** 0x7FFFFFFF represents infinity for these values.
  12729.  
  12730. Reboot the system using `shutdown'.
  12731.  
  12732. By default, the entries in `/etc/conf/cf.d/mtune' are set to:
  12733.  
  12734.      Value           Default         Min             Max
  12735.      -----           -------         ---             ---
  12736.      SVMMLIM         0x9000000       0x1000000       0x7FFFFFFF
  12737.      HVMMLIM         0x9000000       0x1000000       0x7FFFFFFF
  12738.      SSTKLIM         0x1000000       0x2000          0x7FFFFFFF
  12739.      HSTKLIM         0x1000000       0x2000          0x7FFFFFFF
  12740.  
  12741. We recommend setting these values as follows:
  12742.  
  12743.      SDATLIM 0x7FFFFFFF
  12744.      HDATLIM 0x7FFFFFFF
  12745.      SSTKLIM 0x7FFFFFFF
  12746.      HSTKLIM 0x7FFFFFFF
  12747.      SVMMLIM 0x7FFFFFFF
  12748.      HVMMLIM 0x7FFFFFFF
  12749.      SFNOLIM 2048
  12750.      HFNOLIM 2048
  12751.  
  12752. We recommend tuning the system, but the proper parameter values to use
  12753. depend on the number of users accessing the application or database and
  12754. size the of the database (that is, the used buffer pool). The following
  12755. will affect the following kernel parameters defined in
  12756. `/etc/conf/cf.d/stune':
  12757.  
  12758. `SHMMAX' (recommended setting: 128MB) and `SHMSEG' (recommended
  12759. setting: 15).  These parameters have influence on the MySQL database
  12760. engine to create user buffer pools.
  12761.  
  12762. `SFNOLIM' and `HFNOLIM' should be at maximum 2048.
  12763.  
  12764. `NPROC' should be set to at least 3000/4000 (depends on number of
  12765. users).
  12766.  
  12767. Also is recommended to use following formula to count value for
  12768. `SEMMSL', `SEMMNS', and `SEMMNU':
  12769.  
  12770.      SEMMSL = 13
  12771.  
  12772. 13 is what has been found to be the best for both Progress and MySQL.
  12773.  
  12774. `SEMMNS' = `SEMMSL' * number of db servers to be run on the system.
  12775.  
  12776. Set `SEMMNS' to the value of `SEMMSL' multiplied by the number of db
  12777. servers (maximum) that you will be running on the system at one time.
  12778.  
  12779. `SEMMNU' = `SEMMNS'
  12780.  
  12781. Set the value of `SEMMNU' to equal the value of `SEMMNS'. You could
  12782. probably set this to 75% of `SEMMNS', but this is a conservative
  12783. estimate.
  12784.  
  12785. OS/2 Notes
  12786. ----------
  12787.  
  12788. MySQL uses quite a few open files. Because of this, you should add
  12789. something like the following to your `CONFIG.SYS' file:
  12790.  
  12791.      SET EMXOPT=-c -n -h1024
  12792.  
  12793. If you don't do this, you will probably run into the following error:
  12794.  
  12795.      File 'XXXX' not found (Errcode: 24)
  12796.  
  12797. When using MySQL with OS/2 Warp 3, FixPack 29 or above is required.
  12798. With OS/2 Warp 4, FixPack 4 or above is required. This is a requirement
  12799. of the Pthreads library.  MySQL must be installed on a partition with a
  12800. type that supports long filenames, such as HPFS, FAT32, and so on.
  12801.  
  12802. The `INSTALL.CMD' script must be run from OS/2's own `CMD.EXE' and may
  12803. not work with replacement shells such as `4OS2.EXE'.
  12804.  
  12805. The `scripts/mysql-install-db' script has been renamed.  It is now
  12806. called `install.cmd' and is a REXX script, which will set up the default
  12807. MySQL security settings and create the WorkPlace Shell icons for MySQL.
  12808.  
  12809. Dynamic module support is compiled in but not fully tested. Dynamic
  12810. modules should be compiled using the Pthreads runtime library.
  12811.  
  12812.      gcc -Zdll -Zmt -Zcrtdll=pthrdrtl -I../include -I../regex -I.. \
  12813.          -o example udf_example.cc -L../lib -lmysqlclient udf_example.def
  12814.      mv example.dll example.udf
  12815.  
  12816. *Note*: Due to limitations in OS/2, UDF module name stems must not
  12817. exceed eight characters. Modules are stored in the `/mysql2/udf'
  12818. directory; the `safe-mysqld.cmd' script will put this directory in the
  12819. `BEGINLIBPATH' environment variable. When using UDF modules, specified
  12820. extensions are ignored--it is assumed to be `.udf'.  For example, in
  12821. Unix, the shared module might be named `example.so' and you would load
  12822. a function from it like this:
  12823.  
  12824.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME 'example.so';
  12825.  
  12826. In OS/2, the module would be named `example.udf', but you would not
  12827. specify the module extension:
  12828.  
  12829.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME 'example';
  12830.  
  12831. BeOS Notes
  12832. ----------
  12833.  
  12834. We have in the past talked with some BeOS developers who have said that
  12835. MySQL is 80% ported to BeOS, but we haven't heard from them in a while.
  12836.  
  12837. Perl Installation Notes
  12838. =======================
  12839.  
  12840. Perl support for MySQL is provided by means of the `DBI'/`DBD' client
  12841. interface. The interface requires Perl Version 5.6.0 or later.  It
  12842. _will not work_ if you have an older version of Perl.
  12843.  
  12844. If you want to use transactions with Perl DBI, you need to have
  12845. `DBD::mysql' version 1.2216 or newer. Version 2.9003 or newer is
  12846. recommended.
  12847.  
  12848. If you are using the MySQL 4.1 client library, you must use
  12849. `DBD::mysql' 2.9003 or newer.
  12850.  
  12851. As of MySQL 3.22.8, Perl support is no longer included with MySQL
  12852. distributions. You can obtain the necessary modules from
  12853. `http://search.cpan.org' for Unix, or by using the ActiveState `ppm'
  12854. program on Windows. The following sections describe how to do this.
  12855.  
  12856. Perl support for MySQL must be installed if you want to run the MySQL
  12857. benchmark scripts.  *Note MySQL Benchmarks::.
  12858.  
  12859. Installing Perl on Unix
  12860. -----------------------
  12861.  
  12862. MySQL Perl support requires that you've installed MySQL client
  12863. programming support (libraries and header files).  Most installation
  12864. methods install the necessary files. However, if you installed MySQL
  12865. from RPM files on Linux, be sure that you've installed the developer
  12866. RPM.  The client programs are in the client RPM, but client programming
  12867. support is in the developer RPM.
  12868.  
  12869. If you want to install Perl support, the files you will need can be
  12870. obtained from the CPAN (Comprehensive Perl Archive Network) at
  12871. `http://search.cpan.org'.
  12872.  
  12873. The easiest way to install Perl modules on Unix is to use the `CPAN'
  12874. module. For example:
  12875.  
  12876.      shell> perl -MCPAN -e shell
  12877.      cpan> install DBI
  12878.      cpan> install DBD::mysql
  12879.  
  12880. The `DBD::mysql' installation runs a number of tests.  These tests
  12881. require being able to connect to the local MySQL server as the
  12882. anonymous user with no password. If you have removed anonymous accounts
  12883. or assigned them passwords, the tests fail. You can use `force install
  12884. DBD::mysql' to ignore the failed tests.
  12885.  
  12886. `DBI' requires the `Data::Dumper' module. It may already be installed;
  12887. if not, you should install it before installing `DBI'.
  12888.  
  12889. It is also possible to download the module distributions in the form of
  12890. compressed `tar' archives and build the modules manually. For example,
  12891. to unpack and build a DBI distribution, use a procedure such as this:
  12892.  
  12893.   1. Unpack the distribution into the current directory:
  12894.           shell> gunzip < DBI-VERSION.tar.gz | tar xvf -
  12895.      This command creates a directory named `DBI-VERSION'.
  12896.  
  12897.   2. Change location into the top-level directory of the unpacked
  12898.      distribution:
  12899.           shell> cd DBI-VERSION
  12900.  
  12901.   3. Build the distribution and compile everything:
  12902.           shell> perl Makefile.PL
  12903.           shell> make
  12904.           shell> make test
  12905.           shell> make install
  12906.  
  12907. The `make test' command is important because it verifies that the
  12908. module is working.  Note that when you run that command during the
  12909. `DBD::mysql' installation to exercise the interface code, the MySQL
  12910. server must be running or the test will fail.
  12911.  
  12912. It is a good idea to rebuild and reinstall the `DBD::mysql'
  12913. distribution whenever you install a new release of MySQL, particularly
  12914. if you notice symptoms such as that all your `DBI' scripts fail after
  12915. you upgrade MySQL.
  12916.  
  12917. If you don't have access rights to install Perl modules in the system
  12918. directory or if you want to install local Perl modules, the following
  12919. reference may be useful:
  12920. `http://servers.digitaldaze.com/extensions/perl/modules.html#modules'
  12921.  
  12922. Look under the heading "Installing New Modules that Require Locally
  12923. Installed Modules."
  12924.  
  12925. Installing ActiveState Perl on Windows
  12926. --------------------------------------
  12927.  
  12928. On Windows, you should do the following to install the MySQL `DBD'
  12929. module with ActiveState Perl:
  12930.  
  12931.    * Get ActiveState Perl from
  12932.      `http://www.activestate.com/Products/ActivePerl/' and install it.
  12933.  
  12934.    * Open a console window (a "DOS window").
  12935.  
  12936.    * If required, set the `HTTP_proxy' variable. For example, you might
  12937.      try:
  12938.  
  12939.           set HTTP_proxy=my.proxy.com:3128
  12940.  
  12941.    * Start the PPM program:
  12942.  
  12943.           C:\> C:\perl\bin\ppm.pl
  12944.  
  12945.    * If you have not already done so, install `DBI':
  12946.  
  12947.           ppm> install DBI
  12948.  
  12949.    * If this succeeds, run the following command:
  12950.  
  12951.           install \
  12952.           ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd
  12953.  
  12954. This procedure should work at least with ActiveState Perl Version 5.6.
  12955.  
  12956. If you can't get the procedure to work, you should instead install the
  12957. `MyODBC' driver and connect to the MySQL server through ODBC:
  12958.  
  12959.      use DBI;
  12960.      $dbh= DBI->connect("DBI:ODBC:$dsn",$user,$password) ||
  12961.        die "Got error $DBI::errstr when connecting to $dsn\n";
  12962.  
  12963. Problems Using the Perl `DBI'/`DBD' Interface
  12964. ---------------------------------------------
  12965.  
  12966. If Perl reports that it can't find the `../mysql/mysql.so' module, then
  12967. the problem is probably that Perl can't locate the shared library
  12968. `libmysqlclient.so'.
  12969.  
  12970. You should be able to fix this by one of the following methods:
  12971.  
  12972.    * Compile the `DBD::mysql' distribution with `perl Makefile.PL
  12973.      -static -config' rather than `perl Makefile.PL'.
  12974.  
  12975.    * Copy `libmysqlclient.so' to the directory where your other shared
  12976.      libraries are located (probably `/usr/lib' or `/lib').
  12977.  
  12978.    * Modify the `-L' options used to compile `DBD::mysql' to reflect
  12979.      the actual location of `libmysqlclient.so'.
  12980.  
  12981.    * On Linux, you can add the pathname of the directory where
  12982.      `libmysqlclient.so' is located to the `/etc/ld.so.conf' file.
  12983.  
  12984.    * Add the pathname of the directory where `libmysqlclient.so' is
  12985.      located to the `LD_RUN_PATH' environment variable. Some systems use
  12986.      `LD_LIBRARY_PATH' instead.
  12987.  
  12988. Note that you may also need to modify the `-L' options if there are
  12989. other libraries that the linker fails to find. For example, if the
  12990. linker cannot find `libc' because it is in `/lib' and the link command
  12991. specifies `-L/usr/lib', change the `-L' option to `-L/lib' or add
  12992. `-L/lib' to the existing link command.
  12993.  
  12994. If you get the following errors from `DBD::mysql', you are probably
  12995. using `gcc' (or using an old binary compiled with `gcc'):
  12996.  
  12997.      /usr/bin/perl: can't resolve symbol '__moddi3'
  12998.      /usr/bin/perl: can't resolve symbol '__divdi3'
  12999.  
  13000. Add `-L/usr/lib/gcc-lib/... -lgcc' to the link command when the
  13001. `mysql.so' library gets built (check the output from `make' for
  13002. `mysql.so' when you compile the Perl client).  The `-L' option should
  13003. specify the pathname of the directory where `libgcc.a' is located on
  13004. your system.
  13005.  
  13006. Another cause of this problem may be that Perl and MySQL aren't both
  13007. compiled with `gcc'.  In this case, you can solve the mismatch by
  13008. compiling both with `gcc'.
  13009.  
  13010. You may see the following error from `DBD::mysql' when you run the
  13011. tests:
  13012.  
  13013.      t/00base............install_driver(mysql) failed:
  13014.      Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
  13015.      ../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
  13016.      uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.
  13017.  
  13018. This means that you need to include the `-lz' compression library on the
  13019. link line. That can be done by changing the following line in the file
  13020. `lib/DBD/mysql/Install.pm':
  13021.  
  13022.      $sysliblist .= " -lm";
  13023.  
  13024. Change that line to:
  13025.  
  13026.      $sysliblist .= " -lm -lz";
  13027.  
  13028. After this, you _must_ run `make realclean' and then proceed with the
  13029. installation from the beginning.
  13030.  
  13031. If you want to install DBI on SCO, you have to edit the `Makefile' in
  13032. DBI-XXX and each subdirectory.  Note that the following assumes `gcc'
  13033. 2.95.2 or newer:
  13034.  
  13035.      OLD:                                  NEW:
  13036.      CC = cc                               CC = gcc
  13037.      CCCDLFLAGS = -KPIC -W1,-Bexport       CCCDLFLAGS = -fpic
  13038.      CCDLFLAGS = -wl,-Bexport              CCDLFLAGS =
  13039.      
  13040.      LD = ld                               LD = gcc -G -fpic
  13041.      LDDLFLAGS = -G -L/usr/local/lib       LDDLFLAGS = -L/usr/local/lib
  13042.      LDFLAGS = -belf -L/usr/local/lib      LDFLAGS = -L/usr/local/lib
  13043.      
  13044.      LD = ld                               LD = gcc -G -fpic
  13045.      OPTIMISE = -Od                        OPTIMISE = -O1
  13046.      
  13047.      OLD:
  13048.      CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  13049.      
  13050.      NEW:
  13051.      CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  13052.  
  13053. These changes are necessary because the Perl dynaloader will not load
  13054. the `DBI' modules if they were compiled with `icc' or `cc'.
  13055.  
  13056. If you want to use the Perl module on a system that doesn't support
  13057. dynamic linking (such as SCO), you can generate a static version of
  13058. Perl that includes `DBI' and `DBD::mysql'.  The way this works is that
  13059. you generate a version of Perl with the `DBI' code linked in and
  13060. install it on top of your current Perl.  Then you use that to build a
  13061. version of Perl that additionally has the `DBD' code linked in, and
  13062. install that.
  13063.  
  13064. On SCO, you must have the following environment variables set:
  13065.  
  13066.      LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib
  13067.  
  13068. Or:
  13069.  
  13070.      LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  13071.          /usr/progressive/lib:/usr/skunk/lib
  13072.      LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  13073.          /usr/progressive/lib:/usr/skunk/lib
  13074.      MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:\
  13075.          /usr/skunk/man:
  13076.  
  13077. First, create a Perl that includes a statically linked `DBI' module by
  13078. running these commands in the directory where your `DBI' distribution is
  13079. located:
  13080.  
  13081.      shell> perl Makefile.PL -static -config
  13082.      shell> make
  13083.      shell> make install
  13084.      shell> make perl
  13085.  
  13086. Then you must install the new Perl. The output of `make perl' will
  13087. indicate the exact `make' command you will need to execute to perform
  13088. the installation.  On SCO, this is `make -f Makefile.aperl inst_perl
  13089. MAP_TARGET=perl'.
  13090.  
  13091. Next, use the just-created Perl to create another Perl that also
  13092. includes a statically linked `DBD::mysql' by running these commands in
  13093. the directory where your `DBD::mysql' distribution is located:
  13094.  
  13095.      shell> perl Makefile.PL -static -config
  13096.      shell> make
  13097.      shell> make install
  13098.      shell> make perl
  13099.  
  13100. Finally, you should install this new Perl.  Again, the output of `make
  13101. perl' indicates the command to use.
  13102.  
  13103. MySQL Tutorial
  13104. **************
  13105.  
  13106. This chapter provides a tutorial introduction to MySQL by showing how
  13107. to use the `mysql' client program to create and use a simple database.
  13108. `mysql' (sometimes referred to as the "terminal monitor" or just
  13109. "monitor") is an interactive program that allows you to connect to a
  13110. MySQL server, run queries, and view the results.  `mysql' may also be
  13111. used in batch mode: you place your queries in a file beforehand, then
  13112. tell `mysql' to execute the contents of the file.  Both ways of using
  13113. `mysql' are covered here.
  13114.  
  13115. To see a list of options provided by `mysql', invoke it with the
  13116. `--help' option:
  13117.  
  13118.      shell> mysql --help
  13119.  
  13120. This chapter assumes that `mysql' is installed on your machine and that
  13121. a MySQL server is available to which you can connect.  If this is not
  13122. true, contact your MySQL administrator.  (If *you* are the
  13123. administrator, you will need to consult other sections of this manual.)
  13124.  
  13125. This chapter describes the entire process of setting up and using a
  13126. database.  If you are interested only in accessing an already-existing
  13127. database, you may want to skip over the sections that describe how to
  13128. create the database and the tables it contains.
  13129.  
  13130. Because this chapter is tutorial in nature, many details are necessarily
  13131. omitted.  Consult the relevant sections of the manual for more
  13132. information on the topics covered here.
  13133.  
  13134. Connecting to and Disconnecting from the Server
  13135. ===============================================
  13136.  
  13137. To connect to the server, you'll usually need to provide a MySQL
  13138. username when you invoke `mysql' and, most likely, a password.  If the
  13139. server runs on a machine other than the one where you log in, you'll
  13140. also need to specify a hostname.  Contact your administrator to find
  13141. out what connection parameters you should use to connect (that is, what
  13142. host, username, and password to use).  Once you know the proper
  13143. parameters, you should be able to connect like this:
  13144.  
  13145.      shell> mysql -h HOST -u USER -p
  13146.      Enter password: ********
  13147.  
  13148. `host' and `user' represent the hostname where your MySQL server is
  13149. running and the username of your MySQL account.  Substitute appropriate
  13150. values for your setup.  The `********' represents your password; enter
  13151. it when `mysql' displays the `Enter password:' prompt.
  13152.  
  13153. If that works, you should see some introductory information followed by
  13154. a `mysql>' prompt:
  13155.  
  13156.      shell> mysql -h HOST -u USER -p
  13157.      Enter password: ********
  13158.      Welcome to the MySQL monitor.  Commands end with ; or \g.
  13159.      Your MySQL connection id is 25338 to server version: 4.0.14-log
  13160.      
  13161.      Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  13162.      
  13163.      mysql>
  13164.  
  13165. The prompt tells you that `mysql' is ready for you to enter commands.
  13166.  
  13167. Some MySQL installations allow users to connect as the anonymous
  13168. (unnamed) user to the server running on the local host.  If this is the
  13169. case on your machine, you should be able to connect to that server by
  13170. invoking `mysql' without any options:
  13171.  
  13172.      shell> mysql
  13173.  
  13174. After you have connected successfully, you can disconnect any time by
  13175. typing `QUIT' (or `\q') at the `mysql>' prompt:
  13176.  
  13177.      mysql> QUIT
  13178.      Bye
  13179.  
  13180. On Unix, you can also disconnect by pressing Control-D.
  13181.  
  13182. Most examples in the following sections assume that you are connected
  13183. to the server.  They indicate this by the `mysql>' prompt.
  13184.  
  13185. Entering Queries
  13186. ================
  13187.  
  13188. Make sure that you are connected to the server, as discussed in the
  13189. previous section.  Doing so will not in itself select any database to
  13190. work with, but that's okay.  At this point, it's more important to find
  13191. out a little about how to issue queries than to jump right in creating
  13192. tables, loading data into them, and retrieving data from them.  This
  13193. section describes the basic principles of entering commands, using
  13194. several queries you can try out to familiarize yourself with how
  13195. `mysql' works.
  13196.  
  13197. Here's a simple command that asks the server to tell you its version
  13198. number and the current date.  Type it in as shown here following the
  13199. `mysql>' prompt and press Enter:
  13200.  
  13201.      mysql> SELECT VERSION(), CURRENT_DATE;
  13202.      +--------------+--------------+
  13203.      | VERSION()    | CURRENT_DATE |
  13204.      +--------------+--------------+
  13205.      | 3.22.20a-log | 1999-03-19   |
  13206.      +--------------+--------------+
  13207.      1 row in set (0.01 sec)
  13208.      mysql>
  13209.  
  13210. This query illustrates several things about `mysql':
  13211.  
  13212.    * A command normally consists of an SQL statement followed by a
  13213.      semicolon.  (There are some exceptions where a semicolon may be
  13214.      omitted.  `QUIT', mentioned earlier, is one of them.  We'll get to
  13215.      others later.)
  13216.  
  13217.    * When you issue a command, `mysql' sends it to the server for
  13218.      execution and displays the results, then prints another `mysql>'
  13219.      prompt to indicate that it is ready for another command.
  13220.  
  13221.    * `mysql' displays query output in tabular form (rows and columns).
  13222.      The first row contains labels for the columns.  The rows following
  13223.      are the query results.  Normally, column labels are the names of
  13224.      the columns you fetch from database tables.  If you're retrieving
  13225.      the value of an expression rather than a table column (as in the
  13226.      example just shown), `mysql' labels the column using the
  13227.      expression itself.
  13228.  
  13229.    * `mysql' shows how many rows were returned and how long the query
  13230.      took to execute, which gives you a rough idea of server
  13231.      performance.  These values are imprecise because they represent
  13232.      wall clock time (not CPU or machine time), and because they are
  13233.      affected by factors such as server load and network latency.  (For
  13234.      brevity, the "rows in set" line is not shown in the remaining
  13235.      examples in this chapter.)
  13236.  
  13237. Keywords may be entered in any lettercase.  The following queries are
  13238. equivalent:
  13239.  
  13240.      mysql> SELECT VERSION(), CURRENT_DATE;
  13241.      mysql> select version(), current_date;
  13242.      mysql> SeLeCt vErSiOn(), current_DATE;
  13243.  
  13244. Here's another query.  It demonstrates that you can use `mysql' as a
  13245. simple calculator:
  13246.  
  13247.      mysql> SELECT SIN(PI()/4), (4+1)*5;
  13248.      +-------------+---------+
  13249.      | SIN(PI()/4) | (4+1)*5 |
  13250.      +-------------+---------+
  13251.      |    0.707107 |      25 |
  13252.      +-------------+---------+
  13253.  
  13254. The queries shown thus far have been relatively short, single-line
  13255. statements.  You can even enter multiple statements on a single line.
  13256. Just end each one with a semicolon:
  13257.  
  13258.      mysql> SELECT VERSION(); SELECT NOW();
  13259.      +--------------+
  13260.      | VERSION()    |
  13261.      +--------------+
  13262.      | 3.22.20a-log |
  13263.      +--------------+
  13264.      
  13265.      +---------------------+
  13266.      | NOW()               |
  13267.      +---------------------+
  13268.      | 1999-03-19 00:15:33 |
  13269.      +---------------------+
  13270.  
  13271. A command need not be given all on a single line, so lengthy commands
  13272. that require several lines are not a problem.  `mysql' determines where
  13273. your statement ends by looking for the terminating semicolon, not by
  13274. looking for the end of the input line.  (In other words, `mysql'
  13275. accepts free-format input:  it collects input lines but does not
  13276. execute them until it sees the semicolon.)
  13277.  
  13278. Here's a simple multiple-line statement:
  13279.  
  13280.      mysql> SELECT
  13281.          -> USER()
  13282.          -> ,
  13283.          -> CURRENT_DATE;
  13284.      +--------------------+--------------+
  13285.      | USER()             | CURRENT_DATE |
  13286.      +--------------------+--------------+
  13287.      | joesmith@localhost | 1999-03-18   |
  13288.      +--------------------+--------------+
  13289.  
  13290. In this example, notice how the prompt changes from `mysql>' to `->'
  13291. after you enter the first line of a multiple-line query.  This is how
  13292. `mysql' indicates that it hasn't seen a complete statement and is
  13293. waiting for the rest.  The prompt is your friend, because it provides
  13294. valuable feedback.  If you use that feedback, you will always be aware
  13295. of what `mysql' is waiting for.
  13296.  
  13297. If you decide you don't want to execute a command that you are in the
  13298. process of entering, cancel it by typing `\c':
  13299.  
  13300.      mysql> SELECT
  13301.          -> USER()
  13302.          -> \c
  13303.      mysql>
  13304.  
  13305. Here, too, notice the prompt.  It switches back to `mysql>' after you
  13306. type `\c', providing feedback to indicate that `mysql' is ready for a
  13307. new command.
  13308.  
  13309. The following table shows each of the prompts you may see and
  13310. summarizes what they mean about the state that `mysql' is in:
  13311.  
  13312. *Prompt**Meaning*
  13313. `mysql>'Ready for new command.
  13314. `       Waiting for next line of multiple-line command.
  13315. ->'     
  13316. `       Waiting for next line, collecting a string that begins
  13317. '>'     with a single quote (`'').
  13318. `       Waiting for next line, collecting a string that begins
  13319. ">'     with a double quote (`"').
  13320. `       Waiting for next line, collecting an identifier that
  13321. `>'     begins with a backtick (``').
  13322.  
  13323. Multiple-line statements commonly occur by accident when you intend to
  13324. issue a command on a single line, but forget the terminating semicolon.
  13325. In this case, `mysql' waits for more input:
  13326.  
  13327.      mysql> SELECT USER()
  13328.          ->
  13329.  
  13330. If this happens to you (you think you've entered a statement but the
  13331. only response is a `->' prompt), most likely `mysql' is waiting for the
  13332. semicolon.  If you don't notice what the prompt is telling you, you
  13333. might sit there for a while before realising what you need to do.
  13334. Enter a semicolon to complete the statement, and `mysql' will execute
  13335. it:
  13336.  
  13337.      mysql> SELECT USER()
  13338.          -> ;
  13339.      +--------------------+
  13340.      | USER()             |
  13341.      +--------------------+
  13342.      | joesmith@localhost |
  13343.      +--------------------+
  13344.  
  13345. The `'>' and `">' prompts occur during string collection.  In MySQL,
  13346. you can write strings surrounded by either `'' or `"' characters (for
  13347. example, `'hello'' or `"goodbye"'), and `mysql' lets you enter strings
  13348. that span multiple lines.  When you see a `'>' or `">' prompt, it means
  13349. that you've entered a line containing a string that begins with a `''
  13350. or `"' quote character, but have not yet entered the matching quote
  13351. that terminates the string.  That's fine if you really are entering a
  13352. multiple-line string, but how likely is that?  Not very.  More often,
  13353. the `'>' and `">' prompts indicate that you've inadvertantly left out a
  13354. quote character.  For example:
  13355.  
  13356.      mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
  13357.          '>
  13358.  
  13359. If you enter this `SELECT' statement, then press Enter and wait for the
  13360. result, nothing will happen.  Instead of wondering why this query takes
  13361. so long, notice the clue provided by the `'>' prompt.  It tells you
  13362. that `mysql' expects to see the rest of an unterminated string.  (Do
  13363. you see the error in the statement?  The string `'Smith' is missing the
  13364. second quote.)
  13365.  
  13366. At this point, what do you do?  The simplest thing is to cancel the
  13367. command.  However, you cannot just type `\c' in this case, because
  13368. `mysql' interprets it as part of the string that it is collecting!
  13369. Instead, enter the closing quote character (so `mysql' knows you've
  13370. finished the string), then type `\c':
  13371.  
  13372.      mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
  13373.          '> '\c
  13374.      mysql>
  13375.  
  13376. The prompt changes back to `mysql>', indicating that `mysql' is ready
  13377. for a new command.
  13378.  
  13379. The ``>' prompt is similar to th `'>' and `">' prompts, but indicates
  13380. that you have begun but not completed a backtick-quoted identifier.
  13381.  
  13382. It's important to know what the `'>', `">', and ``>' prompts signify,
  13383. because if you mistakenly enter an unterminated string, any further
  13384. lines you type will appear to be ignored by `mysql'--including a line
  13385. containing `QUIT'!  This can be quite confusing, especially if you
  13386. don't know that you need to supply the terminating quote before you can
  13387. cancel the current command.
  13388.  
  13389. Creating and Using a Database
  13390. =============================
  13391.  
  13392. Now that you know how to enter commands, it's time to access a database.
  13393.  
  13394. Suppose that you have several pets in your home (your menagerie) and
  13395. you'd like to keep track of various types of information about them.
  13396. You can do so by creating tables to hold your data and loading them
  13397. with the desired information.  Then you can answer different sorts of
  13398. questions about your animals by retrieving data from the tables.  This
  13399. section shows you how to:
  13400.  
  13401.    * Create a database
  13402.  
  13403.    * Create a table
  13404.  
  13405.    * Load data into the table
  13406.  
  13407.    * Retrieve data from the table in various ways
  13408.  
  13409.    * Use multiple tables
  13410.  
  13411. The menagerie database will be simple (deliberately), but it is not
  13412. difficult to think of real-world situations in which a similar type of
  13413. database might be used.  For example, a database like this could be
  13414. used by a farmer to keep track of livestock, or by a veterinarian to
  13415. keep track of patient records.  A menagerie distribution containing
  13416. some of the queries and sample data used in the following sections can
  13417. be obtained from the MySQL Web site.  It's available in either
  13418. compressed `tar' format
  13419. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.tar.gz') or
  13420. Zip format
  13421. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.zip').
  13422.  
  13423. Use the `SHOW' statement to find out what databases currently exist on
  13424. the server:
  13425.  
  13426.      mysql> SHOW DATABASES;
  13427.      +----------+
  13428.      | Database |
  13429.      +----------+
  13430.      | mysql    |
  13431.      | test     |
  13432.      | tmp      |
  13433.      +----------+
  13434.  
  13435. The list of databases is probably different on your machine, but the
  13436. `mysql' and `test' databases are likely to be among them.  The `mysql'
  13437. database is required because it describes user access privileges.  The
  13438. `test' database is often provided as a workspace for users to try
  13439. things out.
  13440.  
  13441. Note that you may not see all databases if you don't have the `SHOW
  13442. DATABASES' privilege. *Note `GRANT': GRANT.
  13443.  
  13444. If the `test' database exists, try to access it:
  13445.  
  13446.      mysql> USE test
  13447.      Database changed
  13448.  
  13449. Note that `USE', like `QUIT', does not require a semicolon.  (You can
  13450. terminate such statements with a semicolon if you like; it does no
  13451. harm.)  The `USE' statement is special in another way, too:  it must be
  13452. given on a single line.
  13453.  
  13454. You can use the `test' database (if you have access to it) for the
  13455. examples that follow, but anything you create in that database can be
  13456. removed by anyone else with access to it.  For this reason, you should
  13457. probably ask your MySQL administrator for permission to use a database
  13458. of your own.  Suppose that you want to call yours `menagerie'.  The
  13459. administrator needs to execute a command like this:
  13460.  
  13461.      mysql> GRANT ALL ON menagerie.* TO 'your_mysql_name'@'your_client_host';
  13462.  
  13463. where `your_mysql_name' is the MySQL username assigned to you and
  13464. `your_client_host' is the host from which you connect to the server.
  13465.  
  13466. Creating and Selecting a Database
  13467. ---------------------------------
  13468.  
  13469. If the administrator creates your database for you when setting up your
  13470. permissions, you can begin using it.  Otherwise, you need to create it
  13471. yourself:
  13472.  
  13473.      mysql> CREATE DATABASE menagerie;
  13474.  
  13475. Under Unix, database names are case sensitive (unlike SQL keywords), so
  13476. you must always refer to your database as `menagerie', not as
  13477. `Menagerie', `MENAGERIE', or some other variant.  This is also true for
  13478. table names.  (Under Windows, this restriction does not apply, although
  13479. you must refer to databases and tables using the same lettercase
  13480. throughout a given query.)
  13481.  
  13482. Creating a database does not select it for use; you must do that
  13483. explicitly.  To make `menagerie' the current database, use this command:
  13484.  
  13485.      mysql> USE menagerie
  13486.      Database changed
  13487.  
  13488. Your database needs to be created only once, but you must select it for
  13489. use each time you begin a `mysql' session.  You can do this by issuing a
  13490. `USE' statement as shown in the example.  Alternatively, you can select
  13491. the database on the command line when you invoke `mysql'.  Just specify
  13492. its name after any connection parameters that you might need to
  13493. provide.  For example:
  13494.  
  13495.      shell> mysql -h HOST -u USER -p menagerie
  13496.      Enter password: ********
  13497.  
  13498. Note that `menagerie' is not your password on the command just shown.
  13499. If you want to supply your password on the command line after the `-p'
  13500. option, you must do so with no intervening space (for example, as
  13501. `-pmypassword', not as `-p mypassword').  However, putting your
  13502. password on the command line is not recommended, because doing so
  13503. exposes it to snooping by other users logged in on your machine.
  13504.  
  13505. Creating a Table
  13506. ----------------
  13507.  
  13508. Creating the database is the easy part, but at this point it's empty, as
  13509. `SHOW TABLES' will tell you:
  13510.  
  13511.      mysql> SHOW TABLES;
  13512.      Empty set (0.00 sec)
  13513.  
  13514. The harder part is deciding what the structure of your database should
  13515. be: what tables you will need and what columns will be in each of them.
  13516.  
  13517. You'll want a table that contains a record for each of your pets.  This
  13518. can be called the `pet' table, and it should contain, as a bare minimum,
  13519. each animal's name.  Because the name by itself is not very
  13520. interesting, the table should contain other information.  For example,
  13521. if more than one person in your family keeps pets, you might want to
  13522. list each animal's owner.  You might also want to record some basic
  13523. descriptive information such as species and sex.
  13524.  
  13525. How about age?  That might be of interest, but it's not a good thing to
  13526. store in a database.  Age changes as time passes, which means you'd
  13527. have to update your records often.  Instead, it's better to store a
  13528. fixed value such as date of birth.  Then, whenever you need age, you
  13529. can calculate it as the difference between the current date and the
  13530. birth date.  MySQL provides functions for doing date arithmetic, so
  13531. this is not difficult.  Storing birth date rather than age has other
  13532. advantages, too:
  13533.  
  13534.    * You can use the database for tasks such as generating reminders
  13535.      for upcoming pet birthdays.  (If you think this type of query is
  13536.      somewhat silly, note that it is the same question you might ask in
  13537.      the context of a business database to identify clients to whom
  13538.      you'll soon need to send out birthday greetings, for that
  13539.      computer-assisted personal touch.)
  13540.  
  13541.    * You can calculate age in relation to dates other than the current
  13542.      date.  For example, if you store death date in the database, you
  13543.      can easily calculate how old a pet was when it died.
  13544.  
  13545. You can probably think of other types of information that would be
  13546. useful in the `pet' table, but the ones identified so far are
  13547. sufficient for now: name, owner, species, sex, birth, and death.
  13548.  
  13549. Use a `CREATE TABLE' statement to specify the layout of your table:
  13550.  
  13551.      mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
  13552.          -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
  13553.  
  13554. `VARCHAR' is a good choice for the `name', `owner', and `species'
  13555. columns because the column values will vary in length.  The lengths of
  13556. those columns need not all be the same, and need not be `20'.  You can
  13557. pick any length from `1' to `255', whatever seems most reasonable to
  13558. you.  (If you make a poor choice and it turns out later that you need a
  13559. longer field, MySQL provides an `ALTER TABLE' statement.)
  13560.  
  13561. Several types of values can be chosen to represent sex in animal
  13562. records, such as `'m'' and `'f'', or perhaps `'male'' and `'female''.
  13563. It's simplest to use the single characters `'m'' and `'f''.
  13564.  
  13565. The use of the `DATE' data type for the `birth' and `death' columns is
  13566. a fairly obvious choice.
  13567.  
  13568. Now that you have created a table, `SHOW TABLES' should produce some
  13569. output:
  13570.  
  13571.      mysql> SHOW TABLES;
  13572.      +---------------------+
  13573.      | Tables in menagerie |
  13574.      +---------------------+
  13575.      | pet                 |
  13576.      +---------------------+
  13577.  
  13578. To verify that your table was created the way you expected, use a
  13579. `DESCRIBE' statement:
  13580.  
  13581.      mysql> DESCRIBE pet;
  13582.      +---------+-------------+------+-----+---------+-------+
  13583.      | Field   | Type        | Null | Key | Default | Extra |
  13584.      +---------+-------------+------+-----+---------+-------+
  13585.      | name    | varchar(20) | YES  |     | NULL    |       |
  13586.      | owner   | varchar(20) | YES  |     | NULL    |       |
  13587.      | species | varchar(20) | YES  |     | NULL    |       |
  13588.      | sex     | char(1)     | YES  |     | NULL    |       |
  13589.      | birth   | date        | YES  |     | NULL    |       |
  13590.      | death   | date        | YES  |     | NULL    |       |
  13591.      +---------+-------------+------+-----+---------+-------+
  13592.  
  13593. You can use `DESCRIBE' any time, for example, if you forget the names of
  13594. the columns in your table or what types they have.
  13595.  
  13596. Loading Data into a Table
  13597. -------------------------
  13598.  
  13599. After creating your table, you need to populate it.  The `LOAD DATA' and
  13600. `INSERT' statements are useful for this.
  13601.  
  13602. Suppose that your pet records can be described as shown here.  (Observe
  13603. that MySQL expects dates in `'YYYY-MM-DD'' format; this may be
  13604. different from what you are used to.)
  13605.  
  13606. *name*  *owner* *species**sex**birth*        *death*
  13607. Fluffy  Harold  cat     f    1993-02-04     
  13608. Claws   Gwen    cat     m    1994-03-17     
  13609. Buffy   Harold  dog     f    1989-05-13     
  13610. Fang    Benny   dog     m    1990-08-27     
  13611. Bowser  Diane   dog     m    1979-08-31     1995-07-29
  13612. Chirpy  Gwen    bird    f    1998-09-11     
  13613. WhistlerGwen    bird         1997-12-09     
  13614. Slim    Benny   snake   m    1996-04-29     
  13615.  
  13616. Because you are beginning with an empty table, an easy way to populate
  13617. it is to create a text file containing a row for each of your animals,
  13618. then load the contents of the file into the table with a single
  13619. statement.
  13620.  
  13621. You could create a text file `pet.txt' containing one record per line,
  13622. with values separated by tabs, and given in the order in which the
  13623. columns were listed in the `CREATE TABLE' statement.  For missing
  13624. values (such as unknown sexes or death dates for animals that are still
  13625. living), you can use `NULL' values.  To represent these in your text
  13626. file, use `\N' (backslash, capital-N).  For example, the record for
  13627. Whistler the bird would look like this (where the whitespace between
  13628. values is a single tab character):
  13629.  
  13630. *name*  *owner* *species**sex**birth*        *death*
  13631. `Whistler'`Gwen'  `bird'  `\N' `1997-12-09'   `\N'
  13632.  
  13633. To load the text file `pet.txt' into the `pet' table, use this command:
  13634.  
  13635.      mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;
  13636.  
  13637. Note that if you created the file on Windows with an editor that uses
  13638. `\r\n' as a line terminator, you should use:
  13639.  
  13640.      mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
  13641.          -> LINES TERMINATED BY '\r\n';
  13642.  
  13643. You can specify the column value separator and end of line marker
  13644. explicitly in the `LOAD DATA' statement if you wish, but the defaults
  13645. are tab and linefeed.  These are sufficient for the statement to read
  13646. the file `pet.txt' properly.
  13647.  
  13648. If the statement fails, it is likely that your MySQL installation does
  13649. not have local file capability enabled by default.  See *Note `LOAD
  13650. DATA LOCAL': LOAD DATA LOCAL for information on how to change this.
  13651.  
  13652. When you want to add new records one at a time, the `INSERT' statement
  13653. is useful.  In its simplest form, you supply values for each column, in
  13654. the order in which the columns were listed in the `CREATE TABLE'
  13655. statement.  Suppose that Diane gets a new hamster named Puffball.  You
  13656. could add a new record using an `INSERT' statement like this:
  13657.  
  13658.      mysql> INSERT INTO pet
  13659.          -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
  13660.  
  13661. Note that string and date values are specified as quoted strings here.
  13662. Also, with `INSERT', you can insert `NULL' directly to represent a
  13663. missing value.  You do not use `\N' like you do with `LOAD DATA'.
  13664.  
  13665. From this example, you should be able to see that there would be a lot
  13666. more typing involved to load your records initially using several
  13667. `INSERT' statements rather than a single `LOAD DATA' statement.
  13668.  
  13669. Retrieving Information from a Table
  13670. -----------------------------------
  13671.  
  13672. The `SELECT' statement is used to pull information from a table.  The
  13673. general form of the statement is:
  13674.  
  13675.      SELECT what_to_select
  13676.      FROM which_table
  13677.      WHERE conditions_to_satisfy;
  13678.  
  13679. `what_to_select' indicates what you want to see.  This can be a list of
  13680. columns, or `*' to indicate "all columns." `which_table' indicates the
  13681. table from which you want to retrieve data.  The `WHERE' clause is
  13682. optional.  If it's present, `conditions_to_satisfy' specifies
  13683. conditions that rows must satisfy to qualify for retrieval.
  13684.  
  13685. Selecting All Data
  13686. ..................
  13687.  
  13688. The simplest form of `SELECT' retrieves everything from a table:
  13689.  
  13690.      mysql> SELECT * FROM pet;
  13691.      +----------+--------+---------+------+------------+------------+
  13692.      | name     | owner  | species | sex  | birth      | death      |
  13693.      +----------+--------+---------+------+------------+------------+
  13694.      | Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |
  13695.      | Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |
  13696.      | Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |
  13697.      | Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |
  13698.      | Bowser   | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |
  13699.      | Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |
  13700.      | Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |
  13701.      | Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |
  13702.      | Puffball | Diane  | hamster | f    | 1999-03-30 | NULL       |
  13703.      +----------+--------+---------+------+------------+------------+
  13704.  
  13705. This form of `SELECT' is useful if you want to review your entire table,
  13706. for example, after you've just loaded it with your initial dataset.  For
  13707. example, you may happen to think that the birth date for Bowser doesn't
  13708. seem quite right.  Consulting your original pedigree papers, you find
  13709. that the correct birth year should be 1989, not 1979.
  13710.  
  13711. There are least a couple of ways to fix this:
  13712.  
  13713.    * Edit the file `pet.txt' to correct the error, then empty the table
  13714.      and reload it using `DELETE' and `LOAD DATA':
  13715.  
  13716.           mysql> DELETE FROM pet;
  13717.           mysql> LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;
  13718.  
  13719.      However, if you do this, you must also re-enter the record for
  13720.      Puffball.
  13721.  
  13722.    * Fix only the erroneous record with an `UPDATE' statement:
  13723.  
  13724.           mysql> UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser';
  13725.  
  13726.      The `UPDATE' changes only the record in question and does not
  13727.      require you to reload the table.
  13728.  
  13729. Selecting Particular Rows
  13730. .........................
  13731.  
  13732. As shown in the preceding section, it is easy to retrieve an entire
  13733. table.  Just omit the `WHERE' clause from the `SELECT' statement.  But
  13734. typically you don't want to see the entire table, particularly when it
  13735. becomes large.  Instead, you're usually more interested in answering a
  13736. particular question, in which case you specify some constraints on the
  13737. information you want.  Let's look at some selection queries in terms of
  13738. questions about your pets that they answer.
  13739.  
  13740. You can select only particular rows from your table.  For example, if
  13741. you want to verify the change that you made to Bowser's birth date,
  13742. select Bowser's record like this:
  13743.  
  13744.      mysql> SELECT * FROM pet WHERE name = 'Bowser';
  13745.      +--------+-------+---------+------+------------+------------+
  13746.      | name   | owner | species | sex  | birth      | death      |
  13747.      +--------+-------+---------+------+------------+------------+
  13748.      | Bowser | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  13749.      +--------+-------+---------+------+------------+------------+
  13750.  
  13751. The output confirms that the year is correctly recorded now as 1989,
  13752. not 1979.
  13753.  
  13754. String comparisons normally are case-insensitive, so you can specify the
  13755. name as `'bowser'', `'BOWSER'', etc.  The query result will be the same.
  13756.  
  13757. You can specify conditions on any column, not just `name'.  For example,
  13758. if you want to know which animals were born after 1998, test the `birth'
  13759. column:
  13760.  
  13761.      mysql> SELECT * FROM pet WHERE birth >= '1998-1-1';
  13762.      +----------+-------+---------+------+------------+-------+
  13763.      | name     | owner | species | sex  | birth      | death |
  13764.      +----------+-------+---------+------+------------+-------+
  13765.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  13766.      | Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
  13767.      +----------+-------+---------+------+------------+-------+
  13768.  
  13769. You can combine conditions, for example, to locate female dogs:
  13770.  
  13771.      mysql> SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';
  13772.      +-------+--------+---------+------+------------+-------+
  13773.      | name  | owner  | species | sex  | birth      | death |
  13774.      +-------+--------+---------+------+------------+-------+
  13775.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  13776.      +-------+--------+---------+------+------------+-------+
  13777.  
  13778. The preceding query uses the `AND' logical operator.  There is also an
  13779. `OR' operator:
  13780.  
  13781.      mysql> SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';
  13782.      +----------+-------+---------+------+------------+-------+
  13783.      | name     | owner | species | sex  | birth      | death |
  13784.      +----------+-------+---------+------+------------+-------+
  13785.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  13786.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL  |
  13787.      | Slim     | Benny | snake   | m    | 1996-04-29 | NULL  |
  13788.      +----------+-------+---------+------+------------+-------+
  13789.  
  13790. `AND' and `OR' may be intermixed, although `AND' has higher precedence
  13791. than `OR'.  If you use both operators, it's a good idea to use
  13792. parentheses to indicate explicitly how conditions should be grouped:
  13793.  
  13794.      mysql> SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm')
  13795.          -> OR (species = 'dog' AND sex = 'f');
  13796.      +-------+--------+---------+------+------------+-------+
  13797.      | name  | owner  | species | sex  | birth      | death |
  13798.      +-------+--------+---------+------+------------+-------+
  13799.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  13800.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  13801.      +-------+--------+---------+------+------------+-------+
  13802.  
  13803. Selecting Particular Columns
  13804. ............................
  13805.  
  13806. If you don't want to see entire rows from your table, just name the
  13807. columns in which you're interested, separated by commas.  For example,
  13808. if you want to know when your animals were born, select the `name' and
  13809. `birth' columns:
  13810.  
  13811.      mysql> SELECT name, birth FROM pet;
  13812.      +----------+------------+
  13813.      | name     | birth      |
  13814.      +----------+------------+
  13815.      | Fluffy   | 1993-02-04 |
  13816.      | Claws    | 1994-03-17 |
  13817.      | Buffy    | 1989-05-13 |
  13818.      | Fang     | 1990-08-27 |
  13819.      | Bowser   | 1989-08-31 |
  13820.      | Chirpy   | 1998-09-11 |
  13821.      | Whistler | 1997-12-09 |
  13822.      | Slim     | 1996-04-29 |
  13823.      | Puffball | 1999-03-30 |
  13824.      +----------+------------+
  13825.  
  13826. To find out who owns pets, use this query:
  13827.  
  13828.      mysql> SELECT owner FROM pet;
  13829.      +--------+
  13830.      | owner  |
  13831.      +--------+
  13832.      | Harold |
  13833.      | Gwen   |
  13834.      | Harold |
  13835.      | Benny  |
  13836.      | Diane  |
  13837.      | Gwen   |
  13838.      | Gwen   |
  13839.      | Benny  |
  13840.      | Diane  |
  13841.      +--------+
  13842.  
  13843. However, notice that the query simply retrieves the `owner' field from
  13844. each record, and some of them appear more than once.  To minimize the
  13845. output, retrieve each unique output record just once by adding the
  13846. keyword `DISTINCT':
  13847.  
  13848.      mysql> SELECT DISTINCT owner FROM pet;
  13849.      +--------+
  13850.      | owner  |
  13851.      +--------+
  13852.      | Benny  |
  13853.      | Diane  |
  13854.      | Gwen   |
  13855.      | Harold |
  13856.      +--------+
  13857.  
  13858. You can use a `WHERE' clause to combine row selection with column
  13859. selection.  For example, to get birth dates for dogs and cats only, use
  13860. this query:
  13861.  
  13862.      mysql> SELECT name, species, birth FROM pet
  13863.          -> WHERE species = 'dog' OR species = 'cat';
  13864.      +--------+---------+------------+
  13865.      | name   | species | birth      |
  13866.      +--------+---------+------------+
  13867.      | Fluffy | cat     | 1993-02-04 |
  13868.      | Claws  | cat     | 1994-03-17 |
  13869.      | Buffy  | dog     | 1989-05-13 |
  13870.      | Fang   | dog     | 1990-08-27 |
  13871.      | Bowser | dog     | 1989-08-31 |
  13872.      +--------+---------+------------+
  13873.  
  13874. Sorting Rows
  13875. ............
  13876.  
  13877. You may have noticed in the preceding examples that the result rows are
  13878. displayed in no particular order.  It's often easier to examine query
  13879. output when the rows are sorted in some meaningful way.  To sort a
  13880. result, use an `ORDER BY' clause.
  13881.  
  13882. Here are animal birthdays, sorted by date:
  13883.  
  13884.      mysql> SELECT name, birth FROM pet ORDER BY birth;
  13885.      +----------+------------+
  13886.      | name     | birth      |
  13887.      +----------+------------+
  13888.      | Buffy    | 1989-05-13 |
  13889.      | Bowser   | 1989-08-31 |
  13890.      | Fang     | 1990-08-27 |
  13891.      | Fluffy   | 1993-02-04 |
  13892.      | Claws    | 1994-03-17 |
  13893.      | Slim     | 1996-04-29 |
  13894.      | Whistler | 1997-12-09 |
  13895.      | Chirpy   | 1998-09-11 |
  13896.      | Puffball | 1999-03-30 |
  13897.      +----------+------------+
  13898.  
  13899. On character type columns, sorting--like all other comparison
  13900. operations--is normally performed in a case-insensitive fashion.  This
  13901. means that the order will be undefined for columns that are identical
  13902. except for their case. You can force a case-sensitive sort for a column
  13903. by using the `BINARY' cast: `ORDER BY BINARY col_name'.
  13904.  
  13905. The default sort order is ascending, with smallest values first.  To
  13906. sort in reverse (descending) order, add the `DESC' keyword to the name
  13907. of the column you are sorting by:
  13908.  
  13909.      mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
  13910.      +----------+------------+
  13911.      | name     | birth      |
  13912.      +----------+------------+
  13913.      | Puffball | 1999-03-30 |
  13914.      | Chirpy   | 1998-09-11 |
  13915.      | Whistler | 1997-12-09 |
  13916.      | Slim     | 1996-04-29 |
  13917.      | Claws    | 1994-03-17 |
  13918.      | Fluffy   | 1993-02-04 |
  13919.      | Fang     | 1990-08-27 |
  13920.      | Bowser   | 1989-08-31 |
  13921.      | Buffy    | 1989-05-13 |
  13922.      +----------+------------+
  13923.  
  13924. You can sort on multiple columns, and you can sort columns in different
  13925. directions.  For example, to sort by type of animal in ascending order,
  13926. then by birth date within animal type in descending order (youngest
  13927. animals first), use the following query:
  13928.  
  13929.      mysql> SELECT name, species, birth FROM pet
  13930.          -> ORDER BY species, birth DESC;
  13931.      +----------+---------+------------+
  13932.      | name     | species | birth      |
  13933.      +----------+---------+------------+
  13934.      | Chirpy   | bird    | 1998-09-11 |
  13935.      | Whistler | bird    | 1997-12-09 |
  13936.      | Claws    | cat     | 1994-03-17 |
  13937.      | Fluffy   | cat     | 1993-02-04 |
  13938.      | Fang     | dog     | 1990-08-27 |
  13939.      | Bowser   | dog     | 1989-08-31 |
  13940.      | Buffy    | dog     | 1989-05-13 |
  13941.      | Puffball | hamster | 1999-03-30 |
  13942.      | Slim     | snake   | 1996-04-29 |
  13943.      +----------+---------+------------+
  13944.  
  13945. Note that the `DESC' keyword applies only to the column name immediately
  13946. preceding it (`birth'); it does not affect the `species' column sort
  13947. order.
  13948.  
  13949. Date Calculations
  13950. .................
  13951.  
  13952. MySQL provides several functions that you can use to perform
  13953. calculations on dates, for example, to calculate ages or extract parts
  13954. of dates.
  13955.  
  13956. To determine how many years old each of your pets is, compute the
  13957. difference in the year part of the current date and the birth date, then
  13958. subtract one if the current date occurs earlier in the calendar year
  13959. than the birth date.  The following query shows, for each pet, the
  13960. birth date, the current date, and the age in years.
  13961.  
  13962.      mysql> SELECT name, birth, CURDATE(),
  13963.          -> (YEAR(CURDATE())-YEAR(birth))
  13964.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  13965.          -> AS age
  13966.          -> FROM pet;
  13967.      +----------+------------+------------+------+
  13968.      | name     | birth      | CURDATE()  | age  |
  13969.      +----------+------------+------------+------+
  13970.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  13971.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  13972.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  13973.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  13974.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  13975.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  13976.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  13977.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  13978.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  13979.      +----------+------------+------------+------+
  13980.  
  13981. Here, `YEAR()' pulls out the year part of a date and `RIGHT()' pulls
  13982. off the rightmost five characters that represent the `MM-DD' (calendar
  13983. year) part of the date.  The part of the expression that compares the
  13984. `MM-DD' values evaluates to 1 or 0, which adjusts the year difference
  13985. down a year if `CURDATE()' occurs earlier in the year than `birth'.
  13986. The full expression is somewhat ungainly, so an alias (`age') is used
  13987. to make the output column label more meaningful.
  13988.  
  13989. The query works, but the result could be scanned more easily if the rows
  13990. were presented in some order.  This can be done by adding an `ORDER BY
  13991. name' clause to sort the output by name:
  13992.  
  13993.      mysql> SELECT name, birth, CURDATE(),
  13994.          -> (YEAR(CURDATE())-YEAR(birth))
  13995.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  13996.          -> AS age
  13997.          -> FROM pet ORDER BY name;
  13998.      +----------+------------+------------+------+
  13999.      | name     | birth      | CURDATE()  | age  |
  14000.      +----------+------------+------------+------+
  14001.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  14002.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  14003.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  14004.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  14005.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  14006.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  14007.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  14008.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  14009.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  14010.      +----------+------------+------------+------+
  14011.  
  14012. To sort the output by `age' rather than `name', just use a different
  14013. `ORDER BY' clause:
  14014.  
  14015.      mysql> SELECT name, birth, CURDATE(),
  14016.          -> (YEAR(CURDATE())-YEAR(birth))
  14017.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  14018.          -> AS age
  14019.          -> FROM pet ORDER BY age;
  14020.      +----------+------------+------------+------+
  14021.      | name     | birth      | CURDATE()  | age  |
  14022.      +----------+------------+------------+------+
  14023.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  14024.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  14025.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  14026.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  14027.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  14028.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  14029.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  14030.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  14031.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  14032.      +----------+------------+------------+------+
  14033.  
  14034. A similar query can be used to determine age at death for animals that
  14035. have died.  You determine which animals these are by checking whether
  14036. the `death' value is `NULL'.  Then, for those with non-`NULL' values,
  14037. compute the difference between the `death' and `birth' values:
  14038.  
  14039.      mysql> SELECT name, birth, death,
  14040.          -> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5)<RIGHT(birth,5))
  14041.          -> AS age
  14042.          -> FROM pet WHERE death IS NOT NULL ORDER BY age;
  14043.      +--------+------------+------------+------+
  14044.      | name   | birth      | death      | age  |
  14045.      +--------+------------+------------+------+
  14046.      | Bowser | 1989-08-31 | 1995-07-29 |    5 |
  14047.      +--------+------------+------------+------+
  14048.  
  14049. The query uses `death IS NOT NULL' rather than `death <> NULL' because
  14050. `NULL' is a special value that cannot be compared using the usual
  14051. comparison operators.  This is discussed later.  *Note Working with
  14052. `NULL': Working with NULL.
  14053.  
  14054. What if you want to know which animals have birthdays next month?  For
  14055. this type of calculation, year and day are irrelevant; you simply want
  14056. to extract the month part of the `birth' column.  MySQL provides several
  14057. date-part extraction functions, such as `YEAR()', `MONTH()', and
  14058. `DAYOFMONTH()'.  `MONTH()' is the appropriate function here.  To see
  14059. how it works, run a simple query that displays the value of both
  14060. `birth' and `MONTH(birth)':
  14061.  
  14062.      mysql> SELECT name, birth, MONTH(birth) FROM pet;
  14063.      +----------+------------+--------------+
  14064.      | name     | birth      | MONTH(birth) |
  14065.      +----------+------------+--------------+
  14066.      | Fluffy   | 1993-02-04 |            2 |
  14067.      | Claws    | 1994-03-17 |            3 |
  14068.      | Buffy    | 1989-05-13 |            5 |
  14069.      | Fang     | 1990-08-27 |            8 |
  14070.      | Bowser   | 1989-08-31 |            8 |
  14071.      | Chirpy   | 1998-09-11 |            9 |
  14072.      | Whistler | 1997-12-09 |           12 |
  14073.      | Slim     | 1996-04-29 |            4 |
  14074.      | Puffball | 1999-03-30 |            3 |
  14075.      +----------+------------+--------------+
  14076.  
  14077. Finding animals with birthdays in the upcoming month is easy, too.
  14078. Suppose that the current month is April.  Then the month value is `4'
  14079. and you look for animals born in May (month `5') like this:
  14080.  
  14081.      mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
  14082.      +-------+------------+
  14083.      | name  | birth      |
  14084.      +-------+------------+
  14085.      | Buffy | 1989-05-13 |
  14086.      +-------+------------+
  14087.  
  14088. There is a small complication if the current month is December.  You
  14089. don't just add one to the month number (`12') and look for animals born
  14090. in month `13', because there is no such month.  Instead, you look for
  14091. animals born in January (month `1').
  14092.  
  14093. You can even write the query so that it works no matter what the current
  14094. month is.  That way you don't have to use a particular month number in
  14095. the query.  `DATE_ADD()' allows you to add a time interval to a given
  14096. date.  If you add a month to the value of `CURDATE()', then extract the
  14097. month part with `MONTH()', the result produces the month in which to
  14098. look for birthdays:
  14099.  
  14100.      mysql> SELECT name, birth FROM pet
  14101.          -> WHERE MONTH(birth) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH));
  14102.  
  14103. A different way to accomplish the same task is to add `1' to get the
  14104. next month after the current one (after using the modulo function
  14105. (`MOD') to wrap around the month value to `0' if it is currently `12'):
  14106.  
  14107.      mysql> SELECT name, birth FROM pet
  14108.          -> WHERE MONTH(birth) = MOD(MONTH(CURDATE()), 12) + 1;
  14109.  
  14110. Note that `MONTH' returns a number between `1' and `12'. And
  14111. `MOD(something,12)' returns a number between `0' and `11'. So the
  14112. addition has to be after the `MOD()', otherwise we would go from
  14113. November (`11') to January (`1').
  14114.  
  14115. Working with `NULL' Values
  14116. ..........................
  14117.  
  14118. The `NULL' value can be surprising until you get used to it.
  14119. Conceptually, `NULL' means missing value or unknown value and it is
  14120. treated somewhat differently than other values.  To test for `NULL',
  14121. you cannot use the arithmetic comparison operators such as `=', `<', or
  14122. `<>'.  To demonstrate this for yourself, try the following query:
  14123.  
  14124.      mysql> SELECT 1 = NULL, 1 <> NULL, 1 < NULL, 1 > NULL;
  14125.      +----------+-----------+----------+----------+
  14126.      | 1 = NULL | 1 <> NULL | 1 < NULL | 1 > NULL |
  14127.      +----------+-----------+----------+----------+
  14128.      |     NULL |      NULL |     NULL |     NULL |
  14129.      +----------+-----------+----------+----------+
  14130.  
  14131. Clearly you get no meaningful results from these comparisons.  Use the
  14132. `IS NULL' and `IS NOT NULL' operators instead:
  14133.  
  14134.      mysql> SELECT 1 IS NULL, 1 IS NOT NULL;
  14135.      +-----------+---------------+
  14136.      | 1 IS NULL | 1 IS NOT NULL |
  14137.      +-----------+---------------+
  14138.      |         0 |             1 |
  14139.      +-----------+---------------+
  14140.  
  14141. Note that in MySQL, `0' or `NULL' means false and anything else means
  14142. true. The default truth value from a boolean operation is `1'.
  14143.  
  14144. This special treatment of `NULL' is why, in the previous section, it
  14145. was necessary to determine which animals are no longer alive using
  14146. `death IS NOT NULL' instead of `death <> NULL'.
  14147.  
  14148. Two `NULL' values are regarded as equal in a `GROUP BY'.
  14149.  
  14150. When doing an `ORDER BY', `NULL' values are presented first if you do
  14151. `ORDER BY ... ASC' and last if you do `ORDER BY ... DESC'.
  14152.  
  14153. Note that MySQL 4.0.2 to 4.0.10 incorrectly always sorts `NULL' values
  14154. first regardless of the sort direction.
  14155.  
  14156. Pattern Matching
  14157. ................
  14158.  
  14159. MySQL provides standard SQL pattern matching as well as a form of
  14160. pattern matching based on extended regular expressions similar to those
  14161. used by Unix utilities such as `vi', `grep', and `sed'.
  14162.  
  14163. SQL pattern matching allows you to use `_' to match any single
  14164. character and `%' to match an arbitrary number of characters (including
  14165. zero characters).  In MySQL, SQL patterns are case-insensitive by
  14166. default.  Some examples are shown here.  Note that you do not use `='
  14167. or `<>' when you use SQL patterns; use the `LIKE' or `NOT LIKE'
  14168. comparison operators instead.
  14169.  
  14170. To find names beginning with `b':
  14171.  
  14172.      mysql> SELECT * FROM pet WHERE name LIKE 'b%';
  14173.      +--------+--------+---------+------+------------+------------+
  14174.      | name   | owner  | species | sex  | birth      | death      |
  14175.      +--------+--------+---------+------+------------+------------+
  14176.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  14177.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  14178.      +--------+--------+---------+------+------------+------------+
  14179.  
  14180. To find names ending with `fy':
  14181.  
  14182.      mysql> SELECT * FROM pet WHERE name LIKE '%fy';
  14183.      +--------+--------+---------+------+------------+-------+
  14184.      | name   | owner  | species | sex  | birth      | death |
  14185.      +--------+--------+---------+------+------------+-------+
  14186.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  14187.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  14188.      +--------+--------+---------+------+------------+-------+
  14189.  
  14190. To find names containing a `w':
  14191.  
  14192.      mysql> SELECT * FROM pet WHERE name LIKE '%w%';
  14193.      +----------+-------+---------+------+------------+------------+
  14194.      | name     | owner | species | sex  | birth      | death      |
  14195.      +----------+-------+---------+------+------------+------------+
  14196.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  14197.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  14198.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  14199.      +----------+-------+---------+------+------------+------------+
  14200.  
  14201. To find names containing exactly five characters, use five instances of
  14202. the `_' pattern character:
  14203.  
  14204.      mysql> SELECT * FROM pet WHERE name LIKE '_____';
  14205.      +-------+--------+---------+------+------------+-------+
  14206.      | name  | owner  | species | sex  | birth      | death |
  14207.      +-------+--------+---------+------+------------+-------+
  14208.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  14209.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  14210.      +-------+--------+---------+------+------------+-------+
  14211.  
  14212. The other type of pattern matching provided by MySQL uses extended
  14213. regular expressions.  When you test for a match for this type of
  14214. pattern, use the `REGEXP' and `NOT REGEXP' operators (or `RLIKE' and
  14215. `NOT RLIKE', which are synonyms).
  14216.  
  14217. Some characteristics of extended regular expressions are:
  14218.  
  14219.    * `.' matches any single character.
  14220.  
  14221.    * A character class `[...]' matches any character within the
  14222.      brackets.  For example, `[abc]' matches `a', `b', or `c'.  To name
  14223.      a range of characters, use a dash.  `[a-z]' matches any letter,
  14224.      whereas `[0-9]' matches any digit.
  14225.  
  14226.    * `*' matches zero or more instances of the thing preceding it.  For
  14227.      example, `x*' matches any number of `x' characters, `[0-9]*'
  14228.      matches any number of digits, and `.*' matches any number of
  14229.      anything.
  14230.  
  14231.    * A `REGEXP' pattern match succeed if the pattern matches anywhere
  14232.      in the value being tested.  (This differs from a `LIKE' pattern
  14233.      match, which succeeds only if the pattern matches the entire
  14234.      value.)
  14235.  
  14236.    * To anchor a pattern so that it must match the beginning or end of
  14237.      the value being tested, use `^' at the beginning or `$' at the end
  14238.      of the pattern.
  14239.  
  14240. To demonstrate how extended regular expressions work, the `LIKE' queries
  14241. shown previously are rewritten here to use `REGEXP'.
  14242.  
  14243. To find names beginning with `b', use `^' to match the beginning of the
  14244. name:
  14245.  
  14246.      mysql> SELECT * FROM pet WHERE name REGEXP '^b';
  14247.      +--------+--------+---------+------+------------+------------+
  14248.      | name   | owner  | species | sex  | birth      | death      |
  14249.      +--------+--------+---------+------+------------+------------+
  14250.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  14251.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  14252.      +--------+--------+---------+------+------------+------------+
  14253.  
  14254. Prior to MySQL Version 3.23.4, `REGEXP' is case sensitive, and the
  14255. previous query will return no rows. In this case, to match either
  14256. lowercase or uppercase `b', use this query instead:
  14257.  
  14258.      mysql> SELECT * FROM pet WHERE name REGEXP '^[bB]';
  14259.  
  14260. From MySQL 3.23.4 on, if you really want to force a `REGEXP' comparison
  14261. to be case sensitive, use the `BINARY' keyword to make one of the
  14262. strings a binary string. This query will match only lowercase `b' at
  14263. the beginning of a name:
  14264.  
  14265.      mysql> SELECT * FROM pet WHERE name REGEXP BINARY '^b';
  14266.  
  14267. To find names ending with `fy', use `$' to match the end of the name:
  14268.  
  14269.      mysql> SELECT * FROM pet WHERE name REGEXP 'fy$';
  14270.      +--------+--------+---------+------+------------+-------+
  14271.      | name   | owner  | species | sex  | birth      | death |
  14272.      +--------+--------+---------+------+------------+-------+
  14273.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  14274.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  14275.      +--------+--------+---------+------+------------+-------+
  14276.  
  14277. To find names containing a `w', use this query:
  14278.  
  14279.      mysql> SELECT * FROM pet WHERE name REGEXP 'w';
  14280.      +----------+-------+---------+------+------------+------------+
  14281.      | name     | owner | species | sex  | birth      | death      |
  14282.      +----------+-------+---------+------+------------+------------+
  14283.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  14284.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  14285.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  14286.      +----------+-------+---------+------+------------+------------+
  14287.  
  14288. Because a regular expression pattern matches if it occurs anywhere in
  14289. the value, it is not necessary in the previous query to put a wildcard
  14290. on either side of the pattern to get it to match the entire value like
  14291. it would be if you used an SQL pattern.
  14292.  
  14293. To find names containing exactly five characters, use `^' and `$' to
  14294. match the beginning and end of the name, and five instances of `.' in
  14295. between:
  14296.  
  14297.      mysql> SELECT * FROM pet WHERE name REGEXP '^.....$';
  14298.      +-------+--------+---------+------+------------+-------+
  14299.      | name  | owner  | species | sex  | birth      | death |
  14300.      +-------+--------+---------+------+------------+-------+
  14301.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  14302.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  14303.      +-------+--------+---------+------+------------+-------+
  14304.  
  14305. You could also write the previous query using the `{n}'
  14306. "repeat-`n'-times" operator:
  14307.  
  14308.      mysql> SELECT * FROM pet WHERE name REGEXP '^.{5}$';
  14309.      +-------+--------+---------+------+------------+-------+
  14310.      | name  | owner  | species | sex  | birth      | death |
  14311.      +-------+--------+---------+------+------------+-------+
  14312.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  14313.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  14314.      +-------+--------+---------+------+------------+-------+
  14315.  
  14316. Counting Rows
  14317. .............
  14318.  
  14319. Databases are often used to answer the question, "How often does a
  14320. certain type of data occur in a table?"  For example, you might want to
  14321. know how many pets you have, or how many pets each owner has, or you
  14322. might want to perform various kinds of census operations on your
  14323. animals.
  14324.  
  14325. Counting the total number of animals you have is the same question as
  14326. "How many rows are in the `pet' table?" because there is one record per
  14327. pet.  `COUNT(*)' counts the number of rows, so the query to count your
  14328. animals looks like this:
  14329.  
  14330.      mysql> SELECT COUNT(*) FROM pet;
  14331.      +----------+
  14332.      | COUNT(*) |
  14333.      +----------+
  14334.      |        9 |
  14335.      +----------+
  14336.  
  14337. Earlier, you retrieved the names of the people who owned pets.  You can
  14338. use `COUNT()' if you want to find out how many pets each owner has:
  14339.  
  14340.      mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
  14341.      +--------+----------+
  14342.      | owner  | COUNT(*) |
  14343.      +--------+----------+
  14344.      | Benny  |        2 |
  14345.      | Diane  |        2 |
  14346.      | Gwen   |        3 |
  14347.      | Harold |        2 |
  14348.      +--------+----------+
  14349.  
  14350. Note the use of `GROUP BY' to group together all records for each
  14351. `owner'.  Without it, all you get is an error message:
  14352.  
  14353.      mysql> SELECT owner, COUNT(*) FROM pet;
  14354.      ERROR 1140: Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
  14355.      with no GROUP columns is illegal if there is no GROUP BY clause
  14356.  
  14357. `COUNT()' and `GROUP BY' are useful for characterizing your data in
  14358. various ways.  The following examples show different ways to perform
  14359. animal census operations.
  14360.  
  14361. Number of animals per species:
  14362.  
  14363.      mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
  14364.      +---------+----------+
  14365.      | species | COUNT(*) |
  14366.      +---------+----------+
  14367.      | bird    |        2 |
  14368.      | cat     |        2 |
  14369.      | dog     |        3 |
  14370.      | hamster |        1 |
  14371.      | snake   |        1 |
  14372.      +---------+----------+
  14373.  
  14374. Number of animals per sex:
  14375.  
  14376.      mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
  14377.      +------+----------+
  14378.      | sex  | COUNT(*) |
  14379.      +------+----------+
  14380.      | NULL |        1 |
  14381.      | f    |        4 |
  14382.      | m    |        4 |
  14383.      +------+----------+
  14384.  
  14385. (In this output, `NULL' indicates that the sex is unknown.)
  14386.  
  14387. Number of animals per combination of species and sex:
  14388.  
  14389.      mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
  14390.      +---------+------+----------+
  14391.      | species | sex  | COUNT(*) |
  14392.      +---------+------+----------+
  14393.      | bird    | NULL |        1 |
  14394.      | bird    | f    |        1 |
  14395.      | cat     | f    |        1 |
  14396.      | cat     | m    |        1 |
  14397.      | dog     | f    |        1 |
  14398.      | dog     | m    |        2 |
  14399.      | hamster | f    |        1 |
  14400.      | snake   | m    |        1 |
  14401.      +---------+------+----------+
  14402.  
  14403. You need not retrieve an entire table when you use `COUNT()'.  For
  14404. example, the previous query, when performed just on dogs and cats,
  14405. looks like this:
  14406.  
  14407.      mysql> SELECT species, sex, COUNT(*) FROM pet
  14408.          -> WHERE species = 'dog' OR species = 'cat'
  14409.          -> GROUP BY species, sex;
  14410.      +---------+------+----------+
  14411.      | species | sex  | COUNT(*) |
  14412.      +---------+------+----------+
  14413.      | cat     | f    |        1 |
  14414.      | cat     | m    |        1 |
  14415.      | dog     | f    |        1 |
  14416.      | dog     | m    |        2 |
  14417.      +---------+------+----------+
  14418.  
  14419. Or, if you wanted the number of animals per sex only for known-sex
  14420. animals:
  14421.  
  14422.      mysql> SELECT species, sex, COUNT(*) FROM pet
  14423.          -> WHERE sex IS NOT NULL
  14424.          -> GROUP BY species, sex;
  14425.      +---------+------+----------+
  14426.      | species | sex  | COUNT(*) |
  14427.      +---------+------+----------+
  14428.      | bird    | f    |        1 |
  14429.      | cat     | f    |        1 |
  14430.      | cat     | m    |        1 |
  14431.      | dog     | f    |        1 |
  14432.      | dog     | m    |        2 |
  14433.      | hamster | f    |        1 |
  14434.      | snake   | m    |        1 |
  14435.      +---------+------+----------+
  14436.  
  14437. Using More Than one Table
  14438. .........................
  14439.  
  14440. The `pet' table keeps track of which pets you have.  If you want to
  14441. record other information about them, such as events in their lives like
  14442. visits to the vet or when litters are born, you need another table.
  14443. What should this table look like? It needs:
  14444.  
  14445.    * To contain the pet name so you know which animal each event
  14446.      pertains to.
  14447.  
  14448.    * A date so you know when the event occurred.
  14449.  
  14450.    * A field to describe the event.
  14451.  
  14452.    * An event type field, if you want to be able to categorize events.
  14453.  
  14454. Given these considerations, the `CREATE TABLE' statement for the
  14455. `event' table might look like this:
  14456.  
  14457.      mysql> CREATE TABLE event (name VARCHAR(20), date DATE,
  14458.          -> type VARCHAR(15), remark VARCHAR(255));
  14459.  
  14460. As with the `pet' table, it's easiest to load the initial records by
  14461. creating a tab-delimited text file containing the information:
  14462.  
  14463. *name*      *date*      *type*      *remark*
  14464. Fluffy      1995-05-15  litter      4 kittens, 3 female, 1
  14465.                                     male
  14466. Buffy       1993-06-23  litter      5 puppies, 2 female, 3
  14467.                                     male
  14468. Buffy       1994-06-19  litter      3 puppies, 3 female
  14469. Chirpy      1999-03-21  vet         needed beak straightened
  14470. Slim        1997-08-03  vet         broken rib
  14471. Bowser      1991-10-12  kennel      
  14472. Fang        1991-10-12  kennel      
  14473. Fang        1998-08-28  birthday    Gave him a new chew toy
  14474. Claws       1998-03-17  birthday    Gave him a new flea
  14475.                                     collar
  14476. Whistler    1998-12-09  birthday    First birthday
  14477.  
  14478. Load the records like this:
  14479.  
  14480.      mysql> LOAD DATA LOCAL INFILE 'event.txt' INTO TABLE event;
  14481.  
  14482. Based on what you've learned from the queries you've run on the `pet'
  14483. table, you should be able to perform retrievals on the records in the
  14484. `event' table; the principles are the same.  But when is the `event'
  14485. table by itself insufficient to answer questions you might ask?
  14486.  
  14487. Suppose that you want to find out the ages at which each pet had its
  14488. litters. We saw earlier how to calculate ages from two dates.  The
  14489. litter date of the mother is in the `event' table, but to calculate her
  14490. age on that date you need her birth date, which is stored in the `pet'
  14491. table.  This means the query requires both tables:
  14492.  
  14493.      mysql> SELECT pet.name,
  14494.          -> (YEAR(date)-YEAR(birth)) - (RIGHT(date,5)<RIGHT(birth,5)) AS age,
  14495.          -> remark
  14496.          -> FROM pet, event
  14497.          -> WHERE pet.name = event.name AND type = 'litter';
  14498.      +--------+------+-----------------------------+
  14499.      | name   | age  | remark                      |
  14500.      +--------+------+-----------------------------+
  14501.      | Fluffy |    2 | 4 kittens, 3 female, 1 male |
  14502.      | Buffy  |    4 | 5 puppies, 2 female, 3 male |
  14503.      | Buffy  |    5 | 3 puppies, 3 female         |
  14504.      +--------+------+-----------------------------+
  14505.  
  14506. There are several things to note about this query:
  14507.  
  14508.    * The `FROM' clause lists two tables because the query needs to pull
  14509.      information from both of them.
  14510.  
  14511.    * When combining (joining) information from multiple tables, you
  14512.      need to specify how records in one table can be matched to records
  14513.      in the other.  This is easy because they both have a `name'
  14514.      column.  The query uses `WHERE' clause to match up records in the
  14515.      two tables based on the `name' values.
  14516.  
  14517.    * Because the `name' column occurs in both tables, you must be
  14518.      specific about which table you mean when referring to the column.
  14519.      This is done by prepending the table name to the column name.
  14520.  
  14521. You need not have two different tables to perform a join.  Sometimes it
  14522. is useful to join a table to itself, if you want to compare records in
  14523. a table to other records in that same table.  For example, to find
  14524. breeding pairs among your pets, you can join the `pet' table with
  14525. itself to produce candidate pairs of males and females of like species:
  14526.  
  14527.      mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
  14528.          -> FROM pet AS p1, pet AS p2
  14529.          -> WHERE p1.species = p2.species AND p1.sex = 'f' AND p2.sex = 'm';
  14530.      +--------+------+--------+------+---------+
  14531.      | name   | sex  | name   | sex  | species |
  14532.      +--------+------+--------+------+---------+
  14533.      | Fluffy | f    | Claws  | m    | cat     |
  14534.      | Buffy  | f    | Fang   | m    | dog     |
  14535.      | Buffy  | f    | Bowser | m    | dog     |
  14536.      +--------+------+--------+------+---------+
  14537.  
  14538. In this query, we specify aliases for the table name in order to refer
  14539. to the columns and keep straight which instance of the table each
  14540. column reference is associated with.
  14541.  
  14542. Getting Information About Databases and Tables
  14543. ==============================================
  14544.  
  14545. What if you forget the name of a database or table, or what the
  14546. structure of a given table is (for example, what its columns are
  14547. called)?  MySQL addresses this problem through several statements that
  14548. provide information about the databases and tables it supports.
  14549.  
  14550. You have already seen `SHOW DATABASES', which lists the databases
  14551. managed by the server.  To find out which database is currently
  14552. selected, use the `DATABASE()' function:
  14553.  
  14554.      mysql> SELECT DATABASE();
  14555.      +------------+
  14556.      | DATABASE() |
  14557.      +------------+
  14558.      | menagerie  |
  14559.      +------------+
  14560.  
  14561. If you haven't selected any database yet, the result is `NULL' (or the
  14562. empty string before MySQL 4.1.1).
  14563.  
  14564. To find out what tables the current database contains (for example, when
  14565. you're not sure about the name of a table), use this command:
  14566.  
  14567.      mysql> SHOW TABLES;
  14568.      +---------------------+
  14569.      | Tables in menagerie |
  14570.      +---------------------+
  14571.      | event               |
  14572.      | pet                 |
  14573.      +---------------------+
  14574.  
  14575. If you want to find out about the structure of a table, the `DESCRIBE'
  14576. command is useful; it displays information about each of a table's
  14577. columns:
  14578.  
  14579.      mysql> DESCRIBE pet;
  14580.      +---------+-------------+------+-----+---------+-------+
  14581.      | Field   | Type        | Null | Key | Default | Extra |
  14582.      +---------+-------------+------+-----+---------+-------+
  14583.      | name    | varchar(20) | YES  |     | NULL    |       |
  14584.      | owner   | varchar(20) | YES  |     | NULL    |       |
  14585.      | species | varchar(20) | YES  |     | NULL    |       |
  14586.      | sex     | char(1)     | YES  |     | NULL    |       |
  14587.      | birth   | date        | YES  |     | NULL    |       |
  14588.      | death   | date        | YES  |     | NULL    |       |
  14589.      +---------+-------------+------+-----+---------+-------+
  14590.  
  14591. `Field' indicates the column name, `Type' is the data type for the
  14592. column, `NULL' indicates whether the column can contain `NULL' values,
  14593. `Key' indicates whether the column is indexed, and `Default' specifies
  14594. the column's default value.
  14595.  
  14596. If you have indexes on a table, `SHOW INDEX FROM TBL_NAME' produces
  14597. information about them.
  14598.  
  14599. Using `mysql' in Batch Mode
  14600. ===========================
  14601.  
  14602. In the previous sections, you used `mysql' interactively to enter
  14603. queries and view the results.  You can also run `mysql' in batch mode.
  14604. To do this, put the commands you want to run in a file, then tell
  14605. `mysql' to read its input from the file:
  14606.  
  14607.      shell> mysql < BATCH-FILE
  14608.  
  14609. If you are running `mysql' under Windows and have some special
  14610. characters in the file that cause problems, you can do this:
  14611.  
  14612.      C:\> mysql -e "source BATCH-FILE"
  14613.  
  14614. If you need to specify connection parameters on the command line, the
  14615. command might look like this:
  14616.  
  14617.      shell> mysql -h HOST -u USER -p < BATCH-FILE
  14618.      Enter password: ********
  14619.  
  14620. When you use `mysql' this way, you are creating a script file, then
  14621. executing the script.
  14622.  
  14623. If you want the script to continue even if some of the statements in it
  14624. produce errors, you should use the `--force' command-line option.
  14625.  
  14626. Why use a script?  Here are a few reasons:
  14627.  
  14628.    * If you run a query repeatedly (say, every day or every week),
  14629.      making it a script allows you to avoid retyping it each time you
  14630.      execute it.
  14631.  
  14632.    * You can generate new queries from existing ones that are similar
  14633.      by copying and editing script files.
  14634.  
  14635.    * Batch mode can also be useful while you're developing a query,
  14636.      particularly for multiple-line commands or multiple-statement
  14637.      sequences of commands.  If you make a mistake, you don't have to
  14638.      retype everything.  Just edit your script to correct the error,
  14639.      then tell `mysql' to execute it again.
  14640.  
  14641.    * If you have a query that produces a lot of output, you can run the
  14642.      output through a pager rather than watching it scroll off the top
  14643.      of your screen:
  14644.  
  14645.           shell> mysql < BATCH-FILE | more
  14646.  
  14647.    * You can catch the output in a file for further processing:
  14648.  
  14649.           shell> mysql < BATCH-FILE > mysql.out
  14650.  
  14651.    * You can distribute your script to other people so they can run the
  14652.      commands, too.
  14653.  
  14654.    * Some situations do not allow for interactive use, for example,
  14655.      when you run a query from a `cron' job.  In this case, you must
  14656.      use batch mode.
  14657.  
  14658. The default output format is different (more concise) when you run
  14659. `mysql' in batch mode than when you use it interactively.  For example,
  14660. the output of `SELECT DISTINCT species FROM pet' looks like this when
  14661. `mysql' is run interactively:
  14662.  
  14663.      +---------+
  14664.      | species |
  14665.      +---------+
  14666.      | bird    |
  14667.      | cat     |
  14668.      | dog     |
  14669.      | hamster |
  14670.      | snake   |
  14671.      +---------+
  14672.  
  14673. In batch mode, the output looks like this instead:
  14674.  
  14675.      species
  14676.      bird
  14677.      cat
  14678.      dog
  14679.      hamster
  14680.      snake
  14681.  
  14682. If you want to get the interactive output format in batch mode, use
  14683. `mysql -t'.  To echo to the output the commands that are executed, use
  14684. `mysql -vvv'.
  14685.  
  14686. You can also use scripts from the `mysql' prompt by using the `source'
  14687. or `\.' command:
  14688.  
  14689.      mysql> source filename;
  14690.      mysql> \. filename
  14691.  
  14692. Examples of Common Queries
  14693. ==========================
  14694.  
  14695. Here are examples of how to solve some common problems with MySQL.
  14696.  
  14697. Some of the examples use the table `shop' to hold the price of each
  14698. article (item number) for certain traders (dealers).  Supposing that
  14699. each trader has a single fixed price per article, then (`article',
  14700. `dealer') is a primary key for the records.
  14701.  
  14702. Start the command-line tool `mysql' and select a database:
  14703.  
  14704.      shell> mysql your-database-name
  14705.  
  14706. (In most MySQL installations, you can use the database name `test').
  14707.  
  14708. You can create and populate the example table with these statements:
  14709.  
  14710.      mysql> CREATE TABLE shop (
  14711.          -> article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  14712.          -> dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
  14713.          -> price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
  14714.          -> PRIMARY KEY(article, dealer));
  14715.      mysql> INSERT INTO shop VALUES
  14716.          -> (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),
  14717.          -> (3,'C',1.69),(3,'D',1.25),(4,'D',19.95);
  14718.  
  14719. After issuing the statements, the table should have the following
  14720. contents:
  14721.  
  14722.      mysql> SELECT * FROM shop;
  14723.      +---------+--------+-------+
  14724.      | article | dealer | price |
  14725.      +---------+--------+-------+
  14726.      |    0001 | A      |  3.45 |
  14727.      |    0001 | B      |  3.99 |
  14728.      |    0002 | A      | 10.99 |
  14729.      |    0003 | B      |  1.45 |
  14730.      |    0003 | C      |  1.69 |
  14731.      |    0003 | D      |  1.25 |
  14732.      |    0004 | D      | 19.95 |
  14733.      +---------+--------+-------+
  14734.  
  14735. The Maximum Value for a Column
  14736. ------------------------------
  14737.  
  14738. "What's the highest item number?"
  14739.  
  14740.      SELECT MAX(article) AS article FROM shop;
  14741.      
  14742.      +---------+
  14743.      | article |
  14744.      +---------+
  14745.      |       4 |
  14746.      +---------+
  14747.  
  14748. The Row Holding the Maximum of a Certain Column
  14749. -----------------------------------------------
  14750.  
  14751. "Find number, dealer, and price of the most expensive article."
  14752.  
  14753. In standard SQL (and as of MySQL 4.1), this is easily done with a
  14754. subquery:
  14755.  
  14756.      SELECT article, dealer, price
  14757.      FROM   shop
  14758.      WHERE  price=(SELECT MAX(price) FROM shop);
  14759.  
  14760. In MySQL versions prior to 4.1, just do it in two steps:
  14761.  
  14762.   1. Get the maximum price value from the table with a `SELECT'
  14763.      statement.
  14764.           mysql> SELECT MAX(price) FROM shop;
  14765.           +------------+
  14766.           | MAX(price) |
  14767.           +------------+
  14768.           |      19.95 |
  14769.           +------------+
  14770.  
  14771.   2. Using the value 19.95 shown by the previous query to be the maximum
  14772.      article price, write a query to locate and display the
  14773.      corresponding record:
  14774.           mysql> SELECT article, dealer, price
  14775.               -> FROM   shop
  14776.               -> WHERE  price=19.95;
  14777.           +---------+--------+-------+
  14778.           | article | dealer | price |
  14779.           +---------+--------+-------+
  14780.           |    0004 | D      | 19.95 |
  14781.           +---------+--------+-------+
  14782.  
  14783. Another solution is to sort all rows descending by price and only get
  14784. the first row using the MySQL-specific `LIMIT' clause:
  14785.  
  14786.      SELECT article, dealer, price
  14787.      FROM   shop
  14788.      ORDER BY price DESC
  14789.      LIMIT 1;
  14790.  
  14791. Note:  If there were several most expensive articles, each with a price
  14792. of 19.95, the `LIMIT' solution would show only one of them!
  14793.  
  14794. Maximum of Column per Group
  14795. ---------------------------
  14796.  
  14797. "What's the highest price per article?"
  14798.  
  14799.      SELECT article, MAX(price) AS price
  14800.      FROM   shop
  14801.      GROUP BY article
  14802.      
  14803.      +---------+-------+
  14804.      | article | price |
  14805.      +---------+-------+
  14806.      |    0001 |  3.99 |
  14807.      |    0002 | 10.99 |
  14808.      |    0003 |  1.69 |
  14809.      |    0004 | 19.95 |
  14810.      +---------+-------+
  14811.  
  14812. The Rows Holding the Group-wise Maximum of a Certain Field
  14813. ----------------------------------------------------------
  14814.  
  14815. "For each article, find the dealer or dealers with the most expensive
  14816. price."
  14817.  
  14818. In standard SQL (and as of MySQL 4.1), the problem can be solved with a
  14819. subquery like this:
  14820.  
  14821.      SELECT article, dealer, price
  14822.      FROM   shop s1
  14823.      WHERE  price=(SELECT MAX(s2.price)
  14824.                    FROM shop s2
  14825.                    WHERE s1.article = s2.article);
  14826.  
  14827. In MySQL versions prior to 4.1, it's best do it in several steps:
  14828.  
  14829.   1. Get the list of (article,maxprice) pairs.
  14830.  
  14831.   2. For each article, get the corresponding rows that have the stored
  14832.      maximum price.
  14833.  
  14834. This can easily be done with a temporary table and a join:
  14835.  
  14836.      CREATE TEMPORARY TABLE tmp (
  14837.              article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  14838.              price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL);
  14839.      
  14840.      LOCK TABLES shop READ;
  14841.      
  14842.      INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article;
  14843.      
  14844.      SELECT shop.article, dealer, shop.price FROM shop, tmp
  14845.      WHERE shop.article=tmp.article AND shop.price=tmp.price;
  14846.      
  14847.      UNLOCK TABLES;
  14848.      
  14849.      DROP TABLE tmp;
  14850.  
  14851. If you don't use a `TEMPORARY' table, you must also lock the `tmp'
  14852. table.
  14853.  
  14854. "Can it be done with a single query?"
  14855.  
  14856. Yes, but only by using a quite inefficient trick called the "MAX-CONCAT
  14857. trick":
  14858.  
  14859.      SELECT article,
  14860.             SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer,
  14861.        0.00+LEFT(      MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price
  14862.      FROM   shop
  14863.      GROUP BY article;
  14864.      
  14865.      +---------+--------+-------+
  14866.      | article | dealer | price |
  14867.      +---------+--------+-------+
  14868.      |    0001 | B      |  3.99 |
  14869.      |    0002 | A      | 10.99 |
  14870.      |    0003 | C      |  1.69 |
  14871.      |    0004 | D      | 19.95 |
  14872.      +---------+--------+-------+
  14873.  
  14874. The last example can be made a bit more efficient by doing the
  14875. splitting of the concatenated column in the client.
  14876.  
  14877. Using User Variables
  14878. --------------------
  14879.  
  14880. You can use MySQL user variables to remember results without having to
  14881. store them in temporary variables in the client.  *Note Variables::.
  14882.  
  14883. For example, to find the articles with the highest and lowest price you
  14884. can do this:
  14885.  
  14886.      mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
  14887.      mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
  14888.      +---------+--------+-------+
  14889.      | article | dealer | price |
  14890.      +---------+--------+-------+
  14891.      |    0003 | D      |  1.25 |
  14892.      |    0004 | D      | 19.95 |
  14893.      +---------+--------+-------+
  14894.  
  14895. Using Foreign Keys
  14896. ------------------
  14897.  
  14898. In MySQL 3.23.44 and up, `InnoDB' tables support checking of foreign
  14899. key constraints. *Note `InnoDB': InnoDB.  See also *Note ANSI diff
  14900. Foreign Keys::.
  14901.  
  14902. You don't actually need foreign keys to join two tables.  For table
  14903. types other than `InnoDB', the only things MySQL currently doesn't do
  14904. are 1) `CHECK' to make sure that the keys you use really exist in the
  14905. table or tables you're referencing and 2) automatically delete rows
  14906. from a table with a foreign key definition. Using your keys to join
  14907. tables will work just fine:
  14908.  
  14909.      CREATE TABLE person (
  14910.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  14911.          name CHAR(60) NOT NULL,
  14912.          PRIMARY KEY (id)
  14913.      );
  14914.      
  14915.      CREATE TABLE shirt (
  14916.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  14917.          style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
  14918.          color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
  14919.          owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id),
  14920.          PRIMARY KEY (id)
  14921.      );
  14922.      
  14923.      
  14924.      INSERT INTO person VALUES (NULL, 'Antonio Paz');
  14925.      
  14926.      INSERT INTO shirt VALUES
  14927.      (NULL, 'polo', 'blue', LAST_INSERT_ID()),
  14928.      (NULL, 'dress', 'white', LAST_INSERT_ID()),
  14929.      (NULL, 't-shirt', 'blue', LAST_INSERT_ID());
  14930.      
  14931.      
  14932.      INSERT INTO person VALUES (NULL, 'Lilliana Angelovska');
  14933.      
  14934.      INSERT INTO shirt VALUES
  14935.      (NULL, 'dress', 'orange', LAST_INSERT_ID()),
  14936.      (NULL, 'polo', 'red', LAST_INSERT_ID()),
  14937.      (NULL, 'dress', 'blue', LAST_INSERT_ID()),
  14938.      (NULL, 't-shirt', 'white', LAST_INSERT_ID());
  14939.      
  14940.      
  14941.      SELECT * FROM person;
  14942.      +----+---------------------+
  14943.      | id | name                |
  14944.      +----+---------------------+
  14945.      |  1 | Antonio Paz         |
  14946.      |  2 | Lilliana Angelovska |
  14947.      +----+---------------------+
  14948.      
  14949.      SELECT * FROM shirt;
  14950.      +----+---------+--------+-------+
  14951.      | id | style   | color  | owner |
  14952.      +----+---------+--------+-------+
  14953.      |  1 | polo    | blue   |     1 |
  14954.      |  2 | dress   | white  |     1 |
  14955.      |  3 | t-shirt | blue   |     1 |
  14956.      |  4 | dress   | orange |     2 |
  14957.      |  5 | polo    | red    |     2 |
  14958.      |  6 | dress   | blue   |     2 |
  14959.      |  7 | t-shirt | white  |     2 |
  14960.      +----+---------+--------+-------+
  14961.      
  14962.      
  14963.      SELECT s.* FROM person p, shirt s
  14964.       WHERE p.name LIKE 'Lilliana%'
  14965.         AND s.owner = p.id
  14966.         AND s.color <> 'white';
  14967.      
  14968.      +----+-------+--------+-------+
  14969.      | id | style | color  | owner |
  14970.      +----+-------+--------+-------+
  14971.      |  4 | dress | orange |     2 |
  14972.      |  5 | polo  | red    |     2 |
  14973.      |  6 | dress | blue   |     2 |
  14974.      +----+-------+--------+-------+
  14975.  
  14976. Searching on Two Keys
  14977. ---------------------
  14978.  
  14979. MySQL doesn't yet optimize when you search on two different keys
  14980. combined with `OR' (searching on one key with different `OR' parts is
  14981. optimized quite well):
  14982.  
  14983.      SELECT field1_index, field2_index FROM test_table
  14984.      WHERE field1_index = '1' OR  field2_index = '1'
  14985.  
  14986. The reason is that we haven't yet had time to come up with an efficient
  14987. way to handle this in the general case. (The `AND' handling is, in
  14988. comparison, now completely general and works very well.)
  14989.  
  14990. In MySQL 4.0 and up, you can solve this problem efficiently by using a
  14991. `UNION' that combines the output of two separate `SELECT' statements.
  14992. *Note UNION::.  Each `SELECT' searches only one key and can be
  14993. optimized:
  14994.  
  14995.      SELECT field1_index, field2_index
  14996.          FROM test_table WHERE field1_index = '1'
  14997.      UNION
  14998.      SELECT field1_index, field2_index
  14999.          FROM test_table WHERE field2_index = '1';
  15000.  
  15001. Prior to MySQL 4.0, you can achieve the same effect by using a
  15002. `TEMPORARY' table and separate `SELECT' statements.  This type of
  15003. optimization is also very good if you are using very complicated
  15004. queries where the SQL server does the optimizations in the wrong order.
  15005.  
  15006.      CREATE TEMPORARY TABLE tmp
  15007.      SELECT field1_index, field2_index
  15008.          FROM test_table WHERE field1_index = '1';
  15009.      INSERT INTO tmp
  15010.      SELECT field1_index, field2_index
  15011.          FROM test_table WHERE field2_index = '1';
  15012.      SELECT * from tmp;
  15013.      DROP TABLE tmp;
  15014.  
  15015. This method of solving the problem is in effect a `UNION' of two
  15016. queries.
  15017.  
  15018. Calculating Visits Per Day
  15019. --------------------------
  15020.  
  15021. The following example shows how you can use the bit group functions to
  15022. calculate the number of days per month a user has visited a Web page.
  15023.  
  15024.      CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL,
  15025.                   day INT(2) UNSIGNED ZEROFILL);
  15026.      INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2),
  15027.                  (2000,2,23),(2000,2,23);
  15028.  
  15029. The example table contains year-month-day values representing visits by
  15030. users to the page. To determine how many different days in each month
  15031. these visits occur, use this query:
  15032.  
  15033.      SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1
  15034.             GROUP BY year,month;
  15035.  
  15036. Which returns:
  15037.  
  15038.      +------+-------+------+
  15039.      | year | month | days |
  15040.      +------+-------+------+
  15041.      | 2000 |    01 |    3 |
  15042.      | 2000 |    02 |    2 |
  15043.      +------+-------+------+
  15044.  
  15045. The query calculates how many different days appear in the table for
  15046. each year/month combination, with automatic removal of duplicate
  15047. entries.
  15048.  
  15049. Using `AUTO_INCREMENT'
  15050. ----------------------
  15051.  
  15052. The `AUTO_INCREMENT' attribute can be used to generate a unique
  15053. identity for new rows:
  15054.  
  15055.      CREATE TABLE animals (
  15056.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  15057.                   name CHAR(30) NOT NULL,
  15058.                   PRIMARY KEY (id)
  15059.                   );
  15060.      INSERT INTO animals (name) VALUES ('dog'),('cat'),('penguin'),
  15061.                                        ('lax'),('whale'),('ostrich');
  15062.      SELECT * FROM animals;
  15063.  
  15064. Which returns:
  15065.  
  15066.      +----+---------+
  15067.      | id | name    |
  15068.      +----+---------+
  15069.      |  1 | dog     |
  15070.      |  2 | cat     |
  15071.      |  3 | penguin |
  15072.      |  4 | lax     |
  15073.      |  5 | whale   |
  15074.      |  6 | ostrich |
  15075.      +----+---------+
  15076.  
  15077. You can retrieve the most recent `AUTO_INCREMENT' value with the
  15078. `LAST_INSERT_ID()' SQL function or the `mysql_insert_id()' C API
  15079. function. These functions are connection-specific, so their return value
  15080. is not affected by another connection also doing inserts.
  15081.  
  15082. Note: For a multiple-row insert, `LAST_INSERT_ID()'/`mysql_insert_id()'
  15083. will actually return the `AUTO_INCREMENT' key from the *first* of the
  15084. inserted rows.  This allows multiple-row inserts to be reproduced
  15085. correctly on other servers in a replication setup.
  15086.  
  15087. For `MyISAM' and `BDB' tables you can specify `AUTO_INCREMENT' on a
  15088. secondary column in a multiple-column index.  In this case, the
  15089. generated value for the `AUTO_INCREMENT' column is calculated as
  15090. `MAX(auto_increment_column)+1 WHERE prefix=given-prefix'.  This is
  15091. useful when you want to put data into ordered groups.
  15092.  
  15093.      CREATE TABLE animals (
  15094.                   grp ENUM('fish','mammal','bird') NOT NULL,
  15095.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  15096.                   name CHAR(30) NOT NULL,
  15097.                   PRIMARY KEY (grp,id)
  15098.                   );
  15099.      INSERT INTO animals (grp,name) VALUES('mammal','dog'),('mammal','cat'),
  15100.                        ('bird','penguin'),('fish','lax'),('mammal','whale'),
  15101.                        ('bird','ostrich');
  15102.      SELECT * FROM animals ORDER BY grp,id;
  15103.  
  15104. Which returns:
  15105.  
  15106.      +--------+----+---------+
  15107.      | grp    | id | name    |
  15108.      +--------+----+---------+
  15109.      | fish   |  1 | lax     |
  15110.      | mammal |  1 | dog     |
  15111.      | mammal |  2 | cat     |
  15112.      | mammal |  3 | whale   |
  15113.      | bird   |  1 | penguin |
  15114.      | bird   |  2 | ostrich |
  15115.      +--------+----+---------+
  15116.  
  15117. Note that in this case (when the `AUTO_INCREMENT' column is part of a
  15118. multiple-column index), `AUTO_INCREMENT' values will be reused if you
  15119. delete the row with the biggest `AUTO_INCREMENT' value in any group.
  15120. This happens even for `MyISAM' tables, for which `AUTO_INCREMENT'
  15121. values normally are not reused.)
  15122.  
  15123. Queries from the Twin Project
  15124. =============================
  15125.  
  15126. At Analytikerna and Lentus, we have been doing the systems and field
  15127. work for a big research project. This project is a collaboration
  15128. between the Institute of Environmental Medicine at Karolinska
  15129. Institutet Stockholm and the Section on Clinical Research in Aging and
  15130. Psychology at the University of Southern California.
  15131.  
  15132. The project involves a screening part where all twins in Sweden older
  15133. than 65 years are interviewed by telephone. Twins who meet certain
  15134. criteria are passed on to the next stage. In this latter stage, twins
  15135. who want to participate are visited by a doctor/nurse team. Some of the
  15136. examinations include physical and neuropsychological examination,
  15137. laboratory testing, neuroimaging, psychological status assessment, and
  15138. family history collection. In addition, data are collected on medical
  15139. and environmental risk factors.
  15140.  
  15141. More information about Twin studies can be found at:
  15142. `http://www.mep.ki.se/twinreg/index_en.html'
  15143.  
  15144. The latter part of the project is administered with a Web interface
  15145. written using Perl and MySQL.
  15146.  
  15147. Each night all data from the interviews is moved into a MySQL database.
  15148.  
  15149. Find All Non-distributed Twins
  15150. ------------------------------
  15151.  
  15152. The following query is used to determine who goes into the second part
  15153. of the project:
  15154.  
  15155.      SELECT
  15156.          CONCAT(p1.id, p1.tvab) + 0 AS tvid,
  15157.          CONCAT(p1.christian_name, ' ', p1.surname) AS Name,
  15158.          p1.postal_code AS Code,
  15159.          p1.city AS City,
  15160.          pg.abrev AS Area,
  15161.          IF(td.participation = 'Aborted', 'A', ' ') AS A,
  15162.          p1.dead AS dead1,
  15163.          l.event AS event1,
  15164.          td.suspect AS tsuspect1,
  15165.          id.suspect AS isuspect1,
  15166.          td.severe AS tsevere1,
  15167.          id.severe AS isevere1,
  15168.          p2.dead AS dead2,
  15169.          l2.event AS event2,
  15170.          h2.nurse AS nurse2,
  15171.          h2.doctor AS doctor2,
  15172.          td2.suspect AS tsuspect2,
  15173.          id2.suspect AS isuspect2,
  15174.          td2.severe AS tsevere2,
  15175.          id2.severe AS isevere2,
  15176.          l.finish_date
  15177.      FROM
  15178.          twin_project AS tp
  15179.          /* For Twin 1 */
  15180.          LEFT JOIN twin_data AS td ON tp.id = td.id
  15181.                    AND tp.tvab = td.tvab
  15182.          LEFT JOIN informant_data AS id ON tp.id = id.id
  15183.                    AND tp.tvab = id.tvab
  15184.          LEFT JOIN harmony AS h ON tp.id = h.id
  15185.                    AND tp.tvab = h.tvab
  15186.          LEFT JOIN lentus AS l ON tp.id = l.id
  15187.                    AND tp.tvab = l.tvab
  15188.          /* For Twin 2 */
  15189.          LEFT JOIN twin_data AS td2 ON p2.id = td2.id
  15190.                    AND p2.tvab = td2.tvab
  15191.          LEFT JOIN informant_data AS id2 ON p2.id = id2.id
  15192.                    AND p2.tvab = id2.tvab
  15193.          LEFT JOIN harmony AS h2 ON p2.id = h2.id
  15194.                    AND p2.tvab = h2.tvab
  15195.          LEFT JOIN lentus AS l2 ON p2.id = l2.id
  15196.                    AND p2.tvab = l2.tvab,
  15197.          person_data AS p1,
  15198.          person_data AS p2,
  15199.          postal_groups AS pg
  15200.      WHERE
  15201.          /* p1 gets main twin and p2 gets his/her twin. */
  15202.          /* ptvab is a field inverted from tvab */
  15203.          p1.id = tp.id AND p1.tvab = tp.tvab AND
  15204.          p2.id = p1.id AND p2.ptvab = p1.tvab AND
  15205.          /* Just the sceening survey */
  15206.          tp.survey_no = 5 AND
  15207.          /* Skip if partner died before 65 but allow emigration (dead=9) */
  15208.          (p2.dead = 0 OR p2.dead = 9 OR
  15209.           (p2.dead = 1 AND
  15210.            (p2.death_date = 0 OR
  15211.             (((TO_DAYS(p2.death_date) - TO_DAYS(p2.birthday)) / 365)
  15212.              >= 65))))
  15213.          AND
  15214.          (
  15215.          /* Twin is suspect */
  15216.          (td.future_contact = 'Yes' AND td.suspect = 2) OR
  15217.          /* Twin is suspect - Informant is Blessed */
  15218.          (td.future_contact = 'Yes' AND td.suspect = 1
  15219.                                     AND id.suspect = 1) OR
  15220.          /* No twin - Informant is Blessed */
  15221.          (ISNULL(td.suspect) AND id.suspect = 1
  15222.                              AND id.future_contact = 'Yes') OR
  15223.          /* Twin broken off - Informant is Blessed */
  15224.          (td.participation = 'Aborted'
  15225.           AND id.suspect = 1 AND id.future_contact = 'Yes') OR
  15226.          /* Twin broken off - No inform - Have partner */
  15227.          (td.participation = 'Aborted' AND ISNULL(id.suspect)
  15228.                                        AND p2.dead = 0))
  15229.          AND
  15230.          l.event = 'Finished'
  15231.          /* Get at area code */
  15232.          AND SUBSTRING(p1.postal_code, 1, 2) = pg.code
  15233.          /* Not already distributed */
  15234.          AND (h.nurse IS NULL OR h.nurse=00 OR h.doctor=00)
  15235.          /* Has not refused or been aborted */
  15236.          AND NOT (h.status = 'Refused' OR h.status = 'Aborted'
  15237.          OR h.status = 'Died' OR h.status = 'Other')
  15238.      ORDER BY
  15239.          tvid;
  15240.  
  15241. Some explanations:
  15242. `CONCAT(p1.id, p1.tvab) + 0 AS tvid'
  15243.      We want to sort on the concatenated `id' and `tvab' in numerical
  15244.      order. Adding `0' to the result causes MySQL to treat the result
  15245.      as a number.
  15246.  
  15247. column `id'
  15248.      This identifies a pair of twins. It is a key in all tables.
  15249.  
  15250. column `tvab'
  15251.      This identifies a twin in a pair. It has a value of `1' or `2'.
  15252.  
  15253. column `ptvab'
  15254.      This is an inverse of `tvab'. When `tvab' is `1' this is `2', and
  15255.      vice versa. It exists to save typing and to make it easier for
  15256.      MySQL to optimize the query.
  15257.  
  15258. This query demonstrates, among other things, how to do lookups on a
  15259. table from the same table with a join (`p1' and `p2'). In the example,
  15260. this is used to check whether a twin's partner died before the age of
  15261. 65. If so, the row is not returned.
  15262.  
  15263. All of the above exist in all tables with twin-related information. We
  15264. have a key on both `id,tvab' (all tables), and `id,ptvab'
  15265. (`person_data') to make queries faster.
  15266.  
  15267. On our production machine (A 200MHz UltraSPARC), this query returns
  15268. about 150-200 rows and takes less than one second.
  15269.  
  15270. The current number of records in the tables used in the query:
  15271. *Table*            *Rows*
  15272. `person_data'      71074
  15273. `lentus'           5291
  15274. `twin_project'     5286
  15275. `twin_data'        2012
  15276. `informant_data'   663
  15277. `harmony'          381
  15278. `postal_groups'    100
  15279.  
  15280. Show a Table of Twin Pair Status
  15281. --------------------------------
  15282.  
  15283. Each interview ends with a status code called `event'. The query shown
  15284. here is used to display a table over all twin pairs combined by event.
  15285. This indicates in how many pairs both twins are finished, in how many
  15286. pairs one twin is finished and the other refused, and so on.
  15287.  
  15288.      SELECT
  15289.              t1.event,
  15290.              t2.event,
  15291.              COUNT(*)
  15292.      FROM
  15293.              lentus AS t1,
  15294.              lentus AS t2,
  15295.              twin_project AS tp
  15296.      WHERE
  15297.              /* We are looking at one pair at a time */
  15298.              t1.id = tp.id
  15299.              AND t1.tvab=tp.tvab
  15300.              AND t1.id = t2.id
  15301.              /* Just the sceening survey */
  15302.              AND tp.survey_no = 5
  15303.              /* This makes each pair only appear once */
  15304.              AND t1.tvab='1' AND t2.tvab='2'
  15305.      GROUP BY
  15306.              t1.event, t2.event;
  15307.  
  15308. Using MySQL with Apache
  15309. =======================
  15310.  
  15311. There are programs that let you authenticate your users from a MySQL
  15312. database and also let you write your log files into a MySQL table.
  15313.  
  15314. You can change the Apache logging format to be easily readable by MySQL
  15315. by putting the following into the Apache configuration file:
  15316.  
  15317.      LogFormat \
  15318.              "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",  \
  15319.              \"%U\",\"%{Referer}i\",\"%{User-Agent}i\""
  15320.  
  15321. To load a log file in that format into MySQL, you can use a statement
  15322. something like this:
  15323.  
  15324.      LOAD DATA INFILE '/LOCAL/ACCESS_LOG' INTO TABLE TBL_NAME
  15325.      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
  15326.  
  15327. The named table should be created to have columns that correspond to
  15328. those that the `LogFormat' line writes to the log file.
  15329.  
  15330. Using MySQL Programs
  15331. ********************
  15332.  
  15333. This chapter provides a brief overview of the programs provided by
  15334. MySQL AB and discusses how to specify options when you run these
  15335. programs.  Most programs have options that are specific to their own
  15336. operation, but the syntax for specifying options is similar for all of
  15337. them. Later chapters provide more detailed descriptions of individual
  15338. programs, including which options they recognize.
  15339.  
  15340. Overview of MySQL Programs
  15341. ==========================
  15342.  
  15343. MySQL AB provides several types of programs:
  15344.  
  15345. The MYSQL server and server startup scripts:
  15346.         * `mysqld' is the MySQL server
  15347.  
  15348.         * `mysqld_safe', `mysql.server', and `mysqld_multi' are server
  15349.           startup scripts
  15350.  
  15351.         * `mysql_install_db' initializes the data directory and the
  15352.           initial databases
  15353.  
  15354.      These programs are discussed further in *Note MySQL Database
  15355.      Administration::.
  15356.  
  15357. Client programs that access the server:
  15358.         * `mysql' is a command-line client for executing SQL statements
  15359.           interactively or in batch mode
  15360.  
  15361.         * `mysqlcc' (MySQL Control Center) is an interactive graphical
  15362.           tool for executing SQL statements and administration
  15363.  
  15364.         * `mysqladmin' is an administrative client
  15365.  
  15366.         * `mysqlcheck' performs table maintenance operations
  15367.  
  15368.         * `mysqldump' and `mysqlhotcopy' make database backups
  15369.  
  15370.         * `mysqlimport' imports data files
  15371.  
  15372.         * `mysqlshow' displays information about databases and tables
  15373.  
  15374.      These programs are discussed further in *Note Client-Side
  15375.      Scripts::.
  15376.  
  15377. Utility programs that operate independently of the server:
  15378.         * `myisamchk' performs table maintenance operations
  15379.  
  15380.         * `myisampack' produces compressed, read-only tables
  15381.  
  15382.         * `mysqlbinlog' is a tool for processing binary log files
  15383.  
  15384.         * `perror' displays error code meanings
  15385.  
  15386.      `myisamchk' is discussed further in *Note MySQL Database
  15387.      Administration::.  The other programs are further in *Note
  15388.      Client-Side Scripts::.
  15389.  
  15390. Most MySQL distributions include all of these programs, except for those
  15391. programs that are platform-specific. (For example, the server startup
  15392. scripts are not used on Windows.) The exception is that RPM
  15393. distributions are more specialized. There is one RPM for the server,
  15394. another for the client programs, and so forth. If you appear to be
  15395. missing one or more programs, see *Note Installing:: for information on
  15396. types of distributions and what they contain.  It may be that you need
  15397. to install something else.
  15398.  
  15399. Invoking MySQL Programs
  15400. =======================
  15401.  
  15402. To invoke a MySQL program at the command line (that is, from your shell
  15403. or command prompt), enter the program name followed by any options or
  15404. other arguments needed to instruct the program what you want it to do.
  15405. The following commands show some sample program invocations. "`shell>'"
  15406. represents the prompt for your command interpreter; it is not part of
  15407. what you type.  The particular prompt you will see depends on your
  15408. command interpreter.  Typical prompts are `$' for `sh' or `bash', `%'
  15409. for `csh' or `tcsh', and `C:\>' for Windows `command.com' or `cmd.exe'.
  15410.  
  15411.      shell> mysql test
  15412.      shell> mysqladmin extended-status variables
  15413.      shell> mysqlshow --help
  15414.      shell> mysqldump --user=root personnel
  15415.  
  15416. Arguments that begin with a dash are option arguments. They typically
  15417. specify the type of connection a program should make to the server or
  15418. affect its operational mode. Options have a syntax that is described in
  15419. *Note Program Options::.
  15420.  
  15421. Non-option arguments (arguments with no leading dash) provide additional
  15422. information to the program. For example, the `mysql' program interprets
  15423. the first non-option argument as a database name, so the command `mysql
  15424. test' indicates that you want to use the `test' database.
  15425.  
  15426. Later sections that describe individual programs indicate which options
  15427. a program understands and describe the meaning of any additional
  15428. non-option arguments.
  15429.  
  15430. Some options are common to a number of programs. The most common of
  15431. these are the `--host', `--user', and `--password' options that specify
  15432. connection parameters. They indicate the host where the MySQL server is
  15433. running, and the username and password of your MySQL account. All MySQL
  15434. client programs understand these options; they allow you to specify
  15435. which server to connect to and the account to use on that server.
  15436.  
  15437. You may find it necessary to invoke MySQL programs using the pathname
  15438. to the `bin' directory in which they are installed. This is likely to
  15439. be the case if you get a "program not found" error whenever you attempt
  15440. to run a MySQL program from any directory other than the `bin'
  15441. directory.  To make it more convenient to use MySQL, you can add the
  15442. pathname of the `bin' directory to your `PATH' environment variable
  15443. setting. Then to run a program you need only type its name, not its
  15444. entire pathname.
  15445.  
  15446. Consult the documentation for your command interpreter for instructions
  15447. on setting your `PATH'. The syntax for setting environment variables is
  15448. interpreter-specific.
  15449.  
  15450. Specifying Program Options
  15451. ==========================
  15452.  
  15453. You can provide options for MySQL programs in several ways:
  15454.  
  15455.    * On the command line following the program name. This is most
  15456.      common for options that apply to a specific invocation of the
  15457.      program.
  15458.  
  15459.    * In an option file that the program reads when it starts. This is
  15460.      common for options that you want the program to use each time it
  15461.      runs.
  15462.  
  15463.    * In environment variables. These are useful for options that you
  15464.      want to apply each time the program runs, although in practice
  15465.      option files are used more commonly for this purpose.  (*Note
  15466.      Multiple Unix servers:: discusses one situation in which
  15467.      environment variables can be very helpful. It describes a handy
  15468.      technique that uses such variables to specify the TCP/IP port
  15469.      number and Unix socket file for both the server and client
  15470.      programs.)
  15471.  
  15472.  
  15473. MySQL programs determine which options are given first by examining
  15474. environment variables, then option files, and then the command line.
  15475. If an option is specified multiple times, the last occurrence takes
  15476. precedence.  This means that environment variables have the lowest
  15477. precedence and command-line options the highest.
  15478.  
  15479. You can take advantage of the way that MySQL programs process options by
  15480. specifying the default values for a program's options in an option
  15481. file. Then you need not type them each time you run the program, but
  15482. can override the defaults if necessary by using command-line options.
  15483.  
  15484. Using Options on the Command Line
  15485. ---------------------------------
  15486.  
  15487. Program options specified on the command line follow these rules:
  15488.  
  15489.    * Options are given after the command name.
  15490.  
  15491.    * An option argument begins with one dash or two dashes, depending
  15492.      on whether it has a short name or a long name. Many options have
  15493.      both forms.  For example, `-?' and `--help' are the short and long
  15494.      forms of the option that instructs a MySQL program to display a
  15495.      help message.
  15496.  
  15497.    * Option names are case sensitive.  `-v' and `-V' are both legal and
  15498.      have different meanings. (They are the corresponding short forms
  15499.      of the `--verbose' and `--version' options.)
  15500.  
  15501.    * Some options take a value following the option name.  For example,
  15502.      `-h localhost' or `--host=localhost' indicate the MySQL server
  15503.      host to a client program.  The option value tells the program the
  15504.      name of the host where the MySQL server is running.
  15505.  
  15506.    * For a long option that takes a value, separate the option name and
  15507.      the value by an `=' sign.  For a short option that takes a value,
  15508.      the option value can immediately follow the option letter, or
  15509.      there can be a space between.  (`-hlocalhost' and `-h localhost'
  15510.      are equivalent.)  An exception to this rule is the option for
  15511.      specifying your MySQL password.  This option can be given in long
  15512.      form as `--password=pass_val' or as `--password'. In the latter
  15513.      case (with no password value given), the program will prompt you
  15514.      for the password.  The password option also may be given in short
  15515.      form as `-ppass_val' or as `-p'. However, for the short form, if
  15516.      the password value is given, it must follow the option letter with
  15517.      _no intervening space_. The reason for this is that if a space
  15518.      follows the option letter, the program has no way to tell whether
  15519.      a following argument is supposed to be the password value or some
  15520.      other kind of argument.  Consequently, the following two commands
  15521.      have two completely different meanings:
  15522.  
  15523.           shell> mysql -ptest
  15524.           shell> mysql -p test
  15525.  
  15526.      The first command instructs `mysql' to use a password value of
  15527.      `test', but specifies no default database.  The second instructs
  15528.      `mysql' to prompt for the password value and to use `test' as the
  15529.      default database.
  15530.  
  15531.  
  15532. MySQL 4.0 introduced some additional flexibility in the way you specify
  15533. options. These changes were made in MySQL 4.0.2. Some of them relate to
  15534. the way you specify options that have "enabled" and "disabled" states,
  15535. and to the use of options that might be present in one version of MySQL
  15536. but not another.  Those capabilities are discussed in this section.
  15537. Another change pertains to the way you use options to set program
  15538. variables.  *Note Program variables:: discusses that topic further.
  15539.  
  15540. Some options control behavior that can be turned on or off. For example,
  15541. the `mysql' client supports a `--column-names' option that determines
  15542. whether or not to display a row of column names at the beginning of
  15543. query results. By default, this option is enabled. However, you may
  15544. want to disable it in some instances, such as when sending the output
  15545. of `mysql' into another program that expects to see only data and not
  15546. an initial header line.
  15547.  
  15548. To disable column names, you can specify the option using any of these
  15549. forms:
  15550.  
  15551.      --disable-column-names
  15552.      --skip-column-names
  15553.      --column-names=0
  15554.  
  15555. The `--disable' and `--skip' prefixes and the `=0' suffix all have the
  15556. same effect: They turn the option off.
  15557.  
  15558. The "enabled" form of the option may be specified in any of these ways:
  15559.  
  15560.      --column-names
  15561.      --enable-column-names
  15562.      --column-names=1
  15563.  
  15564. Another change to option processing introduced in MySQL 4.0 is that you
  15565. can use the `--loose' prefix for command-line options. If an option is
  15566. prefixed by `--loose', the program will not exit with an error if it
  15567. does not recognize the option, but instead will issue only a warning:
  15568.  
  15569.      shell> mysql --loose-no-such-option
  15570.      mysql: WARNING: unknown option '--no-such-option'
  15571.  
  15572. The `--loose' prefix can be useful when you run programs from multiple
  15573. installations of MySQL on the same machine, at least if all the
  15574. versions are as recent as 4.0.2.  This prefix is particularly useful
  15575. when you list options in an option file.  An option that may not be
  15576. recognized by all versions of a program can be given using the `--loose'
  15577. prefix (or `loose' in an option file). Versions of the program that do
  15578. not recognize the option will issue a warning and ignore it. This
  15579. strategy requires that versions involved be 4.0.2 or later, because
  15580. earlier versions know nothing of the `--loose' convention.
  15581.  
  15582. Using Option Files
  15583. ------------------
  15584.  
  15585. MySQL programs can read startup options from option files (also
  15586. sometimes called configuration files).  Option files provide a
  15587. convenient way to specify commonly used options so that they need not
  15588. be entered on the command line each time you run a program.  Option
  15589. file capability is available from MySQL 3.22 on.
  15590.  
  15591. The following programs support option files: `myisamchk', `myisampack',
  15592. `mysql', `mysql.server', `mysqladmin', `mysqlbinlog', `mysqlcc',
  15593. `mysqlcheck', `mysqld_safe', `mysqldump', `mysqld', `mysqlhotcopy',
  15594. `mysqlimport', and `mysqlshow'.
  15595.  
  15596. On Windows, MySQL programs read startup options from the following
  15597. files:
  15598.  
  15599. *Filename*             *Purpose*
  15600. `WINDIR\my.ini'        Global options
  15601. `C:\my.cnf'            Global options
  15602.  
  15603. WINDIR represents the location of your Windows directory.  This is
  15604. commonly `C:\Windows' or `C:\WinNT'.  You can determine its exact
  15605. location from the value of the `WINDIR' environment variable using the
  15606. following command:
  15607.  
  15608.      C:\> echo %WINDIR%
  15609.  
  15610. On Unix, MySQL programs read startup options from the following files:
  15611.  
  15612. *Filename*             *Purpose*
  15613. `/etc/my.cnf'          Global options
  15614. `DATADIR/my.cnf'       Server-specific options
  15615. `defaults-extra-file'  The file specified with
  15616.                        `--defaults-extra-file=PATH', if any
  15617. `~/.my.cnf'            User-specific options
  15618.  
  15619. DATADIR represents the location of the MySQL data directory. Typically
  15620. this is `/usr/local/mysql/data' for a binary installation or
  15621. `/usr/local/var' for a source installation.  Note that this is the data
  15622. directory location that was specified at configuration time, not the
  15623. one specified with `--datadir' when `mysqld' starts.  Use of
  15624. `--datadir' at runtime has no effect on where the server looks for
  15625. option files, because it looks for them before processing any
  15626. command-line arguments.
  15627.  
  15628. MySQL looks for option files in the order just described and reads any
  15629. that exist. If an option file that you want to use does not exist,
  15630. create it with a plain text editor.  If multiple option files exist, an
  15631. option specified in a file read later takes precedence over the same
  15632. option specified in a file read earlier.
  15633.  
  15634. Any long option that may be given on the command line when running a
  15635. MySQL program can be given in an option file as well.  To get the list
  15636. of available options for a program, run it with the `--help' option.
  15637.  
  15638. The syntax for specifying options in an option file is similar to
  15639. command-line syntax, except that you omit the leading two dashes. For
  15640. example, `--quick' or `--host=localhost' on the command line should be
  15641. specified as `quick' or `host=localhost' in an option file.  To specify
  15642. an option of the form `--loose-opt_name' in an option file, write it as
  15643. `loose-opt_name'.
  15644.  
  15645. Empty lines in option files are ignored. Non-empty lines can take any
  15646. of the following forms:
  15647.  
  15648. `#COMMENT'
  15649. `;COMMENT'
  15650.      Comment lines start with `#' or `;'. As of MySQL 4.0.14, a
  15651.      `#'-comment can start in the middle of a line as well.
  15652.  
  15653. `[GROUP]'
  15654.      GROUP is the name of the program or group for which you want to set
  15655.      options.  After a group line, any OPT_NAME or `set-variable' lines
  15656.      apply to the named group until the end of the option file or
  15657.      another group line is given.
  15658.  
  15659. `OPT_NAME'
  15660.      This is equivalent to `--OPT_NAME' on the command line.
  15661.  
  15662. `OPT_NAME=VALUE'
  15663.      This is equivalent to `--OPT_NAME=VALUE' on the command line.  In
  15664.      an option file, you can have spaces around the `=' character,
  15665.      something that is not true on the command line.  As of MySQL
  15666.      4.0.16, you can quote the value with double quotes or single
  15667.      quotes.  This is useful if the value contains a `#' comment
  15668.      character or whitespace.
  15669.  
  15670. `set-variable = VAR_NAME=VALUE'
  15671.      Set the program variable VAR_NAME to the given value.  This is
  15672.      equivalent to `--set-variable=VAR_NAME=VALUE' on the command line.
  15673.      Spaces are allowed around the first `=' character but not around
  15674.      the second.  This syntax is deprecated as of MySQL 4.0.  See *Note
  15675.      Program variables:: for more information on setting program
  15676.      variables.
  15677.  
  15678. Leading and trailing blanks are automatically deleted from option names
  15679. and values.  You may use the escape sequences `\b', `\t', `\n', `\r',
  15680. `\\', and `\s' in option values to represent the backspace, tab,
  15681. newline, carriage return, and space characters.
  15682.  
  15683. On Windows, if an option value represents a pathname, you should
  15684. specify the value using `/' rather than `\' as the pathname separator.
  15685. If you use `\', you must double it as `\\', because `\' is the escape
  15686. character in MySQL.
  15687.  
  15688. If an option group name is the same as a program name, options in the
  15689. group apply specifically to that program.
  15690.  
  15691. The `[client]' option group is read by all client programs (but not by
  15692. `mysqld'). This allows you to specify options that apply to every
  15693. client. For example, `[client]' is the perfect group to use to specify
  15694. the password that you use to connect to the server.  (But make sure that
  15695. the option file is readable and writable only by yourself, so that other
  15696. people cannot find out your password.) Be sure not to put an option in
  15697. the `[client]' group unless it is recognized by _all_ client programs
  15698. that you use. Programs that do not understand the option will quit after
  15699. displaying an error message if you try to run them.
  15700.  
  15701. As of MySQL 4.0.14, if you want to create option groups that should be
  15702. read only by one specific `mysqld' server release series, you can do
  15703. this by using groups with names of `[mysqld-4.0]', `[mysqld-4.1]', and
  15704. so forth. The following group indicates that the `--new' option should
  15705. be used only by MySQL servers with 4.0.x version numbers:
  15706.  
  15707.      [mysqld-4.0]
  15708.      new
  15709.  
  15710. Here is a typical global option file:
  15711.  
  15712.      [client]
  15713.      port=3306
  15714.      socket=/tmp/mysql.sock
  15715.      
  15716.      [mysqld]
  15717.      port=3306
  15718.      socket=/tmp/mysql.sock
  15719.      key_buffer_size=16M
  15720.      max_allowed_packet=8M
  15721.      
  15722.      [mysqldump]
  15723.      quick
  15724.  
  15725. The preceding option file uses `VAR_NAME=VALUE' syntax for the lines
  15726. that set the `key_buffer_size' and `max_allowed_packet' variables.
  15727. Prior to MySQL 4.0.2, you would need to use `set-variable' syntax
  15728. instead (described earlier in this section).
  15729.  
  15730. Here is a typical user option file:
  15731.  
  15732.      [client]
  15733.      # The following password will be sent to all standard MySQL clients
  15734.      password="my_password"
  15735.      
  15736.      [mysql]
  15737.      no-auto-rehash
  15738.      set-variable = connect_timeout=2
  15739.      
  15740.      [mysqlhotcopy]
  15741.      interactive-timeout
  15742.  
  15743. This option file uses `set-variable' syntax to set the
  15744. `connect_timeout' variable. For MySQL 4.0.2 and up, you can also set
  15745. the variable using just `connect_timeout=2'.
  15746.  
  15747. If you have a source distribution, you will find sample option files
  15748. named `my-XXXX.cnf' in the `support-files' directory.  If you have a
  15749. binary distribution, look in the `support-files' directory under your
  15750. MySQL installation directory (typically `C:\mysql' on Windows or
  15751. `/usr/local/mysql' on Unix).  Currently there are sample option files
  15752. for small, medium, large, and very large systems. To experiment with
  15753. one of these files, copy it to `C:\my.cnf' on Windows or to `.my.cnf'
  15754. in your home directory on Unix.
  15755.  
  15756. *Note*: On Windows, the `.cnf' option file extension might not be
  15757. displayed.
  15758.  
  15759. All MySQL programs that support option files handle the following
  15760. command-line options:
  15761.  
  15762. `--no-defaults'
  15763.      Don't read any option files.
  15764.  
  15765. `--print-defaults'
  15766.      Print the program name and all options that it will get from
  15767.      option files.
  15768.  
  15769. `--defaults-file=PATH_NAME'
  15770.      Use only the given option file. PATH_NAME is the full pathname to
  15771.      the file.
  15772.  
  15773. `--defaults-extra-file=PATH_NAME'
  15774.      Read this option file after the global option file but before the
  15775.      user option file. PATH_NAME is the full pathname to the file.
  15776.  
  15777. To work properly, each of these options must immediately follow the
  15778. command name on the command line, with the exception that
  15779. `--print-defaults' may be used immediately after `--defaults-file' or
  15780. `--defaults-extra-file'.
  15781.  
  15782. In shell scripts, you can use the `my_print_defaults' program to parse
  15783. option files. The following example shows the output that
  15784. `my_print_defaults' might produce when asked to show the options found
  15785. in the `[client]' and `[mysql]' groups:
  15786.  
  15787.      shell> my_print_defaults client mysql
  15788.      --port=3306
  15789.      --socket=/tmp/mysql.sock
  15790.      --no-auto-rehash
  15791.  
  15792. Note for developers:  Option file handling is implemented in the C
  15793. client library simply by processing all matching options (that is,
  15794. options in the appropriate group) before any command-line arguments.
  15795. This works nicely for programs that use the last instance of an option
  15796. that is specified multiple times. If you have a C or C++ program that
  15797. handles multiply specified options this way but doesn't read option
  15798. files, you need add only two lines to give it that capability.  Check
  15799. the source code of any of the standard MySQL clients to see how to do
  15800. this.
  15801.  
  15802. Several other language interfaces to MySQL are based on the C client
  15803. library, and some of them provide a way to access option file contents.
  15804. These include Perl and Python. See the documentation for your preferred
  15805. interface for details.
  15806.  
  15807. Using Environment Variables to Specify Options
  15808. ----------------------------------------------
  15809.  
  15810. To specify an option using an environment variable, set the variable
  15811. using the syntax appropriate for your comment processor. For example,
  15812. on Windows or NetWare, you can set the `USER' variable to specify your
  15813. MySQL account name.  To do so, use this syntax:
  15814.  
  15815.      SET USER=YOUR_NAME
  15816.  
  15817. The syntax on Unix depends on your shell. Suppose that you want to
  15818. specify the TCP/IP port number using the `MYSQL_TCP_PORT' variable. The
  15819. syntax for Bourne shell and variants (`sh', `bash', `zsh', etc.) is:
  15820.  
  15821.      MYSQL_TCP_PORT=3306
  15822.  
  15823. For `csh' and `tcsh', use this syntax:
  15824.  
  15825.      setenv MYSQL_TCP_PORT 3306
  15826.  
  15827. The commands to set environment variables can be executed at your
  15828. command prompt to take effect immediately. These settings persist until
  15829. you log out.  To have the settings take effect each time you log in,
  15830. place the appropriate command or commands in a startup file that your
  15831. command interpreter reads each time it starts. Typical startup files are
  15832. `AUTOEXEC.BAT' for Windows, `.bash_profile' for `bash', or `.tcshrc'
  15833. for `tcsh'. Consult the documentation for your command interpreter for
  15834. specific details.
  15835.  
  15836. *Note Environment variables:: lists all environment variables that
  15837. affect MySQL program operation.
  15838.  
  15839. Using Options to Set Program Variables
  15840. --------------------------------------
  15841.  
  15842. Many MySQL programs have internal variables that can be set at runtime.
  15843. As of MySQL 4.0.2, program variables are set the same way as any other
  15844. long option that takes a value.  For example, `mysql' has a
  15845. `max_allowed_packet' variable that controls the maximum size of its
  15846. communication buffer.  To set the `max_allowed_packet' variable for
  15847. `mysql' to a value of 16MB, use either of the following commands:
  15848.  
  15849.      shell> mysql --max_allowed_packet=16777216
  15850.      shell> mysql --max_allowed_packet=16M
  15851.  
  15852. The first command specifies the value in bytes. The second specifies
  15853. the value in megabytes. Variable values can have a suffix of `K', `M',
  15854. or `G' (either uppercase or lowercase) to indicate units of kilobytes,
  15855. megabytes, or gigabytes.
  15856.  
  15857. In an option file, the variable setting is given without the leading
  15858. dashes:
  15859.  
  15860.      [mysql]
  15861.      max_allowed_packet=16777216
  15862.  
  15863. Or:
  15864.  
  15865.      [mysql]
  15866.      max_allowed_packet=16M
  15867.  
  15868. If you like, underscores in a variable name can be specified as dashes.
  15869.  
  15870. Prior to MySQL 4.0.2, program variable names are not recognized as
  15871. option names.  Instead, use the `--set-variable' option to assign a
  15872. value to a variable:
  15873.  
  15874.      shell> mysql --set-variable=max_allowed_packet=16777216
  15875.      shell> mysql --set-variable=max_allowed_packet=16M
  15876.  
  15877. In an option file, omit the leading dashes:
  15878.  
  15879.      [mysql]
  15880.      set-variable = max_allowed_packet=16777216
  15881.  
  15882. Or:
  15883.  
  15884.      [mysql]
  15885.      set-variable = max_allowed_packet=16M
  15886.  
  15887. With `--set-variable', underscores in variable names cannot be given as
  15888. dashes for versions of MySQL older than 4.0.2.
  15889.  
  15890. The `--set-variable' option is still recognized in MySQL 4.0.2 and up,
  15891. but is deprecated.
  15892.  
  15893. Some server variables can be set at runtime. For details, see *Note
  15894. Dynamic System Variables::.
  15895.  
  15896. Database Administration
  15897. ***********************
  15898.  
  15899. This chapter covers topics that deal with administering a MySQL
  15900. installation, such as configuring the server, managing user accounts,
  15901. and performing backups.
  15902.  
  15903. The MySQL Server and Server Startup Scripts
  15904. ===========================================
  15905.  
  15906. The MySQL server, `mysqld', is the main program that does most of the
  15907. work in a MySQL installation. The server is accompanied by several
  15908. related scripts that perform setup operations when you install MySQL or
  15909. that are helper programs to assist you in starting and stopping the
  15910. server.
  15911.  
  15912. This section provides an overview of the server and related programs,
  15913. and information about server startup scripts. Information about
  15914. configuring the server itself is given in *Note Configuring MySQL::.
  15915.  
  15916. Overview of the Server-Side Scripts and Utilities
  15917. -------------------------------------------------
  15918.  
  15919. All MySQL programs take many different options. However, every MySQL
  15920. program provides a `--help' option that you can use to get a
  15921. description of the program's options. For example, try `mysqld --help'.
  15922.  
  15923. You can override default options for all standard programs by specifying
  15924. options on the command line or in an option file.  *Note Program
  15925. Options::.
  15926.  
  15927. The following list briefly describes the MySQL server and server-related
  15928. programs:
  15929.  
  15930. `mysqld'
  15931.      The SQL daemon (that is, the MySQL server). To use client
  15932.      programs, this program must be running, because clients gain
  15933.      access to databases by connecting to the server.  *Note
  15934.      Configuring MySQL::.
  15935.  
  15936. `mysqld-max'
  15937.      A version of the server that includes additional features.  *Note
  15938.      `mysqld-max': mysqld-max.
  15939.  
  15940. `mysqld_safe'
  15941.      A server startup script.  `mysqld_safe' attempts to start
  15942.      `mysqld-max' if it exists, and `mysqld' otherwise.  *Note
  15943.      `mysqld_safe': mysqld_safe.
  15944.  
  15945. `mysql.server'
  15946.      A server startup script.  This script is used on systems that use
  15947.      run directories containing scripts that start system services for
  15948.      particular run levels. It invokes `mysqld_safe' to start the MySQL
  15949.      server.  *Note `mysql.server': mysql.server.
  15950.  
  15951. `mysqld_multi'
  15952.      A server startup script that can start or stop multiple servers
  15953.      installed on the system.  *Note `mysqld_multi': mysqld_multi.
  15954.  
  15955. `mysql_install_db'
  15956.      This script creates the MySQL grant tables with default
  15957.      privileges. It is usually executed only once, when first
  15958.      installing MySQL on a system.
  15959.  
  15960. `mysql_fix_privilege_tables'
  15961.      This script is used after an upgrade install operation, to update
  15962.      the grant tables with any changes that have been made in newer
  15963.      versions of MySQL.
  15964.  
  15965. There are several other programs that also are run on the server host:
  15966.  
  15967. `myisamchk'
  15968.      A utility to describe, check, optimize, and repair `MyISAM' tables.
  15969.      `myisamchk' is described in *Note Table maintenance::.
  15970.  
  15971. `make_binary_distribution'
  15972.      This program makes a binary release of a compiled MySQL. This
  15973.      could be sent by FTP to `/pub/mysql/upload/' on `ftp.mysql.com'
  15974.      for the convenience of other MySQL users.
  15975.  
  15976. `mysqlbug'
  15977.      The MySQL bug reporting script.  It can be used to send a bug
  15978.      report to the MySQL mailing list. (You can also visit
  15979.      `http://bugs.mysql.com/' to file a bug report online.)
  15980.  
  15981. The `mysqld-max' Extended MySQL Server
  15982. --------------------------------------
  15983.  
  15984. A MySQL-Max server is a version of the `mysqld' MySQL server that has
  15985. been built to include additional features.
  15986.  
  15987. The distribution to use depends on your platform:
  15988.  
  15989.    * For Windows, MySQL binary distributions include both the standard
  15990.      server (`mysqld.exe') and the MySQL-Max server (`mysqld-max.exe'),
  15991.      so you need not get a special distribution. Just use a regular
  15992.      Windows distribution, available at
  15993.      `http://dev.mysql.com/downloads/mysql-4.0.html'.  *Note Windows
  15994.      installation::.
  15995.  
  15996.    * For Linux, if you install MySQL using RPM distributions, use the
  15997.      regular `MySQL-server' RPM first to install a standard server named
  15998.      `mysqld'.  Then use the `MySQL-Max' RPM to install a server named
  15999.      `mysqld-max'.  The `MySQL-Max' RPM presupposes that you have
  16000.      already installed the regular server RPM.  See *Note Linux-RPM::
  16001.      for more information on the Linux RPM packages.
  16002.  
  16003.    * All other MySQL-Max distributions contain a single server that is
  16004.      named `mysqld' but that has the additional features included.
  16005.  
  16006.  
  16007. You can find the MySQL-Max binaries on the MySQL AB Web site at
  16008. `http://dev.mysql.com/downloads/mysql-4.0.html'.
  16009.  
  16010. MySQL AB builds the MySQL-Max servers by using the following
  16011. `configure' options:
  16012.  
  16013. `--with-server-suffix=-max'
  16014.      This option adds a `-max' suffix to the `mysqld' version string.
  16015.  
  16016. `--with-innodb'
  16017.      This option enables support for the `InnoDB' storage engine.
  16018.      MySQL-Max servers always include `InnoDB' support, but this option
  16019.      actually is needed only for MySQL 3.23.  From MySQL 4 on, `InnoDB'
  16020.      is included by default in binary distributions, so you do not need
  16021.      a MySQL-Max server to obtain `InnoDB' support.
  16022.  
  16023. `--with-bdb'
  16024.      This option enables support for the Berkeley DB (`BDB') storage
  16025.      engine.
  16026.  
  16027. `CFLAGS=-DUSE_SYMDIR'
  16028.      This define enables symbolic link support for Windows.
  16029.  
  16030. MySQL-Max binary distributions are a convenience for those who wish to
  16031. install precompiled programs. If you build MySQL using a source
  16032. distribution, you can build your own Max-like server by enabling the
  16033. same features at configuration time that the MySQL-Max binary
  16034. distributions are built with.
  16035.  
  16036. MySQL-Max servers include the BerkeleyDB (`BDB') storage engine
  16037. whenever possible, but not all platforms support `BDB'.  The following
  16038. table shows which platforms allow MySQL-Max binaries to include `BDB':
  16039.  
  16040. *System*       `BDB'
  16041.                *Support*
  16042. AIX 4.3        N
  16043. HP-UX 11.0     N
  16044. Linux-Alpha    N
  16045. Linux-IA-64    N
  16046. Linux-Intel    Y
  16047. Mac OS X       N
  16048. NetWare        N
  16049. SCO OSR5       Y
  16050. Solaris-Intel  N
  16051. Solaris-SPARC  Y
  16052. UnixWare       Y
  16053. Windows/NT     Y
  16054.  
  16055. To find out which storage engines your server supports, issue the
  16056. following statement:
  16057.  
  16058.      mysql> SHOW ENGINES;
  16059.  
  16060. Before MySQL 4.1.2, `SHOW ENGINES' is unavailable. Use the following
  16061. statement instead and check the value of the variable for the storage
  16062. engine in which you are interested:
  16063.  
  16064.      mysql> SHOW VARIABLES LIKE 'have_%';
  16065.      +------------------+----------+
  16066.      | Variable_name    | Value    |
  16067.      +------------------+----------+
  16068.      | have_bdb         | NO       |
  16069.      | have_crypt       | YES      |
  16070.      | have_innodb      | YES      |
  16071.      | have_isam        | NO       |
  16072.      | have_raid        | NO       |
  16073.      | have_symlink     | DISABLED |
  16074.      | have_openssl     | NO       |
  16075.      | have_query_cache | YES      |
  16076.      +------------------+----------+
  16077.  
  16078. The values in the second column indicate the server's level of support
  16079. for each feature:
  16080.  
  16081. *Value*     *Meaning*
  16082. `YES'       The feature is supported and is active.
  16083. `NO'        The feature is not supported.
  16084. `DISABLED'  The feature is supported but has been disabled.
  16085.  
  16086. A value of `NO' means that the server was compiled without support for
  16087. the feature, so it cannot be activated at runtime.
  16088.  
  16089. A value of `DISABLED' occurs either because the server was started with
  16090. an option that disables the feature, or because not all options
  16091. required to enable it were given. In the latter case, the
  16092. `HOST_NAME.err' error log file should contain a reason indicating why
  16093. the option is disabled.
  16094.  
  16095. One situation in which you might see `DISABLED' occurs with MySQL 3.23
  16096. when the `InnoDB' storage engine is compiled in. In MySQL 3.23, you
  16097. must supply at least the `innodb_data_file_path' option at runtime to
  16098. set up the `InnoDB' tablespace. Without this option, `InnoDB' disables
  16099. itself.  *Note `InnoDB' in MySQL 3.23: InnoDB in MySQL 3.23.  You can
  16100. specify configuration options for the `BDB' storage engine, too, but
  16101. `BDB' will not disable itself if you do not provide them.  *Note `BDB'
  16102. start: BDB start.
  16103.  
  16104. You might also see `DISABLED' for the `InnoDB', `BDB', or `ISAM'
  16105. storage engines if the server was compiled to support them, but was
  16106. started with the `--skip-innodb', `--skip-bdb', or `--skip-isam'
  16107. options at runtime.
  16108.  
  16109. As of Version 3.23, all MySQL servers support `MyISAM' tables, because
  16110. `MyISAM' is the default storage engine.
  16111.  
  16112. The `mysqld_safe' Server Startup Script
  16113. ---------------------------------------
  16114.  
  16115. `mysqld_safe' is the recommended way to start a `mysqld' server on Unix
  16116. and NetWare.  `mysqld_safe' adds some safety features such as
  16117. restarting the server when an error occurs and logging runtime
  16118. information to an error log file. NetWare-specific behaviors are listed
  16119. later in this section.
  16120.  
  16121. *Note*: Before MySQL 4.0, `mysqld_safe' is named `safe_mysqld'.  To
  16122. preserve backward compatibility, MySQL binary distributions for some
  16123. time will include `safe_mysqld' as a symbolic link to `mysqld_safe'.
  16124.  
  16125. By default, `mysqld_safe' tries to start an executable named
  16126. `mysqld-max' if it exists, or `mysqld' otherwise.  Be aware of the
  16127. implications of this behavior:
  16128.  
  16129.    * On Linux, the `MySQL-Max' RPM relies on this `mysqld_safe'
  16130.      behavior. The RPM installs an executable named `mysqld-max', which
  16131.      causes `mysqld_safe' to automatically use that executable from that
  16132.      point on.
  16133.  
  16134.    * If you install a MySQL-Max distribution that includes a server
  16135.      named `mysqld-max', then upgrade later to a non-Max version of
  16136.      MySQL, `mysqld_safe' will still attempt to run the old `mysqld-max'
  16137.      server.  If you perform such an upgrade, you should manually
  16138.      remove the old `mysqld-max' server to ensure that `mysqld_safe'
  16139.      runs the new `mysqld' server.
  16140.  
  16141.  
  16142. To override the default behavior and specify explicitly which server you
  16143. want to run, specify a `--mysqld' or `--mysqld-version' option to
  16144. `mysqld_safe'.
  16145.  
  16146. Many of the options to `mysqld_safe' are the same as the options to
  16147. `mysqld'. *Note Server options::.
  16148.  
  16149. All options specified to `mysqld_safe' on the command line are passed
  16150. to `mysqld'.  If you want to use any options that are specific to
  16151. `mysqld_safe' and that `mysqld' doesn't support, do not specify them on
  16152. the command line. Instead, list them in the `[mysqld_safe]' group of an
  16153. option file.  *Note Option files::.
  16154.  
  16155. `mysqld_safe' reads all options from the `[mysqld]', `[server]', and
  16156. `[mysqld_safe]' sections in option files.  For backward compatibility,
  16157. it also reads `[safe_mysqld]' sections, although you should rename such
  16158. sections to `[mysqld_safe]' when you begin using MySQL 4.0 or later.
  16159.  
  16160. `mysqld_safe' supports the following options:
  16161.  
  16162. `--basedir=PATH'
  16163.      The path to the MySQL installation directory.
  16164.  
  16165. `--core-file-size=SIZE'
  16166.      The size of the core file `mysqld' should be able to create. The
  16167.      option value is passed to `ulimit -c'.
  16168.  
  16169. `--datadir=PATH'
  16170.      The path to the data directory.
  16171.  
  16172. `--defaults-extra-file=PATH'
  16173.      The name of an option file to be read in addition to the usual
  16174.      option files.
  16175.  
  16176. `--defaults-file=PATH'
  16177.      The name of an option file to be read instead of the usual option
  16178.      files.
  16179.  
  16180. `--err-log=PATH'
  16181.      The old form of the `--log-error' option, to be used before MySQL
  16182.      4.0.
  16183.  
  16184. `--ledir=PATH'
  16185.      The path to the directory containing the `mysqld' program.  Use
  16186.      this option to explicitly indicate the location of the server.
  16187.  
  16188. `--log-error=PATH'
  16189.      Write the error log to the given file. *Note Error log::.
  16190.  
  16191. `--mysqld=PROG_NAME'
  16192.      The name of the server program (in the `ledir' directory) that you
  16193.      want to start. This option is needed if you use the MySQL binary
  16194.      distribution but have the data directory outside of the binary
  16195.      distribution.
  16196.  
  16197. `--mysqld-version=SUFFIX'
  16198.      This option is similar to the `--mysqld' option, but you specify
  16199.      only the suffix for the server program name. The basename is
  16200.      assumed to be `mysqld'.  For example, if you use
  16201.      `--mysqld-version=max', `mysqld_safe' will start the `mysqld-max'
  16202.      program in the `ledir' directory.  If the argument to
  16203.      `--mysqld-version' is empty, `mysqld_safe' uses `mysqld' in the
  16204.      `ledir' directory.
  16205.  
  16206. `--nice=PRIORITY'
  16207.      Use the `nice' program to set the server's scheduling priority to
  16208.      the given value.  This option was added in MySQL 4.0.14.
  16209.  
  16210. `--no-defaults'
  16211.      Do not read any option files.
  16212.  
  16213. `--open-files-limit=COUNT'
  16214.      The number of files `mysqld' should be able to open. The option
  16215.      value is passed to `ulimit -n'. Note that you need to start
  16216.      `mysqld_safe' as `root' for this to work properly!
  16217.  
  16218. `--pid-file=PATH'
  16219.      The path to the process ID file.
  16220.  
  16221. `--port=PORT_NUM'
  16222.      The port number to use when listening for TCP/IP connections.
  16223.  
  16224. `--socket=PATH'
  16225.      The Unix socket file to use for local connections.
  16226.  
  16227. `--timezone=ZONE'
  16228.      Set the `TZ' time zone environment variable to the given option
  16229.      value.  Consult your operating system documentation for legal time
  16230.      zone specification formats.
  16231.  
  16232. `--user={USER_NAME | USER_ID}'
  16233.      Run the `mysqld' server as the user having the name USER_NAME or
  16234.      the numeric user ID USER_ID.  ("User" in this context refers to a
  16235.      system login account, not a MySQL user listed in the grant tables.)
  16236.  
  16237. The `mysqld_safe' script is written so that it normally can start a
  16238. server that was installed from either a source or a binary distribution
  16239. of MySQL, even though these types of distributions typically install
  16240. the server in slightly different locations.  (*Note Installation
  16241. layouts::.)  `mysqld_safe' expects one of the following conditions to
  16242. be true:
  16243.  
  16244.    * The server and databases can be found relative to the directory
  16245.      from which `mysqld_safe' is invoked.  For binary distributions,
  16246.      `mysqld_safe' looks under its working directory for `bin' and
  16247.      `data' directories.  For source distributions, it looks for
  16248.      `libexec' and `var' directories.  This condition should be met if
  16249.      you execute `mysqld_safe' from your MySQL installation directory
  16250.      (for example, `/usr/local/mysql' for a binary distribution).
  16251.  
  16252.    * If the server and databases cannot be found relative to the working
  16253.      directory, `mysqld_safe' attempts to locate them by absolute
  16254.      pathnames.  Typical locations are `/usr/local/libexec' and
  16255.      `/usr/local/var'.  The actual locations are determined from the
  16256.      values configured into the distribution at the time it was built.
  16257.      They should be correct if MySQL is installed in the location
  16258.      specified at configuration time.
  16259.  
  16260. Because `mysqld_safe' will try to find the server and databases relative
  16261. to its own working directory, you can install a binary distribution of
  16262. MySQL anywhere, as long as you run `mysqld_safe' from the MySQL
  16263. installation directory:
  16264.  
  16265.      shell> cd mysql_installation_directory
  16266.      shell> bin/mysqld_safe &
  16267.  
  16268. If `mysqld_safe' fails, even when invoked from the MySQL installation
  16269. directory, you can specify the `--ledir' and `--datadir' options to
  16270. indicate the directories in which the server and databases are located
  16271. on your system.
  16272.  
  16273. Normally, you should not edit the `mysqld_safe' script.  Instead,
  16274. configure `mysqld_safe' by using command-line options or options in the
  16275. `[mysqld_safe]' section of a `my.cnf' option file.  In rare cases, it
  16276. might be necessary to edit `mysqld_safe' to get it to start the server
  16277. properly. However, if you do this, your modified version of
  16278. `mysqld_safe' might be overwritten if you upgrade MySQL in the future,
  16279. so you should make a copy of your edited version that you can reinstall.
  16280.  
  16281. On NetWare, `mysqld_safe' is a NetWare Loadable Module (NLM) that is
  16282. ported from the original Unix shell script.  It does the following:
  16283.  
  16284.   1. Runs a number of system and option checks.
  16285.  
  16286.   2. Runs a check on `MyISAM' and `ISAM' tables.
  16287.  
  16288.   3. Provides a screen presence for the MySQL server.
  16289.  
  16290.   4. Starts `mysqld', monitors it, and restarts it if it terminates in
  16291.      error.
  16292.  
  16293.   5. Sends error messages from `mysqld' to the `HOST_NAME.err' file in
  16294.      the data directory.
  16295.  
  16296.   6. Sends `mysqld_safe' screen output to the `HOST_NAME.safe' file in
  16297.      the data directory.
  16298.  
  16299.  
  16300. The `mysql.server' Server Startup Script
  16301. ----------------------------------------
  16302.  
  16303. MySQL distributions on Unix include a script named `mysql.server'.  It
  16304. can be used on systems such as Linux and Solaris that use System V-style
  16305. run directories to start and stop system services. It is also used by
  16306. the Mac OS X Startup Item for MySQL.
  16307.  
  16308. `mysql.server' can be found in the `support-files' directory under your
  16309. MySQL installation directory or in a MySQL source tree.
  16310.  
  16311. If you use the Linux server RPM package (`MySQL-server-VERSION.rpm'),
  16312. the `mysql.server' script will already have been installed in the
  16313. `/etc/init.d' directory with the name `mysql'. You need not install it
  16314. manually. See *Note Linux-RPM:: for more information on the Linux RPM
  16315. packages.
  16316.  
  16317. Some vendors provide RPM packages that install a startup script under a
  16318. different name such as `mysqld'.
  16319.  
  16320. If you install MySQL from a source distribution or using a binary
  16321. distribution format that does not install `mysql.server' automatically,
  16322. you can install it manually. Instructions are provided in *Note
  16323. Automatic start::.
  16324.  
  16325. `mysql.server' reads options from the `[mysql.server]' and `[mysqld]'
  16326. sections of option files.  (For backward compatibility, it also reads
  16327. `[mysql_server]' sections, although you should rename such sections to
  16328. `[mysql.server]' when you begin using MySQL 4.0 or later.)
  16329.  
  16330. The `mysqld_multi' Program for Managing Multiple MySQL Servers
  16331. --------------------------------------------------------------
  16332.  
  16333. `mysqld_multi' is meant for managing several `mysqld' processes that
  16334. listen for connections on different Unix socket files and TCP/IP ports.
  16335. It can start or stop servers, or report their current status.
  16336.  
  16337. The program searches for groups named `[mysqld#]' in `my.cnf' (or in
  16338. the file named by the `--config-file' option).  `#' can be any positive
  16339. integer.  This number is referred to in the following discussion as the
  16340. option group number, or GNR.  Group numbers distinguish option groups
  16341. from one another and are used as arguments to `mysqld_multi' to specify
  16342. which servers you want to start, stop, or obtain a status report for.
  16343. Options listed in these groups are the same that you would use in the
  16344. `[mysqld]' group used for starting `mysqld'.  (See, for example, *Note
  16345. Automatic start::.) However, when using multiple servers it is necessary
  16346. that each one use its own value for options such as the Unix socket
  16347. file and TCP/IP port number. For more information on which options must
  16348. be unique per server in a multiple-server environment, see *Note
  16349. Multiple servers::.
  16350.  
  16351. To invoke `mysqld_multi', use the following syntax:
  16352.  
  16353.      shell> mysqld_multi [OPTIONS] {start|stop|report} [GNR[,GNR]...]
  16354.  
  16355. `start', `stop', and `report' indicate which operation you want to
  16356. perform. You can perform the designated operation on a single server or
  16357. multiple servers, depending on the GNR list that follows the option
  16358. name.  If there is no list, `mysqld_multi' performs the operation for
  16359. all servers in the option file.
  16360.  
  16361. Each GNR value represents an option group number or range of group
  16362. numbers.  The value should be the number at the end of the group name
  16363. in the option file.  For example, the GNR for a group named `[mysqld17]'
  16364. is `17'.  To specify a range of numbers, separate the first and last
  16365. numbers by a dash.  The GNR value `10-13' represents groups
  16366. `[mysqld10]' through `[mysqld13]'.  Multiple groups or group ranges can
  16367. be specified on the command line, separated by commas.  There must be
  16368. no whitespace characters (spaces or tabs) in the GNR list; anything
  16369. after a whitespace character is ignored.
  16370.  
  16371. This command starts a single server using option group `[mysqld17]':
  16372.  
  16373.      shell> mysqld_multi start 17
  16374.  
  16375. This command stops several servers, using option groups `[mysql8]' and
  16376. `[mysqld10]' through `[mysqld13]':
  16377.  
  16378.      shell> mysqld_multi start 8,10-13
  16379.  
  16380. For an example of how you might set up an option file, use this command:
  16381.  
  16382.      shell> mysqld_multi --example
  16383.  
  16384. `mysqld_multi' supports the following options:
  16385.  
  16386. `--config-file=NAME'
  16387.      Specify the name of an alternative option file. This affects where
  16388.      `mysqld_multi' looks for `[mysqld#]' option groups.  Without this
  16389.      option, all options are read from the usual `my.cnf' file.  The
  16390.      option does not affect where `mysqld_multi' reads its own options,
  16391.      which are always taken from the `[mysqld_multi]' group in the
  16392.      usual `my.cnf' file.
  16393.  
  16394. `--example'
  16395.      Display a sample option file.
  16396.  
  16397. `--help'
  16398.      Display a help message and exit.
  16399.  
  16400. `--log=NAME'
  16401.      Specify the name of the log file. If the file exists, log output
  16402.      is appended to it.
  16403.  
  16404. `--mysqladmin=PROG_NAME'
  16405.      The `mysqladmin' binary to be used to stop servers.
  16406.  
  16407. `--mysqld=PROG_NAME'
  16408.      The `mysqld' binary to be used. Note that you can specify
  16409.      `mysqld_safe' as the value for this option also. The options are
  16410.      passed to `mysqld'. Just make sure that you have the directory
  16411.      where `mysqld' is located in your `PATH' environment variable
  16412.      setting or fix `mysqld_safe'.
  16413.  
  16414. `--no-log'
  16415.      Print log information to stdout rather than to the log file. By
  16416.      default, output goes to the log file.
  16417.  
  16418. `--password=PASSWORD'
  16419.      The password of the MySQL account to use when invoking
  16420.      `mysqladmin'.  Note that the password value is not optional for
  16421.      this option, unlike for other MySQL programs.
  16422.  
  16423. `--tcp-ip'
  16424.      Connect to each MySQL server via the TCP/IP port instead of the
  16425.      Unix socket file.  (If a socket file is missing, the server might
  16426.      still be running, but accessible only via the TCP/IP port.)  By
  16427.      default, connections are made using the Unix socket file.  This
  16428.      option affects `stop' and `report' operations.
  16429.  
  16430. `--user=USER_NAME'
  16431.      The username of the MySQL account to use when invoking
  16432.      `mysqladmin'.
  16433.  
  16434. `--version'
  16435.      Display version information and exit.
  16436.  
  16437. Some notes about `mysqld_multi':
  16438.  
  16439.    * Make sure that the MySQL account used for stopping the `mysqld'
  16440.      servers (with the `mysqladmin' program) has the same username and
  16441.      password for each server. Also, make sure that the account has the
  16442.      `SHUTDOWN' privilege. If the servers that you want to manage have
  16443.      many different usernames or passwords for the administrative
  16444.      accounts, you might want to create an account on each server that
  16445.      has the same username and password.  For example, you might set up
  16446.      a common `multi_admin' account by executing the following commands
  16447.      for each server:
  16448.  
  16449.           shell> mysql -u root -S /tmp/mysql.sock -pROOT_PASSWORD
  16450.           mysql> GRANT SHUTDOWN ON *.*
  16451.               -> TO 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';
  16452.  
  16453.      *Note Privileges::.  You will have to do this for each `mysqld'
  16454.      server. Change the connection parameters appropriately when
  16455.      connecting to each one.  Note that the host part of the account
  16456.      name must allow you to connect as `multi_admin' from the host
  16457.      where you want to run `mysqld_multi'.
  16458.  
  16459.    * The `--pid-file' option is very important if you are using
  16460.      `mysqld_safe' to start `mysqld' (for example,
  16461.      `--mysqld=mysqld_safe') Every `mysqld' should have its own process
  16462.      ID file. The advantage of using `mysqld_safe' instead of `mysqld'
  16463.      is that `mysqld_safe' "guards" its `mysqld' process and will
  16464.      restart it if the process terminates due to a signal sent using
  16465.      `kill -9', or for other reasons, such as a segmentation fault.
  16466.      Please note that the `mysqld_safe' script might require that you
  16467.      start it from a certain place. This means that you might have to
  16468.      change location to a certain directory before running
  16469.      `mysqld_multi'. If you have problems starting, please see the
  16470.      `mysqld_safe' script. Check especially the lines:
  16471.  
  16472.           ----------------------------------------------------------------
  16473.           MY_PWD=`pwd`
  16474.           # Check if we are starting this relative (for the binary release)
  16475.           if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \
  16476.            -x ./bin/mysqld
  16477.           ----------------------------------------------------------------
  16478.  
  16479.      *Note `mysqld_safe': mysqld_safe.  The test performed by these
  16480.      lines should be successful, or you might encounter problems.
  16481.  
  16482.    * The Unix socket file and the TCP/IP port number must be different
  16483.      for every `mysqld'.
  16484.  
  16485.    * You might want to use the `--user' option for `mysqld', but in
  16486.      order to do this you need to run the `mysqld_multi' script as the
  16487.      Unix `root' user. Having the option in the option file doesn't
  16488.      matter; you will just get a warning, if you are not the superuser
  16489.      and the `mysqld' processes are started under your own Unix account.
  16490.  
  16491.    * *Important*: Make sure that the data directory is fully accessible
  16492.      to the Unix account that the specific `mysqld' process is started
  16493.      as. _Do not_ use the Unix root account for this, unless you _know_
  16494.      what you are doing.
  16495.  
  16496.    * *Most important*: Before using `mysqld_multi' be sure that you
  16497.      understand the meanings of the options that are passed to the
  16498.      `mysqld' servers and _why_ you would want to have separate `mysqld'
  16499.      processes.  Beware of the dangers of using multiple `mysqld'
  16500.      servers with the same data directory.  Use separate data
  16501.      directories, unless you _know_ what you are doing.  Starting
  16502.      multiple servers with the same data directory _will not_ give you
  16503.      extra performance in a threaded system.  *Note Multiple servers::.
  16504.  
  16505.  
  16506. The following example shows how you might set up an option file for use
  16507. with `mysqld_multi'.  The first and fifth `[mysqld#]' group were
  16508. intentionally left out from the example to illustrate that you can have
  16509. "gaps" in the option file. This gives you more flexibility.  The order
  16510. in which the `mysqld' programs are started or stopped depends on the
  16511. order in which they appear in the option file.
  16512.  
  16513.      # This file should probably be in your home dir (~/.my.cnf)
  16514.      # or /etc/my.cnf
  16515.      # Version 2.1 by Jani Tolonen
  16516.      
  16517.      [mysqld_multi]
  16518.      mysqld     = /usr/local/bin/mysqld_safe
  16519.      mysqladmin = /usr/local/bin/mysqladmin
  16520.      user       = multi_admin
  16521.      password   = multipass
  16522.      
  16523.      [mysqld2]
  16524.      socket     = /tmp/mysql.sock2
  16525.      port       = 3307
  16526.      pid-file   = /usr/local/mysql/var2/hostname.pid2
  16527.      datadir    = /usr/local/mysql/var2
  16528.      language   = /usr/local/share/mysql/english
  16529.      user       = john
  16530.      
  16531.      [mysqld3]
  16532.      socket     = /tmp/mysql.sock3
  16533.      port       = 3308
  16534.      pid-file   = /usr/local/mysql/var3/hostname.pid3
  16535.      datadir    = /usr/local/mysql/var3
  16536.      language   = /usr/local/share/mysql/swedish
  16537.      user       = monty
  16538.      
  16539.      [mysqld4]
  16540.      socket     = /tmp/mysql.sock4
  16541.      port       = 3309
  16542.      pid-file   = /usr/local/mysql/var4/hostname.pid4
  16543.      datadir    = /usr/local/mysql/var4
  16544.      language   = /usr/local/share/mysql/estonia
  16545.      user       = tonu
  16546.      
  16547.      [mysqld6]
  16548.      socket     = /tmp/mysql.sock6
  16549.      port       = 3311
  16550.      pid-file   = /usr/local/mysql/var6/hostname.pid6
  16551.      datadir    = /usr/local/mysql/var6
  16552.      language   = /usr/local/share/mysql/japanese
  16553.      user       = jani
  16554.  
  16555. *Note Option files::.
  16556.  
  16557. Configuring the MySQL Server
  16558. ============================
  16559.  
  16560. This section discusses MySQL server configuration topics:
  16561.  
  16562.    * Startup options that the server supports
  16563.  
  16564.    * How to set the server SQL mode
  16565.  
  16566.    * Server system variables
  16567.  
  16568.    * Server status variables
  16569.  
  16570. `mysqld' Command-Line Options
  16571. -----------------------------
  16572.  
  16573. When you start the `mysqld' server, you can specify program options
  16574. using any of the methods described in *Note Program Options::. The most
  16575. common methods are to provide options in an option file or on the
  16576. command line. However, in most cases it is desirable to make sure that
  16577. the server uses the same options each time it runs. The best way to
  16578. ensure this is to list them in an option file.  *Note Option files::.
  16579.  
  16580. `mysqld' reads options from the `[mysqld]' and `[server]' groups.
  16581. `mysqld_safe' reads options from the `[mysqld]', `[server]',
  16582. `[mysqld_safe]', and `[safe_mysqld]' groups.  `mysql.server' reads
  16583. options from the `[mysqld]' and `[mysql.server]' groups.  An embedded
  16584. MySQL server usually reads options from the `[server]', `[embedded]',
  16585. and `[XXXXX_SERVER]' groups, where XXXXX is the name of the application
  16586. into which the server is embedded.
  16587.  
  16588. `mysqld' accepts many command-line options.  For a list, execute
  16589. `mysqld --help'. Before MySQL 4.1.1, `--help' prints the full help
  16590. message. As of 4.1.1, it prints a brief message; to see the full list,
  16591. use `mysqld --verbose --help'.
  16592.  
  16593. The following list shows some of the most common server options.
  16594. Additional options are described elsewhere:
  16595.  
  16596.    * Options that affect security: See *Note Privileges options::.
  16597.  
  16598.    * SSL-related options: See *Note SSL options::.
  16599.  
  16600.    * Binary log control options: See *Note Binary log::.
  16601.  
  16602.    * Replication-related options: See *Note Replication Options::.
  16603.  
  16604.    * Options specific to particular storage engines: See *Note `MyISAM'
  16605.      start: MyISAM start, *Note `BDB' start: BDB start, *Note `InnoDB'
  16606.      start: InnoDB start.
  16607.  
  16608.  
  16609. You can also set the value of a server system variable by using the
  16610. variable name as an option, as described later in this section.
  16611.  
  16612. `--help, -?'
  16613.      Display a short help message and exit.  Before MySQL 4.1.1,
  16614.      `--help' displays the full help message.  As of 4.1.1, it displays
  16615.      an abbreviated message only.  Use both the `--verbose' and
  16616.      `--help' options to see the full message.
  16617.  
  16618. `--ansi'
  16619.      Use standard SQL syntax instead of MySQL syntax.  *Note ANSI
  16620.      mode::.  For more precise control over the server SQL mode, use
  16621.      the `--sql-mode' option instead.
  16622.  
  16623. `--basedir=PATH, -b PATH'
  16624.      The path to the MySQL installation directory. All paths are
  16625.      usually resolved relative to this.
  16626.  
  16627. `--big-tables'
  16628.      Allow large result sets by saving all temporary sets in files.
  16629.      This option prevents most "table full" errors, but also slows down
  16630.      queries for which in-memory tables would suffice.  Since MySQL
  16631.      3.23.2, the server is able to handle large result sets
  16632.      automatically by using memory for small temporary tables and
  16633.      switching to disk tables where necessary.
  16634.  
  16635. `--bind-address=IP'
  16636.      The IP address to bind to.
  16637.  
  16638. `--console'
  16639.      Write the error log messages to stderr/stdout even if `--log-error'
  16640.      is specified.  On Windows, `mysqld' will not close the console
  16641.      screen if this option is used.
  16642.  
  16643. `--character-sets-dir=PATH'
  16644.      The directory where character sets are installed.  *Note Character
  16645.      sets::.
  16646.  
  16647. `--chroot=PATH'
  16648.      Put the `mysqld' server in a closed environment during startup by
  16649.      using the `chroot()' system call. This is a recommended security
  16650.      measure as of MySQL 4.0. (MySQL 3.23 is not able to provide a
  16651.      `chroot()' jail that is 100% closed.)  Note that use of this
  16652.      option somewhat limits `LOAD DATA INFILE' and `SELECT ... INTO
  16653.      OUTFILE'.
  16654.  
  16655. `--core-file'
  16656.      Write a core file if `mysqld' dies.  For some systems, you must
  16657.      also specify the `--core-file-size' option to `mysqld_safe'.
  16658.      *Note `mysqld_safe': mysqld_safe.  Note that on some systems, such
  16659.      as Solaris, you will not get a core file if you are also using the
  16660.      `--user' option.
  16661.  
  16662. `--datadir=PATH, -h PATH'
  16663.      The path to the data directory.
  16664.  
  16665. `--debug[=DEBUG_OPTIONS], -# [DEBUG_OPTIONS]'
  16666.      If MySQL is configured with `--with-debug', you can use this
  16667.      option to get a trace file of what `mysqld' is doing.  The
  16668.      DEBUG_OPTIONS string often is `'d:t:o,FILE_NAME''.  *Note Making
  16669.      trace files::.
  16670.  
  16671. `--default-character-set=CHARSET'
  16672.      Use CHARSET as the default character set.  *Note Character sets::.
  16673.  
  16674. `--default-collation=COLLATION'
  16675.      Use COLLATION as the default collation.  This option is available
  16676.      as of MySQL 4.1.1.  *Note Character sets::.
  16677.  
  16678. `--default-storage-engine=TYPE'
  16679.      This option is a synonym for `--default-table-type'.  It is
  16680.      available as of MySQL 4.1.2.
  16681.  
  16682. `--default-table-type=TYPE'
  16683.      Set the default table type for tables.  *Note Table types::.
  16684.  
  16685. `--default-time-zone=TYPE'
  16686.      Set the default server time zone.  This option sets the global
  16687.      `time_zone' system variable.  If this option is not given, the
  16688.      default time zone will be the same as the system time zone (given
  16689.      by the value of the `system_time_zone' system variable.  This
  16690.      option is available as of MySQL 4.1.3.
  16691.  
  16692. `--delay-key-write[= OFF | ON | ALL]'
  16693.      How the `DELAYED KEYS' option should be used.  Delayed key writing
  16694.      causes key buffers not to be flushed between writes for `MyISAM'
  16695.      tables.  `OFF' disables delayed key writes.  `ON' enables delayed
  16696.      key writes for those tables that were created with the `DELAYED
  16697.      KEYS' option.  `ALL' delays key writes for all `MyISAM' tables.
  16698.      Available as of MySQL 4.0.3.  *Note Server parameters::. *Note
  16699.      MyISAM start::.
  16700.  
  16701.      *Note*: If you set this variable to `ALL', you should not use
  16702.      `MyISAM' tables from within another program (such as from another
  16703.      MySQL server or with `myisamchk') when the table is in use. Doing
  16704.      so will lead to index corruption.
  16705.  
  16706. `--delay-key-write-for-all-tables'
  16707.      Old form of `--delay-key-write=ALL' for use prior to MySQL 4.0.3.
  16708.      As of 4.0.3, use `--delay-key-write' instead.
  16709.  
  16710. `--des-key-file=FILE_NAME'
  16711.      Read the default keys used by `DES_ENCRYPT()' and `DES_DECRYPT()'
  16712.      from this file.
  16713.  
  16714. `--enable-named-pipe'
  16715.      Enable support for named pipes.  This option applies only on
  16716.      Windows NT, 2000, and XP systems, and can be used only with the
  16717.      `mysqld-nt' and `mysqld-max-nt' servers that support named pipe
  16718.      connections.
  16719.  
  16720. `--exit-info[=FLAGS], -T [FLAGS]'
  16721.      This is a bit mask of different flags you can use for debugging the
  16722.      `mysqld' server. Do not use this option unless you know exactly
  16723.      what it does!
  16724.  
  16725. `--external-locking'
  16726.      Enable system locking.  Note that if you use this option on a
  16727.      system on which `lockd' does not fully work (as on Linux), you
  16728.      will easily get `mysqld' to deadlock.  This option previously was
  16729.      named `--enable-locking'.
  16730.  
  16731.      *Note*: If you use this option to enable updates to `MyISAM'
  16732.      tables from many MySQL processes, you have to ensure that these
  16733.      conditions are satisfied:
  16734.  
  16735.         * You should not use the query cache for queries that use
  16736.           tables that are updated by another process.
  16737.  
  16738.         * You should not use `--delay-key-write=ALL' or
  16739.           `DELAY_KEY_WRITE=1' on any shared tables.
  16740.  
  16741.      The easiest way to ensure this is to always use
  16742.      `--external-locking' together with `--delay-key-write=OFF
  16743.      --query-cache-size=0'.
  16744.  
  16745.      (This is not done by default because in many setups it's useful to
  16746.      have a mixture of the above options.)
  16747.  
  16748. `--flush'
  16749.      Flush all changes to disk after each SQL statement.  Normally MySQL
  16750.      does a write of all changes to disk only after each SQL statement
  16751.      and lets the operating system handle the synching to disk.  *Note
  16752.      Crashing::.
  16753.  
  16754. `--init-file=FILE'
  16755.      Read SQL statements from this file at startup.  Each statement
  16756.      must be on a single line and should not include comments.
  16757.  
  16758. `--innodb-safe-binlog'
  16759.      Adds consistency guarantees between the content of `InnoDB' tables
  16760.      and the binary log.  *Note Binary log::.
  16761.  
  16762. `--language=LANG_NAME, -L LANG_NAME'
  16763.      Client error messages in given language.  LANG_NAME can be given
  16764.      as the language name or as the full pathname to the directory
  16765.      where the language files are installed.  *Note Languages::.
  16766.  
  16767. `--log[=FILE], -l [FILE]'
  16768.      Log connections and queries to this file. *Note Query log::. If
  16769.      you don't specify a filename, MySQL will use `HOST_NAME.log' as
  16770.      the filename.
  16771.  
  16772. `--log-bin=[FILE]'
  16773.      The binary log file.  Log all queries that change data to this
  16774.      file. Used for backup and replication.  *Note Binary log::.  If
  16775.      you don't specify a filename, MySQL will use `HOST_NAME-bin' as
  16776.      the filename.
  16777.  
  16778. `--log-bin-index[=FILE]'
  16779.      The index file for binary log filenames. *Note Binary log::.  If
  16780.      you don't specify a filename, MySQL will use `HOST_NAME-bin.index'
  16781.      as the filename.
  16782.  
  16783. `--log-error[=FILE]'
  16784.      Log errors and startup messages to this file. *Note Error log::.
  16785.      If you don't specify a filename, MySQL will use `HOST_NAME.err' as
  16786.      the filename.
  16787.  
  16788. `--log-isam[=FILE]'
  16789.      Log all `ISAM'/`MyISAM' changes to this file (used only when
  16790.      debugging `ISAM'/`MyISAM').
  16791.  
  16792. `--log-long-format'
  16793.      Log some extra information to the log files (update log, binary
  16794.      update log, and slow queries log, whatever log has been
  16795.      activated). For example, username and timestamp are logged for
  16796.      queries. If you are using `--log-slow-queries' and
  16797.      `--log-long-format', queries that are not using indexes also are
  16798.      logged to the slow query log.  Note that `--log-long-format' is
  16799.      deprecated as of MySQL version 4.1, when `--log-short-format' was
  16800.      introduced (the long log format is the default setting since
  16801.      version 4.1). Also note that starting with MySQL 4.1, the
  16802.      `--log-queries-not-using-indexes' option is available for the
  16803.      purpose of logging queries that do not use indexes to the slow
  16804.      query log.
  16805.  
  16806. `--log-queries-not-using-indexes'
  16807.      If you are using this option with `--log-slow-queries', then
  16808.      queries that are not using indexes also  are logged to the slow
  16809.      query log. This option is available as of MySQL 4.1. *Note Slow
  16810.      query log::.
  16811.  
  16812. `--log-short-format'
  16813.      Log less information to the log files (update log, binary update
  16814.      log, and slow queries log, whatever log has been activated). For
  16815.      example, username and timestamp are not logged for queries. This
  16816.      option was introduced in MySQL 4.1.
  16817.  
  16818. `--log-slow-queries[=FILE]'
  16819.      Log all queries that have taken more than `long_query_time' seconds
  16820.      to execute to this file.  *Note Slow query log::.  Note that the
  16821.      default for the amount of information logged has changed in MySQL
  16822.      4.1. See the `--log-long-format' and `--log-short-format' options
  16823.      for details.
  16824.  
  16825. `--log-update[=FILE]'
  16826.      Log updates to FILE# where # is a unique number if not given.
  16827.      *Note Update log::. The update log is deprecated and is removed in
  16828.      MySQL 5.0.0; you should use the binary log instead (`--log-bin').
  16829.      *Note Binary log::. Starting from version 5.0.0, using
  16830.      `--log-update' will just turn on the binary log instead (*note
  16831.      News-5.0.0::).
  16832.  
  16833. `--log-warnings, -W'
  16834.      Print out warnings such as `Aborted connection...' to the error
  16835.      log.  Enabling this option is recommended, for example, if you use
  16836.      replication (you will get more information about what is happening,
  16837.      such as messages about network failures and reconnections).  This
  16838.      option is enabled by default as of MySQL 4.0.19 and 4.1.2; to
  16839.      disable it, use `--skip-log-warnings'. If you want all warnings to
  16840.      be logged, use -log-warnings=2. This will log 'Aborted
  16841.      connections' also.  *Note Communication errors::.
  16842.  
  16843.      This option was named `--warnings' before MySQL 4.0.
  16844.  
  16845. `--low-priority-updates'
  16846.      Table-modifying operations (`INSERT', `REPLACE', `DELETE',
  16847.      `UPDATE') will have lower priority than selects.  This can also be
  16848.      done via `{INSERT | REPLACE | DELETE | UPDATE} LOW_PRIORITY ...'
  16849.      to lower the priority of only one query, or by `SET
  16850.      LOW_PRIORITY_UPDATES=1' to change the priority in one thread.
  16851.      *Note Table locking::.
  16852.  
  16853. `--memlock'
  16854.      Lock the `mysqld' process in memory.  This works on systems such as
  16855.      Solaris that support the `mlockall()' system call.  This might
  16856.      help if you have a problem where the operating system is causing
  16857.      `mysqld' to swap on disk.  Note that use of this option requires
  16858.      that you run the server as `root', which is normally not a good
  16859.      idea for security reasons.
  16860.  
  16861. `--myisam-recover [=OPTION[,OPTION...]]]'
  16862.      Set the `MyISAM' storage engine recovery mode.  The option value
  16863.      is any combination of the values of `DEFAULT', `BACKUP', `FORCE',
  16864.      or `QUICK'.  If you specify multiple values, separate them by
  16865.      commas.  You can also use a value of `""' to disable this option.
  16866.      If this option is used, `mysqld' will, when it opens a `MyISAM'
  16867.      table, open check whether the table is marked as crashed or wasn't
  16868.      closed properly.  (The last option works only if you are running
  16869.      with `--skip-external-locking'.)  If this is the case, `mysqld'
  16870.      will run a check on the table. If the table was corrupted,
  16871.      `mysqld' will attempt to repair it.
  16872.  
  16873.      The following options affect how the repair works:
  16874.  
  16875.      *Option*   *Description*
  16876.      `DEFAULT'  The same as not giving any option to
  16877.                          `--myisam-recover'.
  16878.      `BACKUP'   If the data file was changed during recovery,
  16879.                 save a                     backup of the
  16880.                 `TBL_NAME.MYD' file as
  16881.                 `TBL_NAME-DATETIME.BAK'.
  16882.      `FORCE'    Run recovery even if we will lose more than
  16883.                 one row                     from the `.MYD'
  16884.                 file.
  16885.      `QUICK'    Don't check the rows in the table if there
  16886.                 aren't any                     delete blocks.
  16887.  
  16888.      Before a table is automatically repaired, MySQL will add a note
  16889.      about this in the error log.  If you want to be able to recover
  16890.      from most problems without user intervention, you should use the
  16891.      options `BACKUP,FORCE'.  This will force a repair of a table even
  16892.      if some rows would be deleted, but it will keep the old data file
  16893.      as a backup so that you can later examine what happened.
  16894.  
  16895.      This option is available as of MySQL 3.23.25.
  16896.  
  16897. `--ndbcluster'
  16898.      If the binary includes support for the `NDBCluster' storage engine
  16899.      the default disabling of support for the `NDB' storage engine can
  16900.      be overruled by using this option. Using the `NDBCluster' storage
  16901.      engine is necessary for using MySQL Cluster. *Note NDBCluster::.
  16902.  
  16903. `--new'
  16904.      From version 4.0.12, the `--new' option can be used to make the
  16905.      server behave as 4.1 in certain respects, easing a 4.0 to 4.1
  16906.      upgrade:
  16907.         * `TIMESTAMP' is returned as a string with the format
  16908.           `'YYYY-MM-DD HH:MM:SS''.  *Note Column types::.
  16909.  
  16910.      This option can be used to help you see how your applications will
  16911.      behave in MySQL 4.1, without actually upgrading to 4.1.
  16912.  
  16913. `--pid-file=PATH'
  16914.      The path to the process ID file used by `mysqld_safe'.
  16915.  
  16916. `--port=PORT_NUM, -P PORT_NUM'
  16917.      The port number to use when listening for TCP/IP connections.
  16918.  
  16919. `--old-protocol, -o'
  16920.      Use the 3.20 protocol for compatibility with some very old clients.
  16921.      *Note Upgrading-from-3.20::.
  16922.  
  16923. `--one-thread'
  16924.      Only use one thread (for debugging under Linux).  This option is
  16925.      available only if the server is built with debugging enabled.
  16926.      *Note Debugging server::.
  16927.  
  16928. `--open-files-limit=COUNT'
  16929.      To change the number of file descriptors available to `mysqld'.
  16930.      If this is not set or set to 0, then `mysqld' will use this value
  16931.      to reserve file descriptors to use with `setrlimit()'.  If this
  16932.      value is 0 then `mysqld' will reserve `max_connections*5' or
  16933.      `max_connections + table_cache*2' (whichever is larger) number of
  16934.      files.  You should try increasing this if `mysqld' gives you the
  16935.      error "Too many open files."
  16936.  
  16937. `--safe-mode'
  16938.      Skip some optimization stages.
  16939.  
  16940. `--safe-show-database'
  16941.      With this option, the `SHOW DATABASES' statement displays only the
  16942.      names of those databases for which the user has some kind of
  16943.      privilege.  As of MySQL 4.0.2, this option is deprecated and
  16944.      doesn't do anything (it is enabled by default), because there is
  16945.      now a `SHOW DATABASES' privilege that can be used to control
  16946.      access to database names on a per-account basis.  *Note Privileges
  16947.      provided::.
  16948.  
  16949. `--safe-user-create'
  16950.      If this is enabled, a user can't create new users with the `GRANT'
  16951.      statement, if the user doesn't have the `INSERT' privilege for the
  16952.      `mysql.user' table or any column in the table.
  16953.  
  16954. `--secure-auth'
  16955.      Disallow authentication for accounts that have old (pre-4.1)
  16956.      passwords.  This option is available as of MySQL 4.1.1.
  16957.  
  16958. `--skip-bdb'
  16959.      Disable the `BDB' storage engine. This saves memory and might speed
  16960.      up some operations.  Do not use this option if you require `BDB'
  16961.      tables.
  16962.  
  16963. `--skip-concurrent-insert'
  16964.      Turn off the ability to select and insert at the same time on
  16965.      `MyISAM' tables. (This is to be used only if you think you have
  16966.      found a bug in this feature.)
  16967.  
  16968. `--skip-delay-key-write'
  16969.      Ignore the `DELAY_KEY_WRITE' option for all tables.  As of MySQL
  16970.      4.0.3, you should use `--delay-key-write=OFF' instead.  *Note
  16971.      Server parameters::.
  16972.  
  16973. `--skip-external-locking'
  16974.      Don't use system locking.  To use `isamchk' or `myisamchk', you
  16975.      must shut down the server.  *Note Stability::.  In MySQL 3.23, you
  16976.      can use `CHECK TABLE' and `REPAIR TABLE' to check and repair
  16977.      `MyISAM' tables.  This option previously was named
  16978.      `--skip-locking'.
  16979.  
  16980. `--skip-grant-tables'
  16981.      This option causes the server not to use the privilege system at
  16982.      all. This gives everyone _full access_ to all databases!  (You can
  16983.      tell a running server to start using the grant tables again by
  16984.      executing a `mysqladmin flush-privileges' or `mysqladmin reload'
  16985.      command, or by issuing a `FLUSH PRIVILEGES' statement.)
  16986.  
  16987. `--skip-host-cache'
  16988.      Do not use the internal hostname cache for faster name-to-IP
  16989.      resolution.  Instead, query the DNS server every time a client
  16990.      connects.  *Note DNS::.
  16991.  
  16992. `--skip-innodb'
  16993.      Disable the `InnoDB' storage engine.  This saves memory and disk
  16994.      space and might speed up some operations.  Do not use this option
  16995.      if you require `InnoDB' tables.
  16996.  
  16997. `--skip-isam'
  16998.      Disable the `ISAM' storage engine.  As of MySQL 4.1, `ISAM' is
  16999.      disabled by default, so this option applies only if the server was
  17000.      configured with support for `ISAM'.  This option was added in
  17001.      MySQL 4.1.1.
  17002.  
  17003. `--skip-name-resolve'
  17004.      Do not resolve hostnames when checking client connections. Use
  17005.      only IP numbers. If you use this option, all `Host' column values
  17006.      in the grant tables must be IP numbers or `localhost'.  *Note
  17007.      DNS::.
  17008.  
  17009. `--skip-ndbcluster'
  17010.      Disable the `NDBCluster' storage engine. This is disabled by
  17011.      default for binaries where it is included. So this option only
  17012.      applies if the server was configured to use the `NDBCluster'
  17013.      storage engine.
  17014.  
  17015. `--skip-networking'
  17016.      Don't listen for TCP/IP connections at all.  All interaction with
  17017.      `mysqld' must be made via named pipes (on Windows) or Unix socket
  17018.      files (on Unix).  This option is highly recommended for systems
  17019.      where only local clients are allowed.  *Note DNS::.
  17020.  
  17021. `--skip-new'
  17022.      Don't use new, possibly wrong routines.
  17023.  
  17024. `--skip-symlink'
  17025.      This is the old form of `--skip-symbolic-links', for use before
  17026.      MySQL 4.0.13.
  17027.  
  17028. `--symbolic-links, --skip-symbolic-links'
  17029.      Enable or disable symbolic link support. This option has different
  17030.      effects on Windows and Unix:
  17031.  
  17032.         * On Windows, enabling symbolic links allows you to establish a
  17033.           symbolic link to a database directory by creating a
  17034.           `directory.sym' file that contains the path to the real
  17035.           directory.  *Note Windows symbolic links::.
  17036.  
  17037.         * On Unix, enabling symbolic links means that you can link a
  17038.           `MyISAM' index file or data file to another directory with
  17039.           the `INDEX DIRECTORY' or `DATA DIRECTORY' options of the
  17040.           `CREATE TABLE' statement.  If you delete or rename the table,
  17041.           the files that its symbolic links point to also are deleted or
  17042.           renamed. *Note `CREATE TABLE': CREATE TABLE.
  17043.  
  17044.      This option was added in MySQL 4.0.13.
  17045.  
  17046. `--skip-safemalloc'
  17047.      If MySQL is configured with `--with-debug=full', all MySQL programs
  17048.      check for memory overruns during each memory allocation and memory
  17049.      freeing operation.  This checking is very slow, so for the server
  17050.      you can avoid it when you don't need it by using the
  17051.      `--skip-safemalloc' option.
  17052.  
  17053. `--skip-show-database'
  17054.      With this option, the `SHOW DATABASES' statement is allowed only to
  17055.      users who have the `SHOW DATABASES' privilege, and the statement
  17056.      displays all database names.  Without this option, `SHOW
  17057.      DATABASES' is allowed to all users, but displays each database
  17058.      name only if the user has the `SHOW DATABASES' privilege or some
  17059.      privilege for the database.
  17060.  
  17061. `--skip-stack-trace'
  17062.      Don't write stack traces.  This option is useful when you are
  17063.      running `mysqld' under a debugger. On some systems, you also must
  17064.      use this option to get a core file. *Note Debugging server::.
  17065.  
  17066. `--skip-thread-priority'
  17067.      Disable using thread priorities for faster response time.
  17068.  
  17069. `--socket=PATH'
  17070.      On Unix, this option specifies the Unix socket file to use for
  17071.      local connections. The default value is `/tmp/mysql.sock'.  On
  17072.      Windows, the option specifies the pipe name to use for local
  17073.      connections that use a named pipe. The default value is `MySQL'.
  17074.  
  17075. `--sql-mode=VALUE[,VALUE[,VALUE...]]'
  17076.      Set the SQL mode for MySQL. *Note Server SQL mode::. This option
  17077.      was added in 3.23.41.
  17078.  
  17079. `--temp-pool'
  17080.      This option causes most temporary files created by the server to
  17081.      use a small set of names, rather than a unique name for each new
  17082.      file. This works around a problem in the Linux kernel dealing with
  17083.      creating many new files with different names. With the old
  17084.      behavior, Linux seems to "leak" memory, because it's being
  17085.      allocated to the directory entry cache rather than to the disk
  17086.      cache.
  17087.  
  17088. `--transaction-isolation=LEVEL'
  17089.      Sets the default transaction isolation level, which can be
  17090.      `READ-UNCOMMITTED', `READ-COMMITTED', `REPEATABLE-READ', or
  17091.      `SERIALIZABLE'.  *Note `SET TRANSACTION': SET TRANSACTION.
  17092.  
  17093. `--tmpdir=PATH, -t PATH'
  17094.      The path of the directory to use for creating temporary files. It
  17095.      might be useful if your default `/tmp' directory resides on a
  17096.      partition that is too small to hold temporary tables.  Starting
  17097.      from MySQL 4.1, this option accepts several paths that are used in
  17098.      round-robin fashion. Paths should be separated by colon characters
  17099.      (`:') on Unix and semicolon characters (`;') on Windows, NetWare,
  17100.      and OS/2.  If the MySQL server is acting as a replication slave,
  17101.      you should not set `--tmpdir' to point to a directory on a
  17102.      memory-based filesystem or to a directory that is cleared when the
  17103.      server host restarts.  A replication slave needs some of its
  17104.      temporary files to survive a machine restart so that it can
  17105.      replicate temporary tables or `LOAD DATA INFILE' operations. If
  17106.      files in the temporary file directory are lost when the server
  17107.      restarts, replication will fail.
  17108.  
  17109. `--user={USER_NAME | USER_ID}, -u {USER_NAME | USER_ID}'
  17110.      Run the `mysqld' server as the user having the name USER_NAME or
  17111.      the numeric user ID USER_ID.  ("User" in this context refers to a
  17112.      system login account, not a MySQL user listed in the grant tables.)
  17113.  
  17114.      This option is _mandatory_ when starting `mysqld' as `root'.  The
  17115.      server will change its user ID during its startup sequence,
  17116.      causing it to run as that particular user rather than as `root'.
  17117.      *Note Security guidelines::.
  17118.  
  17119.      Starting from MySQL 3.23.56 and 4.0.12: To avoid a possible
  17120.      security hole where a user adds a `--user=root' option to some
  17121.      `my.cnf' file (thus causing the server to run as `root'), `mysqld'
  17122.      uses only the first `--user' option specified and produces a
  17123.      warning if there are multiple `--user' options. Options in
  17124.      `/etc/my.cnf' and `datadir/my.cnf' are processed before
  17125.      command-line options, so it is recommended that you put a `--user'
  17126.      option in `/etc/my.cnf' and specify a value other than `root'. The
  17127.      option in `/etc/my.cnf' will be found before any other `--user'
  17128.      options, which ensures that the server runs as a user other than
  17129.      `root', and that a warning results if any other `--user' option is
  17130.      found.
  17131.  
  17132. `--version, -V'
  17133.      Display version information and exit.
  17134.  
  17135. You can assign a value to a server system variable by using an option of
  17136. the form `--VAR_NAME=VALUE'. For example, `--key_buffer_size=32M' sets
  17137. the `key_buffer_size' variable to a value of 32MB.
  17138.  
  17139. Note that when setting a variable to a value, MySQL might automatically
  17140. correct it to stay within a given range, or adjust the value to the
  17141. closest allowable value if only certain values are allowed.
  17142.  
  17143. It is also possible to set variables by using
  17144. `--set-variable=VAR_NAME=VALUE' or `-O VAR_NAME=VALUE' syntax. However,
  17145. this syntax is deprecated as of MySQL 4.0.
  17146.  
  17147. You can find a full description for all variables in *Note Server
  17148. system variables::.  The section on tuning server parameters includes
  17149. information on how to optimize them.  *Note Server parameters::.
  17150.  
  17151. You can change the values of most system variables for a running server
  17152. with the `SET' statement. *Note `SET OPTION': SET OPTION.
  17153.  
  17154. If you want to restrict the maximum value that a startup option can be
  17155. set to with `SET', you can define this by using the
  17156. `--maximum-VAR_NAME' command-line option.
  17157.  
  17158. The Server SQL Mode
  17159. -------------------
  17160.  
  17161. The MySQL server can operate in different SQL modes, and (as of MySQL
  17162. 4.1) can apply these modes differentially for different clients. This
  17163. allows applications to tailor server operation to their own
  17164. requirements.
  17165.  
  17166. Modes define what SQL syntax MySQL should support and what kind of data
  17167. validation checks it should perform.  This makes it easier to use MySQL
  17168. in different environments and to use MySQL together with other database
  17169. servers.
  17170.  
  17171. You can set the default SQL mode by starting `mysqld' with the
  17172. `--sql-mode="modes"' option. Beginning with MySQL 4.1, you can also
  17173. change the mode after startup time by setting the `sql_mode' variable
  17174. with a `SET [SESSION|GLOBAL] sql_mode='modes'' statement.  Setting the
  17175. `GLOBAL' variable affects the operation of all clients that connect
  17176. from that time on. Setting the `SESSION' variable affects only the
  17177. current client.  `modes' is a list of different modes separated by
  17178. comma (`,') characters.  You can retrieve the current mode by issuing a
  17179. `SELECT @@sql_mode' statement. The default value is empty (no modes
  17180. set).
  17181.  
  17182. The value also can be empty (`--sql-mode=""') if you want to reset it.
  17183.  
  17184. The following list describes the supported modes:
  17185.  
  17186. `ANSI_QUOTES'
  17187.      Treat `"' as an identifier quote character (like the ``' quote
  17188.      character) and not as a string quote character. You can still use
  17189.      ``' to quote identifers in ANSI mode. With `ANSI_QUOTES' enabled,
  17190.      you cannot use double quotes to quote a literal string, because it
  17191.      will be interpreted as an identifier.  (New in MySQL 4.0.0.)
  17192.  
  17193. `IGNORE_SPACE'
  17194.      Allow spaces between a function name and the `(' character.  This
  17195.      forces all function names to be treated as reserved words. As a
  17196.      result, if you want to access any database, table, or column name
  17197.      that is a reserved word, you must quote it.  For example, because
  17198.      there is a `USER()' function, the name of the `user' table in the
  17199.      `mysql' database and the `User' column in that table become
  17200.      reserved, so you must quote them:
  17201.  
  17202.           SELECT "User" FROM mysql."user";
  17203.  
  17204.      (New in MySQL 4.0.0.)
  17205.  
  17206. `NO_AUTO_VALUE_ON_ZERO'
  17207.      `NO_AUTO_VALUE_ON_ZERO' affects handling of `AUTO_INCREMENT'
  17208.      columns. Normally, you generate the next sequence number for the
  17209.      column by inserting either `NULL' or `0' into it.
  17210.      `NO_AUTO_VALUE_ON_ZERO' suppresses this behavior for `0' so that
  17211.      only `NULL' generates the next sequence number. This mode can be
  17212.      useful if `0' has been stored in a table's `AUTO_INCREMENT'
  17213.      column. (This is not a recommended practice, by the way.)  For
  17214.      example, if you dump the table with `mysqldump' and then reload
  17215.      it, normally MySQL generates new sequence numbers when it
  17216.      encounters the `0' values, resulting in a table with different
  17217.      contents than the one that was dumped. Enabling
  17218.      `NO_AUTO_VALUE_ON_ZERO' before reloading the dump file solves this
  17219.      problem. As of MySQL 4.1.1, `mysqldump' automatically includes
  17220.      statements in the dump output to enable `NO_AUTO_VALUE_ON_ZERO'.
  17221.      (New in MySQL 4.1.1.)
  17222.  
  17223. `NO_DIR_IN_CREATE'
  17224.      When creating a table, ignore all `INDEX DIRECTORY' and `DATA
  17225.      DIRECTORY' directives. This option is useful on slave replication
  17226.      servers.  (New in MySQL 4.0.15.)
  17227.  
  17228. `NO_FIELD_OPTIONS'
  17229.      Don't print MySQL-specific column options in the output of `SHOW
  17230.      CREATE TABLE'. This mode is used by `mysqldump' in portability
  17231.      mode.  (New in MySQL 4.1.1.)
  17232.  
  17233. `NO_KEY_OPTIONS'
  17234.      Don't print MySQL-specific index options in the output of `SHOW
  17235.      CREATE TABLE'. This mode is used by `mysqldump' in portability
  17236.      mode.  (New in MySQL 4.1.1.)
  17237.  
  17238. `NO_TABLE_OPTIONS'
  17239.      Don't print MySQL-specific table options (such as `ENGINE') in the
  17240.      output of `SHOW CREATE TABLE'. This mode is used by `mysqldump' in
  17241.      portability mode.  (New in MySQL 4.1.1.)
  17242.  
  17243. `NO_UNSIGNED_SUBTRACTION'
  17244.      In subtraction operations, don't mark the result as `UNSIGNED' if
  17245.      one of the operands is unsigned. Note that this makes `UNSIGNED
  17246.      BIGINT' not 100% usable in all contexts. *Note Cast Functions::.
  17247.      (New in MySQL 4.0.2.)
  17248.  
  17249. `ONLY_FULL_GROUP_BY'
  17250.      Don't allow queries that in the `GROUP BY' part refer to a not
  17251.      selected column.  (New in MySQL 4.0.0.)
  17252.  
  17253. `PIPES_AS_CONCAT'
  17254.      Treat `||' as a string concatenation operator (same as `CONCAT()')
  17255.      rather than as a synonym for `OR'.  (New in MySQL 4.0.0.)
  17256.  
  17257. `REAL_AS_FLOAT'
  17258.      Treat `REAL' as a synonym for `FLOAT' rather than as a synonym for
  17259.      `DOUBLE'.  (New in MySQL 4.0.0.)
  17260.  
  17261. The following special modes are provided as shorthand for combinations
  17262. of mode values from the preceding list.  They are available as of MySQL
  17263. 4.1.1.
  17264.  
  17265. `ANSI'
  17266.      Equivalent to `REAL_AS_FLOAT', `PIPES_AS_CONCAT', `ANSI_QUOTES',
  17267.      `IGNORE_SPACE', `ONLY_FULL_GROUP_BY'. *Note ANSI mode::.
  17268.  
  17269. `DB2'
  17270.      Equivalent to `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  17271.      `NO_KEY_OPTIONS', `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS'.
  17272.  
  17273. `MAXDB'
  17274.      Equivalent to `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  17275.      `NO_KEY_OPTIONS', `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS'.
  17276.  
  17277. `MSSQL'
  17278.      Equivalent to `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  17279.      `NO_KEY_OPTIONS', `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS'.
  17280.  
  17281. `MYSQL323'
  17282.      Equivalent to `NO_FIELD_OPTIONS'.
  17283.  
  17284. `MYSQL40'
  17285.      Equivalent to `NO_FIELD_OPTIONS'.
  17286.  
  17287. `ORACLE'
  17288.      Equivalent to `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  17289.      `NO_KEY_OPTIONS', `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS'.
  17290.  
  17291. `POSTGRESQL'
  17292.      Equivalent to `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  17293.      `NO_KEY_OPTIONS', `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS'.
  17294.  
  17295. Server System Variables
  17296. -----------------------
  17297.  
  17298. The server maintains many system variables that indicate how it is
  17299. configured.  All of them have default values. They can be set at server
  17300. startup using options on the command line or in option files. Most of
  17301. them can be set at runtime using the `SET' statement.
  17302.  
  17303. Beginning with MySQL 4.0.3, the `mysqld' server maintains two kinds of
  17304. variables.  Global variables affect the overall operation of the server.
  17305. Session variables affect its operation for individual client
  17306. connections.
  17307.  
  17308. When the server starts, it initializes all global variables to their
  17309. default values. These defaults can be changed by options specified in
  17310. option files or on the command line.  After the server starts, those
  17311. global variables that are dynamic can be changed by connecting to the
  17312. server and issuing a `SET GLOBAL VAR_NAME' statement. To change a
  17313. global variable, you must have the `SUPER' privilege.
  17314.  
  17315. The server also maintains a set of session variables for each client
  17316. that connects. The client's session variables are initialized at connect
  17317. time using the current values of the corresponding global variables. For
  17318. those session variables that are dynamic, the client can change them by
  17319. issuing a `SET SESSION VAR_NAME' statement. Setting a session variable
  17320. requires no special privilege, but a client can change only its own
  17321. session variables, not those of any other client.
  17322.  
  17323. A change to a global variable is visible to any client that accesses
  17324. that global variable. However, it affects the corresponding session
  17325. variable that is initialized from the global variable only for clients
  17326. that connect after the change.  It does not affect the session variable
  17327. for any client that is already connected (not even that of the client
  17328. that issues the `SET GLOBAL' statement).
  17329.  
  17330. When setting a variable using a startup option, variable values can be
  17331. given with a suffix of `K', `M', or `G' to indicate kilobytes,
  17332. megabytes, or gigabytes, respectively. For example, the following
  17333. command starts the server with a key buffer size of 16 megabytes:
  17334.  
  17335.      mysqld --key_buffer_size=16M
  17336.  
  17337. Before MySQL 4.0, use this syntax instead:
  17338.  
  17339.      mysqld --set-variable=key_buffer_size=16M
  17340.  
  17341. The lettercase of suffix letters does not matter; `16M' and `16m' are
  17342. equivalent.
  17343.  
  17344. At runtime, use the `SET' statement to set system variables. In this
  17345. context, suffix letters cannot be used, but the value can take the form
  17346. of an expression:
  17347.  
  17348.      mysql> SET sort_buffer_size = 10 * 1024 * 1024;
  17349.  
  17350. To specify explicitly whether to set the global or session variable,
  17351. use the `GLOBAL' or `SESSION' options:
  17352.  
  17353.      mysql> SET GLOBAL sort_buffer_size = 10 * 1024 * 1024;
  17354.      mysql> SET SESSION sort_buffer_size = 10 * 1024 * 1024;
  17355.  
  17356. Without either option, the statement sets the session variable.
  17357.  
  17358. The variables that can be set at runtime are listed in *Note Dynamic
  17359. System Variables::.
  17360.  
  17361. If you want to restrict the maximum value to which a system variable can
  17362. be set with the `SET' statement, you can specify this maximum by using
  17363. an option of the form `--maximum-VAR_NAME' at server startup. For
  17364. example, to prevent the value of `query_cache_size' from being
  17365. increased to more than 32MB at runtime, use the option
  17366. `--maximum-query_cache_size=32M'. This feature is available as of MySQL
  17367. 4.0.2.
  17368.  
  17369. You can view system variables and their values by using the `SHOW
  17370. VARIABLES' statement.  See *Note System Variables:: for more
  17371. information.
  17372.  
  17373.      mysql> SHOW VARIABLES;
  17374.      +---------------------------------+------------------------------+
  17375.      | Variable_name                   | Value                        |
  17376.      +---------------------------------+------------------------------|
  17377.      | back_log                        | 50                           |
  17378.      | basedir                         | /usr/local/mysql             |
  17379.      | bdb_cache_size                  | 8388572                      |
  17380.      | bdb_home                        | /usr/local/mysql             |
  17381.      | bdb_log_buffer_size             | 32768                        |
  17382.      | bdb_logdir                      |                              |
  17383.      | bdb_max_lock                    | 10000                        |
  17384.      | bdb_shared_data                 | OFF                          |
  17385.      | bdb_tmpdir                      | /tmp/                        |
  17386.      | bdb_version                     | Sleepycat Software: ...      |
  17387.      | binlog_cache_size               | 32768                        |
  17388.      | bulk_insert_buffer_size         | 8388608                      |
  17389.      | character_set                   | latin1                       |
  17390.      | character_sets                  | latin1 big5 czech euc_kr     |
  17391.      | concurrent_insert               | ON                           |
  17392.      | connect_timeout                 | 5                            |
  17393.      | convert_character_set           |                              |
  17394.      | datadir                         | /usr/local/mysql/data/       |
  17395.      | default_week_format             | 0                            |
  17396.      | delay_key_write                 | ON                           |
  17397.      | delayed_insert_limit            | 100                          |
  17398.      | delayed_insert_timeout          | 300                          |
  17399.      | delayed_queue_size              | 1000                         |
  17400.      | flush                           | OFF                          |
  17401.      | flush_time                      | 0                            |
  17402.      | ft_boolean_syntax               | + -><()~*:""&|               |
  17403.      | ft_max_word_len                 | 84                           |
  17404.      | ft_min_word_len                 | 4                            |
  17405.      | ft_query_expansion_limit        | 20                           |
  17406.      | ft_stopword_file                | (built-in)                   |
  17407.      | have_bdb                        | YES                          |
  17408.      | have_innodb                     | YES                          |
  17409.      | have_isam                       | YES                          |
  17410.      | have_openssl                    | YES                          |
  17411.      | have_query_cache                | YES                          |
  17412.      | have_raid                       | NO                           |
  17413.      | have_symlink                    | DISABLED                     |
  17414.      | init_file                       |                              |
  17415.      | innodb_additional_mem_pool_size | 1048576                      |
  17416.      | innodb_buffer_pool_size         | 8388608                      |
  17417.      | innodb_data_file_path           | ibdata1:10M:autoextend       |
  17418.      | innodb_data_home_dir            |                              |
  17419.      | innodb_fast_shutdown            | ON                           |
  17420.      | innodb_file_io_threads          | 4                            |
  17421.      | innodb_flush_log_at_trx_commit  | 1                            |
  17422.      | innodb_flush_method             |                              |
  17423.      | innodb_force_recovery           | 0                            |
  17424.      | innodb_lock_wait_timeout        | 50                           |
  17425.      | innodb_log_arch_dir             |                              |
  17426.      | innodb_log_archive              | OFF                          |
  17427.      | innodb_log_buffer_size          | 1048576                      |
  17428.      | innodb_log_file_size            | 5242880                      |
  17429.      | innodb_log_files_in_group       | 2                            |
  17430.      | innodb_log_group_home_dir       | ./                           |
  17431.      | innodb_mirrored_log_groups      | 1                            |
  17432.      | innodb_thread_concurrency       | 8                            |
  17433.      | interactive_timeout             | 28800                        |
  17434.      | join_buffer_size                | 131072                       |
  17435.      | key_buffer_size                 | 16773120                     |
  17436.      | key_cache_age_threshold         | 300                          |
  17437.      | key_cache_block_size            | 1024                         |
  17438.      | key_cache_division_limit        | 100                          |
  17439.      | language                        | /usr/local/mysql/share/...   |
  17440.      | large_files_support             | ON                           |
  17441.      | local_infile                    | ON                           |
  17442.      | locked_in_memory                | OFF                          |
  17443.      | log                             | OFF                          |
  17444.      | log_bin                         | OFF                          |
  17445.      | log_slave_updates               | OFF                          |
  17446.      | log_slow_queries                | OFF                          |
  17447.      | log_update                      | OFF                          |
  17448.      | log_warnings                    | OFF                          |
  17449.      | long_query_time                 | 10                           |
  17450.      | low_priority_updates            | OFF                          |
  17451.      | lower_case_table_names          | 0                            |
  17452.      | max_allowed_packet              | 1047552                      |
  17453.      | max_binlog_cache_size           | 4294967295                   |
  17454.      | max_binlog_size                 | 1073741824                   |
  17455.      | max_connect_errors              | 10                           |
  17456.      | max_connections                 | 100                          |
  17457.      | max_delayed_threads             | 20                           |
  17458.      | max_error_count                 | 64                           |
  17459.      | max_heap_table_size             | 16777216                     |
  17460.      | max_join_size                   | 4294967295                   |
  17461.      | max_relay_log_size              | 0                            |
  17462.      | max_sort_length                 | 1024                         |
  17463.      | max_tmp_tables                  | 32                           |
  17464.      | max_user_connections            | 0                            |
  17465.      | max_write_lock_count            | 4294967295                   |
  17466.      | myisam_max_extra_sort_file_size | 268435456                    |
  17467.      | myisam_max_sort_file_size       | 2147483647                   |
  17468.      | myisam_recover_options          | force                        |
  17469.      | myisam_repair_threads           | 1                            |
  17470.      | myisam_sort_buffer_size         | 8388608                      |
  17471.      | net_buffer_length               | 16384                        |
  17472.      | net_read_timeout                | 30                           |
  17473.      | net_retry_count                 | 10                           |
  17474.      | net_write_timeout               | 60                           |
  17475.      | open_files_limit                | 1024                         |
  17476.      | pid_file                        | /usr/local/mysql/name.pid    |
  17477.      | port                            | 3306                         |
  17478.      | protocol_version                | 10                           |
  17479.      | query_cache_limit               | 1048576                      |
  17480.      | query_cache_size                | 0                            |
  17481.      | query_cache_type                | ON                           |
  17482.      | read_buffer_size                | 131072                       |
  17483.      | read_rnd_buffer_size            | 262144                       |
  17484.      | rpl_recovery_rank               | 0                            |
  17485.      | server_id                       | 0                            |
  17486.      | skip_external_locking           | ON                           |
  17487.      | skip_networking                 | OFF                          |
  17488.      | skip_show_database              | OFF                          |
  17489.      | slave_net_timeout               | 3600                         |
  17490.      | slow_launch_time                | 2                            |
  17491.      | socket                          | /tmp/mysql.sock              |
  17492.      | sort_buffer_size                | 2097116                      |
  17493.      | sql_mode                        |                              |
  17494.      | table_cache                     | 64                           |
  17495.      | table_type                      | MYISAM                       |
  17496.      | thread_cache_size               | 3                            |
  17497.      | thread_stack                    | 131072                       |
  17498.      | timezone                        | EEST                         |
  17499.      | tmp_table_size                  | 33554432                     |
  17500.      | tmpdir                          | /tmp/:/mnt/hd2/tmp/          |
  17501.      | tx_isolation                    | READ-COMMITTED               |
  17502.      | version                         | 4.0.4-beta                   |
  17503.      | wait_timeout                    | 28800                        |
  17504.      +---------------------------------+------------------------------+
  17505.  
  17506. Most system variables are described here.  Variables with no version
  17507. indicated have been present since at least MySQL 3.22.  `InnoDB' system
  17508. variables are listed at *Note `InnoDB' start: InnoDB start.
  17509.  
  17510. Values for buffer sizes, lengths, and stack sizes are given in bytes
  17511. unless otherwise specified.
  17512.  
  17513. Information on tuning these variables can be found in *Note Server
  17514. parameters::.
  17515.  
  17516. `ansi_mode'
  17517.      This is `ON' if `mysqld' was started with `--ansi'.  *Note ANSI
  17518.      mode::.  This variable was added in MySQL 3.23.6 and removed in
  17519.      3.23.41.  See the description for `sql_mode'.
  17520.  
  17521. `back_log'
  17522.      The number of outstanding connection requests MySQL can have. This
  17523.      comes into play when the main MySQL thread gets very many
  17524.      connection requests in a very short time. It then takes some time
  17525.      (although very little) for the main thread to check the connection
  17526.      and start a new thread. The `back_log' value indicates how many
  17527.      requests can be stacked during this short time before MySQL
  17528.      momentarily stops answering new requests. You need to increase
  17529.      this only if you expect a large number of connections in a short
  17530.      period of time.
  17531.  
  17532.      In other words, this value is the size of the listen queue for
  17533.      incoming TCP/IP connections.  Your operating system has its own
  17534.      limit on the size of this queue.  The manual page for the Unix
  17535.      `listen()' system call should have more details.  Check your OS
  17536.      documentation for the maximum value for this variable.  Attempting
  17537.      to set `back_log' higher than your operating system limit will be
  17538.      ineffective.
  17539.  
  17540. `basedir'
  17541.      The MySQL installation base directory. This variable can be set
  17542.      with the `--basedir' option.
  17543.  
  17544. `bdb_cache_size'
  17545.      The size of the buffer that is allocated for caching indexes and
  17546.      rows for `BDB' tables.  If you don't use `BDB' tables, you should
  17547.      start `mysqld' with `--skip-bdb' to not waste memory for this
  17548.      cache.  This variable was added in MySQL 3.23.14.
  17549.  
  17550. `bdb_home'
  17551.      The base directory for `BDB' tables.  This should be assigned the
  17552.      same value as the `datadir' variable.  This variable was added in
  17553.      MySQL 3.23.14.
  17554.  
  17555. `bdb_log_buffer_size'
  17556.      The size of the buffer that is allocated for caching indexes and
  17557.      rows for `BDB' tables.  If you don't use `BDB' tables, you should
  17558.      set this to 0 or start `mysqld' with `--skip-bdb' to not waste
  17559.      memory for this cache.  This variable was added in MySQL 3.23.31.
  17560.  
  17561. `bdb_logdir'
  17562.      The directory where the `BDB' storage engine writes its log files.
  17563.      This variable can be set with the `--bdb-logdir' option.  This
  17564.      variable was added in MySQL 3.23.14.
  17565.  
  17566. `bdb_max_lock'
  17567.      The maximum number of locks you can have active on a `BDB' table
  17568.      (10,000 by default). You should increase this if errors such as the
  17569.      following occur when you perform long transactions or when
  17570.      `mysqld' has to examine many rows to calculate a query:
  17571.  
  17572.           bdb: Lock table is out of available locks
  17573.           Got error 12 from ...
  17574.  
  17575.      This variable was added in MySQL 3.23.29.
  17576.  
  17577. `bdb_shared_data'
  17578.      This is `ON' if you are using `--bdb-shared-data'.  This variable
  17579.      was added in MySQL 3.23.29.
  17580.  
  17581. `bdb_tmpdir'
  17582.      The value of the `--bdb-tmpdir' option.  This variable was added
  17583.      in MySQL 3.23.14.
  17584.  
  17585. `bdb_version'
  17586.      The `BDB' storage engine version.  This variable was added in
  17587.      MySQL 3.23.31.
  17588.  
  17589. `binlog_cache_size'
  17590.      The size of the cache to hold the SQL statements for the binary
  17591.      log during a transaction.  A binary log cache is allocated for
  17592.      each client if the server supports any transactional storage
  17593.      engines and, starting from MySQL 4.1.2, if the server has binary
  17594.      log enabled (`--log-bin' option). If you often use big,
  17595.      multiple-statement transactions, you can increase this to get more
  17596.      performance.  The `Binlog_cache_use' and `Binlog_cache_disk_use'
  17597.      status variables can be useful for tuning the size of this
  17598.      variable.  This variable was added in MySQL 3.23.29.  *Note Binary
  17599.      log::.
  17600.  
  17601. `bulk_insert_buffer_size'
  17602.      `MyISAM' uses a special tree-like cache to make bulk inserts
  17603.      faster for `INSERT ... SELECT', `INSERT ... VALUES (...), (...),
  17604.      ...', and `LOAD DATA INFILE'. This variable limits the size of the
  17605.      cache tree in bytes per thread. Setting it to 0 disables this
  17606.      optimization.  *Note*: This cache is used only when adding data to
  17607.      a non-empty table.  The default value is 8MB.  This variable was
  17608.      added in MySQL 4.0.3.  This variable previously was named
  17609.      `myisam_bulk_insert_tree_size'.
  17610.  
  17611. `character_set'
  17612.      The default character set.  This variable was added in MySQL
  17613.      3.23.3, then removed in MySQL 4.1.1 and replaced by the various
  17614.      `character_set_XXX' variables.
  17615.  
  17616. `character_set_client'
  17617.      The character set for statements that arrive from the client.
  17618.      This variable was added in MySQL 4.1.1.
  17619.  
  17620. `character_set_connection'
  17621.      The character set used for literals that do not have a character
  17622.      set introducer, for some functions, and for number-to-string
  17623.      conversion.  This variable was added in MySQL 4.1.1.
  17624.  
  17625. `character_set_database'
  17626.      The character set used by the default database.  The server sets
  17627.      this variable whenever the default database changes.  If there is
  17628.      no default database, the variable has the same value as
  17629.      `character_set_server'.  This variable was added in MySQL 4.1.1.
  17630.  
  17631. `character_set_results'
  17632.      The character set used for returning query results to the client.
  17633.      This variable was added in MySQL 4.1.1.
  17634.  
  17635. `character_set_server'
  17636.      The server default character set.  This variable was added in
  17637.      MySQL 4.1.1.
  17638.  
  17639. `character_set_system'
  17640.      The character set used by the server for storing identifiers.  The
  17641.      value is always `utf8'.  This variable was added in MySQL 4.1.1.
  17642.  
  17643. `character_sets'
  17644.      The supported character sets.  This variable was added in MySQL
  17645.      3.23.15.
  17646.  
  17647. `collation_connection'
  17648.      The collation of the connection character set.  This variable was
  17649.      added in MySQL 4.1.1.
  17650.  
  17651. `collation_database'
  17652.      The collation used by the default database.  The server sets this
  17653.      variable whenever the default database changes.  If there is no
  17654.      default database, the variable has the same value as
  17655.      `collation_server'.  This variable was added in MySQL 4.1.1.
  17656.  
  17657. `collation_server'
  17658.      The server default collation.  This variable was added in MySQL
  17659.      4.1.1.
  17660.  
  17661. `concurrent_insert'
  17662.      If `ON' (the default), MySQL allows `INSERT' and `SELECT'
  17663.      statements to run concurrently for `MyISAM' tables that have no
  17664.      free blocks in the middle.  You can turn this option off by
  17665.      starting `mysqld' with `--safe' or `--skip-new'.  This variable
  17666.      was added in MySQL 3.23.7.
  17667.  
  17668. `connect_timeout'
  17669.      The number of seconds the `mysqld' server waits for a connect
  17670.      packet before responding with `Bad handshake'.
  17671.  
  17672. `datadir'
  17673.      The MySQL data directory. This variable can be set with the
  17674.      `--datadir' option.
  17675.  
  17676. `default_week_format'
  17677.      The default mode value to use for the `WEEK()' function.  This
  17678.      variable is available as of MySQL 4.0.14.
  17679.  
  17680. `delay_key_write'
  17681.      This option applies only to `MyISAM' tables. It can have one of the
  17682.      following values to affect handling of the `DELAY_KEY_WRITE' table
  17683.      option that can be used in `CREATE TABLE' statements.
  17684.  
  17685.      *Option**Description*
  17686.      `OFF'   `DELAYED_KEY_WRITE' is ignored.
  17687.      `ON'    MySQL honors the `DELAY_KEY_WRITE' option for
  17688.              `CREATE TABLE'. This is the default value.
  17689.      `ALL'   All new opened tables are treated as if they were
  17690.              created with the `DELAY_KEY_WRITE' option enabled.
  17691.  
  17692.      If `DELAY_KEY_WRITE' is enabled, this means that the key buffer for
  17693.      tables with this option are not flushed on every index update, but
  17694.      only when a table is closed.  This will speed up writes on keys a
  17695.      lot, but if you use this feature, you should add automatic
  17696.      checking of all `MyISAM' tables by starting the server with the
  17697.      `--myisam-recover' option (for example,
  17698.      `--myisam-recover=BACKUP,FORCE').  See *Note Server options:: and
  17699.      *Note MyISAM start::.
  17700.  
  17701.      Note that `--external-locking' doesn't offer any protection against
  17702.      index corruption for tables that use delayed key writes.
  17703.  
  17704.      This variable was added in MySQL 3.23.8.
  17705.  
  17706. `delayed_insert_limit'
  17707.      After inserting `delayed_insert_limit' delayed rows, the `INSERT
  17708.      DELAYED' handler thread checks whether there are any `SELECT'
  17709.      statements pending. If so, it allows them to execute before
  17710.      continuing to insert delayed rows.
  17711.  
  17712. `delayed_insert_timeout'
  17713.      How long an `INSERT DELAYED' handler thread should wait for
  17714.      `INSERT' statements before terminating.
  17715.  
  17716. `delayed_queue_size'
  17717.      How many rows to queue when handling `INSERT DELAYED' statements.
  17718.      If the queue becomes full, any client that issues an `INSERT
  17719.      DELAYED' statement will wait until there is room in the queue
  17720.      again.
  17721.  
  17722. `expire_logs_days'
  17723.      The number of days for automatic binary log rotation.  The default
  17724.      is 0, which means "no automatic rotation."  This variable was
  17725.      added in MySQL 4.1.0.
  17726.  
  17727. `flush'
  17728.      This is `ON' if you have started `mysqld' with the `--flush'
  17729.      option.  This variable was added in MySQL 3.22.9.
  17730.  
  17731. `flush_time'
  17732.      If this is set to a non-zero value, all tables will be closed every
  17733.      `flush_time' seconds to free up resources and sync unflushed data
  17734.      to disk.  We recommend this option only on Windows 9x or Me, or on
  17735.      systems with minimal resources available.  This variable was added
  17736.      in MySQL 3.22.18.
  17737.  
  17738. `ft_boolean_syntax'
  17739.      The list of operators supported by boolean full-text searches
  17740.      performed using `IN BOOLEAN MODE'.  This variable was added in
  17741.      MySQL 4.0.1.  *Note Fulltext Boolean::.
  17742.  
  17743.      The default variable value is `'+ -><()~*:""&|''. The rules for
  17744.      changing the value are as follows:
  17745.  
  17746.         * Operator function is determined by position within the string.
  17747.  
  17748.         * The replacement value must be 14 characters.
  17749.  
  17750.         * Each character must be an ASCII non-alphanumeric character.
  17751.  
  17752.         * Either the first or second character must be a space.
  17753.  
  17754.         * No duplicates are allowed except the phrase quoting operators
  17755.           in positions 11 and 12. These two characters are not required
  17756.           to be the same, but they are the only two that may be.
  17757.  
  17758.         * Positions 10, 13, and 14 (which by default are set to `:',
  17759.           `&', and `|') are reserved for future extensions.
  17760.  
  17761.  
  17762. `ft_max_word_len'
  17763.      The maximum length of the word to be included in a `FULLTEXT'
  17764.      index.  This variable was added in MySQL 4.0.0.
  17765.  
  17766.      *Note*: `FULLTEXT' indexes must be rebuilt after changing this
  17767.      variable.  Use `REPAIR TABLE TBL_NAME QUICK'.
  17768.  
  17769. `ft_min_word_len'
  17770.      The minimum length of the word to be included in a `FULLTEXT'
  17771.      index.  This variable was added in MySQL 4.0.0.
  17772.  
  17773.      *Note*: `FULLTEXT' indexes must be rebuilt after changing this
  17774.      variable.  Use `REPAIR TABLE TBL_NAME QUICK'.
  17775.  
  17776. `ft_query_expansion_limit'
  17777.      The number of top matches to use for full-text searches performed
  17778.      using `WITH QUERY EXPANSION'.  This variable was added in MySQL
  17779.      4.1.1.
  17780.  
  17781. `ft_stopword_file'
  17782.      The file from which to read the list of stopwords for full-text
  17783.      searches.  All the words from the file are used; comments are
  17784.      _not_ honored.  By default, a built-in list of stopwords is used
  17785.      (as defined in the `myisam/ft_static.c' file).  Setting this
  17786.      variable to the empty string (`''') disables stopword filtering.
  17787.      This variable was added in MySQL 4.0.10.
  17788.  
  17789.      *Note*: `FULLTEXT' indexes must be rebuilt after changing this
  17790.      variable.  Use `REPAIR TABLE TBL_NAME QUICK'.
  17791.  
  17792. `group_concat_max_len'
  17793.      The maximum allowed result length for the `GROUP_CONCAT()'
  17794.      function.  This variable was added in MySQL 4.1.0.
  17795.  
  17796. `have_bdb'
  17797.      `YES' if `mysqld' supports `BDB' tables. `DISABLED' if
  17798.      `--skip-bdb' is used.  This variable was added in MySQL 3.23.30.
  17799.  
  17800. `have_innodb'
  17801.      `YES' if `mysqld' supports `InnoDB' tables. `DISABLED' if
  17802.      `--skip-innodb' is used.  This variable was added in MySQL 3.23.37.
  17803.  
  17804. `have_isam'
  17805.      `YES' if `mysqld' supports `ISAM' tables. `DISABLED' if
  17806.      `--skip-isam' is used.  This variable was added in MySQL 3.23.30.
  17807.  
  17808. `have_raid'
  17809.      `YES' if `mysqld' supports the `RAID' option.  This variable was
  17810.      added in MySQL 3.23.30.
  17811.  
  17812. `have_openssl'
  17813.      `YES' if `mysqld' supports SSL (encryption) of the client/server
  17814.      protocol.  This variable was added in MySQL 3.23.43.
  17815.  
  17816. `init_connect'
  17817.      A string to be executed by the server for each client that
  17818.      connects.  The string consists of one or more SQL statements. To
  17819.      specify multiple statements, separate them by semicolon characters.
  17820.      For example, each client begins by default with autocommit mode
  17821.      enabled.  There is no global server variable to specify that
  17822.      autocommit should be disabled by default, but `init_connect' can
  17823.      be used to achieve the same effect:
  17824.  
  17825.           SET GLOBAL init_connect='SET AUTOCOMMIT=0';
  17826.  
  17827.      This variable can also be set on the command line or in an option
  17828.      file.  To set the variable as just shown using an option file,
  17829.      include these lines:
  17830.  
  17831.           [mysqld]
  17832.           init_connect='SET AUTOCOMMIT=0'
  17833.  
  17834.      This variable was added in MySQL 4.1.2.
  17835.  
  17836. `init_file'
  17837.      The name of the file specified with the `--init-file' option when
  17838.      you start the server.  This is a file containing SQL statements
  17839.      that you want the server to execute when it starts.  Each
  17840.      statement must be on a single line and should not include comments.
  17841.      This variable was added in MySQL 3.23.2.
  17842.  
  17843. `init_slave'
  17844.      This variable is similar to `init_connect', but is a string to be
  17845.      executed by a slave server each time the SQL thread starts.  The
  17846.      format of the string is the same as for the `init_connect'
  17847.      variable.  This variable was added in MySQL 4.1.2.
  17848.  
  17849. `innodb_XXX'
  17850.      The `InnoDB' system variables are listed at *Note `InnoDB' start:
  17851.      InnoDB start.
  17852.  
  17853. `interactive_timeout'
  17854.      The number of seconds the server waits for activity on an
  17855.      interactive connection before closing it.  An interactive client
  17856.      is defined as a client that uses the `CLIENT_INTERACTIVE' option to
  17857.      `mysql_real_connect()'.  See also `wait_timeout'.
  17858.  
  17859. `join_buffer_size'
  17860.      The size of the buffer that is used for full joins (joins that do
  17861.      not use indexes).  Normally the best way to get fast joins is to
  17862.      add indexes.  Increase the value of `join_buffer_size' to get a
  17863.      faster full join when adding indexes is not possible.  One join
  17864.      buffer is allocated for each full join between two tables. For a
  17865.      complex join between several tables for which indexes are not
  17866.      used, multiple join buffers might be necessary.
  17867.  
  17868. `key_buffer_size'
  17869.      Index blocks for `MyISAM' and `ISAM' tables are buffered and are
  17870.      shared by all threads.  `key_buffer_size' is the size of the buffer
  17871.      used for index blocks.  The key buffer is also known as the key
  17872.      cache.
  17873.  
  17874.      Increase the value to get better index handling (for all reads and
  17875.      multiple writes) to as much as you can afford. Using a value that
  17876.      is 25% of total memory on a machine that mainly runs MySQL is
  17877.      quite common.  However, if you make the value too large (for
  17878.      example, more than 50% of your total memory) your system might
  17879.      start to page and become extremely slow.  MySQL relies on the
  17880.      operating system to perform filesystem caching for data reads, so
  17881.      you must leave some room for the filesystem cache.
  17882.  
  17883.      For even more speed when writing many rows at the same time, use
  17884.      `LOCK TABLES'.  *Note `LOCK TABLES': LOCK TABLES.
  17885.  
  17886.      You can check the performance of the key buffer by issuing a `SHOW
  17887.      STATUS' statement and examining the `Key_read_requests',
  17888.      `Key_reads', `Key_write_requests', and `Key_writes' status
  17889.      variables.  *Note `SHOW': SHOW.
  17890.  
  17891.      The `Key_reads/Key_read_requests' ratio should normally be less
  17892.      than 0.01.  The `Key_writes/Key_write_requests' ratio is usually
  17893.      near 1 if you are using mostly updates and deletes, but might be
  17894.      much smaller if you tend to do updates that affect many rows at
  17895.      the same time or if you are using the `DELAY_KEY_WRITE' table
  17896.      option.
  17897.  
  17898.      The fraction of the key buffer in use can be determined using
  17899.      `key_buffer_size' in conjunction with the `Key_blocks_used' status
  17900.      variable and the buffer block size.  From MySQL 4.1.1 on, the
  17901.      buffer block size is available from the `key_cache_block_size'
  17902.      server variable. The fraction of the buffer in use is:
  17903.  
  17904.           (Key_blocks_used * key_cache_block_size) / key_buffer_size
  17905.  
  17906.      Before MySQL 4.1.1, key cache blocks are 1024 bytes, so the
  17907.      fraction of the key buffer in use is:
  17908.  
  17909.           (Key_blocks_used * 1024) / key_buffer_size
  17910.  
  17911.      *Note `MyISAM' key cache: MyISAM key cache.
  17912.  
  17913. `key_cache_age_threshold'
  17914.      This value controls the demotion of buffers from the hot sub-chain
  17915.      of a key cache to the warm sub-chain.  Lower values cause demotion
  17916.      to happen more quickly.  The minimum value is 100.  The default
  17917.      value is 300.  This variable was added in MySQL 4.1.1.  *Note
  17918.      `MyISAM' key cache: MyISAM key cache.
  17919.  
  17920. `key_cache_block_size'
  17921.      The size in bytes of blocks in the key cache.  The default value
  17922.      is 1024.  This variable was added in MySQL 4.1.1.  *Note `MyISAM'
  17923.      key cache: MyISAM key cache.
  17924.  
  17925. `key_cache_division_limit'
  17926.      The division point between the hot and warm sub-chains of the key
  17927.      cache buffer chain. The value is the percentage of the buffer
  17928.      chain to use for the warm sub-chain.  Allowable values range from
  17929.      1 to 100.  The default value is 100.  This variable was added in
  17930.      MySQL 4.1.1.  *Note `MyISAM' key cache: MyISAM key cache.
  17931.  
  17932. `language'
  17933.      The language used for error messages.
  17934.  
  17935. `large_file_support'
  17936.      Whether `mysqld' was compiled with options for large file support.
  17937.      This variable was added in MySQL 3.23.28.
  17938.  
  17939. `local_infile'
  17940.      Whether `LOCAL' is supported for `LOAD DATA INFILE' statements.
  17941.      This variable was added in MySQL 4.0.3.
  17942.  
  17943. `locked_in_memory'
  17944.      Whether `mysqld' was locked in memory with `--memlock'.  This
  17945.      variable was added in MySQL 3.23.25.
  17946.  
  17947. `log'
  17948.      Whether logging of all queries to the general query log is enabled.
  17949.      *Note Query log::.
  17950.  
  17951. `log_bin'
  17952.      Whether the binary log is enabled.  This variable was added in
  17953.      MySQL 3.23.14.  *Note Binary log::.
  17954.  
  17955. `log_slave_updates'
  17956.      Whether updates received by a slave server from a master server
  17957.      should be logged to the slave's own binary log. Binary logging
  17958.      must be enabled on the slave for this to have any effect.  This
  17959.      variable was added in MySQL 3.23.17.  *Note Replication Options::.
  17960.  
  17961. `log_slow_queries'
  17962.      Whether slow queries should be logged.  "Slow" is determined by
  17963.      the value of the `long_query_time' variable.  This variable was
  17964.      added in MySQL 4.0.2.  *Note Slow query log::.
  17965.  
  17966. `log_update'
  17967.      Whether the update log is enabled.  This variable was added in
  17968.      MySQL 3.22.18.  Note that the binary log is preferable to the
  17969.      update log, which is unavailable as of MySQL 5.0.  *Note Update
  17970.      log::.
  17971.  
  17972. `long_query_time'
  17973.      If a query takes longer than this many seconds, the `Slow_queries'
  17974.      status variable is incremented. If you are using the
  17975.      `--log-slow-queries' option, the query is logged to the slow query
  17976.      log file. This value is measured in real time, not CPU time, so a
  17977.      query that is under the threshold on a lightly loaded system might
  17978.      be above the threshold on a heavily loaded one.  *Note Slow query
  17979.      log::.
  17980.  
  17981. `low_priority_updates'
  17982.      If set to `1', all `INSERT', `UPDATE', `DELETE', and `LOCK TABLE
  17983.      WRITE' statements wait until there is no pending `SELECT' or `LOCK
  17984.      TABLE READ' on the affected table.  This variable previously was
  17985.      named `sql_low_priority_updates'.  It was added in MySQL 3.22.5.
  17986.  
  17987. `lower_case_table_names'
  17988.      If set to 1, table names are stored in lowercase on disk and table
  17989.      name comparisons are not case sensitive.  This variable was added
  17990.      in MySQL 3.23.6.  If set to 2 (new in 4.0.18), table names are
  17991.      stored as given but compared in lowercase.  From MySQL 4.0.2, this
  17992.      option also applies to database names.  From 4.1.1, it also
  17993.      applies to table aliases.  *Note Name case sensitivity::.
  17994.  
  17995.      You should _not_ set this variable to 0 if you are running MySQL
  17996.      on a system that does not have case-sensitive filenames (such as
  17997.      Windows or Mac OS X).  New in 4.0.18:  If this variable is 0 and
  17998.      the filesystem on which the data directory is located does not have
  17999.      case-sensitive filenames, MySQL automatically sets
  18000.      `lower_case_table_names' to 2.
  18001.  
  18002. `max_allowed_packet'
  18003.      The maximum size of one packet or any generated/intermediate
  18004.      string.
  18005.  
  18006.      The packet message buffer is initialized to `net_buffer_length'
  18007.      bytes, but can grow up to `max_allowed_packet' bytes when needed.
  18008.      This value by default is small, to catch big (possibly wrong)
  18009.      packets.
  18010.  
  18011.      You must increase this value if you are using big `BLOB' columns or
  18012.      long strings. It should be as big as the biggest `BLOB' you want to
  18013.      use.  The protocol limit for `max_allowed_packet' is 16MB before
  18014.      MySQL 4.0 and 1GB thereafter.
  18015.  
  18016. `max_binlog_cache_size'
  18017.      If a multiple-statement transaction requires more than this amount
  18018.      of memory, you will get the error `Multi-statement transaction
  18019.      required more than 'max_binlog_cache_size' bytes of storage'.
  18020.      This variable was added in MySQL 3.23.29.
  18021.  
  18022. `max_binlog_size'
  18023.      If a write to the binary log exceeds the given value, rotate the
  18024.      binary logs.  You cannot set this variable to more than 1GB or to
  18025.      less than 4096 bytes.  (The minimum before MYSQL 4.0.14 is 1024
  18026.      bytes.) The default value is 1GB.  This variable was added in
  18027.      MySQL 3.23.33.
  18028.  
  18029.      Note if you are using transactions: A transaction is written in
  18030.      one chunk to the binary log, hence it is never split between
  18031.      several binary logs.  Therefore, if you have big transactions, you
  18032.      might see binary logs bigger than `max_binlog_size'.
  18033.  
  18034.      If `max_relay_log_size' is 0, the value of `max_binlog_size'
  18035.      applies to relay logs as well. `max_relay_log_size' was added in
  18036.      MySQL 4.0.14.
  18037.  
  18038. `max_connect_errors'
  18039.      If there are more than this number of interrupted connections from
  18040.      a host, that host is blocked from further connections.  You can
  18041.      unblock blocked hosts with the `FLUSH HOSTS' statement.
  18042.  
  18043. `max_connections'
  18044.      The number of simultaneous client connections allowed. Increasing
  18045.      this value increases the number of file descriptors that `mysqld'
  18046.      requires.  See *Note Table cache:: for comments on file descriptor
  18047.      limits.  Also see *Note Too many connections::.
  18048.  
  18049. `max_delayed_threads'
  18050.      Don't start more than this number of threads to handle `INSERT
  18051.      DELAYED' statements.  If you try to insert data into a new table
  18052.      after all `INSERT DELAYED' threads are in use, the row will be
  18053.      inserted as if the `DELAYED' attribute wasn't specified. If you
  18054.      set this to 0, MySQL never creates a thread to handle `DELAYED'
  18055.      rows; in effect, this disables `DELAYED' entirely.  This variable
  18056.      was added in MySQL 3.23.0.
  18057.  
  18058. `max_error_count'
  18059.      The maximum number of error, warning, and note messages to be
  18060.      stored for display by `SHOW ERRORS' or `SHOW WARNINGS'.  This
  18061.      variable was added in MySQL 4.1.0.
  18062.  
  18063. `max_heap_table_size'
  18064.      This variable sets the maximum size to which `MEMORY' (`HEAP')
  18065.      tables are allowed to grow.  The value of the variable is used to
  18066.      calculate `MEMORY' table `MAX_ROWS' values.  Setting this variable
  18067.      has no effect on any existing `MEMORY' table, unless the table is
  18068.      re-created with a statement such as `CREATE TABLE' or `TRUNCATE
  18069.      TABLE', or altered with `ALTER TABLE'.  This variable was added in
  18070.      MySQL 3.23.0.
  18071.  
  18072. `max_insert_delayed_threads'
  18073.      This variable is a synonym for `max_delayed_threads'.  It was
  18074.      added in MySQL 4.0.19.
  18075.  
  18076. `max_join_size'
  18077.      Don't allow `SELECT' statements that probably will need to examine
  18078.      more than `max_join_size' row combinations or are likely to do more
  18079.      than `max_join_size' disk seeks.  By setting this value, you can
  18080.      catch `SELECT' statements where keys are not used properly and
  18081.      that would probably take a long time.  Set it if your users tend
  18082.      to perform joins that lack a `WHERE' clause, that take a long
  18083.      time, or that return millions of rows.
  18084.  
  18085.      Setting this variable to a value other than `DEFAULT' resets the
  18086.      `SQL_BIG_SELECTS' value to `0'.  If you set the `SQL_BIG_SELECTS'
  18087.      value again, the `max_join_size' variable is ignored.
  18088.  
  18089.      If a query result already is in the query cache, no result size
  18090.      check is performed, because the result has already been computed
  18091.      and it does not burden the server to send it to the client.
  18092.  
  18093.      This variable previously was named `sql_max_join_size'.
  18094.  
  18095. `max_relay_log_size'
  18096.      If a write by a replication slave to its relay log exceeds the
  18097.      given value, rotate the relay log.  This variable enables you to
  18098.      put different size constraints on relay logs and binary logs.
  18099.      However, setting the variable to 0 makes MySQL use
  18100.      `max_binlog_size' for both binary logs and relay logs.  You must
  18101.      set `max_relay_log_size' to between 4096 bytes and 1GB
  18102.      (inclusive), or to 0. The default value is 0.  This variable was
  18103.      added in MySQL 4.0.14.  *Note Replication Implementation Details::.
  18104.  
  18105. `max_seeks_for_key'
  18106.      Limit the assumed maximum number of seeks when looking up rows
  18107.      based on a key.  The MySQL optimizer will assume that no more than
  18108.      this number of key seeks will be required when searching for
  18109.      matching rows in a table by scanning a key, regardless of the
  18110.      actual cardinality of the key (*note SHOW INDEX::). By setting
  18111.      this to a low value (100?), you can force MySQL to prefer keys
  18112.      instead of table scans.
  18113.  
  18114.      This variable was added in MySQL 4.0.14.
  18115.  
  18116. `max_sort_length'
  18117.      The number of bytes to use when sorting `BLOB' or `TEXT' values.
  18118.      Only the first `max_sort_length' bytes of each value are used; the
  18119.      rest are ignored.
  18120.  
  18121. `max_tmp_tables'
  18122.      The maximum number of temporary tables a client can keep open at
  18123.      the same time.  (This option doesn't yet do anything.)
  18124.  
  18125. `max_user_connections'
  18126.      The maximum number of simultaneous connections allowed to any
  18127.      given MySQL account.  A value of 0 means "no limit."  This
  18128.      variable was added in MySQL 3.23.34.
  18129.  
  18130. `max_write_lock_count'
  18131.      After this many write locks, allow some read locks to run in
  18132.      between.  This variable was added in MySQL 3.23.7.
  18133.  
  18134. `myisam_data_pointer_size'
  18135.      Default pointer size in bytes to be used by `CREATE TABLE' for
  18136.      `MyISAM' tables when no `MAX_ROWS' option is specified.  This
  18137.      variable cannot be less than 2 or larger than 8.  The default
  18138.      value is 4.  This variable was added in MySQL 4.1.2.  *Note
  18139.      `myisam_data_pointer_size': Full table.
  18140.  
  18141. `myisam_max_extra_sort_file_size'
  18142.      If the temporary file used for fast `MyISAM' index creation would
  18143.      be larger than using the key cache by the amount specified here,
  18144.      prefer the key cache method.  This is mainly used to force long
  18145.      character keys in large tables to use the slower key cache method
  18146.      to create the index.  This variable was added in MySQL 3.23.37.
  18147.      *Note*: The value is given in megabytes before 4.0.3 and in bytes
  18148.      thereafter.
  18149.  
  18150. `myisam_max_sort_file_size'
  18151.      The maximum size of the temporary file MySQL is allowed to use
  18152.      while re-creating a `MyISAM' index (during `REPAIR TABLE', `ALTER
  18153.      TABLE', or `LOAD DATA INFILE').  If the file size would be bigger
  18154.      than this value, the index will be created using the key cache
  18155.      instead, which is slower.  This variable was added in MySQL
  18156.      3.23.37.  *Note*: The value is given in megabytes before 4.0.3 and
  18157.      in bytes thereafter.
  18158.  
  18159. `myisam_recover_options'
  18160.      The value of the `--myisam-recover' option.  This variable was
  18161.      added in MySQL 3.23.36.
  18162.  
  18163. `myisam_repair_threads'
  18164.      If this value is greater than 1, `MyISAM' table indexes are
  18165.      created in parallel (each index in its own thread) during the
  18166.      `Repair by sorting' process.  The default value is 1.  *Note*:
  18167.      Multi-threaded repair is still _alpha_ quality code.  This
  18168.      variable was added in MySQL 4.0.13.
  18169.  
  18170. `myisam_sort_buffer_size'
  18171.      The buffer that is allocated when sorting `MyISAM' indexes during a
  18172.      `REPAIR TABLE' or when creating indexes with `CREATE INDEX' or
  18173.      `ALTER TABLE'.  This variable was added in MySQL 3.23.16.
  18174.  
  18175. `named_pipe'
  18176.      On Windows, indicates whether the server supports connections over
  18177.      named pipes.  This variable was added in MySQL 3.23.50.
  18178.  
  18179. `net_buffer_length'
  18180.      The communication buffer is reset to this size between queries.
  18181.      This should not normally be changed, but if you have very little
  18182.      memory, you can set it to the expected length of SQL statements
  18183.      sent by clients.  If statements exceed this length, the buffer is
  18184.      automatically enlarged, up to `max_allowed_packet' bytes.
  18185.  
  18186. `net_read_timeout'
  18187.      The number of seconds to wait for more data from a connection
  18188.      before aborting the read.  When the server is reading from the
  18189.      client, `net_read_timeout' is the timeout value controlling when
  18190.      to abort.  When the server is writing to the client,
  18191.      `net_write_timeout' is the timeout value controlling when to abort.
  18192.      See also `slave_net_timeout'.  This variable was added in MySQL
  18193.      3.23.20.
  18194.  
  18195. `net_retry_count'
  18196.      If a read on a communication port is interrupted, retry this many
  18197.      times before giving up.  This value should be set quite high on
  18198.      FreeBSD because internal interrupts are sent to all threads.  This
  18199.      variable was added in MySQL 3.23.7.
  18200.  
  18201. `net_write_timeout'
  18202.      The number of seconds to wait for a block to be written to a
  18203.      connection before aborting the write.  See also `net_read_timeout'.
  18204.      This variable was added in MySQL 3.23.20.
  18205.  
  18206. `open_files_limit'
  18207.      The number of files that the operating system allows `mysqld' to
  18208.      open.  This is the real value allowed by the system and might be
  18209.      different from the value you gave `mysqld' as a startup option.
  18210.      The value is 0 on systems where MySQL can't change the number of
  18211.      open files.  This variable was added in MySQL 3.23.20.
  18212.  
  18213. `optimizer_prune_level'
  18214.      Controls the heuristics applied during query optimization to prune
  18215.      less-promising partial plans from the optimizer search space. A
  18216.      value of 0 disables heuristics so that the optimizer performs an
  18217.      exhaustive search. A value off 1 causes the optimizer to prune
  18218.      plans based on the number of rows retrieved by intermediate plans.
  18219.      This variable was added in MySQL 5.0.1.
  18220.  
  18221. `optimizer_search_depth'
  18222.      The maximum depth of search performed by the query optimizer.
  18223.      Values larger than the number of relations in a query result in
  18224.      better query plans, but take longer to generate an execution plan
  18225.      for a query. Values smaller than the number of relations in a
  18226.      query return an execution plan quicker, but the resulting plan may
  18227.      be far from being optimal. If set to 0, the system automaticallys
  18228.      pick a reasonable value. If set to the maximum number of tables
  18229.      used in a query plus 2, the optimizer switches to the original
  18230.      algorithm used before MySQL 5.0.1 that performs an exhaustive
  18231.      search.  This variable was added in MySQL 5.0.1.
  18232.  
  18233. `pid_file'
  18234.      The pathname of the process ID (PID) file. This variable can be set
  18235.      with the `--pid-file' option.  This variable was added in MySQL
  18236.      3.23.23.
  18237.  
  18238. `port'
  18239.      The port on which the server listens for TCP/IP connections.  This
  18240.      variable can be set with the `--port' option.
  18241.  
  18242. `protocol_version'
  18243.      The version of the client/server protocol used by the MySQL server.
  18244.      This variable was added in MySQL 3.23.18.
  18245.  
  18246. `query_alloc_block_size'
  18247.      The allocation size of memory blocks that are allocated for
  18248.      objects created during query parsing and execution. If you have
  18249.      problems with memory fragmentation, it might help to increase this
  18250.      a bit.  This variable was added in MySQL 4.0.16.
  18251.  
  18252. `query_cache_limit'
  18253.      Don't cache results that are bigger than this. The default value
  18254.      is 1MB.  This variable was added in MySQL 4.0.1.
  18255.  
  18256. `query_cache_min_res_unit'
  18257.      The minimum size for blocks allocated by the query cache.  The
  18258.      default value is 4KB. Tuning information for this variable is
  18259.      given in *Note Query Cache Configuration::.  This variable is
  18260.      present from MySQL 4.1.
  18261.  
  18262. `query_cache_size'
  18263.      The amount of memory allocated for caching query results.  The
  18264.      default value is 0, which disables the query cache.  Note that
  18265.      this amount of memory will be allocated even if `query_cache_type'
  18266.      is set to 0.  This variable was added in MySQL 4.0.1.
  18267.  
  18268. `query_cache_type'
  18269.      Set query cache type. Setting the `GLOBAL' value sets the type for
  18270.      all clients that connect thereafter. Individual clients can set the
  18271.      `SESSION' value to affect their own use of the query cache.
  18272.  
  18273.      *Option*   *Description*
  18274.      `0' or     Don't cache or retrieve results.  Note that
  18275.      `OFF'      this will not deallocate the query cache
  18276.                 buffer. To do that, you should set
  18277.                 `query_cache_size' to 0.
  18278.      `1' or     Cache all query results except for those that
  18279.      `ON'       begin with `SELECT SQL_NO_CACHE'.
  18280.      `2' or     Cache results only for queries that begin with
  18281.      `DEMAND'   `SELECT SQL_CACHE'.
  18282.  
  18283.      This variable was added in MySQL 4.0.3.
  18284.  
  18285. `query_cache_wlock_invalidate'
  18286.      Normally, when one client acquires a `WRITE' lock on a `MyISAM'
  18287.      table, other clients are not blocked from issuing queries for the
  18288.      table if the query results are present in the query cache. Setting
  18289.      this variable to 1 causes acquisition of a `WRITE' lock for a
  18290.      table to invalidate any queries in the query cache that refer to
  18291.      the table. This forces other clients that attempt to access the
  18292.      table to wait while the lock is in effect.  This variable was
  18293.      added in MySQL 4.0.19.
  18294.  
  18295. `query_prealloc_size'
  18296.      The size of the persistent buffer used for query parsing and
  18297.      execution.  This buffer is not freed between queries.  If you are
  18298.      running complex queries, a larger `query_prealloc_size' value
  18299.      might be helpful in improving performance, because it can reduce
  18300.      the need for the server to perform memory allocation during query
  18301.      execution operations.  This variable was added in MySQL 4.0.16.
  18302.  
  18303. `range_alloc_block_size'
  18304.      The size of blocks that are allocated when doing range
  18305.      optimization.  This variable was added in MySQL 4.0.16.
  18306.  
  18307. `read_buffer_size'
  18308.      Each thread that does a sequential scan allocates a buffer of this
  18309.      size for each table it scans. If you do many sequential scans, you
  18310.      might want to increase this value.  This variable was added in
  18311.      MySQL 4.0.3.  Previously, it was named `record_buffer'.
  18312.  
  18313. `read_only'
  18314.      When the variable is set to `ON' for a replication slave server, it
  18315.      causes the slave to allow no updates except from slave threads or
  18316.      from users with the `SUPER' privilege.  This can be useful to
  18317.      ensure that a slave server accepts no updates from clients.  This
  18318.      variable was added in MySQL 4.0.14.
  18319.  
  18320. `read_rnd_buffer_size'
  18321.      When reading rows in sorted order after a sort, the rows are read
  18322.      through this buffer to avoid disk seeks.  Setting the variable to
  18323.      a large value can improve `ORDER BY' performance by a lot.
  18324.      However, this is a buffer allocated for each client, so you should
  18325.      not set the global variable to a large value. Instead, change the
  18326.      session variable only from within those clients that need to run
  18327.      large queries.  This variable was added in MySQL 4.0.3.
  18328.      Previously, it was named `record_rnd_buffer'.
  18329.  
  18330. `safe_show_database'
  18331.      Don't show databases for which the user has no database or table
  18332.      privileges. This can improve security if you're concerned about
  18333.      people being able to see what databases other users have. See also
  18334.      `skip_show_database'.
  18335.  
  18336.      This variable was removed in MySQL 4.0.5. Instead, use the `SHOW
  18337.      DATABASES' privilege to control access by MySQL accounts to
  18338.      database names.
  18339.  
  18340. `secure_auth'
  18341.      If the MySQL server has been started with the `--secure-auth'
  18342.      option, it blocks connections from all accounts that have
  18343.      passwords stored in the old (pre-4.1) format. In that case, the
  18344.      value of this variable is `ON', otherwise it is `OFF'.
  18345.  
  18346.      You should enable this option if you want to prevent all usage of
  18347.      passwords in old format (and hence insecure communication over the
  18348.      network).  This variable was added in MySQL 4.1.1.
  18349.  
  18350.      Server startup will fail with an error if this option is enabled
  18351.      and the privilege tables are in pre-4.1 format.
  18352.  
  18353.      When used as a client-side option, the client refuses to connect
  18354.      to a server if the server requires a password in old format for
  18355.      the client account.
  18356.  
  18357. `server_id'
  18358.      The value of the `--server-id' option. It is used for master and
  18359.      slave replication servers.  This variable was added in MySQL
  18360.      3.23.26.
  18361.  
  18362. `skip_external_locking'
  18363.      This is `OFF' if `mysqld' uses external locking.  This variable
  18364.      was added in MySQL 4.0.3.  Previously, it was named `skip_locking'.
  18365.  
  18366. `skip_networking'
  18367.      This is `ON' if the server allows only local (non-TCP/IP)
  18368.      connections.  On Unix, local connections use a Unix socket file.
  18369.      On Windows, local connections use a named pipe.  On NetWare, only
  18370.      TCP/IP connections are supported, so do not set this variable to
  18371.      `ON'.  This variable was added in MySQL 3.22.23.
  18372.  
  18373. `skip_show_database'
  18374.      This prevents people from using the `SHOW DATABASES' statement if
  18375.      they don't have the `SHOW DATABASES' privilege. This can improve
  18376.      security if you're concerned about people being able to see what
  18377.      databases other users have. See also `safe_show_database'.  This
  18378.      variable was added in MySQL 3.23.4.  As of MySQL 4.0.2, its effect
  18379.      also depends on the `SHOW DATABASES' privilege: If the variable
  18380.      value is `ON', the `SHOW DATABASES' statement is allowed only to
  18381.      users who have the `SHOW DATABASES' privilege, and the statement
  18382.      displays all database names.  If the value is `OFF', `SHOW
  18383.      DATABASES' is allowed to all users, but displays each database
  18384.      name only if the user has the `SHOW DATABASES' privilege or some
  18385.      privilege for the database.
  18386.  
  18387. `slave_net_timeout'
  18388.      The number of seconds to wait for more data from a master/slave
  18389.      connection before aborting the read.  This variable was added in
  18390.      MySQL 3.23.40.
  18391.  
  18392. `slow_launch_time'
  18393.      If creating a thread takes longer than this many seconds, the
  18394.      server increments the `Slow_launch_threads' status variable.  This
  18395.      variable was added in MySQL 3.23.15.
  18396.  
  18397. `socket'
  18398.      On Unix, this is the Unix socket file used for local client
  18399.      connections.  On Windows, this is the name of the named pipe used
  18400.      for local client connections.
  18401.  
  18402. `sort_buffer_size'
  18403.      Each thread that needs to do a sort allocates a buffer of this
  18404.      size. Increase this value for faster `ORDER BY' or `GROUP BY'
  18405.      operations.  *Note Temporary files::.
  18406.  
  18407. `sql_mode'
  18408.      The current server SQL mode.  This variable was added in MySQL
  18409.      3.23.41.  *Note Server SQL mode::.
  18410.  
  18411. `storage_engine'
  18412.      This variable is a synonym for `table_type'.  It was added in
  18413.      MySQL 4.1.2.
  18414.  
  18415. `sync_binlog'
  18416.      If positive, the MySQL server will synchronize its binary log to
  18417.      disk (`fdatasync()') after every `sync_binlog''th write to this
  18418.      binary log. Note that there is one write to the binary log per
  18419.      statement if in autocommit mode, and otherwise one write per
  18420.      transaction. The default value is 0 which does no sync'ing to
  18421.      disk. A value of 1 is the safest choice, because in case of crash
  18422.      you will lose at most one statement/transaction from the binary
  18423.      log; but it is also the slowest choice (unless the disk has a
  18424.      battery-backed cache, which makes sync'ing very fast). This
  18425.      variable was added in MySQL 4.1.3.
  18426.  
  18427. `sync_frm'
  18428.      This was added as a command-line option in MySQL 4.0.18, and is
  18429.      also a settable global variable since MySQL 4.1.3. If set to 1,
  18430.      when a non-temporary table is created it will synchronize its
  18431.      `frm' file to disk (`fdatasync()'); this is slower but safer in
  18432.      case of crash. Default is 1.
  18433.  
  18434. `system_time_zone'
  18435.      The server system time zone. When the server starts, it attempts
  18436.      to detemine the time zone of the host machine. For example, if the
  18437.      `TZ' environment variable is set, its value is used to set
  18438.      `system_time_zone'.  This variable was added in MySQL 4.1.3.
  18439.  
  18440. `table_cache'
  18441.      The number of open tables for all threads. Increasing this value
  18442.      increases the number of file descriptors that `mysqld' requires.
  18443.      You can check whether you need to increase the table cache by
  18444.      checking the `Opened_tables' status variable.  *Note Server status
  18445.      variables::.  If the value of `Opened_tables' is large and you
  18446.      don't do `FLUSH TABLES' a lot (which just forces all tables to be
  18447.      closed and reopened), then you should increase the value of the
  18448.      `table_cache' variable.
  18449.  
  18450.      For more information about the table cache, see *Note Table
  18451.      cache::.
  18452.  
  18453. `table_type'
  18454.      The default table type (storage engine).  To set the table type at
  18455.      server startup, use the `--default-table-type' option.  This
  18456.      variable was added in MySQL 3.23.0.  *Note Server options::.
  18457.  
  18458. `thread_cache_size'
  18459.      How many threads the server should cache for reuse.  When a client
  18460.      disconnects, the client's threads are put in the cache if there
  18461.      aren't already `thread_cache_size' threads there.  Requests for
  18462.      threads are satisfied by reusing threads taken from the cache if
  18463.      possible, and only when the cache is empty is a new thread
  18464.      created.  This variable can be increased to improve performance if
  18465.      you have a lot of new connections. (Normally this doesn't give a
  18466.      notable performance improvement if you have a good thread
  18467.      implementation.)  By examining the difference between the
  18468.      `Connections' and `Threads_created' status variables (*note Server
  18469.      status variables:: for details) you can see how efficient the
  18470.      thread cache is.  This variable was added in MySQL 3.23.16.
  18471.  
  18472. `thread_concurrency'
  18473.      On Solaris, `mysqld' calls `thr_setconcurrency()' with this value.
  18474.      This function allows applications to give the threads system a
  18475.      hint about the desired number of threads that should be run at the
  18476.      same time.  This variable was added in MySQL 3.23.7.
  18477.  
  18478. `thread_stack'
  18479.      The stack size for each thread.  Many of the limits detected by the
  18480.      `crash-me' test are dependent on this value. The default is large
  18481.      enough for normal operation.  *Note MySQL Benchmarks::.
  18482.  
  18483. `time_zone'
  18484.      The current time zone. The initial value of this is `'SYSTEM''
  18485.      (use the value of `system_time_zone'), but can be specified
  18486.      explicitly at server startup time with the `--default-time-zone'
  18487.      option.  This variable was added in MySQL 4.1.3.
  18488.  
  18489. `timezone'
  18490.      The time zone for the server.  This is set from the `TZ'
  18491.      environment variable when `mysqld' is started.  The time zone also
  18492.      can be set by giving a `--timezone' argument to `mysqld_safe'.
  18493.      This variable was added in MySQL 3.23.15. As of MySQL 4.1.3, it is
  18494.      obsolete and has been replaced by the `system_time_zone' variable.
  18495.      *Note Timezone problems::.
  18496.  
  18497. `tmp_table_size'
  18498.      If an in-memory temporary table exceeds this size, MySQL
  18499.      automatically converts it to an on-disk `MyISAM' table.  Increase
  18500.      the value of `tmp_table_size' if you do many advanced `GROUP BY'
  18501.      queries and you have lots of memory.
  18502.  
  18503. `tmpdir'
  18504.      The directory used for temporary files and temporary tables.
  18505.      Starting from MySQL 4.1, this variable can be set to a list of
  18506.      several paths that are used in round-robin fashion. Paths should
  18507.      be separated by colon characters (`:') on Unix and semicolon
  18508.      characters (`;') on Windows, NetWare, and OS/2.
  18509.  
  18510.      This feature can be used to spread the load between several
  18511.      physical disks.  If the MySQL server is acting as a replication
  18512.      slave, you should not set `tmpdir' to point to a directory on a
  18513.      memory-based filesystem or to a directory that is cleared when the
  18514.      server host restarts.  A replication slave needs some of its
  18515.      temporary files to survive a machine restart so that it can
  18516.      replicate temporary tables or `LOAD DATA INFILE' operations. If
  18517.      files in the temporary file directory are lost when the server
  18518.      restarts, replication will fail.
  18519.  
  18520.      This variable was added in MySQL 3.22.4.
  18521.  
  18522. `transaction_alloc_block_size'
  18523.      The allocation size of memory blocks that are allocated for
  18524.      storing queries that are part of a transaction to be stored in the
  18525.      binary log when doing a commit.  This variable was added in MySQL
  18526.      4.0.16.
  18527.  
  18528. `transaction_prealloc_size'
  18529.      The size of the persistent buffer for `transaction_alloc_blocks'
  18530.      that is not freed between queries. By making this big enough to
  18531.      fit all queries in a common transaction, you can avoid a lot of
  18532.      `malloc()' calls.  This variable was added in MySQL 4.0.16.
  18533.  
  18534. `tx_isolation'
  18535.      The default transaction isolation level.  This variable was added
  18536.      in MySQL 4.0.3.
  18537.  
  18538. `version'
  18539.      The version number for the server.
  18540.  
  18541. `wait_timeout'
  18542.      The number of seconds the server waits for activity on a
  18543.      non-interactive connection before closing it.
  18544.  
  18545.      On thread startup, the session `wait_timeout' value is initialized
  18546.      from the global `wait_timeout' value or from the global
  18547.      `interactive_timeout' value, depending on the type of client (as
  18548.      defined by the `CLIENT_INTERACTIVE' connect option to
  18549.      `mysql_real_connect()'). See also `interactive_timeout'.
  18550.  
  18551. Dynamic System Variables
  18552. ........................
  18553.  
  18554. Beginning with MySQL 4.0.3, many server system variables are dynamic
  18555. and can be set at runtime using `SET GLOBAL' or `SET SESSION'. You can
  18556. also select their values using `SELECT'.  *Note System Variables::.
  18557.  
  18558. The following table shows the full list of all dynamic system variables.
  18559. The last column indicates for each variable whether `GLOBAL' or
  18560. `SESSION' (or both) apply.
  18561.  
  18562. *Variable Name*                  *Value Type*       *Type*
  18563. `autocommit'                     boolean            `SESSION'
  18564. `big_tables'                     boolean            `SESSION'
  18565. `binlog_cache_size'              numeric            `GLOBAL'
  18566. `bulk_insert_buffer_size'        numeric            `GLOBAL' | `SESSION'
  18567. `character_set_client'           string             `GLOBAL' | `SESSION'
  18568. `character_set_connection'       string             `GLOBAL' | `SESSION'
  18569. `character_set_results'          string             `GLOBAL' | `SESSION'
  18570. `character_set_server'           string             `GLOBAL' | `SESSION'
  18571. `collation_connection'           string             `GLOBAL' | `SESSION'
  18572. `collation_server'               string             `GLOBAL' | `SESSION'
  18573. `concurrent_insert'              boolean            `GLOBAL'
  18574. `connect_timeout'                numeric            `GLOBAL'
  18575. `convert_character_set'          string             `GLOBAL' | `SESSION'
  18576. `default_week_format'            numeric            `GLOBAL' | `SESSION'
  18577. `delay_key_write'                `OFF' | `ON' |     `GLOBAL'
  18578.                                  `ALL'              
  18579. `delayed_insert_limit'           numeric            `GLOBAL'
  18580. `delayed_insert_timeout'         numeric            `GLOBAL'
  18581. `delayed_queue_size'             numeric            `GLOBAL'
  18582. `error_count'                    numeric            `SESSION'
  18583. `expire_logs_days'               numeric            `GLOBAL'
  18584. `flush'                          boolean            `GLOBAL'
  18585. `flush_time'                     numeric            `GLOBAL'
  18586. `foreign_key_checks'             boolean            `SESSION'
  18587. `ft_boolean_syntax'              numeric            `GLOBAL'
  18588. `group_concat_max_len'           numeric            `GLOBAL' | `SESSION'
  18589. `identity'                       numeric            `SESSION'
  18590. `insert_id'                      boolean            `SESSION'
  18591. `interactive_timeout'            numeric            `GLOBAL' | `SESSION'
  18592. `join_buffer_size'               numeric            `GLOBAL' | `SESSION'
  18593. `key_buffer_size'                numeric            `GLOBAL'
  18594. `last_insert_id'                 numeric            `SESSION'
  18595. `local_infile'                   boolean            `GLOBAL'
  18596. `log_warnings'                   boolean            `GLOBAL'
  18597. `long_query_time'                numeric            `GLOBAL' | `SESSION'
  18598. `low_priority_updates'           boolean            `GLOBAL' | `SESSION'
  18599. `max_allowed_packet'             numeric            `GLOBAL' | `SESSION'
  18600. `max_binlog_cache_size'          numeric            `GLOBAL'
  18601. `max_binlog_size'                numeric            `GLOBAL'
  18602. `max_connect_errors'             numeric            `GLOBAL'
  18603. `max_connections'                numeric            `GLOBAL'
  18604. `max_delayed_threads'            numeric            `GLOBAL'
  18605. `max_error_count'                numeric            `GLOBAL' | `SESSION'
  18606. `max_heap_table_size'            numeric            `GLOBAL' | `SESSION'
  18607. `max_insert_delayed_threads'     numeric            `GLOBAL'
  18608. `max_join_size'                  numeric            `GLOBAL' | `SESSION'
  18609. `max_relay_log_size'             numeric            `GLOBAL'
  18610. `max_seeks_for_key'              numeric            `GLOBAL' | `SESSION'
  18611. `max_sort_length'                numeric            `GLOBAL' | `SESSION'
  18612. `max_tmp_tables'                 numeric            `GLOBAL'
  18613. `max_user_connections'           numeric            `GLOBAL'
  18614. `max_write_lock_count'           numeric            `GLOBAL'
  18615. `myisam_max_extra_sort_file_size'numeric            `GLOBAL' | `SESSION'
  18616. `myisam_max_sort_file_size'      numeric            `GLOBAL' | `SESSION'
  18617. `myisam_repair_threads'          numeric            `GLOBAL' | `SESSION'
  18618. `myisam_sort_buffer_size'        numeric            `GLOBAL' | `SESSION'
  18619. `net_buffer_length'              numeric            `GLOBAL' | `SESSION'
  18620. `net_read_timeout'               numeric            `GLOBAL' | `SESSION'
  18621. `net_retry_count'                numeric            `GLOBAL' | `SESSION'
  18622. `net_write_timeout'              numeric            `GLOBAL' | `SESSION'
  18623. `optimizer_prune_level'          numeric            `GLOBAL' | `SESSION'
  18624. `optimizer_search_depth'         numeric            `GLOBAL' | `SESSION'
  18625. `query_alloc_block_size'         numeric            `GLOBAL' | `SESSION'
  18626. `query_cache_limit'              numeric            `GLOBAL'
  18627. `query_cache_size'               numeric            `GLOBAL'
  18628. `query_cache_type'               enumeration        `GLOBAL' | `SESSION'
  18629. `query_cache_wlock_invalidate'   boolean            `GLOBAL' | `SESSION'
  18630. `query_prealloc_size'            numeric            `GLOBAL' | `SESSION'
  18631. `range_alloc_block_size'         numeric            `GLOBAL' | `SESSION'
  18632. `read_buffer_size'               numeric            `GLOBAL' | `SESSION'
  18633. `read_only'                      numeric            `GLOBAL'
  18634. `read_rnd_buffer_size'           numeric            `GLOBAL' | `SESSION'
  18635. `rpl_recovery_rank'              numeric            `GLOBAL'
  18636. `safe_show_database'             boolean            `GLOBAL'
  18637. `server_id'                      numeric            `GLOBAL'
  18638. `slave_compressed_protocol'      boolean            `GLOBAL'
  18639. `slave_net_timeout'              numeric            `GLOBAL'
  18640. `slow_launch_time'               numeric            `GLOBAL'
  18641. `sort_buffer_size'               numeric            `GLOBAL' | `SESSION'
  18642. `sql_auto_is_null'               boolean            `SESSION'
  18643. `sql_big_selects'                boolean            `SESSION'
  18644. `sql_big_tables'                 boolean            `SESSION'
  18645. `sql_buffer_result'              boolean            `SESSION'
  18646. `sql_log_bin'                    boolean            `SESSION'
  18647. `sql_log_off'                    boolean            `SESSION'
  18648. `sql_log_update'                 boolean            `SESSION'
  18649. `sql_low_priority_updates'       boolean            `GLOBAL' | `SESSION'
  18650. `sql_max_join_size'              numeric            `GLOBAL' | `SESSION'
  18651. `sql_quote_show_create'          boolean            `SESSION'
  18652. `sql_safe_updates'               boolean            `SESSION'
  18653. `sql_select_limit'               numeric            `SESSION'
  18654. `sql_slave_skip_counter'         numeric            `GLOBAL'
  18655. `sql_warnings'                   boolean            `SESSION'
  18656. `storage_engine'                 enumeration        `GLOBAL' | `SESSION'
  18657. `table_cache'                    numeric            `GLOBAL'
  18658. `table_type'                     enumeration        `GLOBAL' | `SESSION'
  18659. `thread_cache_size'              numeric            `GLOBAL'
  18660. `time_zone'                      string             `GLOBAL' | `SESSION'
  18661. `timestamp'                      boolean            `SESSION'
  18662. `tmp_table_size'                 enumeration        `GLOBAL' | `SESSION'
  18663. `transaction_alloc_block_size'   numeric            `GLOBAL' | `SESSION'
  18664. `transaction_prealloc_size'      numeric            `GLOBAL' | `SESSION'
  18665. `tx_isolation'                   enumeration        `GLOBAL' | `SESSION'
  18666. `unique_checks'                  boolean            `SESSION'
  18667. `wait_timeout'                   numeric            `GLOBAL' | `SESSION'
  18668. `warning_count'                  numeric            `SESSION'
  18669.  
  18670. Variables that are marked as "string" take a string value.  Variables
  18671. that are marked as "numeric" take a numeric value. Variables that are
  18672. marked as "boolean" can be set to 0, 1, `ON' or `OFF'. Variables that
  18673. are marked as "enumeration" normally should be set to one of the
  18674. available values for the variable, but can also be set to the number
  18675. that corresponds to the desired enumeration value.  For
  18676. enumeration-valued system variables, the first enumeration value
  18677. corresponds to 0. This differs from `ENUM' columns, for which the first
  18678. enumeration value corresponds to 1.
  18679.  
  18680. Server Status Variables
  18681. -----------------------
  18682.  
  18683. The server maintains many status variables that provide information
  18684. about its operations. You can view these variables and their values by
  18685. using the `SHOW STATUS' statement:
  18686.  
  18687.      mysql> SHOW STATUS;
  18688.      +--------------------------+------------+
  18689.      | Variable_name            | Value      |
  18690.      +--------------------------+------------+
  18691.      | Aborted_clients          | 0          |
  18692.      | Aborted_connects         | 0          |
  18693.      | Bytes_received           | 155372598  |
  18694.      | Bytes_sent               | 1176560426 |
  18695.      | Connections              | 30023      |
  18696.      | Created_tmp_disk_tables  | 0          |
  18697.      | Created_tmp_files        | 60         |
  18698.      | Created_tmp_tables       | 8340       |
  18699.      | Delayed_errors           | 0          |
  18700.      | Delayed_insert_threads   | 0          |
  18701.      | Delayed_writes           | 0          |
  18702.      | Flush_commands           | 1          |
  18703.      | Handler_delete           | 462604     |
  18704.      | Handler_read_first       | 105881     |
  18705.      | Handler_read_key         | 27820558   |
  18706.      | Handler_read_next        | 390681754  |
  18707.      | Handler_read_prev        | 6022500    |
  18708.      | Handler_read_rnd         | 30546748   |
  18709.      | Handler_read_rnd_next    | 246216530  |
  18710.      | Handler_update           | 16945404   |
  18711.      | Handler_write            | 60356676   |
  18712.      | Key_blocks_used          | 14955      |
  18713.      | Key_read_requests        | 96854827   |
  18714.      | Key_reads                | 162040     |
  18715.      | Key_write_requests       | 7589728    |
  18716.      | Key_writes               | 3813196    |
  18717.      | Max_used_connections     | 0          |
  18718.      | Not_flushed_delayed_rows | 0          |
  18719.      | Not_flushed_key_blocks   | 0          |
  18720.      | Open_files               | 2          |
  18721.      | Open_streams             | 0          |
  18722.      | Open_tables              | 1          |
  18723.      | Opened_tables            | 44600      |
  18724.      | Qcache_free_blocks       | 36         |
  18725.      | Qcache_free_memory       | 138488     |
  18726.      | Qcache_hits              | 79570      |
  18727.      | Qcache_inserts           | 27087      |
  18728.      | Qcache_lowmem_prunes     | 3114       |
  18729.      | Qcache_not_cached        | 22989      |
  18730.      | Qcache_queries_in_cache  | 415        |
  18731.      | Qcache_total_blocks      | 912        |
  18732.      | Questions                | 2026873    |
  18733.      | Select_full_join         | 0          |
  18734.      | Select_full_range_join   | 0          |
  18735.      | Select_range             | 99646      |
  18736.      | Select_range_check       | 0          |
  18737.      | Select_scan              | 30802      |
  18738.      | Slave_open_temp_tables   | 0          |
  18739.      | Slave_running            | OFF        |
  18740.      | Slow_launch_threads      | 0          |
  18741.      | Slow_queries             | 0          |
  18742.      | Sort_merge_passes        | 30         |
  18743.      | Sort_range               | 500        |
  18744.      | Sort_rows                | 30296250   |
  18745.      | Sort_scan                | 4650       |
  18746.      | Table_locks_immediate    | 1920382    |
  18747.      | Table_locks_waited       | 0          |
  18748.      | Threads_cached           | 0          |
  18749.      | Threads_connected        | 1          |
  18750.      | Threads_created          | 30022      |
  18751.      | Threads_running          | 1          |
  18752.      | Uptime                   | 80380      |
  18753.      +--------------------------+------------+
  18754.  
  18755. Many status variables are reset to 0 by the `FLUSH STATUS' statement.
  18756.  
  18757. The status variables have the following meanings.  The `Com_XXX'
  18758. statement counter variables were added beginning with MySQL 3.23.47. The
  18759. `Qcache_XXX' query cache variables were added beginning with MySQL
  18760. 4.0.1. Otherwise, variables with no version indicated have been present
  18761. since at least MySQL 3.22.
  18762.  
  18763. `Aborted_clients'
  18764.      The number of connections that were aborted because the client
  18765.      died without closing the connection properly.  *Note Communication
  18766.      errors::.
  18767.  
  18768. `Aborted_connects'
  18769.      The number of tries to connect to the MySQL server that failed.
  18770.      *Note Communication errors::.
  18771.  
  18772. `Binlog_cache_use'
  18773.      The number of transactions that used the temporary binary log
  18774.      cache.  This variable was added in MySQL 4.1.2.
  18775.  
  18776. `Binlog_cache_disk_use'
  18777.      The number of transactions that used the temporary binary log
  18778.      cache but that exceeded the value of `binlog_cache_size' and used
  18779.      a temporary file to store statements from the transaction.  This
  18780.      variable was added in MySQL 4.1.2.
  18781.  
  18782. `Bytes_received'
  18783.      The number of bytes received from all clients.  This variable was
  18784.      added in MySQL 3.23.7.
  18785.  
  18786. `Bytes_sent'
  18787.      The number of bytes sent to all clients.  This variable was added
  18788.      in MySQL 3.23.7.
  18789.  
  18790. `Com_XXX'
  18791.      The number of times each XXX statement has been executed.  There
  18792.      is one status variable for each type of statement. For example,
  18793.      `Com_delete' and `Com_insert' count `DELETE' and `INSERT'
  18794.      statements.
  18795.  
  18796. `Connections'
  18797.      The number of connection attempts (successful or not) to the MySQL
  18798.      server.
  18799.  
  18800. `Created_tmp_disk_tables'
  18801.      The number of temporary tables on disk created automatically by
  18802.      the server while executing statements.  This variable was added in
  18803.      MySQL 3.23.24.
  18804.  
  18805. `Created_tmp_files'
  18806.      How many temporary files `mysqld' has created.  This variable was
  18807.      added in MySQL 3.23.28.
  18808.  
  18809. `Created_tmp_tables'
  18810.      The number of in-memory temporary tables created automatically by
  18811.      the server while executing statements.  If
  18812.      `Created_tmp_disk_tables' is big, you may want to increase the
  18813.      `tmp_table_size' value to cause temporary tables to be memory-based
  18814.      instead of disk-based.
  18815.  
  18816. `Delayed_errors'
  18817.      The number of rows written with `INSERT DELAYED' for which some
  18818.      error occurred (probably `duplicate key').
  18819.  
  18820. `Delayed_insert_threads'
  18821.      The number of `INSERT DELAYED' handler threads in use.
  18822.  
  18823. `Delayed_writes'
  18824.      The number of `INSERT DELAYED' rows written.
  18825.  
  18826. `Flush_commands'
  18827.      The number of executed `FLUSH' statements.
  18828.  
  18829. `Handler_commit'
  18830.      The number of internal `COMMIT' statements.  This variable was
  18831.      added in MySQL 4.0.2.
  18832.  
  18833. `Handler_delete'
  18834.      The number of times a row was deleted from a table.
  18835.  
  18836. `Handler_read_first'
  18837.      The number of times the first entry was read from an index.  If
  18838.      this is high, it suggests that the server is doing a lot of full
  18839.      index scans; for example, `SELECT col1 FROM foo', assuming that
  18840.      `col1' is indexed.
  18841.  
  18842. `Handler_read_key'
  18843.      The number of requests to read a row based on a key. If this is
  18844.      high, it is a good indication that your queries and tables are
  18845.      properly indexed.
  18846.  
  18847. `Handler_read_next'
  18848.      The number of requests to read the next row in key order. This
  18849.      will be incremented if you are querying an index column with a
  18850.      range constraint or if you are doing an index scan.
  18851.  
  18852. `Handler_read_prev'
  18853.      The number of requests to read the previous row in key order.
  18854.      This read method is mainly used to optimize `ORDER BY ... DESC'.
  18855.      This variable was added in MySQL 3.23.6.
  18856.  
  18857. `Handler_read_rnd'
  18858.      The number of requests to read a row based on a fixed position.
  18859.      This will be high if you are doing a lot of queries that require
  18860.      sorting of the result.  You probably have a lot of queries that
  18861.      require MySQL to scan whole tables or you have joins that don't
  18862.      use keys properly.
  18863.  
  18864. `Handler_read_rnd_next'
  18865.      The number of requests to read the next row in the data file.
  18866.      This will be high if you are doing a lot of table scans. Generally
  18867.      this suggests that your tables are not properly indexed or that
  18868.      your queries are not written to take advantage of the indexes you
  18869.      have.
  18870.  
  18871. `Handler_rollback'
  18872.      The number of internal `ROLLBACK' statements.  This variable was
  18873.      added in MySQL 4.0.2.
  18874.  
  18875. `Handler_update'
  18876.      The number of requests to update a row in a table.
  18877.  
  18878. `Handler_write'
  18879.      The number of requests to insert a row in a table.
  18880.  
  18881. `Key_blocks_used'
  18882.      The number of used blocks in the key cache.  You can use this
  18883.      value to determine how much of the key cache is in use; see the
  18884.      discussion of `key_buffer_size' in *Note Server system variables::.
  18885.  
  18886. `Key_read_requests'
  18887.      The number of requests to read a key block from the cache.
  18888.  
  18889. `Key_reads'
  18890.      The number of physical reads of a key block from disk.  If
  18891.      `Key_reads' is big, then your `key_buffer_size' value is probably
  18892.      too small.  The cache miss rate can be calculated as
  18893.      `Key_reads'/`Key_read_requests'.
  18894.  
  18895. `Key_write_requests'
  18896.      The number of requests to write a key block to the cache.
  18897.  
  18898. `Key_writes'
  18899.      The number of physical writes of a key block to disk.
  18900.  
  18901. `Last_query_cost'
  18902.      The total cost of the last compiled query as computed by the query
  18903.      optimizer. Useful for comparing the cost of different query plans
  18904.      for the same query. The default value of -1 means that no query
  18905.      has been compiled yet. This variable was added in MySQL 5.0.1.
  18906.  
  18907. `Max_used_connections'
  18908.      The maximum number of connections that have been in use
  18909.      simultaneously since the server started.
  18910.  
  18911. `Not_flushed_delayed_rows'
  18912.      The number of rows waiting to be written in `INSERT DELAY' queues.
  18913.  
  18914. `Not_flushed_key_blocks'
  18915.      The number of key blocks in the key cache that have changed but
  18916.      haven't yet been flushed to disk.
  18917.  
  18918. `Open_files'
  18919.      The number of files that are open.
  18920.  
  18921. `Open_streams'
  18922.      The number of streams that are open (used mainly for logging).
  18923.  
  18924. `Open_tables'
  18925.      The number of tables that are open.
  18926.  
  18927. `Opened_tables'
  18928.      The number of tables that have been opened.  If `Opened_tables' is
  18929.      big, your `table_cache' value is probably too small.
  18930.  
  18931. `Qcache_free_blocks'
  18932.      The number of free memory blocks in query cache.
  18933.  
  18934. `Qcache_free_memory'
  18935.      The amount of free memory for query cache.
  18936.  
  18937. `Qcache_hits'
  18938.      The number of cache hits.
  18939.  
  18940. `Qcache_inserts'
  18941.      The number of queries added to the cache.
  18942.  
  18943. `Qcache_lowmem_prunes'
  18944.      The number of queries that were deleted from the cache because of
  18945.      low memory.
  18946.  
  18947. `Qcache_not_cached'
  18948.      The number of non-cached queries (not cachable, or due to
  18949.      `query_cache_type').
  18950.  
  18951. `Qcache_queries_in_cache'
  18952.      The number of queries registered in the cache.
  18953.  
  18954. `Qcache_total_blocks'
  18955.      The total number of blocks in the query cache.
  18956.  
  18957. `Questions'
  18958.      The number of queries that have been sent to the server.
  18959.  
  18960. `Rpl_status'
  18961.      The status of failsafe replication (not yet implemented).
  18962.  
  18963. `Select_full_join'
  18964.      The number of joins that do not use indexes.  If this value is not
  18965.      0, you should carefully check the indexes of your tables.  This
  18966.      variable was added in MySQL 3.23.25.
  18967.  
  18968. `Select_full_range_join'
  18969.      The number of joins that used a range search on a reference table.
  18970.      This variable was added in MySQL 3.23.25.
  18971.  
  18972. `Select_range'
  18973.      The number of joins that used ranges on the first table. (It's
  18974.      normally not critical even if this is big.)  This variable was
  18975.      added in MySQL 3.23.25.
  18976.  
  18977. `Select_range_check'
  18978.      The number of joins without keys that check for key usage after
  18979.      each row.  (If this is not 0, you should carefully check the
  18980.      indexes of your tables.)  This variable was added in MySQL 3.23.25.
  18981.  
  18982. `Select_scan'
  18983.      The number of joins that did a full scan of the first table.  This
  18984.      variable was added in MySQL 3.23.25.
  18985.  
  18986. `Slave_open_temp_tables'
  18987.      The number of temporary tables currently open by the slave SQL
  18988.      thread.  This variable was added in MySQL 3.23.29.
  18989.  
  18990. `Slave_running'
  18991.      This is `ON' if this server is a slave that is connected to a
  18992.      master.  This variable was added in MySQL 3.23.16.
  18993.  
  18994. `Slow_launch_threads'
  18995.      The number of threads that have taken more than `slow_launch_time'
  18996.      seconds to create.  This variable was added in MySQL 3.23.15.
  18997.  
  18998. `Slow_queries'
  18999.      The number of queries that have taken more than `long_query_time'
  19000.      seconds. *Note Slow query log::.
  19001.  
  19002. `Sort_merge_passes'
  19003.      The number of merge passes the sort algorithm has had to do. If
  19004.      this value is large, you should consider increasing the value of
  19005.      the `sort_buffer_size' system variable.  This variable was added
  19006.      in MySQL 3.23.28.
  19007.  
  19008. `Sort_range'
  19009.      The number of sorts that were done with ranges.  This variable was
  19010.      added in MySQL 3.23.25.
  19011.  
  19012. `Sort_rows'
  19013.      The number of sorted rows.  This variable was added in MySQL
  19014.      3.23.25.
  19015.  
  19016. `Sort_scan'
  19017.      The number of sorts that were done by scanning the table.  This
  19018.      variable was added in MySQL 3.23.25.
  19019.  
  19020. `Ssl_XXX'
  19021.      Variables used for SSL connections.  These variables were added in
  19022.      MySQL 4.0.0.
  19023.  
  19024. `Table_locks_immediate'
  19025.      The number of times that a table lock was acquired immediately.
  19026.      This variable was added as of MySQL 3.23.33.
  19027.  
  19028. `Table_locks_waited'
  19029.      The number of times that a table lock could not be acquired
  19030.      immediately and a wait was needed. If this is high, and you have
  19031.      performance problems, you should first optimize your queries, and
  19032.      then either split your table or tables or use replication.  This
  19033.      variable was added as of MySQL 3.23.33.
  19034.  
  19035. `Threads_cached'
  19036.      The number of threads in the thread cache.  This variable was
  19037.      added in MySQL 3.23.17.
  19038.  
  19039. `Threads_connected'
  19040.      The number of currently open connections.
  19041.  
  19042. `Threads_created'
  19043.      The number of threads created to handle connections.  If
  19044.      `Threads_created' is big, you may want to increase the
  19045.      `thread_cache_size' value.  The cache hit rate can be calculated
  19046.      as `Threads_created'/`Connections'.  This variable was added in
  19047.      MySQL 3.23.31.
  19048.  
  19049. `Threads_running'
  19050.      The number of threads that are not sleeping.
  19051.  
  19052. `Uptime'
  19053.      The number of seconds the server has been up.
  19054.  
  19055. General Security Issues
  19056. =======================
  19057.  
  19058. This section describes some general security issues to be aware of and
  19059. what you can do to make your MySQL installation more secure against
  19060. attack or misuse. For information specifically about the access control
  19061. system that MySQL uses for setting up user accounts and checking
  19062. database access, see *Note Privilege system::.
  19063.  
  19064. General Security Guidelines
  19065. ---------------------------
  19066.  
  19067. Anyone using MySQL on a computer connected to the Internet should read
  19068. this section to avoid the most common security mistakes.
  19069.  
  19070. In discussing security, we emphasize the necessity of fully protecting
  19071. the entire server host (not just the MySQL server) against all types of
  19072. applicable attacks: eavesdropping, altering, playback, and denial of
  19073. service. We do not cover all aspects of availability and fault tolerance
  19074. here.
  19075.  
  19076. MySQL uses security based on Access Control Lists (ACLs) for all
  19077. connections, queries, and other operations that users can attempt to
  19078. perform. There is also some support for SSL-encrypted connections
  19079. between MySQL clients and servers. Many of the concepts discussed here
  19080. are not specific to MySQL at all; the same general ideas apply to
  19081. almost all applications.
  19082.  
  19083. When running MySQL, follow these guidelines whenever possible:
  19084.  
  19085.    * *Do not ever give anyone (except MySQL `root' accounts) access to
  19086.      the `user' table in the `mysql' database!*  This is critical.
  19087.      *The encrypted password is the real password in MySQL.* Anyone who
  19088.      knows the password that is listed in the `user' table and has
  19089.      access to the host listed for the account *can easily log in as
  19090.      that user*.
  19091.  
  19092.    * Learn the MySQL access privilege system. The `GRANT' and `REVOKE'
  19093.      statements are used for controlling access to MySQL. Do not grant
  19094.      any more privileges than necessary. Never grant privileges to all
  19095.      hosts.
  19096.  
  19097.      Checklist:
  19098.         - Try `mysql -u root'. If you are able to connect successfully
  19099.           to the server without being asked for a password, you have
  19100.           problems. Anyone can connect to your MySQL server as the MySQL
  19101.           `root' user with full privileges!  Review the MySQL
  19102.           installation instructions, paying particular attention to the
  19103.           information about setting a `root' password.  *Note Default
  19104.           privileges::.
  19105.  
  19106.         - Use the `SHOW GRANTS' statement and check to see who has
  19107.           access to what.  Then use the `REVOKE' statement to remove
  19108.           those privileges that are not necessary.
  19109.  
  19110.    * Do not store any plain-text passwords in your database. If your
  19111.      computer becomes compromised, the intruder can take the full list
  19112.      of passwords and use them. Instead, use `MD5()', `SHA1()', or some
  19113.      other one-way hashing function.
  19114.  
  19115.    * Do not choose passwords from dictionaries. There are special
  19116.      programs to break them. Even passwords like "xfish98" are very
  19117.      bad.  Much better is "duag98" which contains the same word "fish"
  19118.      but typed one key to the left on a standard QWERTY keyboard.
  19119.      Another method is to use "Mhall" which is taken from the first
  19120.      characters of each word in the sentence "Mary had a little lamb."
  19121.      This is easy to remember and type, but difficult to guess for
  19122.      someone who does not know it.
  19123.  
  19124.    * Invest in a firewall. This protects you from at least 50% of all
  19125.      types of exploits in any software. Put MySQL behind the firewall
  19126.      or in a demilitarized zone (DMZ).
  19127.  
  19128.      Checklist:
  19129.         - Try to scan your ports from the Internet using a tool such as
  19130.           `nmap'. MySQL uses port 3306 by default. This port should not
  19131.           be accessible from untrusted hosts. Another simple way to
  19132.           check whether or not your MySQL port is open is to try the
  19133.           following command from some remote machine, where
  19134.           `server_host' is the host on which your MySQL server runs:
  19135.  
  19136.                shell> telnet server_host 3306
  19137.  
  19138.           If you get a connection and some garbage characters, the port
  19139.           is open, and should be closed on your firewall or router,
  19140.           unless you really have a good reason to keep it open. If
  19141.           `telnet' just hangs or the connection is refused, everything
  19142.           is OK; the port is blocked.
  19143.  
  19144.    * Do not trust any data entered by users of your applications. They
  19145.      can try to trick your code by entering special or escaped
  19146.      character sequences in Web forms, URLs, or whatever application
  19147.      you have built. Be sure that your application remains secure if a
  19148.      user enters something like "`; DROP DATABASE mysql;'". This is an
  19149.      extreme example, but large security leaks and data loss might
  19150.      occur as a result of hackers using similar techniques, if you do
  19151.      not prepare for them.
  19152.  
  19153.      A common mistake is to protect only string data values.  Remember
  19154.      to check numeric data as well.  If an application generates a
  19155.      query such as `SELECT * FROM table WHERE ID=234' when a user
  19156.      enters the value `234', the user can enter the value `234 OR 1=1'
  19157.      to cause the application to generate the query `SELECT * FROM
  19158.      table WHERE ID=234 OR 1=1'.  As a result, the server retrieves
  19159.      every record in the table.  This exposes every record and causes
  19160.      excessive server load.  The simplest way to protect from this type
  19161.      of attack is to use apostrophes around the numeric constants:
  19162.      `SELECT * FROM table WHERE ID='234''. If the user enters extra
  19163.      information, it all becomes part of the string. In numeric context,
  19164.      MySQL automatically converts this string to a number and strips
  19165.      any trailing non-numeric characters from it.
  19166.  
  19167.      Sometimes people think that if a database contains only publicly
  19168.      available data, it need not be protected. This is incorrect.  Even
  19169.      if it is allowable to display any record in the database, you
  19170.      should still protect against denial of service attacks (for
  19171.      example, those that are based on the technique in the preceding
  19172.      paragraph that causes the server to waste resources). Otherwise,
  19173.      your server becomes unresponsive to legitimate users.
  19174.  
  19175.      Checklist:
  19176.         - Try to enter `'' and `"' in all your Web forms. If you get
  19177.           any kind of MySQL error, investigate the problem right away.
  19178.  
  19179.         - Try to modify any dynamic URLs by adding `%22' (`"'), `%23'
  19180.           (`#'), and `%27' (`'') in the URL.
  19181.  
  19182.         - Try to modify data types in dynamic URLs from numeric ones to
  19183.           character ones containing characters from previous examples.
  19184.           Your application should be safe against this and similar
  19185.           attacks.
  19186.  
  19187.         - Try to enter characters, spaces, and special symbols rather
  19188.           than numbers in numeric fields. Your application should
  19189.           remove them before passing them to MySQL or else generate an
  19190.           error. Passing unchecked values to MySQL is very dangerous!
  19191.  
  19192.         - Check data sizes before passing them to MySQL.
  19193.  
  19194.         - Consider having your application connect to the database
  19195.           using a different username than the one you use for
  19196.           administrative purposes. Do not give your applications any
  19197.           access privileges they do not need.
  19198.  
  19199.    * Many application programming interfaces provide a means of
  19200.      escaping special characters in data values. Properly used, this
  19201.      prevents application users from entering values that cause the
  19202.      application to generate statements that have a different effect
  19203.      than you intend:
  19204.         - MySQL C API: Use the `mysql_real_escape_string()' API call.
  19205.  
  19206.         - MySQL++: Use the `escape' and `quote' modifiers for query
  19207.           streams.
  19208.  
  19209.         - PHP: Use the `mysql_escape_string()' function, which is based
  19210.           on the function of the same name in the MySQL C API.  Prior
  19211.           to PHP 4.0.3, use  `addslashes()' instead.
  19212.  
  19213.         - Perl DBI: Use the `quote()' method or use placeholders.
  19214.  
  19215.         - Java JDBC: Use a `PreparedStatement' object and placeholders.
  19216.  
  19217.      Other programming interfaces might have similar capabilities.
  19218.  
  19219.    * Do not transmit plain (unencrypted) data over the Internet. This
  19220.      information is accessible to everyone who has the time and ability
  19221.      to intercept it and use it for their own purposes. Instead, use an
  19222.      encrypted protocol such as SSL or SSH. MySQL supports internal SSL
  19223.      connections as of Version 4.0.0.  SSH port-forwarding can be used
  19224.      to create an encrypted (and compressed) tunnel for the
  19225.      communication.
  19226.  
  19227.    * Learn to use the `tcpdump' and `strings' utilities. For most cases,
  19228.      you can check whether MySQL data streams are unencrypted by
  19229.      issuing a command like the following:
  19230.  
  19231.           shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
  19232.  
  19233.      (This works under Linux and should work with small modifications
  19234.      under other systems.)  Warning: If you do not see plaintext data,
  19235.      this doesn't always mean that the information actually is
  19236.      encrypted. If you need high security, you should consult with a
  19237.      security expert.
  19238.  
  19239. Making MySQL Secure Against Attackers
  19240. -------------------------------------
  19241.  
  19242. When you connect to a MySQL server, you should use a password.  The
  19243. password is not transmitted in clear text over the connection. Password
  19244. handling during the client connection sequence was upgraded in MySQL
  19245. 4.1.1 to be very secure.  If you are using an older version of MySQL,
  19246. or are still using pre-4.1.1-style passwords, the encryption algorithm
  19247. is less strong and with some effort a clever attacker who can sniff the
  19248. traffic between the client and the server can crack the password.  (See
  19249. *Note Password hashing:: for a discussion of the different password
  19250. handling methods.)  If the connection between the client and the server
  19251. goes through an untrusted network, you should use an SSH tunnel to
  19252. encrypt the communication.
  19253.  
  19254. All other information is transferred as text that can be read by anyone
  19255. who is able to watch the connection.  If you are concerned about this,
  19256. you can use the compressed protocol (in MySQL 3.22 and above) to make
  19257. traffic much more difficult to decipher.  To make the connection even
  19258. more secure, you should use SSH to get an encrypted TCP/IP connection
  19259. between a MySQL server and a MySQL client.  You can find an Open Source
  19260. SSH client at `http://www.openssh.org/', and a commercial SSH client at
  19261. `http://www.ssh.com/'.
  19262.  
  19263. If you are using MySQL 4.0 or newer, you can also use internal OpenSSL
  19264. support.  *Note Secure connections::.
  19265.  
  19266. To make a MySQL system secure, you should strongly consider the
  19267. following suggestions:
  19268.  
  19269.    * Use passwords for all MySQL users. A client program does not
  19270.      necessarily know the identity of the person running it. It is
  19271.      common for client/server applications that the user can specify
  19272.      any username to the client program.  For example, anyone can use
  19273.      the `mysql' program to connect as any other person simply by
  19274.      invoking it as `mysql -u OTHER_USER DB_NAME' if OTHER_USER has no
  19275.      password. If all users have a password, connecting using another
  19276.      user's account becomes much more difficult.
  19277.  
  19278.      To change the password for a user, use the `SET PASSWORD'
  19279.      statement.  It is also possible to update the `user' table in the
  19280.      `mysql' database directly.  For example, to change the password of
  19281.      all MySQL accounts that have a username of `root', do this:
  19282.  
  19283.           shell> mysql -u root
  19284.           mysql> UPDATE mysql.user SET Password=PASSWORD('NEWPWD')
  19285.               -> WHERE User='root';
  19286.           mysql> FLUSH PRIVILEGES;
  19287.  
  19288.    * Don't run the MySQL server as the Unix `root' user.  This is very
  19289.      dangerous, because any user with the `FILE' privilege will be able
  19290.      to create files as `root' (for example, `~root/.bashrc'). To
  19291.      prevent this, `mysqld' refuses to run as `root' unless that is
  19292.      specified explicitly using a `--user=root' option.
  19293.  
  19294.      `mysqld' can be run as an ordinary unprivileged user instead.  You
  19295.      can also create a separate Unix account named `mysql' to make
  19296.      everything even more secure. Use the account only for
  19297.      administering MySQL.  To start `mysqld' as another Unix user, add
  19298.      a `user' option that specifies the username to the `[mysqld]'
  19299.      group of the `/etc/my.cnf' option file or the `my.cnf' option file
  19300.      in the server's data directory. For example:
  19301.  
  19302.           [mysqld]
  19303.           user=mysql
  19304.  
  19305.      This causes the server to start as the designated user whether you
  19306.      start it manually or by using `mysqld_safe' or `mysql.server'.
  19307.      For more details, see *Note Changing MySQL user::.
  19308.  
  19309.      Running `mysqld' as a Unix user other than `root' does not mean
  19310.      that you need to change the `root' username in the `user' table.
  19311.      Usernames for MySQL accounts have nothing to do with usernames for
  19312.      Unix accounts.
  19313.  
  19314.    * Don't allow the use of symlinks to tables. (This can be disabled
  19315.      with the `--skip-symbolic-links' option.) This is especially
  19316.      important if you run `mysqld' as `root', because anyone that has
  19317.      write access to the server's data directory then could delete any
  19318.      file in the system!  *Note Symbolic links to tables::.
  19319.  
  19320.    * Make sure that the only Unix user with read or write privileges in
  19321.      the database directories is the user that `mysqld' runs as.
  19322.  
  19323.    * Don't grant the `PROCESS' or `SUPER' privilege to
  19324.      non-administrative users.  The output of `mysqladmin processlist'
  19325.      shows the text of the currently executing queries, so any user who
  19326.      is allowed to execute that command might be able to see if another
  19327.      user issues an `UPDATE user SET password=PASSWORD('not_secure')'
  19328.      query.
  19329.  
  19330.      `mysqld' reserves an extra connection for users who have the
  19331.      `SUPER' privilege (`PROCESS' before MySQL 4.0.2), so that a MySQL
  19332.      `root' user can log in and check server activity even if all normal
  19333.      connections are in use.
  19334.  
  19335.      The `SUPER' privilege can be used to terminate client connections,
  19336.      change server operation by changing the value of system variables,
  19337.      and control replication servers.
  19338.  
  19339.    * Don't grant the `FILE' privilege to non-administrative users.  Any
  19340.      user that has this privilege can write a file anywhere in the
  19341.      filesystem with the privileges of the `mysqld' daemon!  To make
  19342.      this a bit safer, files generated with `SELECT ... INTO OUTFILE'
  19343.      will not overwrite existing files and are writable by everyone.
  19344.  
  19345.      The `FILE' privilege may also be used to read any file that is
  19346.      world-readable or accessible to the Unix user that the server runs
  19347.      as.  With this privilege, you can read any file into a database
  19348.      table.  This could be abused, for example, by using `LOAD DATA' to
  19349.      load `/etc/passwd' into a table, which then can be displayed with
  19350.      `SELECT'.
  19351.  
  19352.    * If you don't trust your DNS, you should use IP numbers rather than
  19353.      hostnames in the grant tables. In any case, you should be very
  19354.      careful about creating grant table entries using hostname values
  19355.      that contain wildcards!
  19356.  
  19357.    * If you want to restrict the number of connections allowed to a
  19358.      single account, you can do so by setting the
  19359.      `max_user_connections' variable in `mysqld'.  The `GRANT'
  19360.      statement also supports resource control options for limiting the
  19361.      extent of server use allowed to an account.
  19362.  
  19363. Startup Options for `mysqld' Concerning Security
  19364. ------------------------------------------------
  19365.  
  19366. The following `mysqld' options affect security:
  19367.  
  19368. `--local-infile[={0|1}]'
  19369.      If you start the server with `--local-infile=0', clients cannot use
  19370.      `LOCAL' in `LOAD DATA' statements.  *Note `LOAD DATA LOCAL': LOAD
  19371.      DATA LOCAL.
  19372.  
  19373. `--safe-show-database'
  19374.      With this option, the `SHOW DATABASES' statement displays the names
  19375.      of only those databases for which the user has some kind of
  19376.      privilege.  As of MySQL 4.0.2, this option is deprecated and
  19377.      doesn't do anything (it is enabled by default), because there is
  19378.      now a `SHOW DATABASES' privilege that can be used to control
  19379.      access to database names on a per-account basis. *Note `GRANT':
  19380.      GRANT.
  19381.  
  19382. `--safe-user-create'
  19383.      If this is enabled, a user cannot create new users with the `GRANT'
  19384.      statement unless the user has the `INSERT' privilege for the
  19385.      `mysql.user' table.  If you want a user to have the ability to
  19386.      create new users with those privileges that the user has right to
  19387.      grant, you should grant the user the following privilege:
  19388.  
  19389.           mysql> GRANT INSERT(user) ON mysql.user TO 'USER_NAME'@'HOST_NAME';
  19390.  
  19391.      This will ensure that the user can't change any privilege columns
  19392.      directly, but has to use the `GRANT' statement to give privileges
  19393.      to other users.
  19394.  
  19395. `--secure-auth'
  19396.      Disallow authentication for accounts that have old (pre-4.1)
  19397.      passwords.  This option is available as of MySQL 4.1.1.
  19398.  
  19399. `--skip-grant-tables'
  19400.      This option causes the server not to use the privilege system at
  19401.      all. This gives everyone _full access_ to all databases!  (You can
  19402.      tell a running server to start using the grant tables again by
  19403.      executing a `mysqladmin flush-privileges' or `mysqladmin reload'
  19404.      command, or by issuing a `FLUSH PRIVILEGES' statement.)
  19405.  
  19406. `--skip-name-resolve'
  19407.      Hostnames are not resolved.  All `Host' column values in the grant
  19408.      tables must be IP numbers or `localhost'.
  19409.  
  19410. `--skip-networking'
  19411.      Don't allow TCP/IP connections over the network.  All connections
  19412.      to `mysqld' must be made via Unix socket files.  This option is
  19413.      unsuitable when using a MySQL version prior to 3.23.27 with the
  19414.      MIT-pthreads package, because Unix socket files were not supported
  19415.      by MIT-pthreads at that time.
  19416.  
  19417. `--skip-show-database'
  19418.      With this option, the `SHOW DATABASES' statement is allowed only to
  19419.      users who have the `SHOW DATABASES' privilege, and the statement
  19420.      displays all database names.  Without this option, `SHOW
  19421.      DATABASES' is allowed to all users, but displays each database
  19422.      name only if the user has the `SHOW DATABASES' privilege or some
  19423.      privilege for the database.
  19424.  
  19425. Security Issues with `LOAD DATA LOCAL'
  19426. --------------------------------------
  19427.  
  19428. The `LOAD DATA' statement can load a file that is located on the server
  19429. host, or it can load a file that is located on the client host when the
  19430. `LOCAL' keyword is specified.
  19431.  
  19432. There are two potential security issues with supporting the `LOCAL'
  19433. version of `LOAD DATA' statements:
  19434.  
  19435.    * The transfer of the file from the client host to the server host
  19436.      is initiated by the MySQL server. In theory, a patched server
  19437.      could be built that would tell the client program to transfer a
  19438.      file of the server's choosing rather than the file named by the
  19439.      client in the `LOAD DATA' statement. Such a server could access
  19440.      any file on the client host to which the client user has read
  19441.      access.
  19442.  
  19443.    * In a Web environment where the clients are connecting from a Web
  19444.      server, a user could use `LOAD DATA LOCAL' to read any files that
  19445.      the Web server process has read access to (assuming that a user
  19446.      could run any command against the SQL server). In this
  19447.      environment, the client with respect to the MySQL server actually
  19448.      is the Web server, not the program being run by the user
  19449.      connecting to the Web server.
  19450.  
  19451.  
  19452. To deal with these problems, we changed how `LOAD DATA LOCAL' is
  19453. handled as of MySQL 3.23.49 and MySQL 4.0.2 (4.0.13 on Windows):
  19454.  
  19455.    * By default, all MySQL clients and libraries in binary
  19456.      distributions are compiled with the `--enable-local-infile'
  19457.      option, to be compatible with MySQL 3.23.48 and before.
  19458.  
  19459.    * If you build MySQL from source but don't use the
  19460.      `--enable-local-infile' option to `configure', `LOAD DATA LOCAL'
  19461.      cannot be used by any client unless it is written explicitly to
  19462.      invoke `mysql_options(... MYSQL_OPT_LOCAL_INFILE, 0)'.  *Note
  19463.      `mysql_options()': mysql_options.
  19464.  
  19465.    * You can disable all `LOAD DATA LOCAL' commands from the server side
  19466.      by starting `mysqld' with the `--local-infile=0' option.
  19467.  
  19468.    * For the `mysql' command-line client, `LOAD DATA LOCAL' can be
  19469.      enabled by specifying the `--local-infile[=1]' option, or disabled
  19470.      with the `--local-infile=0' option.  Similarly, for `mysqlimport',
  19471.      the `--local' or `-L' option enables local data file loading. In
  19472.      any case, successful use of a local loading operation requires
  19473.      that the server is enabled to allow it.
  19474.  
  19475.    * If you use `LOAD DATA LOCAL' in Perl scripts or other programs that
  19476.      read the `[client]' group from option files, you can add the
  19477.      `local-infile=1' option to that group. However, to keep this from
  19478.      causing problems for programs that do not understand
  19479.      `local-infile', specify it using the `loose-' prefix:
  19480.  
  19481.           [client]
  19482.           loose-local-infile=1
  19483.  
  19484.      The `loose-' prefix can be used as of MySQL 4.0.2.
  19485.  
  19486.    * If `LOAD DATA LOCAL INFILE' is disabled, either in the server or
  19487.      the client, a client that attempts to issue such a statement
  19488.      receives the following error message:
  19489.  
  19490.           ERROR 1148: The used command is not allowed with this MySQL version
  19491.  
  19492.  
  19493. The MySQL Access Privilege System
  19494. =================================
  19495.  
  19496. MySQL has an advanced but non-standard security/privilege system.  This
  19497. section describes how it works.
  19498.  
  19499. What the Privilege System Does
  19500. ------------------------------
  19501.  
  19502. The primary function of the MySQL privilege system is to authenticate a
  19503. user connecting from a given host, and to associate that user with
  19504. privileges on a database such as `SELECT', `INSERT', `UPDATE', and
  19505. `DELETE'.
  19506.  
  19507. Additional functionality includes the ability to have an anonymous user
  19508. and to grant privileges for MySQL-specific functions such as `LOAD DATA
  19509. INFILE' and administrative operations.
  19510.  
  19511. How the Privilege System Works
  19512. ------------------------------
  19513.  
  19514. The MySQL privilege system ensures that all users may perform only the
  19515. operations allowed to them.  As a user, when you connect to a MySQL
  19516. server, your identity is determined by _the host from which you
  19517. connect_ and _the username you specify_.  The system grants privileges
  19518. according to your identity and _what you want to do_.
  19519.  
  19520. MySQL considers both your hostname and username in identifying you
  19521. because there is little reason to assume that a given username belongs
  19522. to the same person everywhere on the Internet.  For example, the user
  19523. `joe' who connects from `office.com' need not be the same person as the
  19524. user `joe' who connects from `elsewhere.com'.  MySQL handles this by
  19525. allowing you to distinguish users on different hosts that happen to
  19526. have the same name:  You can grant `joe' one set of privileges for
  19527. connections from `office.com', and a different set of privileges for
  19528. connections from `elsewhere.com'.
  19529.  
  19530. MySQL access control involves two stages:
  19531.  
  19532.    * Stage 1: The server checks whether you are even allowed to connect.
  19533.  
  19534.    * Stage 2: Assuming that you can connect, the server checks each
  19535.      statement you issue to see whether you have sufficient privileges
  19536.      to perform it.  For example, if you try to select rows from a
  19537.      table in a database or drop a table from the database, the server
  19538.      verifies that you have the `SELECT' privilege for the table or the
  19539.      `DROP' privilege for the database.
  19540.  
  19541. If your privileges are changed (either by yourself or someone else)
  19542. while you are connected, those changes will not necessarily take effect
  19543. immediately for the next statement you issue.  See *Note Privilege
  19544. changes:: for details.
  19545.  
  19546. The server stores privilege information in the grant tables of the
  19547. `mysql' database (that is, in the database named `mysql').  The MySQL
  19548. server reads the contents of these tables into memory when it starts
  19549. and re-reads them under the circumstances indicated in *Note Privilege
  19550. changes::. Access-control decisions are based on the in-memory copies
  19551. of the grant tables.
  19552.  
  19553. Normally, you manipulate the contents of the grant tables indirectly by
  19554. using the `GRANT' and `REVOKE' statements to set up accounts and control
  19555. the privileges available to each one.  *Note `GRANT': GRANT.  The
  19556. discussion here describes the underlying structure of the grant tables
  19557. and how the server uses their contents when interacting with clients.
  19558.  
  19559. The server uses the `user', `db', and `host' tables in the `mysql'
  19560. database at both stages of access control.  The columns in these grant
  19561. tables are shown here:
  19562.  
  19563. *Table Name*   *user*         *db*           *host*
  19564. *Scope         `Host'         `Host'         `Host'
  19565. columns*                                     
  19566.                `User'         `Db'           `Db'
  19567.                `Password'     `User'         
  19568. *Privilege     `Select_priv'  `Select_priv'  `Select_priv'
  19569. columns*                                     
  19570.                `Insert_priv'  `Insert_priv'  `Insert_priv'
  19571.                `Update_priv'  `Update_priv'  `Update_priv'
  19572.                `Delete_priv'  `Delete_priv'  `Delete_priv'
  19573.                `Index_priv'   `Index_priv'   `Index_priv'
  19574.                `Alter_priv'   `Alter_priv'   `Alter_priv'
  19575.                `Create_priv'  `Create_priv'  `Create_priv'
  19576.                `Drop_priv'    `Drop_priv'    `Drop_priv'
  19577.                `Grant_priv'   `Grant_priv'   `Grant_priv'
  19578.                `References_priv'`References_priv'`References_priv'
  19579.                `Reload_priv'                 
  19580.                `Shutdown_priv'               
  19581.                `Process_priv'                
  19582.                `File_priv'                   
  19583.                `Show_db_priv'                
  19584.                `Super_priv'                  
  19585.                `Create_tmp_table_priv'`Create_tmp_table_priv'`Create_tmp_table_priv'
  19586.                `Lock_tables_priv'`Lock_tables_priv'`Lock_tables_priv'
  19587.                `Execute_priv'                
  19588.                `Repl_slave_priv'               
  19589.                `Repl_client_priv'               
  19590.                `ssl_type'                    
  19591.                `ssl_cipher'                  
  19592.                `x509_issuer'                 
  19593.                `x509_subject'                
  19594.                `max_questions'               
  19595.                `max_updates'                 
  19596.                `max_connections'               
  19597.  
  19598. During the second stage of access control (request verification), the
  19599. server may, if the request involves tables, additionally consult the
  19600. `tables_priv' and `columns_priv' tables that provide finer control at
  19601. the table and column levels.  The columns in these tables are shown
  19602. here:
  19603.  
  19604. *Table Name*   *tables_priv*  *columns_priv*
  19605. *Scope         `Host'         `Host'
  19606. columns*                      
  19607.                `Db'           `Db'
  19608.                `User'         `User'
  19609.                `Table_name'   `Table_name'
  19610.                               `Column_name'
  19611. *Privilege     `Table_priv'   `Column_priv'
  19612. columns*                      
  19613.                `Column_priv'  
  19614. *Other         `Timestamp'    `Timestamp'
  19615. columns*                      
  19616.                `Grantor'      
  19617.  
  19618. The `Timestamp' and `Grantor' columns currently are unused and are
  19619. discussed no further here.
  19620.  
  19621. Each grant table contains scope columns and privilege columns:
  19622.  
  19623.    * Scope columns determine the scope of each entry (row) in the
  19624.      tables; that is, the context in which the entry applies.  For
  19625.      example, a `user' table entry with `Host' and `User' values of
  19626.      `'thomas.loc.gov'' and `'bob'' would be used for authenticating
  19627.      connections made to the server from the host `thomas.loc.gov' by a
  19628.      client that specifies a username of `bob'.  Similarly, a `db'
  19629.      table entry with `Host', `User', and `Db' column values of
  19630.      `'thomas.loc.gov'', `'bob'' and `'reports'' would be used when
  19631.      `bob' connects from the host `thomas.loc.gov' to access the
  19632.      `reports' database.  The `tables_priv' and `columns_priv' tables
  19633.      contain scope columns indicating tables or table/column
  19634.      combinations to which each entry applies.
  19635.  
  19636.    * Privilege columns indicate the privileges granted by a table
  19637.      entry; that is, what operations can be performed.  The server
  19638.      combines the information in the various grant tables to form a
  19639.      complete description of a user's privileges.  The rules used to do
  19640.      this are described in *Note Request access::.
  19641.  
  19642.  
  19643. Scope columns contain strings. They are declared as shown here; the
  19644. default value for each is the empty string:
  19645.  
  19646. *Column Name*  *Type*
  19647. `Host'         `CHAR(60)'
  19648. `User'         `CHAR(16)'
  19649. `Password'     `CHAR(16)'
  19650. `Db'           `CHAR(64)'
  19651. `Table_name'   `CHAR(60)'
  19652. `Column_name'  `CHAR(60)'
  19653.  
  19654. Before MySQL 3.23, the `Db' column is `CHAR(32)' in some tables and
  19655. `CHAR(60)' in others.
  19656.  
  19657. For access-checking purposes, comparisons of `Host' values are
  19658. case-insensitive.  `User', `Password', `Db', and `Table_name' values
  19659. are case sensitive.  `Column_name' values are case insensitive in MySQL
  19660. 3.22.12 or later.
  19661.  
  19662. In the `user', `db', and `host' tables, each privilege is listed in a
  19663. separate column that is declared as `ENUM('N','Y') DEFAULT 'N''. In
  19664. other words, each privilege can disabled or enabled, with the default
  19665. being disabled.
  19666.  
  19667. In the `tables_priv' and `columns_priv' tables, the privilege columns
  19668. are declared as `SET' columns. Values in these columns can contain any
  19669. combination of the privileges controlled by the table:
  19670.  
  19671. *Table      *Column     *Possible Set Elements*
  19672. Name*       Name*       
  19673. `tables_priv'`Table_priv'`'Select', 'Insert', 'Update',
  19674.                         'Delete', 'Create', 'Drop', 'Grant',
  19675.                         'References', 'Index', 'Alter''
  19676. `tables_priv'`Column_priv'`'Select', 'Insert', 'Update',
  19677.                         'References''
  19678. `columns_priv'`Column_priv'`'Select', 'Insert', 'Update',
  19679.                         'References''
  19680.  
  19681. Briefly, the server uses the grant tables as follows:
  19682.  
  19683.    * The `user' table scope columns determine whether to reject or allow
  19684.      incoming connections.  For allowed connections, any privileges
  19685.      granted in the `user' table indicate the user's global (superuser)
  19686.      privileges.  These privileges apply to _all_ databases on the
  19687.      server.
  19688.  
  19689.    * The `db' table scope columns determine which users can access which
  19690.      databases from which hosts.  The privilege columns determine which
  19691.      operations are allowed. A privilege granted at the database level
  19692.      applies to the database and to all its tables.
  19693.  
  19694.    * The `host' table is used in conjunction with the `db' table when
  19695.      you want a given `db' table entry to apply to several hosts.  For
  19696.      example, if you want a user to be able to use a database from
  19697.      several hosts in your network, leave the `Host' value empty in the
  19698.      user's `db' table entry, then populate the `host' table with an
  19699.      entry for each of those hosts.  This mechanism is described more
  19700.      detail in *Note Request access::.
  19701.  
  19702.      *Note*: The `host' table is not affected by the `GRANT' and
  19703.      `REVOKE' statements. Most MySQL installations need not use this
  19704.      table at all.
  19705.  
  19706.    * The `tables_priv' and `columns_priv' tables are similar to the
  19707.      `db' table, but are more fine-grained: They apply at the table and
  19708.      column levels rather than at the database level.  A privilege
  19709.      granted at the table level applies to the table and to all its
  19710.      columns.  A privilege granted at the column level applies only to
  19711.      a specific column.
  19712.  
  19713. Administrative privileges (such as `RELOAD' or `SHUTDOWN') are
  19714. specified only in the `user' table.  This is because administrative
  19715. operations are operations on the server itself and are not
  19716. database-specific, so there is no reason to list these privileges in the
  19717. other grant tables.  In fact, to determine whether you can perform an
  19718. administrative operation, the server need consult only the `user' table.
  19719.  
  19720. The `FILE' privilege also is specified only in the `user' table.  It is
  19721. not an administrative privilege as such, but your ability to read or
  19722. write files on the server host is independent of the database you are
  19723. accessing.
  19724.  
  19725. The `mysqld' server reads the contents of the grant tables into memory
  19726. when it starts. You can tell it to re-read the tables by issuing a
  19727. `FLUSH PRIVILEGES' statement or executing a `mysqladmin
  19728. flush-privileges' or `mysqladmin reload' command.  Changes to the grant
  19729. tables take effect as indicated in *Note Privilege changes::.
  19730.  
  19731. When you modify the contents of the grant tables, it is a good idea to
  19732. make sure that your changes set up privileges the way you want. One way
  19733. to check the privileges for a given account is to use the `SHOW GRANTS'
  19734. statement.  For example, to determine the privileges that are granted
  19735. to an account with `Host' and `User' values of `pc84.example.com' and
  19736. `bob', issue this statement:
  19737.  
  19738.      mysql> SHOW GRANTS FOR 'bob'@'pc84.example.com';
  19739.  
  19740. A useful diagnostic tool is the `mysqlaccess' script, which Yves
  19741. Carlier has provided for the MySQL distribution.  Invoke `mysqlaccess'
  19742. with the `--help' option to find out how it works.  Note that
  19743. `mysqlaccess' checks access using only the `user', `db', and `host'
  19744. tables.  It does not check table or column privileges specified in the
  19745. `tables_priv' or `columns_priv' tables.
  19746.  
  19747. For additional help in diagnosing privilege-related problems, see *Note
  19748. Access denied::.  For general advice on security issues, see *Note
  19749. Security::.
  19750.  
  19751. Privileges Provided by MySQL
  19752. ----------------------------
  19753.  
  19754. Information about account privileges is stored in the `user', `db',
  19755. `host', `tables_priv', and `columns_priv' tables in the `mysql'
  19756. database.  The MySQL server reads the contents of these tables into
  19757. memory when it starts and re-reads them under the circumstances
  19758. indicated in *Note Privilege changes::.  Access-control decisions are
  19759. based on the in-memory copies of the grant tables.
  19760.  
  19761. The names used in this manual to refer to the privileges provided by
  19762. MySQL are shown in the following table, along with the table column name
  19763. associated with each privilege in the grant tables and the context in
  19764. which the privilege applies. Further information about the meaning of
  19765. each privilege may be found at *Note `GRANT': GRANT.
  19766.  
  19767. *Privilege* *Column*       *Context*
  19768. `ALTER'     `Alter_priv'   tables
  19769. `DELETE'    `Delete_priv'  tables
  19770. `INDEX'     `Index_priv'   tables
  19771. `INSERT'    `Insert_priv'  tables
  19772. `SELECT'    `Select_priv'  tables
  19773. `UPDATE'    `Update_priv'  tables
  19774. `CREATE'    `Create_priv'  databases, tables, or
  19775.                            indexes
  19776. `DROP'      `Drop_priv'    databases or tables
  19777. `GRANT'     `Grant_priv'   databases or tables
  19778. `REFERENCES'`References_priv'databases or tables
  19779. `CREATE     `Create_tmp_table_priv'server administration
  19780. TEMPORARY                  
  19781. TABLES'                    
  19782. `EXECUTE'   `Execute_priv' server administration
  19783. `FILE'      `File_priv'    file access on server
  19784.                            host
  19785. `LOCK       `Lock_tables_priv'server administration
  19786. TABLES'                    
  19787. `PROCESS'   `Process_priv' server administration
  19788. `RELOAD'    `Reload_priv'  server administration
  19789. `REPLICATION`Repl_client_priv'server administration
  19790. CLIENT'                    
  19791. `REPLICATION`Repl_slave_priv'server administration
  19792. SLAVE'                     
  19793. `SHOW       `Show_db_priv' server administration
  19794. DATABASES'                 
  19795. `SHUTDOWN'  `Shutdown_priv'server administration
  19796. `SUPER'     `Super_priv'   server administration
  19797.  
  19798. The `CREATE TEMPORARY TABLES', `EXECUTE', `LOCK TABLES', `REPLICATION
  19799. CLIENT', `REPLICATION SLAVE', `SHOW DATABASES', and `SUPER' privileges
  19800. were added in MySQL 4.0.2.
  19801.  
  19802. The `EXECUTE' and `REFERENCES' privileges currently are unused.
  19803.  
  19804. The `SELECT', `INSERT', `UPDATE', and `DELETE' privileges allow you to
  19805. perform operations on rows in existing tables in a database.
  19806.  
  19807. `SELECT' statements require the `SELECT' privilege only if they
  19808. actually retrieve rows from a table.  Some `SELECT' statements do not
  19809. access tables and can be executed without permission for any database.
  19810. For example, you can use the `mysql' client as a simple calculator to
  19811. evaluate expressions that make no reference to tables:
  19812.  
  19813.      mysql> SELECT 1+1;
  19814.      mysql> SELECT PI()*2;
  19815.  
  19816. The `CREATE' and `DROP' privileges allow you to create new databases
  19817. and tables, or to drop (remove) existing databases and tables.  If you
  19818. grant the `DROP' privilege for the `mysql' database to a user, that
  19819. user can drop the database in which the MySQL access privileges are
  19820. stored!
  19821.  
  19822. The `INDEX' privilege allows you to create or drop (remove) indexes.
  19823. `INDEX' applies to existing tables.  If you have the `CREATE' privilege
  19824. for a table, you can include index definitions in the `CREATE TABLE'
  19825. statement.
  19826.  
  19827. The `ALTER' privilege allows you to use `ALTER TABLE' to change the
  19828. structure of or rename tables.
  19829.  
  19830. The `GRANT' privilege allows you to give to other users those
  19831. privileges that you yourself possess.
  19832.  
  19833. The `FILE' privilege gives you permission to read and write files on
  19834. the server host using the `LOAD DATA INFILE' and `SELECT ... INTO
  19835. OUTFILE' statements. A user who has the `FILE' privilege can read any
  19836. file on the server host that is either world-readable or readable by
  19837. the MySQL server. (This implies the user can read any file in any
  19838. database directory, because the server can access any of those files.)
  19839. The `FILE' privilege also allows the user to create new files in any
  19840. directory where the MySQL server has write access. Existing files
  19841. cannot be overwritten.
  19842.  
  19843. The remaining privileges are used for administrative operations. Many of
  19844. them can be performed by using the `mysqladmin' program or by issuing
  19845. SQL statements.  The following table shows which `mysqladmin' commands
  19846. each administrative privilege allows you to execute:
  19847.  
  19848. *Privilege* *Commands Permitted to Privilege Holders*
  19849. `RELOAD'    `flush-hosts', `flush-logs', `flush-privileges',
  19850.             `flush-status', `flush-tables', `flush-threads',
  19851.             `refresh', `reload'
  19852. `SHUTDOWN'  `shutdown'
  19853. `PROCESS'   `processlist'
  19854. `SUPER'     `kill'
  19855.  
  19856. The `reload' command tells the server to re-read the grant tables into
  19857. memory.  `flush-privileges' is a synonym for `reload'.  The `refresh'
  19858. command closes and reopens the log files and flushes all tables.  The
  19859. other `flush-XXX' commands perform functions similar to `refresh', but
  19860. are more specific and may be preferable in some instances.  For
  19861. example, if you want to flush just the log files, `flush-logs' is a
  19862. better choice than `refresh'.
  19863.  
  19864. The `shutdown' command shuts down the server. This command can be issued
  19865. only from `mysqladmin'. There is no corresponding SQL statement.
  19866.  
  19867. The `processlist' command displays information about the threads
  19868. executing within the server (that is, about the statements being
  19869. executed by clients associated with other accounts).  The `kill'
  19870. command terminates server threads.  You can always display or kill your
  19871. own threads, but you need the `PROCESS' privilege to display threads
  19872. initiated by other users and the `SUPER' privilege to kill them.  *Note
  19873. `KILL': KILL. Prior to MySQL 4.0.2 when `SUPER' was introduced, the
  19874. `PROCESS' privilege controls the ability to both see and terminate
  19875. threads for other clients.
  19876.  
  19877. The `CREATE TEMPORARY TABLES' privilege allows the use of the keyword
  19878. `TEMPORARY' in `CREATE TABLE' statements.
  19879.  
  19880. The `LOCK TABLES' privilege allows the use of explicit `LOCK TABLES'
  19881. statements to lock tables for which you have the `SELECT' privilege.
  19882. This includes the use of write locks, which prevents anyone else from
  19883. reading the locked table.
  19884.  
  19885. The `REPLICATION CLIENT' privilege allows the use of `SHOW MASTER
  19886. STATUS' and `SHOW SLAVE STATUS'.
  19887.  
  19888. The `REPLICATION SLAVE' privilege should be granted to accounts that are
  19889. used by slave servers when they connect to the current server as their
  19890. master.  Without this privilege, the slave cannot request updates that
  19891. have been made to databases on the master server.
  19892.  
  19893. The `SHOW DATABASES' privilege allows the account to see database names
  19894. by issuing the `SHOW DATABASE' statement. Accounts that do not have this
  19895. privilege see only databases for which they have some privileges, and
  19896. cannot use the statement at all if the server was started with the
  19897. `--skip-show-database' option.
  19898.  
  19899. It is a good idea in general to grant privileges to only those accounts
  19900. that need them, but you should exercise particular caution in granting
  19901. administrative privileges:
  19902.  
  19903.    * The `GRANT' privilege allows users to give their privileges to
  19904.      other users.  Two users with different privileges and with the
  19905.      `GRANT' privilege are able to combine privileges.
  19906.  
  19907.    * The `ALTER' privilege may be used to subvert the privilege system
  19908.      by renaming tables.
  19909.  
  19910.    * The `FILE' privilege can be abused to read into a database table
  19911.      any files that the MySQL server can read on the server host. This
  19912.      includes all world-readable files and files in the server's data
  19913.      directory. The table can then be accessed using `SELECT' to
  19914.      transfer its contents to the client host.
  19915.  
  19916.    * The `SHUTDOWN' privilege can be abused to deny service to other
  19917.      users entirely by terminating the server.
  19918.  
  19919.    * The `PROCESS' privilege can be used to view the plain text of
  19920.      currently executing queries, including queries that set or change
  19921.      passwords.
  19922.  
  19923.    * The `SUPER' privilege can be used to terminate other clients or
  19924.      change how the server operates.
  19925.  
  19926.    * Privileges granted for the `mysql' database itself can be used to
  19927.      change passwords and other access privilege information.
  19928.      Passwords are stored encrypted, so a malicious user cannot simply
  19929.      read them to know the plain text password.  However, a user with
  19930.      write access to the `user' table `Password' column can change an
  19931.      account's password, and then connect to the MySQL server using
  19932.      that account.
  19933.  
  19934.  
  19935. There are some things that you cannot do with the MySQL privilege
  19936. system:
  19937.  
  19938.    * You cannot explicitly specify that a given user should be denied
  19939.      access.  That is, you cannot explicitly match a user and then
  19940.      refuse the connection.
  19941.  
  19942.    * You cannot specify that a user has privileges to create or drop
  19943.      tables in a database but not to create or drop the database itself.
  19944.  
  19945. Connecting to the MySQL Server
  19946. ------------------------------
  19947.  
  19948. MySQL client programs generally expect you to specify connection
  19949. parameters when you want to access a MySQL server:
  19950.  
  19951.    * The name of the host where the MySQL server is running
  19952.  
  19953.    * Your username
  19954.  
  19955.    * Your password
  19956.  
  19957. For example, the `mysql' client can be started as follows from a
  19958. command-line prompt (indicated here by `shell>'):
  19959.  
  19960.      shell> mysql -h HOST_NAME -u USER_NAME -pYOUR_PASS
  19961.  
  19962. Alternate forms of the `-h', `-u', and `-p' options are
  19963. `--host=HOST_NAME', `--user=USER_NAME', and `--password=YOUR_PASS'.
  19964. Note that there is _no space_ between `-p' or `--password=' and the
  19965. password following it.
  19966.  
  19967. If you use a `-p' or `--password' option but do not specify the
  19968. password value, the client program will prompt you to enter the
  19969. password.  The password is not displayed as you enter it.  This is more
  19970. secure than giving the password on the command line.  Any user on your
  19971. system may be able to see a password specified on the command line by
  19972. executing a command such as `ps auxww'.  *Note Password security::.
  19973.  
  19974. MySQL client programs use default values for any connection parameter
  19975. option that you do not specify:
  19976.  
  19977.    * The default hostname is `localhost'.
  19978.  
  19979.    * The default username is `ODBC' on Windows and your Unix login name
  19980.      on Unix.
  19981.  
  19982.    * No password is supplied if `-p' is missing.
  19983.  
  19984. Thus, for a Unix user with a login name of `joe', all of the following
  19985. commands are equivalent:
  19986.  
  19987.      shell> mysql -h localhost -u joe
  19988.      shell> mysql -h localhost
  19989.      shell> mysql -u joe
  19990.      shell> mysql
  19991.  
  19992. Other MySQL clients behave similarly.
  19993.  
  19994. You can specify different default values to be used when you make a
  19995. connection so that you need not enter them on the command line each
  19996. time you invoke a client program.  This can be done in a couple of ways:
  19997.  
  19998.    * You can specify connection parameters in the `[client]' section of
  19999.      an option file.  The relevant section of the file might look like
  20000.      this:
  20001.  
  20002.           [client]
  20003.           host=HOST_NAME
  20004.           user=USER_NAME
  20005.           password=YOUR_PASS
  20006.  
  20007.      Option files are discussed further in *Note Option files::.
  20008.  
  20009.    * You can specify some connection parameters using environment
  20010.      variables.  The host can be specified for `mysql' using
  20011.      `MYSQL_HOST'.  The MySQL username can be specified using `USER'
  20012.      (this is for Windows and NetWare only).  The password can be
  20013.      specified using `MYSQL_PWD', although this is insecure; see *Note
  20014.      Password security::.  For a list of variables, see *Note
  20015.      Environment variables::.
  20016.  
  20017. Access Control, Stage 1: Connection Verification
  20018. ------------------------------------------------
  20019.  
  20020. When you attempt to connect to a MySQL server, the server accepts or
  20021. rejects the connection based on your identity and whether you can
  20022. verify your identity by supplying the correct password.  If not, the
  20023. server denies access to you completely.  Otherwise, the server accepts
  20024. the connection, then enters Stage 2 and waits for requests.
  20025.  
  20026. Your identity is based on two pieces of information:
  20027.  
  20028.    * The client host from which you connect
  20029.  
  20030.    * Your MySQL username
  20031.  
  20032. Identity checking is performed using the three `user' table scope
  20033. columns (`Host', `User', and `Password').  The server accepts the
  20034. connection only if the `Host' and `User' columns in some `user' table
  20035. record match the client hostname and username, and the client supplies
  20036. the password specified in that record.
  20037.  
  20038. `Host' values in the `user' table may be specified as follows:
  20039.  
  20040.    * A `Host' value may be a hostname or an IP number, or `'localhost''
  20041.      to indicate the local host.
  20042.  
  20043.    * You can use the wildcard characters `%' and `_' in `Host' column
  20044.      values.  These have the same meaning as for pattern-matching
  20045.      operations performed with the `LIKE' operator.  For example, a
  20046.      `Host' value of `'%'' matches any hostname, whereas a value of
  20047.      `'%.mysql.com'' matches any host in the `mysql.com' domain.
  20048.  
  20049.    * As of MySQL 3.23, for `Host' values specified as IP numbers, you
  20050.      can specify a netmask indicating how many address bits to use for
  20051.      the network number. For example:
  20052.  
  20053.           mysql> GRANT ALL PRIVILEGES ON db.*
  20054.               -> TO david@'192.58.197.0/255.255.255.0';
  20055.  
  20056.      This allows `david' to connect from any client host having an IP
  20057.      number `client_ip' for which the following condition is true:
  20058.  
  20059.           client_ip & netmask = host_ip
  20060.  
  20061.      That is, for the `GRANT' statement just shown:
  20062.  
  20063.           client_ip & 255.255.255.0 = 192.58.197.0
  20064.  
  20065.      IP numbers that satisfy this condition and can connect to the
  20066.      MySQL server are those that lie in the range from `192.58.197.0' to
  20067.      `192.58.197.255'.
  20068.  
  20069.    * A blank `Host' value in a `db' table record means that its
  20070.      privileges should be combined with those in the entry in the `host'
  20071.      table that matches the client hostname.  The privileges are
  20072.      combined using an AND (intersection) operation, not OR (union).
  20073.      You can find more information about the `host' table in *Note
  20074.      Request access::.
  20075.  
  20076.      A blank `Host' value in the other grant tables is the same as
  20077.      `'%''.
  20078.  
  20079.  
  20080. Because you can use IP wildcard values in the `Host' column (for
  20081. example, `'144.155.166.%'' to match every host on a subnet), someone
  20082. could try to exploit this capability by naming a host
  20083. `144.155.166.somewhere.com'.  To foil such attempts, MySQL disallows
  20084. matching on hostnames that start with digits and a dot. Thus, if you
  20085. have a host named something like `1.2.foo.com', its name will never
  20086. match the `Host' column of the grant tables.  An IP wildcard value can
  20087. match only IP numbers, not hostnames.
  20088.  
  20089. In the `User' column, wildcard characters are not allowed, but you can
  20090. specify a blank value, which matches any name.  If the `user' table
  20091. entry that matches an incoming connection has a blank username, the
  20092. user is considered to be an anonymous user with no name, not a user
  20093. with the name that the client actually specified.  This means that a
  20094. blank username is used for all further access checking for the duration
  20095. of the connection (that is, during Stage 2).
  20096.  
  20097. The `Password' column can be blank.  This is not a wildcard and does
  20098. not mean that any password matches. It means that the user must connect
  20099. without specifying a password.
  20100.  
  20101. Non-blank `Password' values in the `user' table represent encrypted
  20102. passwords.  MySQL does not store passwords in plaintext form for anyone
  20103. to see.  Rather, the password supplied by a user who is attempting to
  20104. connect is encrypted (using the `PASSWORD()' function). The encrypted
  20105. password then is used during the connection process when checking
  20106. whether the password is correct. (This is done without the encrypted
  20107. password ever traveling over the connection.)  From MySQL's point of
  20108. view, the encrypted password is the REAL password, so you should not
  20109. give anyone access to it!  In particular, don't give non-administrative
  20110. users read access to the tables in the `mysql' database!
  20111.  
  20112. From version 4.1 on, MySQL employs a stronger authentication method
  20113. that has better password protection during the connection process than
  20114. in earlier versions. It is secure even if TCP/IP packets are sniffed or
  20115. the `mysql' database is captured.  Password encryption is discussed
  20116. further in *Note Password hashing::.
  20117.  
  20118. The following examples show how various combinations of `Host' and
  20119. `User' values in the `user' table apply to incoming connections:
  20120.  
  20121. `Host' *Value*            `User'      *Connections Matched by Entry*
  20122.                           *Value*     
  20123. `'thomas.loc.gov''        `'fred''    `fred', connecting from
  20124.                                       `thomas.loc.gov'
  20125. `'thomas.loc.gov''        `'''        Any user, connecting from
  20126.                                       `thomas.loc.gov'
  20127. `'%''                     `'fred''    `fred', connecting from any host
  20128. `'%''                     `'''        Any user, connecting from any host
  20129. `'%.loc.gov''             `'fred''    `fred', connecting from any host in
  20130.                                       the `loc.gov' domain
  20131. `'x.y.%''                 `'fred''    `fred', connecting from `x.y.net',
  20132.                                       `x.y.com', `x.y.edu', and so on.
  20133.                                       (this is probably not useful)
  20134. `'144.155.166.177''       `'fred''    `fred', connecting from the host
  20135.                                       with IP address `144.155.166.177'
  20136. `'144.155.166.%''         `'fred''    `fred', connecting from any host in
  20137.                                       the `144.155.166' class C subnet
  20138. `'144.155.166.0/255.255.255.0''`'fred''    Same as previous example
  20139.  
  20140. It is possible for the client hostname and username of an incoming
  20141. connection to match more than one entry in the `user' table.  The
  20142. preceding set of examples demonstrates this: Several of the entries
  20143. shown match a connection from `thomas.loc.gov' by `fred'.
  20144.  
  20145. When multiple matches are possible, the server must determine which of
  20146. them to use.  It resolves this issue as follows:
  20147.  
  20148.    * Whenever the server reads the `user' table into memory, it sorts
  20149.      the entries.
  20150.  
  20151.    * When a client attempts to connect, the server looks through the
  20152.      entries in sorted order.
  20153.  
  20154.    * The server uses the first entry that matches the client hostname
  20155.      and username.
  20156.  
  20157. To see how this works, suppose that the `user' table looks like this:
  20158.  
  20159.      +-----------+----------+-
  20160.      | Host      | User     | ...
  20161.      +-----------+----------+-
  20162.      | %         | root     | ...
  20163.      | %         | jeffrey  | ...
  20164.      | localhost | root     | ...
  20165.      | localhost |          | ...
  20166.      +-----------+----------+-
  20167.  
  20168. When the server reads in the table, it orders the entries with the
  20169. most-specific `Host' values first.  Literal hostnames and IP numbers
  20170. are the most specific. The pattern `'%'' means "any host" and is least
  20171. specific.  Entries with the same `Host' value are ordered with the
  20172. most-specific `User' values first (a blank `User' value means "any
  20173. user" and is least specific). For the `user' table just shown, the
  20174. result after sorting looks like this:
  20175.  
  20176.      +-----------+----------+-
  20177.      | Host      | User     | ...
  20178.      +-----------+----------+-
  20179.      | localhost | root     | ...
  20180.      | localhost |          | ...
  20181.      | %         | jeffrey  | ...
  20182.      | %         | root     | ...
  20183.      +-----------+----------+-
  20184.  
  20185. When a client attempts to connect, the server looks through the sorted
  20186. entries and uses the first match found.  For a connection from
  20187. `localhost' by `jeffrey', two of the entries in the table match: the
  20188. one with `Host' and `User' values of `'localhost'' and `''', and the
  20189. one with values of `'%'' and `'jeffrey''.  The `'localhost'' entry
  20190. appears first in sorted order, so that is the one the server uses.
  20191.  
  20192. Here is another example.  Suppose that the `user' table looks like this:
  20193.  
  20194.      +----------------+----------+-
  20195.      | Host           | User     | ...
  20196.      +----------------+----------+-
  20197.      | %              | jeffrey  | ...
  20198.      | thomas.loc.gov |          | ...
  20199.      +----------------+----------+-
  20200.  
  20201. The sorted table looks like this:
  20202.  
  20203.      +----------------+----------+-
  20204.      | Host           | User     | ...
  20205.      +----------------+----------+-
  20206.      | thomas.loc.gov |          | ...
  20207.      | %              | jeffrey  | ...
  20208.      +----------------+----------+-
  20209.  
  20210. A connection by `jeffrey' from `thomas.loc.gov' is matched by the first
  20211. entry, whereas a connection by `jeffrey' from `whitehouse.gov' is
  20212. matched by the second.
  20213.  
  20214. It is a common misconception to think that, for a given username, all
  20215. entries that explicitly name that user will be used first when the
  20216. server attempts to find a match for the connection.  This is simply not
  20217. true.  The previous example illustrates this, where a connection from
  20218. `thomas.loc.gov' by `jeffrey' is first matched not by the entry
  20219. containing `'jeffrey'' as the `User' column value, but by the entry
  20220. with no username!  As a result, `jeffrey' will be authenticated as an
  20221. anonymous user, even though he specified a username when connecting.
  20222.  
  20223. If you are able to connect to the server, but your privileges are not
  20224. what you expect, you probably are being authenticated as some other
  20225. account.  To find out what account the server used to authenticate you,
  20226. use the `CURRENT_USER()' function. It returns a value in
  20227. `USER_NAME@HOST_NAME' format that indicates the `User' and `Host'
  20228. values from the matching `user' table record.  Suppose that `jeffrey'
  20229. connects and issues the following query:
  20230.  
  20231.      mysql> SELECT CURRENT_USER();
  20232.      +----------------+
  20233.      | CURRENT_USER() |
  20234.      +----------------+
  20235.      | @localhost     |
  20236.      +----------------+
  20237.  
  20238. The result shown here indicates that the matching `user' table entry
  20239. had a blank `User' column value.  In other words, the server is
  20240. treating `jeffrey' as an anonymous user.
  20241.  
  20242. The `CURRENT_USER()' function is available as of MySQL 4.0.6.  *Note
  20243. Information functions::.  Another thing you can do to diagnose
  20244. authentication problems is to print out the `user' table and sort it by
  20245. hand to see where the first match is being made.
  20246.  
  20247. Access Control, Stage 2: Request Verification
  20248. ---------------------------------------------
  20249.  
  20250. Once you establish a connection, the server enters Stage 2 of access
  20251. control.  For each request that comes in on the connection, the server
  20252. determines what operation you want to perform, then checks whether you
  20253. have sufficient privileges to do so.  This is where the privilege
  20254. columns in the grant tables come into play.  These privileges can come
  20255. from any of the `user', `db', `host', `tables_priv', or `columns_priv'
  20256. tables.  (You may find it helpful to refer to *Note Privileges::, which
  20257. lists the columns present in each of the grant tables.)
  20258.  
  20259. The `user' table grants privileges that are assigned to you on a global
  20260. basis and that apply no matter what the current database is.  For
  20261. example, if the `user' table grants you the `DELETE' privilege, you can
  20262. delete rows from any table in any database on the server host!  In
  20263. other words, `user' table privileges are superuser privileges.  It is
  20264. wise to grant privileges in the `user' table only to superusers such as
  20265. database administrators.  For other users, you should leave the
  20266. privileges in the `user' table set to `'N'' and grant privileges at more
  20267. specific levels only. You can grant privileges for particular databases,
  20268. tables, or columns.
  20269.  
  20270. The `db' and `host' tables grant database-specific privileges.  Values
  20271. in the scope columns of these tables can take the following forms:
  20272.  
  20273.    * The wildcard characters `%' and `_' can be used in the `Host' and
  20274.      `Db' columns of either table.  These have the same meaning as for
  20275.      pattern-matching operations performed with the `LIKE' operator.
  20276.      If you want to use either character literally when granting
  20277.      privileges, you must escape it with a backslash.  For example, to
  20278.      include `_' character as part of a database name, specify it as
  20279.      `\_' in the `GRANT' statement.
  20280.  
  20281.    * A `'%'' `Host' value in the `db' table means "any host." A blank
  20282.      `Host' value in the `db' table means "consult the `host' table for
  20283.      further information" (a process that is described later in this
  20284.      section).
  20285.  
  20286.    * A `'%'' or blank `Host' value in the `host' table means "any host."
  20287.  
  20288.    * A `'%'' or blank `Db' value in either table means "any database."
  20289.  
  20290.    * A blank `User' value in either table matches the anonymous user.
  20291.  
  20292. The server reads in and sorts the `db' and `host' tables at the same
  20293. time that it reads the `user' table.  The server sorts the `db' table
  20294. based on the `Host', `Db', and `User' scope columns, and sorts the
  20295. `host' table based on the `Host' and `Db' scope columns.  As with the
  20296. `user' table, sorting puts the most-specific values first and
  20297. least-specific values last, and when the server looks for matching
  20298. entries, it uses the first match that it finds.
  20299.  
  20300. The `tables_priv' and `columns_priv' tables grant table-specific and
  20301. column-specific privileges.  Values in the scope columns of these
  20302. tables can take the following form:
  20303.  
  20304.    * The wildcard characters `%' and `_' can be used in the `Host'
  20305.      column of either table.  These have the same meaning as for
  20306.      pattern-matching operations performed with the `LIKE' operator.
  20307.  
  20308.    * A `'%'' or blank `Host' value in either table means "any host."
  20309.  
  20310.    * The `Db', `Table_name', and `Column_name' columns cannot contain
  20311.      wildcards or be blank in either table.
  20312.  
  20313. The server sorts the `tables_priv' and `columns_priv' tables based on
  20314. the `Host', `Db', and `User' columns.  This is similar to `db' table
  20315. sorting, but simpler because only the `Host' column can contain
  20316. wildcards.
  20317.  
  20318. The request verification process is described here.  (If you are
  20319. familiar with the access-checking source code, you will notice that the
  20320. description here differs slightly from the algorithm used in the code.
  20321. The description is equivalent to what the code actually does; it
  20322. differs only to make the explanation simpler.)
  20323.  
  20324. For requests that require administrative privileges such as `SHUTDOWN'
  20325. or `RELOAD', the server checks only the `user' table entry because that
  20326. is the only table that specifies administrative privileges.  Access is
  20327. granted if the entry allows the requested operation and denied
  20328. otherwise.  For example, if you want to execute `mysqladmin shutdown'
  20329. but your `user' table entry doesn't grant the `SHUTDOWN' privilege to
  20330. you, the server denies access without even checking the `db' or `host'
  20331. tables.  (They contain no `Shutdown_priv' column, so there is no need
  20332. to do so.)
  20333.  
  20334. For database-related requests (`INSERT', `UPDATE', and so on), the
  20335. server first checks the user's global (superuser) privileges by looking
  20336. in the `user' table entry.  If the entry allows the requested operation,
  20337. access is granted.  If the global privileges in the `user' table are
  20338. insufficient, the server determines the user's database-specific
  20339. privileges by checking the `db' and `host' tables:
  20340.  
  20341.   1. The server looks in the `db' table for a match on the `Host',
  20342.      `Db', and `User' columns.  The `Host' and `User' columns are
  20343.      matched to the connecting user's hostname and MySQL username.  The
  20344.      `Db' column is matched to the database that the user wants to
  20345.      access.  If there is no entry for the `Host' and `User', access is
  20346.      denied.
  20347.  
  20348.   2. If there is a matching `db' table entry and its `Host' column is
  20349.      not blank, that entry defines the user's database-specific
  20350.      privileges.
  20351.  
  20352.   3. If the matching `db' table entry's `Host' column is blank, it
  20353.      signifies that the `host' table enumerates which hosts should be
  20354.      allowed access to the database.  In this case, a further lookup is
  20355.      done in the `host' table to find a match on the `Host' and `Db'
  20356.      columns.  If no `host' table entry matches, access is denied.  If
  20357.      there is a match, the user's database-specific privileges are
  20358.      computed as the intersection (_not_ the union!) of the privileges
  20359.      in the `db' and `host' table entries; that is, the privileges that
  20360.      are `'Y'' in both entries.  (This way you can grant general
  20361.      privileges in the `db' table entry and then selectively restrict
  20362.      them on a host-by-host basis using the `host' table entries.)
  20363.  
  20364. After determining the database-specific privileges granted by the `db'
  20365. and `host' table entries, the server adds them to the global privileges
  20366. granted by the `user' table.  If the result allows the requested
  20367. operation, access is granted.  Otherwise, the server successively
  20368. checks the user's table and column privileges in the `tables_priv' and
  20369. `columns_priv' tables, adds those to the user's privileges, and allows
  20370. or denies access based on the result.
  20371.  
  20372. Expressed in boolean terms, the preceding description of how a user's
  20373. privileges are calculated may be summarized like this:
  20374.  
  20375.      global privileges
  20376.      OR (database privileges AND host privileges)
  20377.      OR table privileges
  20378.      OR column privileges
  20379.  
  20380. It may not be apparent why, if the global `user' entry privileges are
  20381. initially found to be insufficient for the requested operation, the
  20382. server adds those privileges to the database, table, and column
  20383. privileges later. The reason is that a request might require more than
  20384. one type of privilege.  For example, if you execute an `INSERT INTO ...
  20385. SELECT' statement, you need both the `INSERT' and the `SELECT'
  20386. privileges.  Your privileges might be such that the `user' table entry
  20387. grants one privilege and the `db' table entry grants the other.  In
  20388. this case, you have the necessary privileges to perform the request,
  20389. but the server cannot tell that from either table by itself; the
  20390. privileges granted by the entries in both tables must be combined.
  20391.  
  20392. The `host' table is not affected by the `GRANT' or `REVOKE' statements,
  20393. so it is unused in most MySQL installations. If you modify it directly,
  20394. you can use it for some specialized purposes, such as to to maintain a
  20395. list of secure servers.  For example, at TcX, the `host' table contains
  20396. a list of all machines on the local network. These are granted all
  20397. privileges.
  20398.  
  20399. You can also use the `host' table to indicate hosts that are _not_
  20400. secure.  Suppose that you have a machine `public.your.domain' that is
  20401. located in a public area that you do not consider secure.  You can
  20402. allow access to all hosts on your network except that machine by using
  20403. `host' table entries like this:
  20404.  
  20405.      +--------------------+----+-
  20406.      | Host               | Db | ...
  20407.      +--------------------+----+-
  20408.      | public.your.domain | %  | ... (all privileges set to 'N')
  20409.      | %.your.domain      | %  | ... (all privileges set to 'Y')
  20410.      +--------------------+----+-
  20411.  
  20412. Naturally, you should always test your entries in the grant tables (for
  20413. example, by using `SHOW GRANTS' or `mysqlaccess') to make sure that
  20414. your access privileges are actually set up the way you think they are.
  20415.  
  20416. When Privilege Changes Take Effect
  20417. ----------------------------------
  20418.  
  20419. When `mysqld' starts, all grant table contents are read into memory and
  20420. become effective for access control at that point.
  20421.  
  20422. When the server reloads the grant tables, privileges for existing
  20423. client connections are affected as follows:
  20424.  
  20425.    * Table and column privilege changes take effect with the client's
  20426.      next request.
  20427.  
  20428.    * Database privilege changes take effect at the next `USE DB_NAME'
  20429.      statement.
  20430.  
  20431.    * Changes to global privileges and passwords take effect the next
  20432.      time the client connects.
  20433.  
  20434. If you modify the grant tables using `GRANT', `REVOKE', or `SET
  20435. PASSWORD', the server notices these changes and reloads the grant
  20436. tables into memory again immediately.
  20437.  
  20438. If you modify the grant tables directly using statements such as
  20439. `INSERT', `UPDATE', or `DELETE', your changes have no effect on
  20440. privilege checking until you either restart the server or tell it to
  20441. reload the tables.  To reload the grant tables manually, issue a `FLUSH
  20442. PRIVILEGES' statement or execute a `mysqladmin flush-privileges' or
  20443. `mysqladmin reload' command.
  20444.  
  20445. If you change the grant tables directly but forget to reload them, your
  20446. changes will have _no effect_ until you restart the server.  This may
  20447. leave you wondering why your changes don't seem to make any difference!
  20448.  
  20449. Causes of `Access denied' Errors
  20450. --------------------------------
  20451.  
  20452. If you encounter problems when you try to connect to the MySQL server,
  20453. the following items describe some courses of action you can take to
  20454. correct the problem.
  20455.  
  20456.    * Make sure that the server is running. If it is not running, you
  20457.      cannot connect to it.  For example, if you attempt to connect to
  20458.      the server and see a message such as one of those following, one
  20459.      cause might be that the server is not running:
  20460.  
  20461.           shell> mysql
  20462.           ERROR 2003: Can't connect to MySQL server on 'HOST_NAME' (111)
  20463.           shell> mysql
  20464.           ERROR 2002: Can't connect to local MySQL server through socket
  20465.           '/tmp/mysql.sock' (111)
  20466.  
  20467.      It might also be that the server is running, but you are trying to
  20468.      connect using a TCP/IP port, named pipe, or Unix socket file
  20469.      different from those on which the server is listening. To correct
  20470.      this when you invoke a client program, specify a `--port' option
  20471.      to indicate the proper port, or a `--socket' option to indicate
  20472.      the proper named pipe or Unix socket file.  To find out what port
  20473.      is used, and where the socket is, you can do:
  20474.  
  20475.           shell> netstat -l | grep mysql
  20476.  
  20477.    * The grant tables must be properly set up so that the server can
  20478.      use them for access control.  For some distribution types (such as
  20479.      binary distributions on Windows on RPM distributions on Linux),
  20480.      the installation process initializes the `mysql' database
  20481.      containing the grant tables.  For distributions that do not do
  20482.      this, you should initialize the grant tables manually by running
  20483.      the `mysql_install_db' script.  For details, see *Note Unix
  20484.      post-installation::.
  20485.  
  20486.      One way to determine whether you need to initialize the grant
  20487.      tables is to look for a `mysql' directory under the data
  20488.      directory. (The data directory normally is named `data' or `var'
  20489.      and is located under your MySQL installation directory.)  Make
  20490.      sure that you have a file named `user.MYD' in the `mysql' database
  20491.      directory.  If you do not, execute the `mysql_install_db' script.
  20492.      After running this script and starting the server, test the
  20493.      initial privileges by executing this command:
  20494.  
  20495.           shell> mysql -u root test
  20496.  
  20497.      The server should let you connect without error.
  20498.  
  20499.    * After a fresh installation, you should connect to the server and
  20500.      set up your users and their access permissions:
  20501.  
  20502.           shell> mysql -u root mysql
  20503.  
  20504.      The server should let you connect because the MySQL `root' user
  20505.      has no password initially.  That is also a security risk, so
  20506.      setting the password for the `root' accounts is something you
  20507.      should do while you're setting up your other MySQL users.  For
  20508.      instructions on setting the initial passwords, see *Note Default
  20509.      privileges::.
  20510.  
  20511.    * If you have updated an existing MySQL installation to a newer
  20512.      version, did you run the `mysql_fix_privilege_tables' script?  If
  20513.      not, do so. The structure of the grant tables changes occasionally
  20514.      when new capabilities are added, so after an upgrade you should
  20515.      always make sure that your tables have the current structure. For
  20516.      instructions, see *Note Upgrading-grant-tables::.
  20517.  
  20518.    * If a client program receives the following error message when it
  20519.      tries to connect, it means that the server expects passwords in a
  20520.      newer format than the client is capable of generating:
  20521.  
  20522.           shell> mysql
  20523.           Client does not support authentication protocol requested
  20524.           by server; consider upgrading MySQL client
  20525.  
  20526.      For information on how to deal with this, see *Note Password
  20527.      hashing:: and *Note Old client::.
  20528.  
  20529.    * If you try to connect as `root' and get the following error, it
  20530.      means that you don't have an entry in the `user' table with a
  20531.      `User' column value of `'root'' and that `mysqld' cannot resolve
  20532.      the hostname for your client:
  20533.  
  20534.           Access denied for user ''@'unknown' to database mysql
  20535.  
  20536.      In this case, you must restart the server with the
  20537.      `--skip-grant-tables' option and edit your `/etc/hosts' or
  20538.      `\windows\hosts' file to add an entry for your host.
  20539.  
  20540.    * Remember that client programs will use connection parameters
  20541.      specified in option files or environment variables.  If a client
  20542.      program seems to be sending incorrect default connection
  20543.      parameters when you don't specify them on the command line, check
  20544.      your environment and any applicable option files. For example, if
  20545.      you get `Access denied' when you run a client without any options,
  20546.      make sure that you haven't specified an old password in any of
  20547.      your option files!
  20548.  
  20549.      You can suppress the use of option files by a client program by
  20550.      invoking it with the `--no-defaults' option. For example:
  20551.  
  20552.           shell> mysqladmin --no-defaults -u root version
  20553.  
  20554.      The option files that clients use are listed in *Note Option
  20555.      files::.  Environment variables are listed in *Note Environment
  20556.      variables::.
  20557.  
  20558.    * If you get the following error, it means that you are using an
  20559.      incorrect `root' password:
  20560.  
  20561.           shell> mysqladmin -u root -pXXXX ver
  20562.           Access denied for user 'root'@'localhost' (using password: YES)
  20563.  
  20564.      If the preceding error occurs even when you haven't specified a
  20565.      password, it means that you have an incorrect password listed in
  20566.      some option file. Try the `--no-defaults' option as described in
  20567.      the previous item.
  20568.  
  20569.      For information on changing passwords, see *Note Passwords::.
  20570.  
  20571.      If you have lost or forgotten the `root' password, you can restart
  20572.      `mysqld' with `--skip-grant-tables' to change the password.  *Note
  20573.      Resetting permissions::.
  20574.  
  20575.    * If you change a password by using `SET PASSWORD', `INSERT', or
  20576.      `UPDATE', you must encrypt the password using the `PASSWORD()'
  20577.      function.  If you do not use `PASSWORD()' for these statements,
  20578.      the password will not work. For example, the following statement
  20579.      sets a password, but fails to encrypt it, so the user will not be
  20580.      able to connect afterward:
  20581.  
  20582.           mysql> SET PASSWORD FOR 'abe'@'HOST_NAME' = 'eagle';
  20583.  
  20584.      Instead, set the password like this:
  20585.  
  20586.           mysql> SET PASSWORD FOR 'abe'@'HOST_NAME' = PASSWORD('eagle');
  20587.  
  20588.      The `PASSWORD()' function is unnecessary when you specify a
  20589.      password using the `GRANT' statement or the `mysqladmin password'
  20590.      command, both of which automatically use `PASSWORD()' to encrypt
  20591.      the password.  *Note Passwords::.
  20592.  
  20593.    * `localhost' is a synonym for your local hostname, and is also the
  20594.      default host to which clients try to connect if you specify no host
  20595.      explicitly.  However, connections to `localhost' on Unix systems
  20596.      do not work if you are using a MySQL version older than 3.23.27
  20597.      that uses MIT-pthreads: `localhost' connections are made using
  20598.      Unix socket files, which were not supported by MIT-pthreads at
  20599.      that time.
  20600.  
  20601.      To avoid this problem on such systems, you can use a
  20602.      `--host=127.0.0.1' option to name the server host explicitly.
  20603.      This will make a TCP/IP connection to the local `mysqld' server.
  20604.      You can also use TCP/IP by specifying a `--host' option that uses
  20605.      the actual hostname of the local host.  In this case, the hostname
  20606.      must be specified in a `user' table entry on the server host, even
  20607.      though you are running the client program on the same host as the
  20608.      server.
  20609.  
  20610.    * If you get an `Access denied' error when trying to connect to the
  20611.      database with `mysql -u user_name', you may have a problem with
  20612.      the `user' table. Check this by executing `mysql -u root mysql'
  20613.      and issuing this SQL statement:
  20614.  
  20615.           mysql> SELECT * FROM user;
  20616.  
  20617.      The result should include an entry with the `Host' and `User'
  20618.      columns matching your computer's hostname and your MySQL username.
  20619.  
  20620.    * The `Access denied' error message will tell you who you are trying
  20621.      to log in as, the client host from which you are trying to
  20622.      connect, and whether or not you were using a password. Normally,
  20623.      you should have one entry in the `user' table that exactly matches
  20624.      the hostname and username that were given in the error message.
  20625.      For example, if you get an error message that contains `using
  20626.      password: NO', it means that you tried to log in without an
  20627.      password.
  20628.  
  20629.    * If the following error occurs when you try to connect from a host
  20630.      other than the one on which the MySQL server is running, it means
  20631.      that there is no row in the `user' table with a `Host' value that
  20632.      matches the client host:
  20633.  
  20634.           Host ... is not allowed to connect to this MySQL server
  20635.  
  20636.      You can fix this by setting up an account for the combination of
  20637.      client hostname and username that you are using when trying to
  20638.      connect.
  20639.  
  20640.      If you don't know the IP number or hostname of the machine from
  20641.      which you are connecting, you should put an entry with `'%'' as
  20642.      the `Host' column value in the `user' table and restart `mysqld'
  20643.      with the `--log' option on the server machine.  After trying to
  20644.      connect from the client machine, the information in the MySQL log
  20645.      will indicate how you really did connect.  (Then change the `'%''
  20646.      in the `user' table entry to the actual hostname that shows up in
  20647.      the log.  Otherwise, you'll have a system that is insecure because
  20648.      it allows connections from any host for the given username.)
  20649.  
  20650.      On Linux, another reason that this error might occur is that you
  20651.      are using a binary MySQL version that is compiled with a different
  20652.      version of the `glibc' library than the one you are using.  In
  20653.      this case, you should either upgrade your operating system or
  20654.      `glibc', or download a source distribution of MySQL version and
  20655.      compile it yourself.  A source RPM is normally trivial to compile
  20656.      and install, so this isn't a big problem.
  20657.  
  20658.    * If you specify a hostname when trying to connect, but get an error
  20659.      message where the hostname is not shown or is an IP number, it
  20660.      means that the MySQL server got an error when trying to resolve the
  20661.      IP number of the client host to a name:
  20662.  
  20663.           shell> mysqladmin -u root -pXXXX -h SOME-HOSTNAME ver
  20664.           Access denied for user 'root'@'' (using password: YES)
  20665.  
  20666.      This indicates a DNS problem.  To fix it, execute `mysqladmin
  20667.      flush-hosts' to reset the internal DNS hostname cache. *Note DNS::.
  20668.  
  20669.      Some permanent solutions are:
  20670.  
  20671.         - Try to find out what is wrong with your DNS server and fix it.
  20672.  
  20673.         - Specify IP numbers rather than hostnames in the MySQL grant
  20674.           tables.
  20675.  
  20676.         - Put an entry for the client machine name in `/etc/hosts'.
  20677.  
  20678.         - Start `mysqld' with the `--skip-name-resolve' option.
  20679.  
  20680.         - Start `mysqld' with the `--skip-host-cache' option.
  20681.  
  20682.         - On Unix, if you are running the server and the client on the
  20683.           same machine, connect to `localhost'. Unix connections to
  20684.           `localhost' use a Unix socket file rather than TCP/IP.
  20685.  
  20686.         - On Windows, if you are running the server and the client on
  20687.           the same machine and the server supports named pipe
  20688.           connections, connect to the hostname `.' (period).
  20689.           Connections to `.' use a named pipe rather than TCP/IP.
  20690.  
  20691.    * If `mysql -u root test' works but `mysql -h YOUR_HOSTNAME -u root
  20692.      test' results in `Access denied' (where YOUR_HOSTNAME is the
  20693.      actual hostname of the local host), you may not have the correct
  20694.      name for your host in the `user' table.  A common problem here is
  20695.      that the `Host' value in the user table entry specifies an
  20696.      unqualified hostname, but your system's name resolution routines
  20697.      return a fully qualified domain name (or vice versa).  For
  20698.      example, if you have an entry with host `'tcx'' in the `user'
  20699.      table, but your DNS tells MySQL that your hostname is
  20700.      `'tcx.subnet.se'', the entry will not work. Try adding an entry to
  20701.      the `user' table that contains the IP number of your host as the
  20702.      `Host' column value.  (Alternatively, you could add an entry to the
  20703.      `user' table with a `Host' value that contains a wildcard; for
  20704.      example, `'tcx.%''.  However, use of hostnames ending with `%' is
  20705.      _insecure_ and is _not_ recommended!)
  20706.  
  20707.    * If `mysql -u USER_NAME test' works but `mysql -u USER_NAME
  20708.      OTHER_DB_NAME' does not, you have not granted database access for
  20709.      OTHER_DB_NAME to the given user.
  20710.  
  20711.    * If `mysql -u USER_NAME' works when executed on the server host, but
  20712.      `mysql -h HOST_NAME -u USER_NAME' doesn't work when executed on a
  20713.      remote client host, you have not enabled access to the server for
  20714.      the given username from the remote host.
  20715.  
  20716.    * If you can't figure out why you get `Access denied', remove from
  20717.      the `user' table all entries that have `Host' values containing
  20718.      wildcards (entries that contain `%' or `_').  A very common error
  20719.      is to insert a new entry with `Host'=`'%'' and
  20720.      `User'=`'SOME_USER'', thinking that this will allow you to specify
  20721.      `localhost' to connect from the same machine.  The reason that this
  20722.      doesn't work is that the default privileges include an entry with
  20723.      `Host'=`'localhost'' and `User'=`'''.  Because that entry has a
  20724.      `Host' value `'localhost'' that is more specific than `'%'', it is
  20725.      used in preference to the new entry when connecting from
  20726.      `localhost'!  The correct procedure is to insert a second entry
  20727.      with `Host'=`'localhost'' and `User'=`'SOME_USER'', or to delete
  20728.      the entry with `Host'=`'localhost'' and `User'=`'''.  After
  20729.      deleting the entry, remember to issue a `FLUSH PRIVILEGES'
  20730.      statement to reload the grant tables.
  20731.  
  20732.    * If you get the following error, you may have a problem with the
  20733.      `db' or `host' table:
  20734.  
  20735.           Access to database denied
  20736.  
  20737.      If the entry selected from the `db' table has an empty value in the
  20738.      `Host' column, make sure that there are one or more corresponding
  20739.      entries in the `host' table specifying which hosts the `db' table
  20740.      entry applies to.
  20741.  
  20742.    * If you are able to connect to the MySQL server, but get an `Access
  20743.      denied' message whenever you issue a `SELECT ...  INTO OUTFILE' or
  20744.      `LOAD DATA INFILE' statement, your entry in the `user' table
  20745.      doesn't have the `FILE' privilege enabled.
  20746.  
  20747.    * If you change the grant tables directly (for example, by using
  20748.      `INSERT', `UPDATE', or `DELETE' statements) and your changes seem
  20749.      to be ignored, remember that you must execute a `FLUSH PRIVILEGES'
  20750.      statement or a `mysqladmin flush-privileges' command to cause the
  20751.      server to re-read the privilege tables. Otherwise, your changes
  20752.      have no effect until the next time the server is restarted.
  20753.      Remember that after you change the `root' password with an
  20754.      `UPDATE' command, you won't need to specify the new password until
  20755.      after you flush the privileges, because the server won't know
  20756.      you've changed the password yet!
  20757.  
  20758.    * If your privileges seem to have changed in the middle of a
  20759.      session, it may be that a MySQL administrator has changed them.
  20760.      Reloading the grant tables affects new client connections, but it
  20761.      also affects existing connections as indicated in *Note Privilege
  20762.      changes::.
  20763.  
  20764.    * If you have access problems with a Perl, PHP, Python, or ODBC
  20765.      program, try to connect to the server with `mysql -u USER_NAME
  20766.      DB_NAME' or `mysql -u USER_NAME -pYOUR_PASS DB_NAME'.  If you are
  20767.      able to connect using the `mysql' client, the problem lies with
  20768.      your program, not with the access privileges.  (There is no space
  20769.      between `-p' and the password; you can also use the
  20770.      `--password=YOUR_PASS' syntax to specify the password. If you use
  20771.      the `-p' option alone, MySQL will prompt you for the password.)
  20772.  
  20773.    * For testing, start the `mysqld' server with the
  20774.      `--skip-grant-tables' option.  Then you can change the MySQL grant
  20775.      tables and use the `mysqlaccess' script to check whether your
  20776.      modifications have the desired effect.  When you are satisfied
  20777.      with your changes, execute `mysqladmin flush-privileges' to tell
  20778.      the `mysqld' server to start using the new grant tables.
  20779.      (Reloading the grant tables overrides the `--skip-grant-tables'
  20780.      option.  This allows you to tell the server to begin using the
  20781.      grant tables again without stopping and restarting it.)
  20782.  
  20783.    * If everything else fails, start the `mysqld' server with a
  20784.      debugging option (for example, `--debug=d,general,query'). This
  20785.      will print host and user information about attempted connections,
  20786.      as well as information about each command issued. *Note Making
  20787.      trace files::.
  20788.  
  20789.    * If you have any other problems with the MySQL grant tables and
  20790.      feel you must post the problem to the mailing list, always provide
  20791.      a dump of the MySQL grant tables. You can dump the tables with the
  20792.      `mysqldump mysql' command. As always, post your problem using the
  20793.      `mysqlbug' script.  *Note Bug reports::.  In some cases, you may
  20794.      need to restart `mysqld' with `--skip-grant-tables' to run
  20795.      `mysqldump'.
  20796.  
  20797.  
  20798. Password Hashing in MySQL 4.1
  20799. -----------------------------
  20800.  
  20801. MySQL user accounts are listed in the `user' table of the `mysql'
  20802. database. Each MySQL account is assigned a password, although what is
  20803. stored in the `Password' column of the `user' table is not the
  20804. plaintext version of the password, but a hash value computed from it.
  20805. Password hash values are computed by the `PASSWORD()' function.
  20806.  
  20807. MySQL uses passwords in two phases of client/server communication:
  20808.  
  20809.    * When a client attempts to connect to the server, there is an
  20810.      initial authentication step in which the client must present a
  20811.      password that has a hash value matching the hash value stored in
  20812.      the `user' table for the account that the client wants to use.
  20813.  
  20814.    * After the client connects, it can (if it has sufficient
  20815.      privileges) set or change the password hashes for accounts listed
  20816.      in the `user' table.  The client can do this by using the
  20817.      `PASSWORD()' function to generate a password hash, or by using the
  20818.      `GRANT' or `SET PASSWORD' statements.
  20819.  
  20820.  
  20821. In other words, the server _uses_ hash values during authentication when
  20822. a client first attempts to connect. The server _generates_ hash values
  20823. if a connected client invokes the `PASSWORD()' function or uses a
  20824. `GRANT' or `SET PASSWORD' statement to set or change a password.
  20825.  
  20826. The password hashing mechanism was updated in MySQL 4.1 to provide
  20827. better security and to reduce the risk of passwords being intercepted.
  20828. However, this new mechanism is understood only by the 4.1 server and
  20829. 4.1 clients, which can result in some compatibility problems.  A 4.1
  20830. client can connect to a pre-4.1 server, because the client understands
  20831. both the old and new password hashing mechanisms. However, a pre-4.1
  20832. client that attempts to connect to a 4.1 server may run into
  20833. difficulties.  For example, a 4.0 `mysql' client that attempts to
  20834. connect to a 4.1 server may fail with the following error message:
  20835.  
  20836.      shell> mysql -h localhost -u root
  20837.      Client does not support authentication protocol requested
  20838.      by server; consider upgrading MySQL client
  20839.  
  20840. The following discussion describes the differences between the old and
  20841. new password mechanisms, and what you should do if you upgrade your
  20842. server to 4.1 but need to maintain backward compatibility with pre-4.1
  20843. clients. Additional information can be found in *Note Old client::.
  20844.  
  20845. *Note*: This discussion contrasts 4.1 behavior with pre-4.1 behavior,
  20846. but the 4.1 behavior described here actually begins with 4.1.1. MySQL
  20847. 4.1.0 is an "odd" release because it has a slightly different mechanism
  20848. than that implemented in 4.1.1 and up.  Differences between 4.1.0 and
  20849. more recent versions are described further in *Note Password hashing
  20850. 4.1.0::.
  20851.  
  20852. Prior to MySQL 4.1, password hashes computed by the `PASSWORD()'
  20853. function are 16 bytes long.  Such hashes look like this:
  20854.  
  20855.      mysql> SELECT PASSWORD('mypass');
  20856.      +--------------------+
  20857.      | PASSWORD('mypass') |
  20858.      +--------------------+
  20859.      | 6f8c114b58f2ce9e   |
  20860.      +--------------------+
  20861.  
  20862. The `Password' column of the `user' table (in which these hashes are
  20863. stored) also is 16 bytes long before MySQL 4.1.
  20864.  
  20865. As of MySQL 4.1, the `PASSWORD()' function has been modified to produce
  20866. a longer 41-byte hash value:
  20867.  
  20868.      mysql> SELECT PASSWORD('mypass');
  20869.      +-----------------------------------------------+
  20870.      | PASSWORD('mypass')                            |
  20871.      +-----------------------------------------------+
  20872.      | *43c8aa34cdc98eddd3de1fe9a9c2c2a9f92bb2098d75 |
  20873.      +-----------------------------------------------+
  20874.  
  20875. Accordingly, the `Password' column in the `user' table also must be 41
  20876. bytes long to store these values:
  20877.  
  20878.    * If you perform a new installation of MySQL 4.1, the `Password'
  20879.      column will be made 41 bytes long automatically.
  20880.  
  20881.    * If you upgrade an older installation to 4.1, you should run the
  20882.      `mysql_fix_privilege_tables' script to increase the length of the
  20883.      `Password' column from 16 to 41 bytes. (The script does not change
  20884.      existing password values, which remain 16 bytes long.)
  20885.  
  20886.  
  20887. A widened `Password' column can store password hashes in both the old
  20888. and new formats. The format of any given password hash value can be
  20889. determined two ways:
  20890.  
  20891.    * The obvious difference is the length (16 bytes versus 41 bytes).
  20892.  
  20893.    * A second difference is that password hashes in the new format
  20894.      always begin with a `*' character, whereas passwords in the old
  20895.      format never do.
  20896.  
  20897.  
  20898. The longer password hash format has better cryptographic properties, and
  20899. client authentication based on long hashes is more secure than that
  20900. based on the older short hashes.
  20901.  
  20902. The differences between short and long password hashes are relevant
  20903. both for how the server uses passwords during authentication and for
  20904. how it generates password hashes for connected clients that perform
  20905. password-changing operations.
  20906.  
  20907. The way in which the server uses password hashes during authentication
  20908. is affected by the width of the `Password' column:
  20909.  
  20910.    * If the column is short, only short-hash authentication is used.
  20911.  
  20912.    * If the column is long, it can hold either short or long hashes, and
  20913.      the server can use either format:
  20914.  
  20915.         - Pre-4.1 clients can connect, although because they know only
  20916.           about the old hashing mechanism, they can authenticate only
  20917.           for accounts that have short hashes.
  20918.  
  20919.         - 4.1 clients can authenticate for accounts that have short or
  20920.           long hashes.
  20921.  
  20922.  
  20923.  
  20924. For short-hash accounts, the authentication process is actually a bit
  20925. more secure for 4.1 clients than for older clients.  In terms of
  20926. security, the gradient from least to most secure is:
  20927.  
  20928.    * Pre-4.1 client authenticating for account with short password hash
  20929.  
  20930.    * 4.1 client authenticating for account with short password hash
  20931.  
  20932.    * 4.1 client authenticating for account with long password hash
  20933.  
  20934.  
  20935. The way in which the server generates password hashes for connected
  20936. clients is affected by the width of the `Password' column and by the
  20937. `--old-passwords' option.  A 4.1 server generates long hashes only if
  20938. certain conditions are met: The `Password' column must be wide enough
  20939. to hold long values and the `--old-passwords' option must not be given.
  20940. These conditions apply as follows:
  20941.  
  20942.    * The `Password' column must be wide enough to hold long hashes (41
  20943.      bytes).  If the column has not been updated and still has the
  20944.      pre-4.1 width of 16 bytes, the server notices that long hashes
  20945.      cannot fit into it and generates only short hashes when a client
  20946.      performs password-changing operations using `PASSWORD()', `GRANT',
  20947.      or `SET PASSWORD'.  This is the behavior that occurs if you have
  20948.      upgraded to 4.1 but have not yet run the
  20949.      `mysql_fix_privilege_tables' script to widen the `Password' column.
  20950.  
  20951.    * If the `Password' column is wide, it can store either short or long
  20952.      password hashes. In this case, `PASSWORD()', `GRANT', and `SET
  20953.      PASSWORD' generate long hashes unless the server was started with
  20954.      the `--old-passwords' option. That option forces the server to
  20955.      generate short password hashes instead.
  20956.  
  20957.  
  20958. The purpose of the `--old-passwords' option is to allow you to maintain
  20959. backward compatibility with pre-4.1 clients under circumstances where
  20960. the server would otherwise generate long password hashes. The option
  20961. doesn't affect authentication (4.1 clients can still use accounts that
  20962. have long password hashes), but it does prevent creation of a long
  20963. password hash in the `user' table as the result of a password-changing
  20964. operation. Were that to occur, the account no longer could be used by
  20965. pre-4.1 clients. Without the `--old-passwords' option, the following
  20966. undesirable scenario is possible:
  20967.  
  20968.    * An old client connects to an account that has a short password
  20969.      hash.
  20970.  
  20971.    * The client changes its own password. Without `--old-passwords',
  20972.      this results in the account having a long password hash.
  20973.  
  20974.    * The next time the old client attempts to connect to the account,
  20975.      it cannot, because the account now has a long password hash that
  20976.      requires the new hashing mechanism during authentication. (Once an
  20977.      account has a long password hash in the user table, only 4.1
  20978.      clients can authenticate for it, because pre-4.1 clients do not
  20979.      understand long hashes.)
  20980.  
  20981.  
  20982. This scenario illustrates that, if you must support older pre-4.1
  20983. clients, it is dangerous to run a 4.1 server without using the
  20984. `--old-passwords' option.  By running the server with
  20985. `--old-passwords', password-changing operations will not generate long
  20986. password hashes and thus do not cause accounts to become inaccessible
  20987. to older clients. (Those clients cannot inadvertently lock themselves
  20988. out by changing their password and ending up with a long password hash.)
  20989.  
  20990. The downside of the `--old-passwords' option is that any passwords you
  20991. create or change will use short hashes, even for 4.1 clients. Thus, you
  20992. lose the additional security provided by long password hashes. If you
  20993. want to create an account that has a long hash (for example, for use by
  20994. 4.1 clients), you must do so while running the server without
  20995. `--old-passwords'.
  20996.  
  20997. The following scenarios are possible for running a 4.1 server:
  20998.  
  20999. *Scenario 1:* Short `Password' column in user table:
  21000.  
  21001.    * Only short hashes can be stored in the `Password' column.
  21002.  
  21003.    * The server uses only short hashes during client authentication.
  21004.  
  21005.    * For connected clients, password hash-generating operations
  21006.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  21007.      exclusively.  Any change to an account's password results in that
  21008.      account having a short password hash.
  21009.  
  21010.    * The `--old-passwords' option can be used but is superfluous because
  21011.      with a short `Password' column, the server will generate only short
  21012.      password hashes anyway.
  21013.  
  21014.  
  21015. *Scenario 2:* Long `Password' column; server not started with
  21016. `--old-passwords' option:
  21017.  
  21018.    * Short or long hashes can be stored in the `Password' column.
  21019.  
  21020.    * 4.1 clients can authenticate for accounts that have short or long
  21021.      hashes.
  21022.  
  21023.    * Pre-4.1 clients can authenticate only for accounts that have short
  21024.      hashes.
  21025.  
  21026.    * For connected clients, password hash-generating operations
  21027.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use long hashes
  21028.      exclusively.  A change to an account's password results in that
  21029.      account having a long password hash.
  21030.  
  21031.  
  21032. As indicated earlier, a danger in this scenario is that it is possible
  21033. for accounts that have a short password hash to become inaccessible to
  21034. pre-4.1 clients. A change to such an account's password made via
  21035. `GRANT', `PASSWORD()', or `SET PASSWORD' results in the account being
  21036. given a long password hash. From that point on, no pre-4.1 client can
  21037. authenticate to that account until the client upgrades to 4.1.
  21038.  
  21039. To deal with this problem, you can change a password in a special way.
  21040. For example, normally you use `SET PASSWORD' as follows to change an
  21041. account password:
  21042.  
  21043.      mysql> SET PASSWORD FOR 'SOME_USER'@'SOME_HOST' = PASSWORD('mypass');
  21044.  
  21045. To change the password but create a short hash, use the
  21046. `OLD_PASSWORD()' function instead:
  21047.  
  21048.      mysql> SET PASSWORD FOR 'SOME_USER'@'SOME_HOST' = OLD_PASSWORD('mypass');
  21049.  
  21050. `OLD_PASSWORD()' is useful for situations in which you explicitly want
  21051. to generate a short hash.
  21052.  
  21053. *Scenario 3:* Long `Password' column; server started with
  21054. `--old-passwords' option:
  21055.  
  21056.    * Short or long hashes can be stored in the `Password' column.
  21057.  
  21058.    * 4.1 clients can authenticate for accounts that have short or long
  21059.      hashes (but note that it is possible to create long hashes only
  21060.      when the server is started without `--old-passwords').
  21061.  
  21062.    * Pre-4.1 clients can authenticate only for accounts that have short
  21063.      hashes.
  21064.  
  21065.    * For connected clients, password hash-generating operations
  21066.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  21067.      exclusively.  Any change to an account's password results in that
  21068.      account having a short password hash.
  21069.  
  21070.  
  21071. In this scenario, you cannot create accounts that have long password
  21072. hashes, because the `--old-passwords' option prevents generation of
  21073. long hashes.  Also, if you create an account with a long hash before
  21074. using the `--old-passwords' option, changing the account's password
  21075. while `--old-passwords' is in effect results in the account being given
  21076. a short password, causing it to lose the security benefits of a longer
  21077. hash.
  21078.  
  21079. The disadvantages for these scenarios may be summarized as follows:
  21080.  
  21081. In scenario 1, you cannot take advantage of longer hashes that provide
  21082. more secure authentication.
  21083.  
  21084. In scenario 2, accounts with short hashes become inaccessible to pre-4.1
  21085. clients if you change their passwords without explicitly using
  21086. `OLD_PASSWORD()'.
  21087.  
  21088. In scenario 3, `--old-passwords' prevents accounts with short hashes
  21089. from becoming inaccessible, but password-changing operations cause
  21090. accounts with long hashes to revert to short hashes, and you cannot
  21091. change them back to long hashes while `--old-passwords' is in effect.
  21092.  
  21093. Implications of Password Hashing Changes for Application Programs
  21094. .................................................................
  21095.  
  21096. An upgrade to MySQL 4.1 can cause a compatibility issue for
  21097. applications that use `PASSWORD()' to generate passwords for their own
  21098. purposes. Applications really should not do this, because `PASSWORD()'
  21099. should be used only to manage passwords for MySQL accounts. But some
  21100. applications use `PASSWORD()' for their own purposes anyway.
  21101.  
  21102. If you upgrade to 4.1 and run the server under conditions where it
  21103. generates long password hashes, an application that uses `PASSWORD()'
  21104. for its own passwords will break.  The recommended course of action is
  21105. to modify the application to use another function, such as `SHA1()' or
  21106. `MD5()', to produce hashed values.  If that is not possible, you can
  21107. use the `OLD_PASSWORD()' function, which is provided to generate short
  21108. hashes in the old format. But note that `OLD_PASSWORD()' may one day no
  21109. longer be supported.
  21110.  
  21111. If the server is running under circumstances where it generates short
  21112. hashes, `OLD_PASSWORD()' is available but is equivalent to `PASSWORD()'.
  21113.  
  21114. Password Hashing in MySQL 4.1.0
  21115. ...............................
  21116.  
  21117. Password hashing in MySQL 4.1.0 differs from hashing in 4.1.1 and up.
  21118. The 4.1.0 differences are:
  21119.  
  21120.    * Password hashes are 45 bytes long rather than 41 bytes.
  21121.  
  21122.    * The `PASSWORD()' function is non-repeatable.  That is, with a given
  21123.      argument X, successive calls to `PASSWORD(X)' generate different
  21124.      results.
  21125.  
  21126.  
  21127. These differences make authentication in 4.1.0 incompatible with that of
  21128. releases that follow it.  If you have upgraded to MySQL 4.1.0, it is
  21129. recommended that you upgrade to a newer version as soon as possible.
  21130. After you do, reassign any long passwords in the `user' table so that
  21131. they are compatible with the 41-byte format.
  21132.  
  21133. MySQL User Account Management
  21134. =============================
  21135.  
  21136. This section describes how to set up accounts for clients of your MySQL
  21137. server. It discusses the following topics:
  21138.  
  21139.    * The meaning of account names and passwords as used in MySQL and
  21140.      how that compares to names and passwords used by your operating
  21141.      system
  21142.  
  21143.    * How to set up new accounts and remove existing accounts
  21144.  
  21145.    * How to change passwords
  21146.  
  21147.    * Guidelines for using passwords securely
  21148.  
  21149.    * How to use secure connections with SSL
  21150.  
  21151.  
  21152. MySQL Usernames and Passwords
  21153. -----------------------------
  21154.  
  21155. A MySQL account is defined in terms of a username and the client host
  21156. or hosts from which the user can connect to the server. The account
  21157. also has a password.  There are several distinctions between the way
  21158. usernames and passwords are used by MySQL and the way they are used by
  21159. your operating system:
  21160.  
  21161.    * Usernames, as used by MySQL for authentication purposes, have
  21162.      nothing to do with usernames (login names) as used by Windows or
  21163.      Unix.  On Unix, most MySQL clients by default try to log in using
  21164.      the current Unix username as the MySQL username, but that is for
  21165.      convenience only. The default can be overridden easily, because
  21166.      client programs allow any username to be specified with a `-u' or
  21167.      `--user' option. Because this means that anyone can attempt to
  21168.      connect to the server using any username, you can't make a
  21169.      database secure in any way unless all MySQL accounts have
  21170.      passwords.  Anyone who specifies a username for an account that
  21171.      has no password will be able to connect successfully to the server.
  21172.  
  21173.    * MySQL usernames can be up to 16 characters long. Operating system
  21174.      usernames might have a different maximum length. For example, Unix
  21175.      usernames typically are limited to eight characters.
  21176.  
  21177.    * MySQL passwords have nothing to do with passwords for logging in
  21178.      to your operating system.  There is no necessary connection
  21179.      between the password you use to log in to a Windows or Unix
  21180.      machine and the password you use to access the MySQL server on
  21181.      that machine.
  21182.  
  21183.    * MySQL encrypts passwords using its own algorithm. This encryption
  21184.      is different from that used during the Unix login process.  MySQL
  21185.      password encryption is the same as that implemented by the
  21186.      `PASSWORD()' SQL function.  Unix password encryption is the same
  21187.      as that implemented by the `ENCRYPT()' SQL function.  See the
  21188.      descriptions of the `PASSWORD()' and `ENCRYPT()' functions in
  21189.      *Note Encryption functions::.  From version 4.1 on, MySQL employs
  21190.      a stronger authentication method that has better password
  21191.      protection during the connection process than in earlier versions.
  21192.      It is secure even if TCP/IP packets are sniffed or the `mysql'
  21193.      database is captured.  (In earlier versions, even though passwords
  21194.      are stored in encrypted form in the `user' table, knowledge of the
  21195.      encrypted password value could be used to connect to the MySQL
  21196.      server.)
  21197.  
  21198.  
  21199. When you install MySQL, the grant tables are populated with an initial
  21200. set of accounts. These accounts have names and access privileges that
  21201. are described in *Note Default privileges::, which also discusses how
  21202. to assign passwords to them.  Thereafter, you normally set up, modify,
  21203. and remove MySQL accounts using the `GRANT' and `REVOKE' statements.
  21204. *Note `GRANT': GRANT.
  21205.  
  21206. When you connect to a MySQL server with a command-line client, you
  21207. should specify the username and password for the account that you want
  21208. to use:
  21209.  
  21210.      shell> mysql --user=monty --password=GUESS DB_NAME
  21211.  
  21212. If you prefer short options, the command looks like this:
  21213.  
  21214.      shell> mysql -u monty -pGUESS DB_NAME
  21215.  
  21216. There must be _no space_ between the `-p' option and the following
  21217. password value.  *Note Connecting::.
  21218.  
  21219. The preceding commands include the password value on the command line,
  21220. which can be a security risk.  *Note Password security::.  To avoid
  21221. this, specify the `--password' or `-p' option without any following
  21222. password value:
  21223.  
  21224.      shell> mysql --user=monty --password DB_NAME
  21225.      shell> mysql -u monty -p DB_NAME
  21226.  
  21227. Then the client program will print a prompt and wait for you to enter
  21228. the password.  (In these examples, DB_NAME is _not_ interpreted as a
  21229. password, because it is separated from the preceding password option by
  21230. a space.)
  21231.  
  21232. On some systems, the library call that MySQL uses to prompt for a
  21233. password automatically limits the password to eight characters.  That
  21234. is a problem with the system library, not with MySQL.  Internally,
  21235. MySQL doesn't have any limit for the length of the password.  To work
  21236. around the problem, change your MySQL password to a value that is eight
  21237. or fewer characters long, or put your password in an option file.
  21238.  
  21239. Adding New User Accounts to MySQL
  21240. ---------------------------------
  21241.  
  21242. You can create MySQL accounts in two ways:
  21243.  
  21244.    * By using `GRANT' statements
  21245.  
  21246.    * By manipulating the MySQL grant tables directly
  21247.  
  21248. The preferred method is to use `GRANT' statements, because they are
  21249. more concise and less error-prone. `GRANT' is available as of MySQL
  21250. 3.22.11; its syntax is described in *Note `GRANT': GRANT.
  21251.  
  21252. Another option for creating accounts is to use one of several available
  21253. third-party programs that offer capabilities for MySQL account
  21254. administration.  `phpMyAdmin' is one such program.
  21255.  
  21256. The following examples show how to use the `mysql' client program to
  21257. set up new users.  These examples assume that privileges are set up
  21258. according to the defaults described in *Note Default privileges::.
  21259. This means that to make changes, you must connect to the MySQL server
  21260. as the MySQL `root' user, and the `root' account must have the `INSERT'
  21261. privilege for the `mysql' database and the `RELOAD' administrative
  21262. privilege.
  21263.  
  21264. First, use the `mysql' program to connect to the server as the MySQL
  21265. `root' user:
  21266.  
  21267.      shell> mysql --user=root mysql
  21268.  
  21269. If you have assigned a password to the `root' account, you'll also need
  21270. to supply a `--password' or `-p' option for this `mysql' command and
  21271. also for those later in this section.
  21272.  
  21273. After connecting to the server as `root', you can add new accounts.
  21274. The following statements use `GRANT' to set up four new accounts:
  21275.  
  21276.      mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
  21277.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  21278.      mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
  21279.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  21280.      mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
  21281.      mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost';
  21282.  
  21283. The accounts created by these `GRANT' statements have the following
  21284. properties:
  21285.  
  21286.    * Two of the accounts have a username of `monty' and a password of
  21287.      `some_pass'. Both accounts are superuser accounts with full
  21288.      privileges to do anything. One account (`'monty'@'localhost'') can
  21289.      be used only when connecting from the local host. The other
  21290.      (`'monty'@'%'') can be used to connect from any other host.  Note
  21291.      that it is necessary to have both accounts for `monty' to be able
  21292.      to connect from anywhere as `monty'.  Without the `localhost'
  21293.      account, the anonymous-user account for `localhost' that is
  21294.      created by `mysql_install_db' would take precedence when `monty'
  21295.      connects from the local host. As a result, `monty' would be
  21296.      treated as an anonymous user.  The reason for this is that the
  21297.      anonymous-user account has a more specific `Host' column value
  21298.      than the `'monty'@'%'' account and thus comes earlier in the
  21299.      `user' table sort order.  (`user' table sorting is discussed in
  21300.      *Note Connection access::.)
  21301.  
  21302.    * One account has a username of `admin' and no password.  This
  21303.      account can be used only by connecting from the local host.  It is
  21304.      granted the `RELOAD' and `PROCESS' administrative privileges.
  21305.      These privileges allow the `admin' user to execute the `mysqladmin
  21306.      reload', `mysqladmin refresh', and `mysqladmin flush-XXX' commands,
  21307.      as well as `mysqladmin processlist' .  No privileges are granted
  21308.      for accessing any databases. You could add such privileges later
  21309.      by issuing additional `GRANT' statements.
  21310.  
  21311.    * One account has a username of `dummy' and no password.  This
  21312.      account can be used only by connecting from the local host.  No
  21313.      privileges are granted. The `USAGE' privilege in the `GRANT'
  21314.      statement allows you to create an account without giving it any
  21315.      privileges. It has the effect of setting all the global privileges
  21316.      to `'N''.  It is assumed that you will grant specific privileges
  21317.      to the account later.
  21318.  
  21319.  
  21320. As an alternative to `GRANT', you can create the same accounts directly
  21321. by issuing `INSERT' statements and then telling the server to reload
  21322. the grant tables:
  21323.  
  21324.      shell> mysql --user=root mysql
  21325.      mysql> INSERT INTO user
  21326.          ->     VALUES('localhost','monty',PASSWORD('some_pass'),
  21327.          ->     'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  21328.      mysql> INSERT INTO user
  21329.          ->     VALUES('%','monty',PASSWORD('some_pass'),
  21330.          ->     'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  21331.      mysql> INSERT INTO user SET Host='localhost',User='admin',
  21332.          ->     Reload_priv='Y', Process_priv='Y';
  21333.      mysql> INSERT INTO user (Host,User,Password)
  21334.          ->     VALUES('localhost','dummy','');
  21335.      mysql> FLUSH PRIVILEGES;
  21336.  
  21337. The reason for using `FLUSH PRIVILEGES' when you create accounts with
  21338. `INSERT' is to tell the server to re-read the grant tables.  Otherwise,
  21339. the changes will go unnoticed until you restart the server. With
  21340. `GRANT', `FLUSH PRIVILEGES' is unnecessary.
  21341.  
  21342. The reason for using the `PASSWORD()' function with `INSERT' is to
  21343. encrypt the password. The `GRANT' statement encrypts the password for
  21344. you, so `PASSWORD()' is unnecessary.
  21345.  
  21346. The `'Y'' values enable privileges for the accounts.  Depending on your
  21347. MySQL version, you may have to use a different number of `'Y'' values
  21348. in the first two `INSERT' statements. (Versions prior to 3.22.11 have
  21349. fewer privilege columns, and versions from 4.0.2 on have more.)  For the
  21350. `admin' account, the more readable extended `INSERT' syntax using `SET'
  21351. that is available starting with MySQL 3.22.11 is used.
  21352.  
  21353. In the `INSERT' statement for the `dummy' account, only the `Host',
  21354. `User', and `Password' columns in the `user' table record are assigned
  21355. values. None of the privilege columns are set explicitly, so MySQL
  21356. assigns them all the default value of `'N''.  This is equivalent to
  21357. what `GRANT USAGE' does.
  21358.  
  21359. Note that to set up a superuser account, it is necessary only to create
  21360. a `user' table entry with the privilege columns set to `'Y''.  `user'
  21361. table privileges are global, so no entries in any of the other grant
  21362. tables are needed.
  21363.  
  21364. The next examples create three accounts and give them access to specific
  21365. databases. Each of them has a username of `custom' and password of
  21366. `obscure'.
  21367.  
  21368. To create the accounts with `GRANT', use the following statements:
  21369.  
  21370.      shell> mysql --user=root mysql
  21371.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  21372.          ->     ON bankaccount.*
  21373.          ->     TO 'custom'@'localhost'
  21374.          ->     IDENTIFIED BY 'obscure';
  21375.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  21376.          ->     ON expenses.*
  21377.          ->     TO 'custom'@'whitehouse.gov'
  21378.          ->     IDENTIFIED BY 'obscure';
  21379.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  21380.          ->     ON customer.*
  21381.          ->     TO 'custom'@'server.domain'
  21382.          ->     IDENTIFIED BY 'obscure';
  21383.  
  21384. The three accounts can be used as follows:
  21385.  
  21386.    * The first account can access the `bankaccount' database, but only
  21387.      from the local host.
  21388.  
  21389.    * The second account can access the `expenses' database, but only
  21390.      from the host `whitehouse.gov'.
  21391.  
  21392.    * The third account can access the `customer' database, but only
  21393.      from the host `server.domain'.
  21394.  
  21395. To set up the `custom' accounts without `GRANT', use `INSERT'
  21396. statements as follows to modify the grant tables directly:
  21397.  
  21398.      shell> mysql --user=root mysql
  21399.      mysql> INSERT INTO user (Host,User,Password)
  21400.          ->     VALUES('localhost','custom',PASSWORD('obscure'));
  21401.      mysql> INSERT INTO user (Host,User,Password)
  21402.          ->     VALUES('whitehouse.gov','custom',PASSWORD('obscure'));
  21403.      mysql> INSERT INTO user (Host,User,Password)
  21404.          ->     VALUES('server.domain','custom',PASSWORD('obscure'));
  21405.      mysql> INSERT INTO db
  21406.          ->     (Host,Db,User,Select_priv,Insert_priv,
  21407.          ->     Update_priv,Delete_priv,Create_priv,Drop_priv)
  21408.          ->     VALUES('localhost','bankaccount','custom',
  21409.          ->     'Y','Y','Y','Y','Y','Y');
  21410.      mysql> INSERT INTO db
  21411.          ->     (Host,Db,User,Select_priv,Insert_priv,
  21412.          ->     Update_priv,Delete_priv,Create_priv,Drop_priv)
  21413.          ->     VALUES('whitehouse.gov','expenses','custom',
  21414.          ->     'Y','Y','Y','Y','Y','Y');
  21415.      mysql> INSERT INTO db
  21416.          ->     (Host,Db,User,Select_priv,Insert_priv,
  21417.          ->     Update_priv,Delete_priv,Create_priv,Drop_priv)
  21418.          ->     VALUES('server.domain','customer','custom',
  21419.          ->     'Y','Y','Y','Y','Y','Y');
  21420.      mysql> FLUSH PRIVILEGES;
  21421.  
  21422. The first three `INSERT' statements add `user' table entries that allow
  21423. the user `custom' to connect from the various hosts with the given
  21424. password, but grant no global privileges (all privileges are set to the
  21425. default value of `'N'').  The next three `INSERT' statements add `db'
  21426. table entries that grant privileges to `custom' for the `bankaccount',
  21427. `expenses', and `customer' databases, but only when accessed from the
  21428. proper hosts.  As usual when you modify the grant tables directly, you
  21429. tell the server to reload them with `FLUSH PRIVILEGES' so that the
  21430. privilege changes take effect.
  21431.  
  21432. If you want to give a specific user access from all machines in a given
  21433. domain (for example, `mydomain.com'), you can issue a `GRANT' statement
  21434. that uses the `%' wildcard character in the host part of the account
  21435. name:
  21436.  
  21437.      mysql> GRANT ...
  21438.          ->     ON *.*
  21439.          ->     TO 'myname'@'%.mydomain.com'
  21440.          ->     IDENTIFIED BY 'mypass';
  21441.  
  21442. To do the same thing by modifying the grant tables directly, do this:
  21443.  
  21444.      mysql> INSERT INTO user (Host,User,Password,...)
  21445.          ->     VALUES('%.mydomain.com','myname',PASSWORD('mypass'),...);
  21446.      mysql> FLUSH PRIVILEGES;
  21447.  
  21448. Removing User Accounts from MySQL
  21449. ---------------------------------
  21450.  
  21451. To remove an account, use the `DROP USER' statement, which was added in
  21452. MySQL 4.1.1.  For older versions of MySQL, use `DELETE' instead.  The
  21453. account removal procedure is described in *Note Drop user::.
  21454.  
  21455. Limiting Account Resources
  21456. --------------------------
  21457.  
  21458. Before MySQL 4.0.2, the only available method for limiting use of MySQL
  21459. server resources is to set the `max_user_connections' system variable
  21460. to a non-zero value. But that method is strictly global.  It does not
  21461. allow for management of individual accounts. Also, it limits only the
  21462. number of simultaneous connections made using a single account, not
  21463. what a client can do once connected. Both types of control are interest
  21464. to many MySQL administrators, particularly those for Internet Service
  21465. Providers.
  21466.  
  21467. Starting from MySQL 4.0.2, you can limit the following server resources
  21468. for individual accounts:
  21469.  
  21470.    * The number of queries that an account can issue per hour
  21471.  
  21472.    * The number of updates that an account can issue per hour
  21473.  
  21474.    * The number of times an account can connect to the server per hour
  21475.  
  21476. Any statement that a client can issue counts against the query limit.
  21477. Only statements that modify databases or tables count against the update
  21478. limit.
  21479.  
  21480. An account in this context is a single record in the `user' table. Each
  21481. account is uniquely identified by its `User' and `Host' column values.
  21482.  
  21483. As a prerequisite for using this feature, the `user' table in the
  21484. `mysql' database must contain the resource-related columns.  Resource
  21485. limits are stored in the `max_questions', `max_updates', and
  21486. `max_connections' columns.  If your `user' table doesn't have these
  21487. columns, it must be upgraded; see *Note Upgrading-grant-tables::.
  21488.  
  21489. To set resource limits with a `GRANT' statement, use a `WITH' clause
  21490. that names each resource to be limited and a per-hour count indicating
  21491. the limit value.  For example, to create a new account that can access
  21492. the `customer' database, but only in a limited fashion, issue this
  21493. statement:
  21494.  
  21495.      mysql> GRANT ALL ON customer.* TO 'francis'@'localhost'
  21496.          ->     IDENTIFIED BY 'frank'
  21497.          ->     WITH MAX_QUERIES_PER_HOUR 20
  21498.          ->          MAX_UPDATES_PER_HOUR 10
  21499.          ->          MAX_CONNECTIONS_PER_HOUR 5;
  21500.  
  21501. The limit types need not all be named in the `WITH' clause, but those
  21502. named can be present in any order. The value for each limit should be an
  21503. integer representing a count per hour. If the `GRANT' statement has no
  21504. `WITH' clause, the limits are each set to the default value of zero
  21505. (that is, no limit).
  21506.  
  21507. To set or change limits for an existing account, use a `GRANT USAGE'
  21508. statement at the global level (`ON *.*'). The following statement
  21509. changes the query limit for `francis' to 100:
  21510.  
  21511.      mysql> GRANT USAGE ON *.* TO 'francis'@'localhost'
  21512.          ->     WITH MAX_QUERIES_PER_HOUR 100;
  21513.  
  21514. This statement leaves the account's existing privileges unchanged and
  21515. modifies only the limit values specified.
  21516.  
  21517. To remove an existing limit, set its value to zero. For example, to
  21518. remove the limit on how many times per hour `francis' can connect, use
  21519. this statement:
  21520.  
  21521.      mysql> GRANT USAGE ON *.* TO 'francis'@'localhost'
  21522.          ->     WITH MAX_CONNECTIONS_PER_HOUR 0;
  21523.  
  21524. Resource-use counting takes place when any account has a non-zero limit
  21525. placed on its use of any of the resources.
  21526.  
  21527. As the server runs, it counts the number of times each account uses
  21528. resources.  If an account reaches its limit on number of connections
  21529. within the last hour, further connections for the account are rejected
  21530. until that hour is up. Similarly, if the account reaches its limit on
  21531. the number of queries or updates, further queries or updates are
  21532. rejected until the hour is up. In all such cases, an appropriate error
  21533. message is issued.
  21534.  
  21535. Resource counting is done per account, not per client. For example, if
  21536. your account has a query limit of 50, you cannot increase your limit to
  21537. 100 by making two simultaneous client connections to the server.
  21538. Queries issued on both connections are counted together.
  21539.  
  21540. The current resource-use counts can be reset globally for all accounts,
  21541. or individually for a given count:
  21542.  
  21543.    * To reset the current counts to zero for all accounts, issue a
  21544.      `FLUSH USER_RESOURCES' statement. The counts also can be reset by
  21545.      reloading the grant tables (for example, with a `FLUSH PRIVILEGES'
  21546.      statement or a `mysqladmin reload' command).
  21547.  
  21548.    * The counts for an individual account can be set to zero by
  21549.      re-granting it any of its limits. To do this, use `GRANT USAGE' as
  21550.      described earlier and specify a limit value equal to the value
  21551.      that the account already has.
  21552.  
  21553.  
  21554. Assigning Account Passwords
  21555. ---------------------------
  21556.  
  21557. Passwords may be assigned from the command line by using the
  21558. `mysqladmin' command:
  21559.  
  21560.      shell> mysqladmin -u USER_NAME -h HOST_NAME password "NEWPWD"
  21561.  
  21562. The account for which this command resets the password is the one with a
  21563. `user' table record that matches USER_NAME in the `User' column and the
  21564. client host _from which you connect_ in the `Host' column.
  21565.  
  21566. Another way to assign a password to an account is to issue a `SET
  21567. PASSWORD' statement:
  21568.  
  21569.      mysql> SET PASSWORD FOR 'jeffrey'@'%' = PASSWORD('biscuit');
  21570.  
  21571. Only users such as `root' with update access to the `mysql' database
  21572. can change the password for other users.  If you are not connected as
  21573. an anonymous user, you can change your own password by omitting the
  21574. `FOR' clause:
  21575.  
  21576.      mysql> SET PASSWORD = PASSWORD('biscuit');
  21577.  
  21578. You can also use a `GRANT USAGE' statement at the global level (`ON
  21579. *.*') to assign a password to an account without affecting the
  21580. account's current privileges:
  21581.  
  21582.      mysql> GRANT USAGE ON *.* TO 'jeffrey'@'%' IDENTIFIED BY 'biscuit';
  21583.  
  21584. Although it is generally preferable to assign passwords using one of the
  21585. preceding methods, you can also do so by modifying the `user' table
  21586. directly:
  21587.  
  21588.    * To establish a password when creating a new account, provide a
  21589.      value for the `Password' column:
  21590.  
  21591.           shell> mysql -u root mysql
  21592.           mysql> INSERT INTO user (Host,User,Password)
  21593.               -> VALUES('%','jeffrey',PASSWORD('biscuit'));
  21594.           mysql> FLUSH PRIVILEGES;
  21595.  
  21596.    * To change the password for an existing account, use `UPDATE' to
  21597.      set the `Password' column value:
  21598.  
  21599.           shell> mysql -u root mysql
  21600.           mysql> UPDATE user SET Password = PASSWORD('bagel')
  21601.               -> WHERE Host = '%' AND User = 'francis';
  21602.           mysql> FLUSH PRIVILEGES;
  21603.  
  21604.  
  21605. When you assign an account a password using `SET PASSWORD', `INSERT',
  21606. or `UPDATE', you must use the `PASSWORD()' function to encrypt it.
  21607. (The only exception is that you need not use `PASSWORD()' if the
  21608. password is empty.) `PASSWORD()' is necessary because the `user' table
  21609. stores passwords in encrypted form, not as plaintext.  If you forget
  21610. that fact, you are likely to set passwords like this:
  21611.  
  21612.      shell> mysql -u root mysql
  21613.      mysql> INSERT INTO user (Host,User,Password)
  21614.          -> VALUES('%','jeffrey','biscuit');
  21615.      mysql> FLUSH PRIVILEGES;
  21616.  
  21617. The result is that the literal value `'biscuit'' is stored as the
  21618. password in the `user' table, not the encrypted value.  When `jeffrey'
  21619. attempts to connect to the server using this password, the value is
  21620. encrypted and compared to the value stored in the `user' table.
  21621. However, the stored value is the literal string `'biscuit'', so the
  21622. comparison fails and the server rejects the connection:
  21623.  
  21624.      shell> mysql -u jeffrey -pbiscuit test
  21625.      Access denied
  21626.  
  21627. If you set passwords using the `GRANT ... IDENTIFIED BY' statement or
  21628. the `mysqladmin password' command, they both take care of encrypting
  21629. the password for you.  The `PASSWORD()' function is unnecessary.
  21630.  
  21631. *Note*: `PASSWORD()' encryption is different from Unix password
  21632. encryption.  *Note User names::.
  21633.  
  21634. Keeping Your Password Secure
  21635. ----------------------------
  21636.  
  21637. On an administrative level, you should never grant access to the
  21638. `mysql.user' table to any non-administrative accounts. Passwords in the
  21639. `user' table are stored in encrypted form, but in versions of MySQL
  21640. earlier than 4.1, knowing the encrypted password for an account makes it
  21641. possible to connect to the server using that account.
  21642.  
  21643. When you run a client program to connect to the MySQL server, it is
  21644. inadvisable to specify your password in a way that exposes it to
  21645. discovery by other users.  The methods you can use to specify your
  21646. password when you run client programs are listed here, along with an
  21647. assessment of the risks of each method:
  21648.  
  21649.    * Use a `-pYOUR_PASS' or `--password=YOUR_PASS' option on the command
  21650.      line.  For example:
  21651.  
  21652.           shell> mysql -u francis -pfrank DB_NAME
  21653.  
  21654.      This is convenient but insecure, because your password becomes
  21655.      visible to system status programs such as `ps' that may be invoked
  21656.      by other users to display command lines.  MySQL clients typically
  21657.      overwrite the command-line password argument with zeros during
  21658.      their initialization sequence, but there is still a brief interval
  21659.      during which the value is visible.
  21660.  
  21661.    * Use a `-p' or `--password' option with no password value
  21662.      specified.  In this case, the client program solicits the password
  21663.      from the terminal:
  21664.  
  21665.           shell> mysql -u francis -p DB_NAME
  21666.           Enter password: ********
  21667.  
  21668.      The `*' characters indicate where you enter your password. The
  21669.      password is not displayed as you enter it.
  21670.  
  21671.      It is more secure to enter your password this way than to specify
  21672.      it on the command line because it is not visible to other users.
  21673.      However, this method of entering a password is suitable only for
  21674.      programs that you run interactively.  If you want to invoke a
  21675.      client from a script that runs non-interactively, there is no
  21676.      opportunity to enter the password from the terminal. On some
  21677.      systems, you may even find that the first line of your script is
  21678.      read and interpreted (incorrectly) as your password!
  21679.  
  21680.    * Store your password in an option file.  For example, on Unix you
  21681.      can list your password in the `[client]' section of the `.my.cnf'
  21682.      file in your home directory:
  21683.  
  21684.           [client]
  21685.           password=your_pass
  21686.  
  21687.      If you store your password in `.my.cnf', the file should not be
  21688.      accessible to anyone but yourself. To ensure this, set the file
  21689.      access mode to `400' or `600'. For example:
  21690.  
  21691.           shell> chmod 600 .my.cnf
  21692.  
  21693.      *Note Option files:: discusses option files in more detail.
  21694.  
  21695.    * Store your password in the `MYSQL_PWD' environment variable.  This
  21696.      method of specifying your MySQL password must be considered
  21697.      extremely insecure and should not be used.  Some versions of `ps'
  21698.      include an option to display the environment of running processes.
  21699.      If you set `MYSQL_PWD', your password will be exposed to any other
  21700.      user who runs `ps'.  Even on systems without such a version of
  21701.      `ps', it is unwise to assume that there are no other methods by
  21702.      which users can examine process environments.  *Note Environment
  21703.      variables::.
  21704.  
  21705.  
  21706. All in all, the safest methods are to have the client program prompt
  21707. for the password or to specify the password in a properly protected
  21708. option file.
  21709.  
  21710. Using Secure Connections
  21711. ------------------------
  21712.  
  21713. Beginning with version 4.0.0, MySQL has support for secure (encrypted)
  21714. connections between MySQL clients and the server using the Secure
  21715. Sockets Layer (SSL) protocol.  This section discusses how to use SSL
  21716. connections.  It also describes a way to set up SSH on Windows.
  21717.  
  21718. The standard configuration of MySQL is intended to be as fast as
  21719. possible, so encrypted connections are not used by default.  Doing so
  21720. would make the client/server protocol much slower.  Encrypting data is
  21721. a CPU-intensive operation that requires the computer to do additional
  21722. work and can delay other MySQL tasks.  For applications that require
  21723. the security provided by encrypted connections, the extra computation
  21724. is warranted.
  21725.  
  21726. MySQL allows encryption to be enabled on a per-connection basis. You can
  21727. choose a normal unencrypted connection or a secure encrypted SSL
  21728. connection according the requirements of individual applications.
  21729.  
  21730. Basic SSL Concepts
  21731. ..................
  21732.  
  21733. To understand how MySQL uses SSL, it's necessary to explain some basic
  21734. SSL and X509 concepts. People who are already familiar with them can
  21735. skip this part.
  21736.  
  21737. By default, MySQL uses unencrypted connections between the client and
  21738. the server. This means that someone with access to the network could
  21739. watch all your traffic and look at the data being sent or received.
  21740. They could even change the data while it is in transit between client
  21741. and server. To improve security a little, you can compress
  21742. client/server traffic by using the `--compress' option when invoking
  21743. client programs.  However, this will not foil a determined attacker.
  21744.  
  21745. When you need to move information over a network in a secure fashion,
  21746. an unencrypted connection is unacceptable.  Encryption is the way to
  21747. make any kind of data unreadable. In fact, today's practice requires
  21748. many additional security elements from encryption algorithms.  They
  21749. should resist many kind of known attacks such as changing the order of
  21750. encrypted messages or replaying data twice.
  21751.  
  21752. SSL is a protocol that uses different encryption algorithms to ensure
  21753. that data received over a public network can be trusted. It has
  21754. mechanisms to detect any data change, loss, or replay. SSL also
  21755. incorporates algorithms that provide identity verification using the
  21756. X509 standard.
  21757.  
  21758. X509 makes it possible to identify someone on the Internet.  It is most
  21759. commonly used in e-commerce applications. In basic terms, there should
  21760. be some company called a "Certificate Authority" (or CA) that assigns
  21761. electronic certificates to anyone who needs them. Certificates rely on
  21762. asymmetric encryption algorithms that have two encryption keys (a
  21763. public key and a secret key). A certificate owner can show the
  21764. certificate to another party as proof of identity. A certificate
  21765. consists of its owner's public key. Any data encrypted with this public
  21766. key can be decrypted only using the corresponding secret key, which is
  21767. held by the owner of the certificate.
  21768.  
  21769. If you need more information about SSL, X509, or encryption, use your
  21770. favorite Internet search engine to search for keywords in which you are
  21771. interested.
  21772.  
  21773. Requirements
  21774. ............
  21775.  
  21776. To use SSL connections between the MySQL server and client programs,
  21777. your system must be able to support OpenSSL and your version of MySQL
  21778. must be 4.0.0 or newer.
  21779.  
  21780. To get secure connections to work with MySQL, you must do the following:
  21781.  
  21782.   1. Install the OpenSSL library. We have tested MySQL with OpenSSL
  21783.      0.9.6.  If you need OpenSSL, visit `http://www.openssl.org'.
  21784.  
  21785.   2. When you configure MySQL, run the `configure' script with the
  21786.      `--with-vio' and `--with-openssl' options.
  21787.  
  21788.   3. Make sure that you have upgraded your grant tables to include the
  21789.      SSL-related columns in the `mysql.user' table.  This is necessary
  21790.      if your grant tables date from a version prior to MySQL 4.0.0.
  21791.      The upgrade procedure is described in *Note
  21792.      Upgrading-grant-tables::.
  21793.  
  21794.   4. To check whether a running `mysqld' server supports OpenSSL,
  21795.      examine the value of the `have_openssl' system variable:
  21796.  
  21797.           mysql> SHOW VARIABLES LIKE 'have_openssl';
  21798.           +---------------+-------+
  21799.           | Variable_name | Value |
  21800.           +---------------+-------+
  21801.           | have_openssl  | YES   |
  21802.           +---------------+-------+
  21803.  
  21804.      If the value is `YES', the server supports OpenSSL connections.
  21805.  
  21806. Setting Up SSL Certificates for MySQL
  21807. .....................................
  21808.  
  21809. Here is an example for setting up SSL certificates for MySQL:
  21810.  
  21811.      DIR=`pwd`/openssl
  21812.      PRIV=$DIR/private
  21813.      
  21814.      mkdir $DIR $PRIV $DIR/newcerts
  21815.      cp /usr/share/ssl/openssl.cnf $DIR
  21816.      replace ./demoCA $DIR -- $DIR/openssl.cnf
  21817.      
  21818.      # Create necessary files: $database, $serial and $new_certs_dir
  21819.      # directory (optional)
  21820.      
  21821.      touch $DIR/index.txt
  21822.      echo "01" > $DIR/serial
  21823.      
  21824.      #
  21825.      # Generation of Certificate Authority(CA)
  21826.      #
  21827.      
  21828.      openssl req -new -x509 -keyout $PRIV/cakey.pem -out $DIR/cacert.pem \
  21829.          -config $DIR/openssl.cnf
  21830.      
  21831.      # Sample output:
  21832.      # Using configuration from /home/monty/openssl/openssl.cnf
  21833.      # Generating a 1024 bit RSA private key
  21834.      # ................++++++
  21835.      # .........++++++
  21836.      # writing new private key to '/home/monty/openssl/private/cakey.pem'
  21837.      # Enter PEM pass phrase:
  21838.      # Verifying password - Enter PEM pass phrase:
  21839.      # -----
  21840.      # You are about to be asked to enter information that will be
  21841.      # incorporated into your certificate request.
  21842.      # What you are about to enter is what is called a Distinguished Name
  21843.      # or a DN.
  21844.      # There are quite a few fields but you can leave some blank
  21845.      # For some fields there will be a default value,
  21846.      # If you enter '.', the field will be left blank.
  21847.      # -----
  21848.      # Country Name (2 letter code) [AU]:FI
  21849.      # State or Province Name (full name) [Some-State]:.
  21850.      # Locality Name (eg, city) []:
  21851.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  21852.      # Organizational Unit Name (eg, section) []:
  21853.      # Common Name (eg, YOUR name) []:MySQL admin
  21854.      # Email Address []:
  21855.      
  21856.      #
  21857.      # Create server request and key
  21858.      #
  21859.      openssl req -new -keyout $DIR/server-key.pem -out \
  21860.          $DIR/server-req.pem -days 3600 -config $DIR/openssl.cnf
  21861.      
  21862.      # Sample output:
  21863.      # Using configuration from /home/monty/openssl/openssl.cnf
  21864.      # Generating a 1024 bit RSA private key
  21865.      # ..++++++
  21866.      # ..........++++++
  21867.      # writing new private key to '/home/monty/openssl/server-key.pem'
  21868.      # Enter PEM pass phrase:
  21869.      # Verifying password - Enter PEM pass phrase:
  21870.      # -----
  21871.      # You are about to be asked to enter information that will be
  21872.      # incorporated into your certificate request.
  21873.      # What you are about to enter is what is called a Distinguished Name
  21874.      # or a DN.
  21875.      # There are quite a few fields but you can leave some blank
  21876.      # For some fields there will be a default value,
  21877.      # If you enter '.', the field will be left blank.
  21878.      # -----
  21879.      # Country Name (2 letter code) [AU]:FI
  21880.      # State or Province Name (full name) [Some-State]:.
  21881.      # Locality Name (eg, city) []:
  21882.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  21883.      # Organizational Unit Name (eg, section) []:
  21884.      # Common Name (eg, YOUR name) []:MySQL server
  21885.      # Email Address []:
  21886.      #
  21887.      # Please enter the following 'extra' attributes
  21888.      # to be sent with your certificate request
  21889.      # A challenge password []:
  21890.      # An optional company name []:
  21891.      
  21892.      #
  21893.      # Remove the passphrase from the key (optional)
  21894.      #
  21895.      
  21896.      openssl rsa -in $DIR/server-key.pem -out $DIR/server-key.pem
  21897.      
  21898.      #
  21899.      # Sign server cert
  21900.      #
  21901.      openssl ca  -policy policy_anything -out $DIR/server-cert.pem \
  21902.          -config $DIR/openssl.cnf -infiles $DIR/server-req.pem
  21903.      
  21904.      # Sample output:
  21905.      # Using configuration from /home/monty/openssl/openssl.cnf
  21906.      # Enter PEM pass phrase:
  21907.      # Check that the request matches the signature
  21908.      # Signature ok
  21909.      # The Subjects Distinguished Name is as follows
  21910.      # countryName           :PRINTABLE:'FI'
  21911.      # organizationName      :PRINTABLE:'MySQL AB'
  21912.      # commonName            :PRINTABLE:'MySQL admin'
  21913.      # Certificate is to be certified until Sep 13 14:22:46 2003 GMT
  21914.      # (365 days)
  21915.      # Sign the certificate? [y/n]:y
  21916.      #
  21917.      #
  21918.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  21919.      # Write out database with 1 new entries
  21920.      # Data Base Updated
  21921.      
  21922.      #
  21923.      # Create client request and key
  21924.      #
  21925.      openssl req -new -keyout $DIR/client-key.pem -out \
  21926.          $DIR/client-req.pem -days 3600 -config $DIR/openssl.cnf
  21927.      
  21928.      # Sample output:
  21929.      # Using configuration from /home/monty/openssl/openssl.cnf
  21930.      # Generating a 1024 bit RSA private key
  21931.      # .....................................++++++
  21932.      # .............................................++++++
  21933.      # writing new private key to '/home/monty/openssl/client-key.pem'
  21934.      # Enter PEM pass phrase:
  21935.      # Verifying password - Enter PEM pass phrase:
  21936.      # -----
  21937.      # You are about to be asked to enter information that will be
  21938.      # incorporated into your certificate request.
  21939.      # What you are about to enter is what is called a Distinguished Name
  21940.      # or a DN.
  21941.      # There are quite a few fields but you can leave some blank
  21942.      # For some fields there will be a default value,
  21943.      # If you enter '.', the field will be left blank.
  21944.      # -----
  21945.      # Country Name (2 letter code) [AU]:FI
  21946.      # State or Province Name (full name) [Some-State]:.
  21947.      # Locality Name (eg, city) []:
  21948.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  21949.      # Organizational Unit Name (eg, section) []:
  21950.      # Common Name (eg, YOUR name) []:MySQL user
  21951.      # Email Address []:
  21952.      #
  21953.      # Please enter the following 'extra' attributes
  21954.      # to be sent with your certificate request
  21955.      # A challenge password []:
  21956.      # An optional company name []:
  21957.      
  21958.      #
  21959.      # Remove a passphrase from the key (optional)
  21960.      #
  21961.      openssl rsa -in $DIR/client-key.pem -out $DIR/client-key.pem
  21962.      
  21963.      #
  21964.      # Sign client cert
  21965.      #
  21966.      
  21967.      openssl ca  -policy policy_anything -out $DIR/client-cert.pem \
  21968.          -config $DIR/openssl.cnf -infiles $DIR/client-req.pem
  21969.      
  21970.      # Sample output:
  21971.      # Using configuration from /home/monty/openssl/openssl.cnf
  21972.      # Enter PEM pass phrase:
  21973.      # Check that the request matches the signature
  21974.      # Signature ok
  21975.      # The Subjects Distinguished Name is as follows
  21976.      # countryName           :PRINTABLE:'FI'
  21977.      # organizationName      :PRINTABLE:'MySQL AB'
  21978.      # commonName            :PRINTABLE:'MySQL user'
  21979.      # Certificate is to be certified until Sep 13 16:45:17 2003 GMT
  21980.      # (365 days)
  21981.      # Sign the certificate? [y/n]:y
  21982.      #
  21983.      #
  21984.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  21985.      # Write out database with 1 new entries
  21986.      # Data Base Updated
  21987.      
  21988.      #
  21989.      # Create a my.cnf file that you can use to test the certificates
  21990.      #
  21991.      
  21992.      cnf=""
  21993.      cnf="$cnf [client]"
  21994.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  21995.      cnf="$cnf ssl-cert=$DIR/client-cert.pem"
  21996.      cnf="$cnf ssl-key=$DIR/client-key.pem"
  21997.      cnf="$cnf [mysqld]"
  21998.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  21999.      cnf="$cnf ssl-cert=$DIR/server-cert.pem"
  22000.      cnf="$cnf ssl-key=$DIR/server-key.pem"
  22001.      echo $cnf | replace " " '
  22002.      ' > $DIR/my.cnf
  22003.  
  22004. To test SSL connections, start the server as follows, where `$DIR' is
  22005. the pathname to the directory where the sample `my.cnf' option file is
  22006. located:
  22007.  
  22008.      shell> mysqld --defaults-file=$DIR/my.cnf &
  22009.  
  22010. Then invoke a client program using the same option file:
  22011.  
  22012.      shell> mysql --defaults-file=$DIR/my.cnf
  22013.  
  22014. If you have a MySQL source distribution, you can also test your setup by
  22015. modifying the preceding `my.cnf' file to refer to the demonstration
  22016. certificate and key files in the `SSL' directory of the distribution.
  22017.  
  22018. SSL `GRANT' Options
  22019. ...................
  22020.  
  22021. MySQL can check X509 certificate attributes in addition to the usual
  22022. authentication that is based on the username and password.  To specify
  22023. SSL-related options for a MySQL account, use the `REQUIRE' clause of
  22024. the `GRANT' statement.  *Note `GRANT': GRANT.
  22025.  
  22026. There are different possibilities for limiting connection types for an
  22027. account:
  22028.  
  22029.    * If an account has no SSL or X509 requirements, unencrypted
  22030.      connections are allowed if the username and password are valid.
  22031.      However, encrypted connections also can be used at the client's
  22032.      option, if the client has the proper certificate and key files.
  22033.  
  22034.    * `REQUIRE SSL' option limits the server to allow only SSL encrypted
  22035.      connections for the account. Note that this option can be omitted
  22036.      if there are any ACL records that allow non-SSL connections.
  22037.  
  22038.           mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
  22039.               -> IDENTIFIED BY 'goodsecret' REQUIRE SSL;
  22040.  
  22041.    * `REQUIRE X509' means that the client must have a valid certificate
  22042.      but that the exact certificate, issuer, and subject do not matter.
  22043.      The only requirement is that it should be possible to verify its
  22044.      signature with one of the CA certificates.
  22045.  
  22046.           mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
  22047.               -> IDENTIFIED BY 'goodsecret' REQUIRE X509;
  22048.  
  22049.    * `REQUIRE ISSUER 'issuer'' places the restriction on connection
  22050.      attempts that the client must present a valid X509 certificate
  22051.      issued by CA `'issuer''.  If the client presents a certificate
  22052.      that is valid but has a different issuer, the server rejects the
  22053.      connection.  Use of X509 certificates always implies encryption,
  22054.      so the `SSL' option is unneccessary.
  22055.  
  22056.           mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
  22057.               -> IDENTIFIED BY 'goodsecret'
  22058.               -> REQUIRE ISSUER '/C=FI/ST=Some-State/L=Helsinki/
  22059.                  O=MySQL Finland AB/CN=Tonu Samuel/Email=tonu@example.com';
  22060.  
  22061.      Note that the `ISSUER' value should be entered as a single string.
  22062.  
  22063.    * `REQUIRE SUBJECT 'subject'' places the restriction on connection
  22064.      attempts that the client must present a valid X509 certificate
  22065.      with subject `'subject'' on it.  If the client presents a
  22066.      certificate that is valid but has a different subject, the server
  22067.      rejects the connection.
  22068.  
  22069.           mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
  22070.               -> IDENTIFIED BY 'goodsecret'
  22071.               -> REQUIRE SUBJECT '/C=EE/ST=Some-State/L=Tallinn/
  22072.                  O=MySQL demo client certificate/
  22073.                  CN=Tonu Samuel/Email=tonu@example.com';
  22074.  
  22075.      Note that the `SUBJECT' value should be entered as a single string.
  22076.  
  22077.    * `REQUIRE CIPHER 'cipher'' is needed to ensure that strong enough
  22078.      ciphers and key lengths will be used. SSL itself can be weak if
  22079.      old algorithms with short encryption keys are used. Using this
  22080.      option, we can ask for some exact cipher method to allow a
  22081.      connection.
  22082.  
  22083.           mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
  22084.               -> IDENTIFIED BY 'goodsecret'
  22085.               -> REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA';
  22086.  
  22087.  
  22088. The `SUBJECT', `ISSUER', and `CIPHER' options can be combined in the
  22089. `REQUIRE' clause like this:
  22090.  
  22091.      mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
  22092.          -> IDENTIFIED BY 'goodsecret'
  22093.          -> REQUIRE SUBJECT '/C=EE/ST=Some-State/L=Tallinn/
  22094.             O=MySQL demo client certificate/
  22095.             CN=Tonu Samuel/Email=tonu@example.com'
  22096.          -> AND ISSUER '/C=FI/ST=Some-State/L=Helsinki/
  22097.             O=MySQL Finland AB/CN=Tonu Samuel/Email=tonu@example.com'
  22098.          -> AND CIPHER 'EDH-RSA-DES-CBC3-SHA';
  22099.  
  22100. Note that the `SUBJECT' and `ISSUER' values each should be entered as a
  22101. single string.
  22102.  
  22103. Starting from MySQL 4.0.4, the `AND' keyword is optional between
  22104. `REQUIRE' options.
  22105.  
  22106. The order of the options does not matter, but no option can be specified
  22107. twice.
  22108.  
  22109. SSL Command-Line Options
  22110. ........................
  22111.  
  22112. The following list describes options that are used for specifying the
  22113. use of SSL, certificate files, and key files.  These options are
  22114. available beginning with MySQL 4.0. They may be given on the command
  22115. line or in an option file.
  22116.  
  22117. `--ssl'
  22118.      For the server, this option specifies that the server allows SSL
  22119.      connections.  For a client program, it allows the client to
  22120.      connect to the server using SSL.  This option is not sufficient in
  22121.      itself to cause an SSL connection to be used.  You must also
  22122.      specify the `--ssl-ca', `--ssl-cert', and `--ssl-key' options.
  22123.  
  22124.      This option is more often used in its opposite form to indicate
  22125.      that SSL should _not_ be used. To do this, specify the option as
  22126.      `--skip-ssl' or `--ssl=0'.
  22127.  
  22128.      Note that use of `--ssl' doesn't _require_ an SSL connection.  For
  22129.      example, if the server or client is compiled without SSL support,
  22130.      a normal unencrypted connection will be used.
  22131.  
  22132.      The secure way to ensure that an SSL connection will be used is to
  22133.      create an account on the server that includes a `REQUIRE SSL'
  22134.      clause in the `GRANT' statement.  Then use this account to connect
  22135.      to the server, with both a server and client that have SSL support
  22136.      enabled.
  22137.  
  22138. `--ssl-ca=FILE_NAME'
  22139.      The path to a file with a list of trusted SSL CAs.
  22140.  
  22141. `--ssl-capath=DIRECTORY_NAME'
  22142.      The path to a directory that contains trusted SSL CA certificates
  22143.      in pem format.
  22144.  
  22145. `--ssl-cert=FILE_NAME'
  22146.      The name of the SSL certificate file to use for establishing a
  22147.      secure connection.
  22148.  
  22149. `--ssl-cipher=CIPHER_LIST'
  22150.      A list of allowable ciphers to use for SSL encryption.
  22151.      CIPHER_LIST has the same format as the `openssl ciphers' command.
  22152.  
  22153.      Example: `--ssl-cipher=ALL:-AES:-EXP'
  22154.  
  22155. `--ssl-key=FILE_NAME'
  22156.      The name of the SSL key file to use for establishing a secure
  22157.      connection.
  22158.  
  22159. Connecting to MySQL Remotely from Windows with SSH
  22160. ..................................................
  22161.  
  22162. Here is a note about how to connect to get a secure connection to remote
  22163. MySQL server with SSH (by David Carlson <dcarlson@mplcomm.com>):
  22164.  
  22165.   1. Install an SSH client on your Windows machine.  As a user, the
  22166.      best non-free one I've found is from `SecureCRT' from
  22167.      `http://www.vandyke.com/'.  Another option is `f-secure' from
  22168.      `http://www.f-secure.com/'. You can also find some free ones on
  22169.      `Google' at
  22170.      `http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cryptography/SSH/Clients/Windows/'.
  22171.  
  22172.   2. Start your Windows SSH client.  Set `Host_Name =
  22173.      yourmysqlserver_URL_or_IP'.  Set `userid=your_userid' to log in to
  22174.      your server. This `userid' value may not be the same as the
  22175.      username of your MySQL account.
  22176.  
  22177.   3. Set up port forwarding. Either do a remote forward (Set
  22178.      `local_port: 3306', `remote_host: yourmysqlservername_or_ip',
  22179.      `remote_port: 3306' ) or a local forward (Set `port: 3306',
  22180.      `host: localhost', `remote port: 3306').
  22181.  
  22182.   4. Save everything, otherwise you'll have to redo it the next time.
  22183.  
  22184.   5. Log in to your server with the SSH session you just created.
  22185.  
  22186.   6. On your Windows machine, start some ODBC application (such as
  22187.      Access).
  22188.  
  22189.   7. Create a new file in Windows and link to MySQL using the ODBC
  22190.      driver the same way you normally do, except type in `localhost'
  22191.      for the MySQL host server, not `yourmysqlservername'.
  22192.  
  22193. You should now have an ODBC connection to MySQL, encrypted using SSH.
  22194.  
  22195. Disaster Prevention and Recovery
  22196. ================================
  22197.  
  22198. This section discusses how to make database backups and how to perform
  22199. table maintenance.  The syntax of the SQL statements described here is
  22200. given in *Note Database Administration::.  Much of the information here
  22201. pertains primarily to `MyISAM' tables.  `InnoDB' backup procedures are
  22202. given in *Note Backing up::.
  22203.  
  22204. Database Backups
  22205. ----------------
  22206.  
  22207. Because MySQL tables are stored as files, it is easy to do a backup. To
  22208. get a consistent backup, do a `LOCK TABLES' on the relevant tables,
  22209. followed by `FLUSH TABLES' for the tables.  See *Note `LOCK TABLES':
  22210. LOCK TABLES and *Note `FLUSH': FLUSH.  You need only a read lock; this
  22211. allows other clients to continue to query the tables while you are
  22212. making a copy of the files in the database directory.  The `FLUSH
  22213. TABLES' statement is needed to ensure that the all active index pages
  22214. are written to disk before you start the backup.
  22215.  
  22216. If you want to make an SQL-level backup of a table, you can use `SELECT
  22217. INTO ... OUTFILE' or `BACKUP TABLE'.  For `SELECT INTO ... OUTFILE',
  22218. the output file cannot already exist.  For `BACKUP TABLE', the same is
  22219. true as of MySQL 3.23.56 and 4.0.12, because this would be a security
  22220. risk.  See *Note `SELECT': SELECT and *Note `BACKUP TABLE': BACKUP
  22221. TABLE.
  22222.  
  22223. Another way to back up a database is to use the `mysqldump' program or
  22224. the `mysqlhotcopy script'.  See *Note `mysqldump': mysqldump and *Note
  22225. `mysqlhotcopy': mysqlhotcopy.
  22226.  
  22227.   1. Do a full backup of your database:
  22228.  
  22229.           shell> mysqldump --tab=/PATH/TO/SOME/DIR --opt DB_NAME
  22230.  
  22231.      Or:
  22232.  
  22233.           shell> mysqlhotcopy DB_NAME /PATH/TO/SOME/DIR
  22234.  
  22235.      You can also simply copy all table files (`*.frm', `*.MYD', and
  22236.      `*.MYI' files) as long as the server isn't updating anything.  The
  22237.      `mysqlhotcopy' script uses this method.  (But note that these
  22238.      methods will not work if your database contains `InnoDB' tables.
  22239.      `InnoDB' does not store table contents in database directories,
  22240.      and `mysqlhotcopy' works only for `MyISAM' and `ISAM' tables.)
  22241.  
  22242.   2. Stop `mysqld' if it's running, then start it with the
  22243.      `--log-bin[=file_name]' option.  *Note Binary log::. The binary
  22244.      log files provide you with the information you need to replicate
  22245.      changes to the database that are made subsequent to the point at
  22246.      which you executed `mysqldump'.
  22247.  
  22248. If your MySQL server is a slave replication server, then regardless of
  22249. the backup method you choose, you should also back up the `master.info'
  22250. and `relay-log.info' files when you back up your slave's data. These
  22251. files are always needed to resume replication after you restore the
  22252. slave's data. If your slave is subject to replicating `LOAD DATA
  22253. INFILE' commands, you should also back up any `SQL_LOAD-*' files that
  22254. may exist in the directory specified by the `--slave-load-tmpdir'
  22255. option. (This location defaults to the value of the `tmpdir' variable
  22256. if not specified.) The slave needs these files to resume replication of
  22257. any interrupted `LOAD DATA INFILE' operations.
  22258.  
  22259. If you have to restore `MyISAM' tables, try to recover them using
  22260. `REPAIR TABLE' or `myisamchk -r' first.  That should work in 99.9% of
  22261. all cases.  If `myisamchk' fails, try the following procedure.  Note
  22262. that it will work only if you have enabled binary logging by starting
  22263. MySQL with the `--log-bin' option; see *Note Binary log::.
  22264.  
  22265.   1. Restore the original `mysqldump' backup, or binary backup.
  22266.  
  22267.   2. Execute the following command to re-run the updates in the binary
  22268.      logs:
  22269.  
  22270.           shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  22271.  
  22272.      In your case, you may want to re-run only certain binary logs, from
  22273.      certain positions (usually you want to re-run all binary logs from
  22274.      the date of the restored backup, excepting possibly some incorrect
  22275.      queries).  See *Note `mysqlbinlog': mysqlbinlog for more
  22276.      information on the `mysqlbinlog' utility and how to use it.
  22277.  
  22278.      If you are using the update logs instead, you can process their
  22279.      contents like this:
  22280.  
  22281.           shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql
  22282.  
  22283.      `ls' is used to sort the update log filenames into the right order.
  22284.  
  22285.  
  22286. You can also do selective backups of individual files:
  22287.  
  22288.    * To dump the table, use `SELECT * INTO OUTFILE 'FILE_NAME' FROM
  22289.      TBL_NAME'.
  22290.  
  22291.    * To reload the table, use and restore with `LOAD DATA INFILE
  22292.      'file_name' REPLACE ...' To avoid duplicate records, the table
  22293.      must have a `PRIMARY KEY' or a `UNIQUE' index. The `REPLACE'
  22294.      keyword causes old records to be replaced with new ones when a new
  22295.      record duplicates an old record on a unique key value.
  22296.  
  22297.  
  22298. If you have performance problems with your server while making backups,
  22299. one strategy that can help is to set up replication and perform backups
  22300. on the slave rather than on the master.  *Note Replication Intro::.
  22301.  
  22302. If you are using a Veritas filesystem, you can make a backup like this:
  22303.  
  22304.   1. From a client program, execute `FLUSH TABLES WITH READ LOCK'.
  22305.  
  22306.   2. From another shell, execute `mount vxfs snapshot'.
  22307.  
  22308.   3. From the first client, execute `UNLOCK TABLES'.
  22309.  
  22310.   4. Copy files from the snapshot.
  22311.  
  22312.   5. Unmount the snapshot.
  22313.  
  22314. Table Maintenance and Crash Recovery
  22315. ------------------------------------
  22316.  
  22317. The following text discusses how to use `myisamchk' to check or repair
  22318. `MyISAM' tables (tables with `.MYI' and `.MYD' files).  The same
  22319. concepts apply to using `isamchk' to check or repair `ISAM' tables
  22320. (tables with `.ISM' and `.ISD' files).  *Note Table types::.
  22321.  
  22322. You can use the `myisamchk' utility to get information about your
  22323. database tables or to check, repair, or optimize them.  The following
  22324. sections describe how to invoke `myisamchk' (including a description of
  22325. its options), how to set up a table maintenance schedule, and how to
  22326. use `myisamchk' to perform its various functions.
  22327.  
  22328. Even though table repair with `myisamchk' is quite secure, it's always
  22329. a good idea to make a backup _before_ doing a repair (or any
  22330. maintenance operation that could make a lot of changes to a table)
  22331.  
  22332. `myisamchk' operations that affect indexes can cause `FULLTEXT' indexes
  22333. to be rebuilt with full-text parameters that are incompatible with the
  22334. values used by the MySQL server. To avoid this, read the instructions in
  22335. *Note `myisamchk' general options: myisamchk general options.
  22336.  
  22337. In many cases, you may find it simpler to do `MyISAM' table maintenance
  22338. using the SQL statements that perform operations that `myisamchk' can
  22339. do:
  22340.  
  22341.    * To check or repair `MyISAM' tables, use `CHECK TABLE' or `REPAIR
  22342.      TABLE'.
  22343.  
  22344.    * To optimize `MyISAM' tables, use `OPTIMIZE TABLE'.
  22345.  
  22346.    * To analyze `MyISAM' tables, use `ANALYZE TABLE'.
  22347.  
  22348.  
  22349. These statements were introduced in different versions, but all are
  22350. available from MySQL 3.23.14 on.  See *Note `ANALYZE TABLE': ANALYZE
  22351. TABLE, *Note `CHECK TABLE': CHECK TABLE, *Note `OPTIMIZE TABLE':
  22352. OPTIMIZE TABLE, and *Note `REPAIR TABLE': REPAIR TABLE.  The statements
  22353. can be used directly, or by means of the `mysqlcheck' client program,
  22354. which provides a command-line interface to them.
  22355.  
  22356. One advantage of these statements over `myisamchk' is that the server
  22357. does all the work. With `myisamchk', you must make sure that the server
  22358. does not use the tables at the same time. Otherwise, there can be
  22359. unwanted interaction betweeen `myisamchk' and the server.
  22360.  
  22361. `myisamchk' Invocation Syntax
  22362. .............................
  22363.  
  22364. Invoke `myisamchk' like this:
  22365.  
  22366.      shell> myisamchk [OPTIONS] TBL_NAME
  22367.  
  22368. The OPTIONS specify what you want `myisamchk' to do.  They are
  22369. described in the following sections.  You can also get a list of
  22370. options by invoking `myisamchk --help'.
  22371.  
  22372. With no options, `myisamchk' simply checks your table as the default
  22373. operation.  To get more information or to tell `myisamchk' to take
  22374. corrective action, specify options as described in the following
  22375. discussion.
  22376.  
  22377. TBL_NAME is the database table you want to check or repair.  If you run
  22378. `myisamchk' somewhere other than in the database directory, you must
  22379. specify the path to the database directory, because `myisamchk' has no
  22380. idea where the database is located.  In fact, `myisamchk' doesn't
  22381. actually care whether the files you are working on are located in a
  22382. database directory. You can copy the files that correspond to a
  22383. database table into some other location and perform recovery operations
  22384. on them there.
  22385.  
  22386. You can name several tables on the `myisamchk' command line if you
  22387. wish.  You can also specify a table by naming its index file (the file
  22388. with the `.MYI' suffix). This allows you to specify all tables in a
  22389. directory by using the pattern `*.MYI'.  For example, if you are in a
  22390. database directory, you can check all the `MyISAM' tables in that
  22391. directory like this:
  22392.  
  22393.      shell> myisamchk *.MYI
  22394.  
  22395. If you are not in the database directory, you can check all the tables
  22396. there by specifying the path to the directory:
  22397.  
  22398.      shell> myisamchk /path/to/database_dir/*.MYI
  22399.  
  22400. You can even check all tables in all databases by specifying a wildcard
  22401. with the path to the MySQL data directory:
  22402.  
  22403.      shell> myisamchk /path/to/datadir/*/*.MYI
  22404.  
  22405. The recommended way to quickly check all `MyISAM' and `ISAM' tables is:
  22406.  
  22407.      shell> myisamchk --silent --fast /path/to/datadir/*/*.MYI
  22408.      shell> isamchk --silent /path/to/datadir/*/*.ISM
  22409.  
  22410. If you want to check all `MyISAM' and `ISAM' tables and repair any that
  22411. are corrupted, you can use the following commands:
  22412.  
  22413.      shell> myisamchk --silent --force --fast --update-state \
  22414.                -O key_buffer=64M -O sort_buffer=64M \
  22415.                -O read_buffer=1M -O write_buffer=1M \
  22416.                /path/to/datadir/*/*.MYI
  22417.      shell> isamchk --silent --force -O key_buffer=64M \
  22418.                -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M \
  22419.                /path/to/datadir/*/*.ISM
  22420.  
  22421. These commands assume that you have more than 64MB free.  For more
  22422. information about memory allocation with `myisamchk', see *Note
  22423. myisamchk memory::.
  22424.  
  22425. You must ensure that no other program is using the tables while you are
  22426. running `myisamchk'.  Otherwise, when you run `myisamchk', it may
  22427. display the following error message:
  22428.  
  22429.      warning: clients are using or haven't closed the table properly
  22430.  
  22431. This means that you are trying to check a table that has been updated by
  22432. another program (such as the `mysqld' server) that hasn't yet closed
  22433. the file or that has died without closing the file properly.
  22434.  
  22435. If `mysqld' is running, you must force it to flush any table
  22436. modifications that are still buffered in memory by using `FLUSH
  22437. TABLES'. You should then ensure that no one is using the tables while
  22438. you are running `myisamchk'.  The easiest way to avoid this problem is
  22439. to use `CHECK TABLE' instead of `myisamchk' to check tables.
  22440.  
  22441. General Options for `myisamchk'
  22442. ...............................
  22443.  
  22444. The options described in this section can be used for any type of table
  22445. maintenance operation performed by `myisamchk'.  The sections following
  22446. this one describe options that pertain only to specific operations,
  22447. such as table checking or repairing.
  22448.  
  22449. `--help, -?'
  22450.      Display a help message and exit.
  22451.  
  22452. `--debug=DEBUG_OPTIONS, -# DEBUG_OPTIONS'
  22453.      Write a debugging log. The DEBUG_OPTIONS string often is
  22454.      `'d:t:o,FILE_NAME''.
  22455.  
  22456. `--silent, -s'
  22457.      Silent mode.  Write output only when errors occur. You can use `-s'
  22458.      twice (`-ss') to make `myisamchk' very silent.
  22459.  
  22460. `--verbose, -v'
  22461.      Verbose mode.  Print more information. This can be used with `-d'
  22462.      and `-e'. Use `-v' multiple times (`-vv', `-vvv') for even more
  22463.      output.
  22464.  
  22465. `--version, -V'
  22466.      Display version information and exit.
  22467.  
  22468. `--wait, -w'
  22469.      Instead of terminating with an error if the table is locked, wait
  22470.      until the table is unlocked before continuing.  Note that if you
  22471.      are running `mysqld' with the `--skip-external-locking' option,
  22472.      the table can be locked only by another `myisamchk' command.
  22473.  
  22474. You can also set the following variables by using `--VAR_NAME=VALUE'
  22475. options:
  22476.  
  22477. *Variable*                *Default Value*
  22478. `decode_bits'             9
  22479. `ft_max_word_len'         version-dependent
  22480. `ft_min_word_len'         4
  22481. `ft_stopword_file'        built-in list
  22482. `key_buffer_size'         523264
  22483. `myisam_block_size'       1024
  22484. `read_buffer_size'        262136
  22485. `sort_buffer_size'        2097144
  22486. `sort_key_blocks'         16
  22487. `write_buffer_size'       262136
  22488.  
  22489. It is also possible to set variables by using
  22490. `--set-variable=VAR_NAME=VALUE' or `-O VAR_NAME=VALUE' syntax. However,
  22491. this syntax is deprecated as of MySQL 4.0.
  22492.  
  22493. The possible `myisamchk' variables and their default values can be
  22494. examined with `myisamchk --help':
  22495.  
  22496. `sort_buffer_size' is used when the keys are repaired by sorting keys,
  22497. which is the normal case when you use `--recover'.
  22498.  
  22499. `key_buffer_size' is used when you are checking the table with
  22500. `--extend-check' or when the keys are repaired by inserting keys row by
  22501. row into the table (like when doing normal inserts). Repairing through
  22502. the key buffer is used in the following cases:
  22503.  
  22504.    * You use `--safe-recover'.
  22505.  
  22506.    * The temporary files needed to sort the keys would be more than
  22507.      twice as big as when creating the key file directly.  This is
  22508.      often the case when you have large key values for  `CHAR',
  22509.      `VARCHAR', or `TEXT' columns, because the sort operation needs to
  22510.      store the complete key values as it proceeds. If you have lots of
  22511.      temporary space and you can force `myisamchk' to repair by
  22512.      sorting, you can use the `--sort-recover' option.
  22513.  
  22514.  
  22515. Repairing through the key buffer takes much less disk space than using
  22516. sorting, but is also much slower.
  22517.  
  22518. If you want a faster repair, set the `key_buffer_size' and
  22519. `sort_buffer_size' variables to about 25% of your available memory.
  22520. You can set both variables to large values, because only one of them is
  22521. used at a time.
  22522.  
  22523. `myisam_block_size' is the size used for index blocks. It is available
  22524. as of MySQL 4.0.0.
  22525.  
  22526. The `ft_min_word_len' and `ft_max_word_len' variables are available as
  22527. of MySQL 4.0.0.  `ft_stopword_file' is available as of MySQL 4.0.19.
  22528.  
  22529. `ft_min_word_len' and `ft_max_word_len' indicate the minimum and
  22530. maximum word length for `FULLTEXT' indexes. `ft_stopword_file' names
  22531. the stopword file. These need to be set under the following
  22532. circumstances.
  22533.  
  22534. If you use `myisamchk' to perform an operation that modifies table
  22535. indexes (such as repair or analyze), the `FULLTEXT' indexes are rebuilt
  22536. using the default full-text parameter values for minimum and maximum
  22537. word length and the stopword file unless you specify otherwise.  This
  22538. can result in queries failing.
  22539.  
  22540. The problem occurs because these parameters are known only by the
  22541. server.  They are not stored in `MyISAM' index files.  To avoid the
  22542. problem if you have modified the minimum or maximum word length or the
  22543. stopword file in the server, specify the same `ft_min_word_len',
  22544. `ft_max_word_len', and `ft_stopword_file' values to `myisamchk' that
  22545. you use for `mysqld'. For example, if you have set the minimum word
  22546. length to 3, you can repair a table with `myisamchk' like this:
  22547.  
  22548.      shell> myisamchk --recover --ft_min_word_len=3 TBL_NAME.MYI
  22549.  
  22550. To ensure that `myisamchk' and the server use the same values for
  22551. full-text parameters, you can place each one in both the `[mysqld]' and
  22552. `[myisamchk]' sections of an option file:
  22553.  
  22554.      [mysqld]
  22555.      ft_min_word_len=3
  22556.      
  22557.      [myisamchk]
  22558.      ft_min_word_len=3
  22559.  
  22560. An alternative to using `myisamchk' is to use the `REPAIR TABLE',
  22561. `ANALYZE TABLE', `OPTIMIZE TABLE', or `ALTER TABLE'.  These statements
  22562. are performed by the server, which knows the proper full-text parameter
  22563. values to use.
  22564.  
  22565. Check Options for `myisamchk'
  22566. .............................
  22567.  
  22568. `myisamchk' supports the following options for table checking
  22569. operations:
  22570.  
  22571. `--check, -c'
  22572.      Check the table for errors. This is the default operation if you
  22573.      specify no option that selects an operation type explicitly.
  22574.  
  22575. `--check-only-changed, -C'
  22576.      Check only tables that have changed since the last check.
  22577.  
  22578. `--extend-check, -e'
  22579.      Check the table very thoroughly. This is quite slow if the table
  22580.      has many indexes.  This option should only be used in extreme
  22581.      cases.  Normally, `myisamchk' or `myisamchk --medium-check' should
  22582.      be able to determine whether there are any errors in the table.
  22583.  
  22584.      If you are using `--extend-check' and have plenty of memory,
  22585.      setting the `key_buffer_size' variable to a large value will help
  22586.      the repair operation run faster.
  22587.  
  22588. `--fast, -F'
  22589.      Check only tables that haven't been closed properly.
  22590.  
  22591. `--force, -f'
  22592.      Do a repair operation automatically if `myisamchk' finds any
  22593.      errors in the table.  The repair type is the same as that
  22594.      specified with the `--repair' or `-r' option.
  22595.  
  22596. `--information, -i'
  22597.      Print informational statistics about the table that is checked.
  22598.  
  22599. `--medium-check, -m'
  22600.      Do a check that is faster than an `--extend-check' operation.
  22601.      This finds only 99.99% of all errors, which should be good enough
  22602.      in most cases.
  22603.  
  22604. `--read-only, -T'
  22605.      Don't mark the table as checked. This is useful if you use
  22606.      `myisamchk' to check a table that is in use by some other
  22607.      application that doesn't use locking, such as `mysqld' when run
  22608.      with the `--skip-external-locking' option.
  22609.  
  22610. `--update-state, -U'
  22611.      Store information in the `.MYI' file to indicate when the table was
  22612.      checked and whether the table crashed.  This should be used to get
  22613.      full benefit of the `--check-only-changed' option, but you
  22614.      shouldn't use this option if the `mysqld' server is using the
  22615.      table and you are running it with the `--skip-external-locking'
  22616.      option.
  22617.  
  22618. Repair Options for `myisamchk'
  22619. ..............................
  22620.  
  22621. `myisamchk' supports the following options for table repair operations:
  22622.  
  22623. `--backup, -B'
  22624.      Make a backup of the `.MYD' file as `file_name-time.BAK'
  22625.  
  22626. `--character-sets-dir=PATH'
  22627.      The directory where character sets are installed.  *Note Character
  22628.      sets::.
  22629.  
  22630. `--correct-checksum'
  22631.      Correct the checksum information for the table.
  22632.  
  22633. `--data-file-length=#, -D #'
  22634.      Maximum length of the data file (when re-creating data file when
  22635.      it's "full").
  22636.  
  22637. `--extend-check, -e'
  22638.      Do a repair that tries to to recover every possible row from the
  22639.      data file.  Normally this will also find a lot of garbage rows.
  22640.      Don't use this option unless you are totally desperate.
  22641.  
  22642. `--force, -f'
  22643.      Overwrite old temporary files (files with names like
  22644.      `TBL_NAME.TMD') instead of aborting.
  22645.  
  22646. `--keys-used=#, -k #'
  22647.      For `myisamchk', the option value indicates which indexes to
  22648.      update.  Each binary bit of the option value corresponds to a
  22649.      table index, where the first index is bit 0.  For `isamchk', the
  22650.      option value indicates that only the first # of the table indexes
  22651.      should be updated.  In either case, an option value of 0 disables
  22652.      updates to all indexes, which can be used to get faster inserts.
  22653.      Deactivated indexes can be reactivated by using `myisamchk -r' or
  22654.      (`isamchk -r').
  22655.  
  22656. `--no-symlinks, -l'
  22657.      Do not follow symbolic links. Normally `myisamchk' repairs the
  22658.      table that a symlink points to.  This option doesn't exist as of
  22659.      MySQL 4.0, because versions from 4.0 on will not remove symlinks
  22660.      during repair operations.
  22661.  
  22662. `--parallel-recover, -p'
  22663.      Uses the same technique as `-r' and `-n', but creates all the keys
  22664.      in parallel, using different threads.  This option was added in
  22665.      MySQL 4.0.2.  _This is alpha code. Use at your own risk!_
  22666.  
  22667. `--quick, -q'
  22668.      Achieve a faster repair by not modifying the data file. You can
  22669.      specify this option twice to force `myisamchk' to modify the
  22670.      original data file in case of duplicate keys.
  22671.  
  22672. `--recover, -r'
  22673.      Do a repair that can fix almost any problem except unique keys
  22674.      that aren't unique (which is an extremely unlikely error with
  22675.      `ISAM'/`MyISAM' tables).  If you want to recover a table, this is
  22676.      the option to try first. You should try `-o' only if `myisamchk'
  22677.      reports that the table can't be recovered by `-r'.  (In the
  22678.      unlikely case that `-r' fails, the data file is still intact.)
  22679.  
  22680.      If you have lots of memory, you should increase the value of
  22681.      `sort_buffer_size'.
  22682.  
  22683. `--safe-recover, -o'
  22684.      Do a repair using an old recovery method that reads through all
  22685.      rows in order and updates all index trees based on the rows found.
  22686.      This is an order of magnitude slower than `-r', but can handle a
  22687.      couple of very unlikely cases that `-r' cannot.  This recovery
  22688.      method also uses much less disk space than `-r'. Normally, you
  22689.      should repair first with `-r', and then with `-o' only if `-r'
  22690.      fails.
  22691.  
  22692.      If you have lots of memory, you should increase the value of
  22693.      `key_buffer_size'.
  22694.  
  22695. `--set-character-set=NAME'
  22696.      Change the character set used by the table indexes.
  22697.  
  22698. `--sort-recover, -n'
  22699.      Force `myisamchk' to use sorting to resolve the keys even if the
  22700.      temporary files should be very big.
  22701.  
  22702. `--tmpdir=PATH, -t PATH'
  22703.      Path of the directory to be used for storing temporary files. If
  22704.      this is not set, `myisamchk' uses the value of the `TMPDIR'
  22705.      environment variable.  Starting from MySQL 4.1, `tmpdir' can be
  22706.      set to a list of directory paths that will be used successively in
  22707.      round-robin fashion for creating temporary files. The separator
  22708.      character between directory names should be colon (`:') on Unix
  22709.      and semicolon (`;') on Windows, NetWare, and OS/2.
  22710.  
  22711. `--unpack, -u'
  22712.      Unpack a table that was packed with `myisampack'.
  22713.  
  22714. Other Options for `myisamchk'
  22715. .............................
  22716.  
  22717. `myisamchk' supports the following options for actions other than table
  22718. checks and repairs:
  22719.  
  22720. `--analyze, -a'
  22721.      Analyze the distribution of keys. This improves join performance
  22722.      by enabling the join optimizer to better choose the order in which
  22723.      to join the tables and which keys it should use. To obtain
  22724.      information about the distribution, use a `myisamchk --description
  22725.      --verbose TBL_NAME' command or the `SHOW KEYS FROM TBL_NAME'
  22726.      statement.
  22727.  
  22728. `--description, -d'
  22729.      Print some descriptive information about the table.
  22730.  
  22731. `--set-auto-increment[=VALUE], -A[VALUE]'
  22732.      Force `AUTO_INCREMENT' numbering for new records to start at the
  22733.      given value (or higher, if there are already records with
  22734.      `AUTO_INCREMENT' values this large). If VALUE is not specified,
  22735.      `AUTO_INCREMENT' number for new records begins with the largest
  22736.      value currently in the table, plus one.
  22737.  
  22738. `--sort-index, -S'
  22739.      Sort the index tree blocks in high-low order.  This optimizes
  22740.      seeks and makes table scanning by key faster.
  22741.  
  22742. `--sort-records=#, -R #'
  22743.      Sort records according to a particular index.  This makes your
  22744.      data much more localized and may speed up range-based `SELECT' and
  22745.      `ORDER BY' operations that use this index. (The first time you use
  22746.      this option to sort a table, it may be very slow.) To determine a
  22747.      table's index numbers, use `SHOW KEYS', which displays a table's
  22748.      indexes in the same order that `myisamchk' sees them.  Indexes are
  22749.      numbered beginning with 1.
  22750.  
  22751. `myisamchk' Memory Usage
  22752. ........................
  22753.  
  22754. Memory allocation is important when you run `myisamchk'.  `myisamchk'
  22755. uses no more memory than you specify with the `-O' options.  If you are
  22756. going to use `myisamchk' on very large tables, you should first decide
  22757. how much memory you want it to use.  The default is to use only about
  22758. 3MB to perform repairs.  By using larger values, you can get
  22759. `myisamchk' to operate faster.  For example, if you have more than 32MB
  22760. RAM, you could use options such as these (in addition to any other
  22761. options you might specify):
  22762.  
  22763.      shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...
  22764.  
  22765. Using `-O sort=16M' should probably be enough for most cases.
  22766.  
  22767. Be aware that `myisamchk' uses temporary files in `TMPDIR'. If `TMPDIR'
  22768. points to a memory filesystem, you may easily get out of memory errors.
  22769. If this happens, set `TMPDIR' to point at some directory located on a
  22770. filesystem with more space and run `myisamchk' again.
  22771.  
  22772. When repairing, `myisamchk' will also need a lot of disk space:
  22773.  
  22774.    * Double the size of the data file (the original one and a copy).
  22775.      This space is not needed if you do a repair with `--quick'; in this
  22776.      case, only the index file is re-created.  This space is needed on
  22777.      the same filesystem as the original data file! (The copy is
  22778.      created in the same directory as the original.)
  22779.  
  22780.    * Space for the new index file that replaces the old one. The old
  22781.      index file is truncated at the start of the repair operation, so
  22782.      you usually ignore this space.  This space is needed on the same
  22783.      filesystem as the original index file!
  22784.  
  22785.    * When using `--recover' or `--sort-recover' (but not when using
  22786.      `--safe-recover'), you will need space for a sort buffer. The
  22787.      amount of space required is:
  22788.  
  22789.           (LARGEST_KEY + ROW_POINTER_LENGTH) * NUMBER_OF_ROWS * 2
  22790.  
  22791.      You can check the length of the keys and the `row_pointer_length'
  22792.      with `myisamchk -dv TBL_NAME'.  This space is allocated in the
  22793.      temporary directory (specified by `TMPDIR' or `--tmpdir=PATH').
  22794.  
  22795.  
  22796. If you have a problem with disk space during repair, you can try to use
  22797. `--safe-recover' instead of `--recover'.
  22798.  
  22799. Using `myisamchk' for Crash Recovery
  22800. ....................................
  22801.  
  22802. If you run `mysqld' with `--skip-external-locking' (which is the
  22803. default on some systems, such as Linux), you can't reliably use
  22804. `myisamchk' to check a table when `mysqld' is using the same table.  If
  22805. you can be sure that no one is accessing the tables through `mysqld'
  22806. while you run `myisamchk', you only have to do `mysqladmin
  22807. flush-tables' before you start checking the tables.  If you can't
  22808. guarantee this, then you must stop `mysqld' while you check the tables.
  22809. If you run `myisamchk' while `mysqld' is updating the tables, you may
  22810. get a warning that a table is corrupt even when it isn't.
  22811.  
  22812. If you are not using `--skip-external-locking', you can use `myisamchk'
  22813. to check tables at any time.  While you do this, all clients that try
  22814. to update the table will wait until `myisamchk' is ready before
  22815. continuing.
  22816.  
  22817. If you use `myisamchk' to repair or optimize tables, you _must_ always
  22818. ensure that the `mysqld' server is not using the table (this also
  22819. applies if you are using `--skip-external-locking').  If you don't take
  22820. down `mysqld', you should at least do a `mysqladmin flush-tables'
  22821. before you run `myisamchk'.  Your tables _may become corrupted_ if the
  22822. server and `myisamchk' access the tables simultaneously.
  22823.  
  22824. This section describes how to check for and deal with data corruption
  22825. in MySQL databases.  If your tables get corrupted frequently you should
  22826. try to find the reason why.  *Note Crashing::.
  22827.  
  22828. The `MyISAM' table section contains reason for why a table could be
  22829. corrupted. *Note `MyISAM' table problems: MyISAM table problems.
  22830.  
  22831. When performing crash recovery, it is important to understand that each
  22832. `MyISAM' table TBL_NAME in a database corresponds to three files in the
  22833. database directory:
  22834.  
  22835. *File*         *Purpose*
  22836. `TBL_NAME.frm' Definition (format) file
  22837. `TBL_NAME.MYD' Data file
  22838. `TBL_NAME.MYI' Index file
  22839.  
  22840. Each of these three file types is subject to corruption in various
  22841. ways, but problems occur most often in data files and index files.
  22842.  
  22843. `myisamchk' works by creating a copy of the `.MYD' data file row by
  22844. row. It ends the repair stage by removing the old `.MYD' file and
  22845. renaming the new file to the original file name.  If you use `--quick',
  22846. `myisamchk' does not create a temporary `.MYD' file, but instead
  22847. assumes that the `.MYD' file is correct and only generates a new index
  22848. file without touching the `.MYD' file. This is safe, because
  22849. `myisamchk' automatically detects whether the `.MYD' file is corrupt
  22850. and aborts the repair if it is.  You can also specify the `--quick'
  22851. option twice to `myisamchk'.  In this case, `myisamchk' does not abort
  22852. on some errors (such as duplicate-key errors) but instead tries to
  22853. resolve them by modifying the `.MYD' file. Normally the use of two
  22854. `--quick' options is useful only if you have too little free disk space
  22855. to perform a normal repair.  In this case, you should at least make a
  22856. backup before running `myisamchk'.
  22857.  
  22858. How to Check `MyISAM' Tables for Errors
  22859. .......................................
  22860.  
  22861. To check a `MyISAM' table, use the following commands:
  22862.  
  22863. `myisamchk TBL_NAME'
  22864.      This finds 99.99% of all errors. What it can't find is corruption
  22865.      that involves _only_ the data file (which is very unusual). If you
  22866.      want to check a table, you should normally run `myisamchk' without
  22867.      options or with either the `-s' or `--silent' option.
  22868.  
  22869. `myisamchk -m TBL_NAME'
  22870.      This finds 99.999% of all errors. It first checks all index
  22871.      entries for errors and then reads through all rows. It calculates
  22872.      a checksum for all keys in the rows and verifies that the checksum
  22873.      matches the checksum for the keys in the index tree.
  22874.  
  22875. `myisamchk -e TBL_NAME'
  22876.      This does a complete and thorough check of all data (`-e' means
  22877.      "extended check"). It does a check-read of every key for each row
  22878.      to verify that they indeed point to the correct row.  This may
  22879.      take a long time for a large table that has many indexes.
  22880.      Normally, `myisamchk' stops after the first error it finds. If you
  22881.      want to obtain more information, you can add the `--verbose'
  22882.      (`-v') option.  This causes `myisamchk' to keep going, up through
  22883.      a maximum of 20 errors.
  22884.  
  22885. `myisamchk -e -i TBL_NAME'
  22886.      Like the previous command, but the `-i' option tells `myisamchk' to
  22887.      print some informational statistics, too.
  22888.  
  22889. In most cases, a simple `myisamchk' with no arguments other than the
  22890. table name is sufficient to check a table.
  22891.  
  22892. How to Repair Tables
  22893. ....................
  22894.  
  22895. The discussion in this section describes how to use `myisamchk' on
  22896. `MyISAM' tables (extensions `.MYI' and `.MYD').  If you are using
  22897. `ISAM' tables (extensions `.ISM' and `.ISD'), you should use `isamchk'
  22898. instead; the concepts are similar.
  22899.  
  22900. If you are using MySQL 3.23.16 and above, you can (and should) use the
  22901. `CHECK TABLE' and `REPAIR TABLE' statements to check and repair
  22902. `MyISAM' tables.  See *Note `CHECK TABLE': CHECK TABLE and *Note
  22903. `REPAIR TABLE': REPAIR TABLE.
  22904.  
  22905. The symptoms of a corrupted table include queries that abort
  22906. unexpectedly and observable errors such as these:
  22907.  
  22908.    * `TBL_NAME.frm' is locked against change
  22909.  
  22910.    * Can't find file `TBL_NAME.MYI' (Errcode: ###)
  22911.  
  22912.    * Unexpected end of file
  22913.  
  22914.    * Record file is crashed
  22915.  
  22916.    * Got error ### from table handler
  22917.  
  22918. To get more information about the error you can run `perror' ###, where
  22919. ### is the error number. The following example shows how to use
  22920. `perror' to find the meanings for the most common error numbers that
  22921. indicate a problem with a table:
  22922.  
  22923.      shell> perror 126 127 132 134 135 136 141 144 145
  22924.      126 = Index file is crashed / Wrong file format
  22925.      127 = Record-file is crashed
  22926.      132 = Old database file
  22927.      134 = Record was already deleted (or record file crashed)
  22928.      135 = No more room in record file
  22929.      136 = No more room in index file
  22930.      141 = Duplicate unique key or constraint on write or update
  22931.      144 = Table is crashed and last repair failed
  22932.      145 = Table was marked as crashed and should be repaired
  22933.  
  22934. Note that error 135 (no more room in record file) and error 136 (no more
  22935. room in index file) are not errors that can be fixed by a simple
  22936. repair. In this case, you have to use `ALTER TABLE' to increase the
  22937. `MAX_ROWS' and `AVG_ROW_LENGTH' table option values:
  22938.  
  22939.      ALTER TABLE TBL_NAME MAX_ROWS=XXX AVG_ROW_LENGTH=YYY;
  22940.  
  22941. If you don't know the current table option values, use `SHOW CREATE
  22942. TABLE tbl_name'.
  22943.  
  22944. For the other errors, you must repair your tables. `myisamchk' can
  22945. usually detect and fix most problems that occur.
  22946.  
  22947. The repair process involves up to four stages, described here. Before
  22948. you begin, you should change location to the database directory and
  22949. check the permissions of the table files. On Unix, make sure that they
  22950. are readable by the user that `mysqld' runs as (and to you, because you
  22951. need to access the files you are checking).  If it turns out you need
  22952. to modify files, they must also be writable by you.
  22953.  
  22954. The options that you can use for table maintenance with `myisamchk' and
  22955. `isamchk' are described in several of the earlier subsections of *Note
  22956. Table maintenance::.
  22957.  
  22958. The following section is for the cases where the above command fails or
  22959. if you want to use the extended features that `myisamchk' and `isamchk'
  22960. provide.
  22961.  
  22962. If you are going to repair a table from the command line, you must first
  22963. stop the `mysqld' server. Note that when you do `mysqladmin shutdown'
  22964. on a remote server, the `mysqld' server will still be alive for a while
  22965. after `mysqladmin' returns, until all queries are stopped and all keys
  22966. have been flushed to disk.
  22967.  
  22968. *Stage 1: Checking your tables*
  22969.  
  22970. Run `myisamchk *.MYI' or `myisamchk -e *.MYI' if you have more time.
  22971. Use the `-s' (silent) option to suppress unnecessary information.
  22972.  
  22973. If the `mysqld' server is down, you should use the `--update-state'
  22974. option to tell `myisamchk' to mark the table as 'checked'.
  22975.  
  22976. You have to repair only those tables for which `myisamchk' announces an
  22977. error.  For such tables, proceed to Stage 2.
  22978.  
  22979. If you get weird errors when checking (such as `out of memory' errors),
  22980. or if `myisamchk' crashes, go to Stage 3.
  22981.  
  22982. *Stage 2: Easy safe repair*
  22983.  
  22984. Note: If you want a repair operation to go much faster, you should set
  22985. the values of the `sort_buffer_size' and `key_buffer_size' variables
  22986. each to about 25% of your available memory when running `myisamchk' or
  22987. `isamchk'.
  22988.  
  22989. First, try `myisamchk -r -q TBL_NAME' (`-r -q' means "quick recovery
  22990. mode"). This will attempt to repair the index file without touching the
  22991. data file.  If the data file contains everything that it should and the
  22992. delete links point at the correct locations within the data file, this
  22993. should work, and the table is fixed. Start repairing the next table.
  22994. Otherwise, use the following procedure:
  22995.  
  22996.   1. Make a backup of the data file before continuing.
  22997.  
  22998.   2. Use `myisamchk -r TBL_NAME' (`-r' means "recovery mode"). This will
  22999.      remove incorrect records and deleted records from the data file and
  23000.      reconstruct the index file.
  23001.  
  23002.   3. If the preceding step fails, use `myisamchk --safe-recover
  23003.      TBL_NAME'.  Safe recovery mode uses an old recovery method that
  23004.      handles a few cases that regular recovery mode doesn't (but is
  23005.      slower).
  23006.  
  23007. If you get weird errors when repairing (such as `out of memory'
  23008. errors), or if `myisamchk' crashes, go to Stage 3.
  23009.  
  23010. *Stage 3: Difficult repair*
  23011.  
  23012. You should reach this stage only if the first 16KB block in the index
  23013. file is destroyed or contains incorrect information, or if the index
  23014. file is missing.  In this case, it's necessary to create a new index
  23015. file. Do so as follows:
  23016.  
  23017.   1. Move the data file to some safe place.
  23018.  
  23019.   2. Use the table description file to create new (empty) data and
  23020.      index files:
  23021.  
  23022.           shell> mysql DB_NAME
  23023.           mysql> SET AUTOCOMMIT=1;
  23024.           mysql> TRUNCATE TABLE TBL_NAME;
  23025.           mysql> quit
  23026.  
  23027.      If your version of MySQL doesn't have `TRUNCATE TABLE', use
  23028.      `DELETE FROM TBL_NAME' instead.
  23029.  
  23030.   3. Copy the old data file back onto the newly created data file.
  23031.      (Don't just move the old file back onto the new file; you want to
  23032.      retain a copy in case something goes wrong.)
  23033.  
  23034. Go back to Stage 2.  `myisamchk -r -q' should work now.  (This shouldn't
  23035. be an endless loop.)
  23036.  
  23037. As of MySQL 4.0.2, you can also use `REPAIR TABLE TBL_NAME USE_FRM',
  23038. which performs the whole procedure automatically.
  23039.  
  23040. *Stage 4: Very difficult repair*
  23041.  
  23042. You should reach this stage only if the `.frm' description file has also
  23043. crashed. That should never happen, because the description file isn't
  23044. changed after the table is created:
  23045.  
  23046.   1. Restore the description file from a backup and go back to Stage 3.
  23047.      You can also restore the index file and go back to Stage 2.  In
  23048.      the latter case, you should start with `myisamchk -r'.
  23049.  
  23050.   2. If you don't have a backup but know exactly how the table was
  23051.      created, create a copy of the table in another database.  Remove
  23052.      the new data file, then move the `.frm' description and `.MYI'
  23053.      index files from the other database to your crashed database.
  23054.      This gives you new description and index files, but leaves the
  23055.      `.MYD' data file alone.  Go back to Stage 2 and attempt to
  23056.      reconstruct the index file.
  23057.  
  23058.  
  23059. Table Optimization
  23060. ..................
  23061.  
  23062. To coalesce fragmented records and eliminate wasted space resulting from
  23063. deleting or updating records, run `myisamchk' in recovery mode:
  23064.  
  23065.      shell> myisamchk -r TBL_NAME
  23066.  
  23067. You can optimize a table in the same way by using the SQL `OPTIMIZE
  23068. TABLE' statement.  `OPTIMIZE TABLE' does a repair of the table and a key
  23069. analysis, and also sorts the index tree to give faster key lookups.
  23070. There is also no possibility of unwanted interaction between a utility
  23071. and the server, because the server does all the work when you use
  23072. `OPTIMIZE TABLE'. *Note `OPTIMIZE TABLE': OPTIMIZE TABLE.
  23073.  
  23074. `myisamchk' also has a number of other options you can use to improve
  23075. the performance of a table:
  23076.  
  23077.    * `-S', `--sort-index'
  23078.  
  23079.    * `-R INDEX_NUM', `--sort-records=INDEX_NUM'
  23080.  
  23081.    * `-a', `--analyze'
  23082.  
  23083. For a full description of the options, see *Note myisamchk syntax::.
  23084.  
  23085. Setting Up a Table Maintenance Schedule
  23086. ---------------------------------------
  23087.  
  23088. It is a good idea to perform table checks on a regular basis rather than
  23089. waiting for problems to occur.  One way to check and repair `MyISAM'
  23090. tables is with the `CHECK TABLE' and `REPAIR TABLE' statements.  These
  23091. are available starting with MySQL 3.23.16.  See *Note `CHECK TABLE':
  23092. CHECK TABLE and *Note `REPAIR TABLE': REPAIR TABLE.
  23093.  
  23094. Another way to check tables is to use `myisamchk'.  For maintenance
  23095. purposes, you can use `myisamchk -s'.  The `-s' option (short for
  23096. `--silent') causes `myisamchk' to run in silent mode, printing messages
  23097. only when errors occur.
  23098.  
  23099. It's also a good idea to check tables when the server starts.  For
  23100. example, whenever the machine has done a restart in the middle of an
  23101. update, you usually need to check all the tables that could have been
  23102. affected. (These are "expected crashed tables.")  To check `MyISAM'
  23103. tables automatically, start the server with the `--myisam-recover'
  23104. option, available as of MySQL 3.23.25.  If your server is too old to
  23105. support this option, you could add a test to `mysqld_safe' that runs
  23106. `myisamchk' to check all tables that have been modified during the last
  23107. 24 hours if there is an old `.pid' (process ID) file left after a
  23108. restart.  (The `.pid' file is created by `mysqld' when it starts and
  23109. removed when it terminates normally.  The presence of a `.pid' file at
  23110. system startup time indicates that `mysqld' terminated abnormally.)
  23111.  
  23112. An even better test would be to check any table whose last-modified time
  23113. is more recent than that of the `.pid' file.
  23114.  
  23115. You should also check your tables regularly during normal system
  23116. operation.  At MySQL AB, we run a `cron' job to check all our important
  23117. tables once a week, using a line like this in a `crontab' file:
  23118.  
  23119.      35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI
  23120.  
  23121. This prints out information about crashed tables so that we can examine
  23122. and repair them when needed.
  23123.  
  23124. Because we haven't had any unexpectedly crashed tables (tables that
  23125. become corrupted for reasons other than hardware trouble) for a couple
  23126. of years now (this is really true), once a week is more than enough for
  23127. us.
  23128.  
  23129. We recommend that to start with, you execute `myisamchk -s' each night
  23130. on all tables that have been updated during the last 24 hours, until
  23131. you come to trust MySQL as much as we do.
  23132.  
  23133. Normally, MySQL tables need little maintenance.  If you are changing
  23134. `MyISAM' tables with dynamic-sized rows (tables with `VARCHAR', `BLOB',
  23135. or `TEXT' columns) or have tables with many deleted rows you may want
  23136. to defragment/reclaim space from the tables from time to time (once a
  23137. month?).
  23138.  
  23139. You can do this by using `OPTIMIZE TABLE' on the tables in question.
  23140. Or, if you can stop the `mysqld' server for a while, change location
  23141. into the data directory and use this command while the server is
  23142. stopped:
  23143.  
  23144.      shell> myisamchk -r -s --sort-index -O sort_buffer_size=16M */*.MYI
  23145.  
  23146. For `ISAM' tables, the command is similar:
  23147.  
  23148.      shell> isamchk -r -s --sort-index -O sort_buffer_size=16M */*.MYI
  23149.  
  23150. Getting Information About a Table
  23151. ---------------------------------
  23152.  
  23153. To obtain a description of a table or statistics about it, use the
  23154. commands shown here. We explain some of the information in more detail
  23155. later:
  23156.  
  23157.    * `myisamchk -d TBL_NAME'
  23158.  
  23159.      Runs `myisamchk' in "describe mode" to produce a description of
  23160.      your table. If you start the MySQL server using the
  23161.      `--skip-external-locking' option, `myisamchk' may report an error
  23162.      for a table that is updated while it runs.  However, because
  23163.      `myisamchk' doesn't change the table in describe mode, there is no
  23164.      risk of destroying data.
  23165.  
  23166.    * `myisamchk -d -v TBL_NAME'
  23167.  
  23168.      Adding `-v' runs `myisamchk' in verbose mode so that it produces
  23169.      more information about what it is doing.
  23170.  
  23171.    * `myisamchk -eis TBL_NAME'
  23172.  
  23173.      Shows only the most important information from a table. This
  23174.      operation is slow because it must read the entire table.
  23175.  
  23176.    * `myisamchk -eiv TBL_NAME'
  23177.  
  23178.      This is like `-eis', but tells you what is being done.
  23179.  
  23180.  
  23181. Sample output for some of these commands follows. They are based on a
  23182. table with these data and index file sizes:
  23183.  
  23184.      -rw-rw-r--   1 monty    tcx     317235748 Jan 12 17:30 company.MYD
  23185.      -rw-rw-r--   1 davida   tcx      96482304 Jan 12 18:35 company.MYM
  23186.  
  23187. Example of `myisamchk -d' output:
  23188.  
  23189.      MyISAM file:     company.MYI
  23190.      Record format:   Fixed length
  23191.      Data records:    1403698  Deleted blocks:         0
  23192.      Recordlength:    226
  23193.      
  23194.      table description:
  23195.      Key Start Len Index   Type
  23196.      1   2     8   unique  double
  23197.      2   15    10  multip. text packed stripped
  23198.      3   219   8   multip. double
  23199.      4   63    10  multip. text packed stripped
  23200.      5   167   2   multip. unsigned short
  23201.      6   177   4   multip. unsigned long
  23202.      7   155   4   multip. text
  23203.      8   138   4   multip. unsigned long
  23204.      9   177   4   multip. unsigned long
  23205.          193   1           text
  23206.  
  23207. Example of `myisamchk -d -v' output:
  23208.  
  23209.      MyISAM file:         company
  23210.      Record format:       Fixed length
  23211.      File-version:        1
  23212.      Creation time:       1999-10-30 12:12:51
  23213.      Recover time:        1999-10-31 19:13:01
  23214.      Status:              checked
  23215.      Data records:            1403698  Deleted blocks:              0
  23216.      Datafile parts:          1403698  Deleted data:                0
  23217.      Datafile pointer (bytes):      3  Keyfile pointer (bytes):     3
  23218.      Max datafile length:  3791650815  Max keyfile length: 4294967294
  23219.      Recordlength:                226
  23220.      
  23221.      table description:
  23222.      Key Start Len Index   Type                  Rec/key     Root Blocksize
  23223.      1   2     8   unique  double                      1 15845376      1024
  23224.      2   15    10  multip. text packed stripped        2 25062400      1024
  23225.      3   219   8   multip. double                     73 40907776      1024
  23226.      4   63    10  multip. text packed stripped        5 48097280      1024
  23227.      5   167   2   multip. unsigned short           4840 55200768      1024
  23228.      6   177   4   multip. unsigned long            1346 65145856      1024
  23229.      7   155   4   multip. text                     4995 75090944      1024
  23230.      8   138   4   multip. unsigned long              87 85036032      1024
  23231.      9   177   4   multip. unsigned long             178 96481280      1024
  23232.          193   1           text
  23233.  
  23234. Example of `myisamchk -eis' output:
  23235.  
  23236.      Checking MyISAM file: company
  23237.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  23238.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  23239.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  23240.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  23241.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  23242.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  23243.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  23244.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  23245.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  23246.      Total:    Keyblocks used:  98%  Packed:   17%
  23247.      
  23248.      Records:          1403698    M.recordlength:     226
  23249.      Packed:             0%
  23250.      Recordspace used:     100%   Empty space:          0%
  23251.      Blocks/Record:   1.00
  23252.      Record blocks:    1403698    Delete blocks:        0
  23253.      Recorddata:     317235748    Deleted data:         0
  23254.      Lost space:             0    Linkdata:             0
  23255.      
  23256.      User time 1626.51, System time 232.36
  23257.      Maximum resident set size 0, Integral resident set size 0
  23258.      Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
  23259.      Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  23260.      Voluntary context switches 639, Involuntary context switches 28966
  23261.  
  23262. Example of `myisamchk -eiv' output:
  23263.  
  23264.      Checking MyISAM file: company
  23265.      Data records: 1403698   Deleted blocks:       0
  23266.      - check file-size
  23267.      - check delete-chain
  23268.      block_size 1024:
  23269.      index  1:
  23270.      index  2:
  23271.      index  3:
  23272.      index  4:
  23273.      index  5:
  23274.      index  6:
  23275.      index  7:
  23276.      index  8:
  23277.      index  9:
  23278.      No recordlinks
  23279.      - check index reference
  23280.      - check data record references index: 1
  23281.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  23282.      - check data record references index: 2
  23283.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  23284.      - check data record references index: 3
  23285.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  23286.      - check data record references index: 4
  23287.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  23288.      - check data record references index: 5
  23289.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  23290.      - check data record references index: 6
  23291.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  23292.      - check data record references index: 7
  23293.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  23294.      - check data record references index: 8
  23295.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  23296.      - check data record references index: 9
  23297.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  23298.      Total:    Keyblocks used:   9%  Packed:   17%
  23299.      
  23300.      - check records and index references
  23301.      [LOTS OF ROW NUMBERS DELETED]
  23302.      
  23303.      Records:         1403698   M.recordlength:   226   Packed:           0%
  23304.      Recordspace used:    100%  Empty space:        0%  Blocks/Record: 1.00
  23305.      Record blocks:   1403698   Delete blocks:      0
  23306.      Recorddata:    317235748   Deleted data:       0
  23307.      Lost space:            0   Linkdata:           0
  23308.      
  23309.      User time 1639.63, System time 251.61
  23310.      Maximum resident set size 0, Integral resident set size 0
  23311.      Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
  23312.      Blocks in 4 out 0, Messages in 0 out 0, Signals 0
  23313.      Voluntary context switches 10604, Involuntary context switches 122798
  23314.  
  23315. Explanations for the types of information `myisamchk' produces are
  23316. given here.  "Keyfile" refers to the index file.  "Record" and "row"
  23317. are synonymous.
  23318.  
  23319.    * `MyISAM file'
  23320.  
  23321.      Name of the `MyISAM' (index) file.
  23322.  
  23323.    * `File-version'
  23324.  
  23325.      Version of `MyISAM' format. Currently always 2.
  23326.  
  23327.    * `Creation time'
  23328.  
  23329.      When the data file was created.
  23330.  
  23331.    * `Recover time'
  23332.  
  23333.      When the index/data file was last reconstructed.
  23334.  
  23335.    * `Data records'
  23336.  
  23337.      How many records are in the table.
  23338.  
  23339.    * `Deleted blocks'
  23340.  
  23341.      How many deleted blocks still have reserved space.  You can
  23342.      optimize your table to minimize this space.  *Note Optimisation::.
  23343.  
  23344.    * `Datafile parts'
  23345.  
  23346.      For dynamic record format, this indicates how many data blocks
  23347.      there are. For an optimized table without fragmented records, this
  23348.      is the same as `Data records'.
  23349.  
  23350.    * `Deleted data'
  23351.  
  23352.      How many bytes of unreclaimed deleted data there are.  You can
  23353.      optimize your table to minimize this space.  *Note Optimisation::.
  23354.  
  23355.    * `Datafile pointer'
  23356.  
  23357.      The size of the data file pointer, in bytes. It is usually 2, 3,
  23358.      4, or 5 bytes. Most tables manage with 2 bytes, but this cannot be
  23359.      controlled from MySQL yet. For fixed tables, this is a record
  23360.      address. For dynamic tables, this is a byte address.
  23361.  
  23362.    * `Keyfile pointer'
  23363.  
  23364.      The size of the index file pointer, in bytes. It is usually 1, 2,
  23365.      or 3 bytes. Most tables manage with 2 bytes, but this is calculated
  23366.      automatically by MySQL. It is always a block address.
  23367.  
  23368.    * `Max datafile length'
  23369.  
  23370.      How long the table data file can become, in bytes.
  23371.  
  23372.    * `Max keyfile length'
  23373.  
  23374.      How long the table index file can become, in bytes.
  23375.  
  23376.    * `Recordlength'
  23377.  
  23378.      How much space each record takes, in bytes.
  23379.  
  23380.    * `Record format'
  23381.  
  23382.      The format used to store table rows.  The preceding examples use
  23383.      `Fixed length'.  Other possible values are `Compressed' and
  23384.      `Packed'.
  23385.  
  23386.    * `table description'
  23387.  
  23388.      A list of all keys in the table. For each key, `myisamchk' displays
  23389.      some low-level information:
  23390.  
  23391.         - `Key'
  23392.  
  23393.           This key's number.
  23394.  
  23395.         - `Start'
  23396.  
  23397.           Where in the record this index part starts.
  23398.  
  23399.         - `Len'
  23400.  
  23401.           How long this index part is. For packed numbers, this should
  23402.           always be the full length of the column. For strings, it may
  23403.           be shorter than the full length of the indexed column,
  23404.           because you can index a prefix of a string column.
  23405.  
  23406.         - `Index'
  23407.  
  23408.           Whether a key value can exist multiple times in the index.
  23409.           Values are `unique' or `multip.' (multiple).
  23410.  
  23411.         - `Type'
  23412.  
  23413.           What data type this index part has. This is a `MyISAM' data
  23414.           type with the options `packed', `stripped', or `empty'.
  23415.  
  23416.         - `Root'
  23417.  
  23418.           Address of the root index block.
  23419.  
  23420.         - `Blocksize'
  23421.  
  23422.           The size of each index block. By default this is 1024, but
  23423.           the value may be changed at compile time when MySQL is built
  23424.           from source.
  23425.  
  23426.         - `Rec/key'
  23427.  
  23428.           This is a statistical value used by the optimizer. It tells
  23429.           how many records there are per value for this key. A unique
  23430.           key always has a value of 1. This may be updated after a
  23431.           table is loaded (or greatly changed) with `myisamchk -a'. If
  23432.           this is not updated at all, a default value of 30 is given.
  23433.  
  23434.      For the table shown in the examples, there are two `table
  23435.      description' lines for the ninth index. This indicates that it is
  23436.      a multiple-part index with two parts.
  23437.  
  23438.    * `Keyblocks used'
  23439.  
  23440.      What percentage of the keyblocks are used. When a table has just
  23441.      been reorganized with `myisamchk', as for the table in the
  23442.      examples, the values are very high (very near the theoretical
  23443.      maximum).
  23444.  
  23445.    * `Packed'
  23446.  
  23447.      MySQL tries to pack keys with a common suffix. This can only be
  23448.      used for indexes on `CHAR', `VARCHAR', or `DECIMAL' columns. For
  23449.      long indexed strings that have similar leftmost parts, this can
  23450.      significantly reduce the space used. In the third example above,
  23451.      the fourth key is 10 characters long and a 60% reduction in space
  23452.      is achieved.
  23453.  
  23454.    * `Max levels'
  23455.  
  23456.      How deep the B-tree for this key is. Large tables with long key
  23457.      values get high values.
  23458.  
  23459.    * `Records'
  23460.  
  23461.      How many rows are in the table.
  23462.  
  23463.    * `M.recordlength'
  23464.  
  23465.      The average record length.  This is the exact record length for
  23466.      tables with fixed-length records, because all records have the
  23467.      same length.
  23468.  
  23469.    * `Packed'
  23470.  
  23471.      MySQL strips spaces from the end of strings. The `Packed' value
  23472.      indicates the percentage of savings achieved by doing this.
  23473.  
  23474.    * `Recordspace used'
  23475.  
  23476.      What percentage of the data file is used.
  23477.  
  23478.    * `Empty space'
  23479.  
  23480.      What percentage of the data file is unused.
  23481.  
  23482.    * `Blocks/Record'
  23483.  
  23484.      Average number of blocks per record (that is, how many links a
  23485.      fragmented record is composed of). This is always 1.0 for
  23486.      fixed-format tables. This value should stay as close to 1.0 as
  23487.      possible. If it gets too big, you can reorganize the table.  *Note
  23488.      Optimisation::.
  23489.  
  23490.    * `Recordblocks'
  23491.  
  23492.      How many blocks (links) are used. For fixed format, this is the
  23493.      same as the number of records.
  23494.  
  23495.    * `Deleteblocks'
  23496.  
  23497.      How many blocks (links) are deleted.
  23498.  
  23499.    * `Recorddata'
  23500.  
  23501.      How many bytes in the data file are used.
  23502.  
  23503.    * `Deleted data'
  23504.  
  23505.      How many bytes in the data file are deleted (unused).
  23506.  
  23507.    * `Lost space'
  23508.  
  23509.      If a record is updated to a shorter length, some space is lost.
  23510.      This is the sum of all such losses, in bytes.
  23511.  
  23512.    * `Linkdata'
  23513.  
  23514.      When the dynamic table format is used, record fragments are linked
  23515.      with pointers (4 to 7 bytes each). `Linkdata' is the sum of the
  23516.      amount of storage used by all such pointers.
  23517.  
  23518.  
  23519. If a table has been compressed with `myisampack', `myisamchk -d' prints
  23520. additional information about each table column.  See *Note
  23521. `myisampack': myisampack, for an example of this information and a
  23522. description of what it means.
  23523.  
  23524. MySQL Localization and International Usage
  23525. ==========================================
  23526.  
  23527. This section describes how to configure the server to use different
  23528. character sets.  It also discusses how to set the server's time zone
  23529. and enable per-connection time zone support.
  23530.  
  23531. The Character Set Used for Data and Sorting
  23532. -------------------------------------------
  23533.  
  23534. By default, MySQL uses the ISO-8859-1 (Latin1) character set with
  23535. sorting according to Swedish/Finnish rules. These defaults are suitable
  23536. for the United States and most of western Europe.
  23537.  
  23538. All MySQL binary distributions are compiled with
  23539. `--with-extra-charsets=complex'.  This adds code to all standard
  23540. programs that enables them to handle `latin1' and all multi-byte
  23541. character sets within the binary. Other character sets will be loaded
  23542. from a character-set definition file when needed.
  23543.  
  23544. The character set determines what characters are allowed in names. It
  23545. also determines how strings are sorted by the `ORDER BY' and `GROUP BY'
  23546. clauses of the `SELECT' statement.
  23547.  
  23548. You can change the character set with the `--default-character-set'
  23549. option when you start the server.  The character sets available depend
  23550. on the `--with-charset=CHARSET' and `--with-extra-charsets=
  23551. LIST-OF-CHARSETS | complex | all | none' options to `configure', and the
  23552. character set configuration files listed in `SHAREDIR/charsets/Index'.
  23553. *Note `configure' options: configure options.
  23554.  
  23555. As of MySQL 4.1.1, you can also change the character set collation with
  23556. the `--default-collation' option when you start the server.  The
  23557. collation must be a legal collation for the default character set.
  23558. (Use the `SHOW COLLATION' statement to determine which collations are
  23559. available for each character set.)  *Note `configure' options:
  23560. configure options.
  23561.  
  23562. If you change the character set when running MySQL, that may also
  23563. change the sort order.  Consequently, you must run `myisamchk -r -q
  23564. --set-character-set=CHARSET' on all tables, or your indexes may not be
  23565. ordered correctly.
  23566.  
  23567. When a client connects to a MySQL server, the server indicates to the
  23568. client what the server's default character set is.  The client will
  23569. switch to use this character set for this connection.
  23570.  
  23571. You should use `mysql_real_escape_string()' when escaping strings for
  23572. an SQL query.  `mysql_real_escape_string()' is identical to the old
  23573. `mysql_escape_string()' function, except that it takes the `MYSQL'
  23574. connection handle as the first parameter so that the appropriate
  23575. character set can be taken into account when escaping characters.
  23576.  
  23577. If the client is compiled with different paths than where the server is
  23578. installed and the user who configured MySQL didn't include all character
  23579. sets in the MySQL binary, you must tell the client where it can find the
  23580. additional character sets it will need if the server runs with a
  23581. different character set than the client.
  23582.  
  23583. You can do this by specifying a `--character-sets-dir' option to
  23584. indicate the path to the directory in which the dynamic MySQL character
  23585. sets are stored. For example, you can put the following in an option
  23586. file:
  23587.  
  23588.      [client]
  23589.      character-sets-dir=/usr/local/mysql/share/mysql/charsets
  23590.  
  23591. You can force the client to use specific character set as follows:
  23592.  
  23593.      [client]
  23594.      default-character-set=CHARSET
  23595.  
  23596. This is normally unnecessary, however.
  23597.  
  23598. Using the German Character Set
  23599. ..............................
  23600.  
  23601. To get German sorting order, you should start `mysqld' with a
  23602. `--default-character-set=latin1_de' option.  This affects server
  23603. behavior in several ways:
  23604.  
  23605.    * When sorting and comparing strings, the following mapping is
  23606.      performed on the strings before doing the comparison:
  23607.  
  23608.           a"  ->  ae
  23609.           o"  ->  oe
  23610.           u"  ->  ue
  23611.           ss  ->  ss
  23612.  
  23613.    * All accented characters are converted to their unaccented uppercase
  23614.      counterpart.  All letters are converted to uppercase.
  23615.  
  23616.    * When comparing strings with `LIKE', the one-character to
  23617.      two-character mapping is not done. All letters are converted to
  23618.      uppercase. Accents are removed from all letters except `U"', `u"',
  23619.      `O"', `o"', `A"', and `a"'.
  23620.  
  23621.  
  23622. Setting the Error Message Language
  23623. ----------------------------------
  23624.  
  23625. By default, `mysqld' produces error messages in English, but they can
  23626. also be displayed in any of these other languages: Czech, Danish,
  23627. Dutch, Estonian, French, German, Greek, Hungarian, Italian, Japanese,
  23628. Korean, Norwegian, Norwegian-ny, Polish, Portuguese, Romanian, Russian,
  23629. Slovak, Spanish, or Swedish.
  23630.  
  23631. To start `mysqld' with a particular language for error messages, use the
  23632. `--language' or `-L' option. The option value can be a language name or
  23633. the full path to the error message file.  For example:
  23634.  
  23635.      shell> mysqld --language=swedish
  23636.  
  23637. Or:
  23638.  
  23639.      shell> mysqld --language=/usr/local/share/swedish
  23640.  
  23641. The language name should be specified in lowercase.
  23642.  
  23643. The language files are located (by default) in the `share/LANGUAGE'
  23644. directory under the MySQL base directory.
  23645.  
  23646. To change the error message file, you should edit the `errmsg.txt' file,
  23647. and then execute the following command to generate the `errmsg.sys'
  23648. file:
  23649.  
  23650.      shell> comp_err errmsg.txt errmsg.sys
  23651.  
  23652. If you upgrade to a newer version of MySQL, remember to repeat your
  23653. changes with the new `errmsg.txt' file.
  23654.  
  23655. Adding a New Character Set
  23656. --------------------------
  23657.  
  23658. This section discusses the procedure for adding add another character
  23659. set to MySQL.  You must have a MySQL source distribution to use these
  23660. instructions.
  23661.  
  23662. To choose the proper procedure, decide whether the character set is
  23663. simple or complex:
  23664.  
  23665.    * If the character set does not need to use special string collating
  23666.      routines for sorting and does not need multi-byte character
  23667.      support, it is simple.
  23668.  
  23669.    * If it needs either of those features, it is complex.
  23670.  
  23671.  
  23672. For example, `latin1' and `danish' are simple character sets, whereas
  23673. `big5' and `czech' are complex character sets.
  23674.  
  23675. In the following procedures, the name of your character set is
  23676. represented by MYSET.
  23677.  
  23678. For a simple character set, do the following:
  23679.  
  23680.   1. Add MYSET to the end of the `sql/share/charsets/Index' file.
  23681.      Assign a unique number to it.
  23682.  
  23683.   2. Create the file `sql/share/charsets/MYSET.conf'.  (You can use a
  23684.      copy of `sql/share/charsets/latin1.conf' as the basis for this
  23685.      file.)
  23686.  
  23687.      The syntax for the file is very simple:
  23688.  
  23689.         * Comments start with a `#' character and proceed to the end of
  23690.           the line.
  23691.  
  23692.         * Words are separated by arbitrary amounts of whitespace.
  23693.  
  23694.         * When defining the character set, every word must be a number
  23695.           in hexadecimal format.
  23696.  
  23697.         * The `ctype' array takes up the first 257 words. The
  23698.           `to_lower[]', `to_upper[]' and `sort_order[]' arrays take up
  23699.           256 words each after that.
  23700.  
  23701.      *Note Character arrays::.
  23702.  
  23703.   3. Add the character set name to the `CHARSETS_AVAILABLE' and
  23704.      `COMPILED_CHARSETS' lists in `configure.in'.
  23705.  
  23706.   4. Reconfigure, recompile, and test.
  23707.  
  23708.  
  23709. For a complex character set, do the following:
  23710.  
  23711.   1. Create the file `strings/ctype-MYSET.c' in the MySQL source
  23712.      distribution.
  23713.  
  23714.   2. Add MYSET to the end of the `sql/share/charsets/Index' file.
  23715.      Assign a unique number to it.
  23716.  
  23717.   3. Look at one of the existing `ctype-*.c' files (such as
  23718.      `strings/ctype-big5.c') to see what needs to be defined.  Note
  23719.      that the arrays in your file must have names like `ctype_MYSET',
  23720.      `to_lower_MYSET', and so on.  These correspond to the arrays for a
  23721.      simple character set. *Note Character arrays::.
  23722.  
  23723.   4. Near the top of the file, place a special comment like this:
  23724.  
  23725.           /*
  23726.            * This comment is parsed by configure to create ctype.c,
  23727.            * so don't change it unless you know what you are doing.
  23728.            *
  23729.            * .configure. number_MYSET=MYNUMBER
  23730.            * .configure. strxfrm_multiply_MYSET=N
  23731.            * .configure. mbmaxlen_MYSET=N
  23732.            */
  23733.  
  23734.      The `configure' program uses this comment to include the character
  23735.      set into the MySQL library automatically.
  23736.  
  23737.      The `strxfrm_multiply' and `mbmaxlen' lines are explained in the
  23738.      following sections.  You need include them only if you need the
  23739.      string collating functions or the multi-byte character set
  23740.      functions, respectively.
  23741.  
  23742.   5. You should then create some of the following functions:
  23743.  
  23744.         * `my_strncoll_MYSET()'
  23745.  
  23746.         * `my_strcoll_MYSET()'
  23747.  
  23748.         * `my_strxfrm_MYSET()'
  23749.  
  23750.         * `my_like_range_MYSET()'
  23751.  
  23752.      *Note String collating::.
  23753.  
  23754.   6. Add the character set name to the `CHARSETS_AVAILABLE' and
  23755.      `COMPILED_CHARSETS' lists in `configure.in'.
  23756.  
  23757.   7. Reconfigure, recompile, and test.
  23758.  
  23759. The `sql/share/charsets/README' file includes additional instructions.
  23760.  
  23761. If you want to have the character set included in the MySQL
  23762. distribution, mail a patch to the MySQL `internals' mailing list.
  23763. *Note Mailing-list::.
  23764.  
  23765. The Character Definition Arrays
  23766. -------------------------------
  23767.  
  23768. `to_lower[]' and `to_upper[]' are simple arrays that hold the lowercase
  23769. and uppercase characters corresponding to each member of the character
  23770. set.  For example:
  23771.  
  23772.      to_lower['A'] should contain 'a'
  23773.      to_upper['a'] should contain 'A'
  23774.  
  23775. `sort_order[]' is a map indicating how characters should be ordered for
  23776. comparison and sorting purposes. Quite often (but not for all character
  23777. sets) this is the same as `to_upper[]', which means that sorting will be
  23778. case-insensitive. MySQL will sort characters based on the values of
  23779. `sort_order[]' elements.  For more complicated sorting rules, see the
  23780. discussion of string collating in *Note String collating::.
  23781.  
  23782. `ctype[]' is an array of bit values, with one element for one character.
  23783. (Note that `to_lower[]', `to_upper[]', and `sort_order[]' are indexed
  23784. by character value, but `ctype[]' is indexed by character value + 1.
  23785. This is an old legacy convention to be able to handle `EOF'.)
  23786.  
  23787. You can find the following bitmask definitions in `m_ctype.h':
  23788.  
  23789.      #define _U      01      /* Uppercase */
  23790.      #define _L      02      /* Lowercase */
  23791.      #define _N      04      /* Numeral (digit) */
  23792.      #define _S      010     /* Spacing character */
  23793.      #define _P      020     /* Punctuation */
  23794.      #define _C      040     /* Control character */
  23795.      #define _B      0100    /* Blank */
  23796.      #define _X      0200    /* heXadecimal digit */
  23797.  
  23798. The `ctype[]' entry for each character should be the union of the
  23799. applicable bitmask values that describe the character.  For example,
  23800. `'A'' is an uppercase character (`_U') as well as a hexadecimal digit
  23801. (`_X'), so `ctype['A'+1]' should contain the value:
  23802.  
  23803.      _U + _X = 01 + 0200 = 0201
  23804.  
  23805. String Collating Support
  23806. ------------------------
  23807.  
  23808. If the sorting rules for your language are too complex to be handled
  23809. with the simple `sort_order[]' table, you need to use the string
  23810. collating functions.
  23811.  
  23812. Right now the best documentation for this is the character sets that are
  23813. already implemented.  Look at the `big5', `czech', `gbk', `sjis', and
  23814. `tis160' character sets for examples.
  23815.  
  23816. You must specify the `strxfrm_multiply_MYSET=N' value in the special
  23817. comment at the top of the file.  N should be set to the maximum ratio
  23818. the strings may grow during `my_strxfrm_MYSET' (it must be a positive
  23819. integer).
  23820.  
  23821. Multi-Byte Character Support
  23822. ----------------------------
  23823.  
  23824. If you want to add support for a new character set that includes
  23825. multi-byte characters, you need to use the multi-byte character
  23826. functions.
  23827.  
  23828. Right now the best documentation on this consists of the character sets
  23829. that are already implemented.  Look at the `euc_kr', `gb2312', `gbk',
  23830. `sjis', and `ujis' character sets for examples. These are implemented
  23831. in the `ctype-CHARSET.c' files in the `strings' directory.
  23832.  
  23833. You must specify the `mbmaxlen_MYSET=N' value in the special comment at
  23834. the top of the source file.  N should be set to the size in bytes of
  23835. the largest character in the set.
  23836.  
  23837. Problems With Character Sets
  23838. ----------------------------
  23839.  
  23840. If you try to use a character set that is not compiled into your binary,
  23841. you might run into the following problems:
  23842.  
  23843.    * Your program has an incorrect path to where the character sets are
  23844.      stored.  (Default `/usr/local/mysql/share/mysql/charsets').  This
  23845.      can be fixed by using the `--character-sets-dir' option when you
  23846.      run the program in question.
  23847.  
  23848.    * The character set is a multi-byte character set that can't be
  23849.      loaded dynamically.  In this case, you must recompile the program
  23850.      with support for the character set.
  23851.  
  23852.    * The character set is a dynamic character set, but you don't have a
  23853.      configure file for it.  In this case, you should install the
  23854.      configure file for the character set from a new MySQL distribution.
  23855.  
  23856.    * If your `Index' file doesn't contain the name for the character
  23857.      set, your program will display the following error message:
  23858.  
  23859.           ERROR 1105: File '/usr/local/share/mysql/charsets/?.conf'
  23860.           not found (Errcode: 2)
  23861.  
  23862.      In this case, you should either get a new `Index' file or manually
  23863.      add the name of any missing character sets to the current file.
  23864.  
  23865. For `MyISAM' tables, you can check the character set name and number
  23866. for a table with `myisamchk -dvv TBL_NAME'.
  23867.  
  23868. MySQL Server Time Zone Support
  23869. ------------------------------
  23870.  
  23871. Before MySQL 4.1.3, you can set the time zone for the server with the
  23872. `--timezone=timezone_name' option to `mysqld_safe'.  You can also set
  23873. it by setting the `TZ' environment variable before you start `mysqld'.
  23874.  
  23875. The allowable values for `--timezone' or `TZ' are system-dependent.
  23876. Consult your operating system documentation to see what values are
  23877. acceptable.
  23878.  
  23879. Beginning with MySQL 4.1.3, the server maintains several time zone
  23880. settings:
  23881.  
  23882.    * The system time zone.  When the server starts, it attempts to
  23883.      determine the time zone of the host machine and uses it to set the
  23884.      `system_time_zone' system variable.
  23885.  
  23886.    * The server's current time zone. The global `time_zone' system
  23887.      variable indicates the time zone the server currently is operating
  23888.      in. The initial value is `'SYSTEM'', which indicates that the
  23889.      server time zone is the same as the system time zone. The initial
  23890.      value can be specified explicitly with the
  23891.      `--default-time-zone=TIMEZONE' option.  If you have the `SUPER'
  23892.      privilege, you can set the global value at runtime with this
  23893.      statement:
  23894.  
  23895.           mysql> SET GLOBAL time_zone = TIMEZONE;
  23896.  
  23897.    * Per-connection time zones. Each client that connects has its own
  23898.      time zone setting, given by the session `time_zone' variable.
  23899.      Initially this is the same as the global `time_zone' variable, but
  23900.      can be reset with this statement:
  23901.  
  23902.           mysql> SET time_zone = TIMEZONE;
  23903.  
  23904.  
  23905. The current values of the global and per-connection time zones can be
  23906. retrieved like this:
  23907.  
  23908.      mysql> SELECT @global.time_zone, @session.time_zone;
  23909.  
  23910. TIMEZONE values can be given as strings indicating an offset from UTC,
  23911. such as `'+10:00'' or `'-6:00''. If the time zone-related tables in the
  23912. `mysql' database have been created and populated, you can also used
  23913. named time zones, such as `'Europe/Helsinki'', `'US/Eastern'', or
  23914. `'MET''. The value `'SYSTEM'' indicates that the time zone should be
  23915. the same as the system time zone.  Time zone names are not case
  23916. sensitive.
  23917.  
  23918. The MySQL installation procedure creates the time zone tables in the
  23919. `mysql' database, but does not load them. You must do so manually.  (If
  23920. you are upgrading to MySQL 4.1.3 or later from an earlier version, you
  23921. should create the tables by upgrading your `mysql' database. Use the
  23922. instructions in *Note Upgrading-grant-tables::.)
  23923.  
  23924. *Note*: Currently, time time zone tables can be populated only on Unix.
  23925. This problem will be addressed soon for Windows.
  23926.  
  23927. The `mysql_tzinfo_to_sql' program is used to load the time zone tables.
  23928. You will need to know the directory under which your system's time zone
  23929. files are stored.  A likely location is `/usr/share/zoneinfo'.  Pass
  23930. the directory name on the command line to `mysql_tzinfo_to_sql', and
  23931. send the output into the `mysql' program. For example:
  23932.  
  23933.      shell> mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
  23934.  
  23935. `mysql_tzinfo_to_sql' reads your system's time zone files and generates
  23936. SQL statements from them.  `mysql' processes those statements to load
  23937. the time zone tables.
  23938.  
  23939. `mysql_tzinfo_to_sql' also can be used to load a single time zone file,
  23940. and to generate leap second information.
  23941.  
  23942. To load a single time zone file TZ_FILE that corresponds to a time zone
  23943. name TZ_NAME, invoke `mysql_tzinfo_to_sql' like this:
  23944.  
  23945.      shell> mysql_tzinfo_to_sql TZ_FILE TZ_NAME | mysql -u root mysql
  23946.  
  23947. If your time zone needs to account for leap seconds, initialize the
  23948. leap second information like this, where TZ_FILE is the name of your
  23949. time zone file:
  23950.  
  23951.      shell> mysql_tzinfo_to_sql --leap TZ_FILE | mysql -u root mysql
  23952.  
  23953. The MySQL Log Files
  23954. ===================
  23955.  
  23956. MySQL has several different log files that can help you find out what's
  23957. going on inside `mysqld':
  23958.  
  23959. *Log File*     *Types of Information Logged to File*
  23960. The error log  Logs problems encountered starting, running, or stopping
  23961.                `mysqld'.
  23962. The isam log   Logs all changes to the `ISAM' tables. Used only for
  23963.                debugging the isam code.
  23964. The query log  Logs established client connections and executed
  23965.                statements.
  23966. The update     Logs statements that change data. This log is deprecated.
  23967. log            
  23968. The binary     Logs all statements that change data. Also used for
  23969. log            replication.
  23970. The slow log   Logs all queries that took more than `long_query_time'
  23971.                seconds to execute or didn't use indexes.
  23972.  
  23973. By default, all logs are created in the `mysqld' data directory.  You
  23974. can force `mysqld' to close and reopen the log files (or in some cases
  23975. switch to a new log) by flushing the logs. Log flushing occurs when you
  23976. issue a `FLUSH LOGS' statement or execute `mysqladmin flush-logs' or
  23977. `mysqladmin refresh'.  *Note FLUSH::.
  23978.  
  23979. If you are using MySQL replication capabilities, slave replication
  23980. servers maintain additional log files called relay logs. These are
  23981. discussed in *Note Replication::.
  23982.  
  23983. The Error Log
  23984. -------------
  23985.  
  23986. The error log file contains information indicating when `mysqld' was
  23987. started and stopped and also any critical errors that occur while the
  23988. server is running.
  23989.  
  23990. If `mysqld' dies unexpectedly and `mysqld_safe' needs to restart it,
  23991. `mysqld_safe' will write a `restarted mysqld' message to the error log.
  23992. If `mysqld' notices a table that needs to be automatically checked or
  23993. repaired, it writes a message to the error log.
  23994.  
  23995. On some operating systems, the error log will contain a stack trace if
  23996. `mysqld' dies. The trace can be used to determine where `mysqld' died.
  23997. *Note Using stack trace::.
  23998.  
  23999. Beginning with MySQL 4.0.10, you can specify where `mysqld' stores the
  24000. error log file with the `--log-error[=FILE_NAME]' option. If no
  24001. FILE_NAME value is given, `mysqld' uses the name `HOST_NAME.err' and
  24002. writes the file in the data directory.  (Prior to MySQL 4.0.10, the
  24003. Windows error log name is `mysql.err'.)  If you execute `FLUSH LOGS',
  24004. the error log is renamed with a suffix of `-old' and `mysqld' creates a
  24005. new empty log file.
  24006.  
  24007. In older MySQL versions on Unix, error log handling was done by
  24008. `mysqld_safe' which redirected the error file to `HOST_NAME.err'.  You
  24009. could change this filename by specifying a `--err-log=FILE_NAME' option
  24010. to `mysqld_safe'.
  24011.  
  24012. If you don't specify `--log-error', or (on Windows) if you use the
  24013. `--console' option, errors are written to stderr, the standard error
  24014. output. Usually this is your terminal.
  24015.  
  24016. On Windows, error output is always written to the `.err' file if
  24017. `--console' is not given.
  24018.  
  24019. The General Query Log
  24020. ---------------------
  24021.  
  24022. If you want to know what happens within `mysqld', you should start it
  24023. with the `--log[=FILE_NAME]' or `-l [FILE_NAME]' option.  If no
  24024. FILE_NAME value is given, the default name is `HOST_NAME.log' This will
  24025. log all connections and statements to the log file.  This log can be
  24026. very useful when you suspect an error in a client and want to know
  24027. exactly what the client sent to `mysqld'.
  24028.  
  24029. Older versions of the `mysql.server' script (from MySQL 3.23.4 to
  24030. 3.23.8) pass a `--log' option to `safe_mysqld' to enable the general
  24031. query log.  If you need better performance when you start using MySQL
  24032. in a production environment, you can remove the `--log' option from
  24033. `mysql.server' or change it to `--log-bin'. *Note Binary log::.
  24034.  
  24035. `mysqld' writes statements to the query log in the order that it
  24036. receives them.  This may be different from the order in which they are
  24037. executed.  This is in contrast to the update log and the binary log,
  24038. which are written after the query is executed, but before any locks are
  24039. released.
  24040.  
  24041. Server restarts and log flushing do not cause a new general query log
  24042. file to be generated (although flushing closes and reopens it). On
  24043. Unix, you can rename the file and create a new one by using the
  24044. following commands:
  24045.  
  24046.      shell> mv hostname.log hostname-old.log
  24047.      shell> mysqladmin flush-logs
  24048.      shell> cp hostname-old.log to-backup-directory
  24049.      shell> rm hostname-old.log
  24050.  
  24051. On Windows, you cannot rename the log file while the server has it open.
  24052. You must stop the server and rename the log. Then restart the server to
  24053. create a new log.
  24054.  
  24055. The Update Log
  24056. --------------
  24057.  
  24058. *Note*: The update log has been deprecated and replaced by the binary
  24059. log. *Note Binary log::.  The binary log can do anything the old update
  24060. log could do, and more. _The update log is unavailable as of MySQL
  24061. 5.0.0_.
  24062.  
  24063. When started with the `--log-update[=FILE_NAME]' option, `mysqld'
  24064. writes a log file containing all SQL statements that update data. If no
  24065. FILE_NAME value is given, the default name is name of the host machine.
  24066. If a filename is given, but it doesn't contain a leading path, the file
  24067. is written in the data directory. If `file_name' doesn't have an
  24068. extension, `mysqld' creates log files with names of the form
  24069. FILE_NAME.###, where ### is a number that is incremented each time you
  24070. start the server or flush the logs.
  24071.  
  24072. *Note*: For this naming scheme to work, you must not create your own
  24073. files with the same names as those that might be used for the log file
  24074. sequence.
  24075.  
  24076. Update logging is smart because it logs only statements that really
  24077. update data. So, an `UPDATE' or a `DELETE' with a `WHERE' that finds no
  24078. rows is not written to the log. It even skips `UPDATE' statements that
  24079. set a column to the value it already has.
  24080.  
  24081. The update logging is done immediately after a query completes but
  24082. before any locks are released or any commit is done. This ensures that
  24083. statements are logged in execution order.
  24084.  
  24085. If you want to update a database from update log files, you could do the
  24086. following (assuming that your update logs have names of the form
  24087. `file_name.###'):
  24088.  
  24089.      shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
  24090.  
  24091. `ls' is used to sort the update log filenames into the right order.
  24092.  
  24093. This can be useful if you have to revert to backup files after a crash
  24094. and you want to redo the updates that occurred between the time of the
  24095. backup and the crash.
  24096.  
  24097. The Binary Log
  24098. --------------
  24099.  
  24100. The binary log has replaced the old update log, which is unavailable
  24101. starting from MySQL 5.0. The binary log contains all information that is
  24102. available in the update log in a more efficient format and in a manner
  24103. that is transactionally safe.
  24104.  
  24105. The binary log contains all statements which updated data or (starting
  24106. from MySQL 4.1.3) could potentially have updated it (for example, a
  24107. `DELETE' which matched no rows).
  24108.  
  24109. The binary log also contains information about how long each statement
  24110. took that updated the database.  It doesn't contain statements that
  24111. don't modify any data.  If you want to log all statements (for example,
  24112. to identify a problem query) you should use the general query log.
  24113. *Note Query log::.
  24114.  
  24115. The primary purpose of the binary log is to be able to update the
  24116. database during a restore operation as fully as possible, because the
  24117. binary log will contain all updates done after a backup was made.
  24118.  
  24119. The binary log is also used on master replication servers as a record
  24120. of the statements to be sent to slave servers.  *Note Replication::.
  24121.  
  24122. Running the server with the binary log enabled makes performance about
  24123. 1% slower. However, the benefits of the binary log for restore
  24124. operations and in allowing you to set up replication generally outweigh
  24125. this minor performance decrement.
  24126.  
  24127. When started with the `--log-bin[=FILE_NAME]' option, `mysqld' writes a
  24128. log file containing all SQL commands that update data. If no FILE_NAME
  24129. value is given, the default name is the name of the host machine
  24130. followed by `-bin'. If file name is given, but it doesn't contain a
  24131. path, the file is written in the data directory.
  24132.  
  24133. If you supply an extension in the log name (for example,
  24134. `--log-bin=FILE_NAME.EXTENSION'), the extension is silently removed and
  24135. ignored.
  24136.  
  24137. `mysqld' appends a numeric extension to the binary log name. The number
  24138. is incremented each time you start the server or flush the logs.  A new
  24139. binary log also is created automatically when the current log's size
  24140. reaches `max_binlog_size'. A binary log may become larger than
  24141. `max_binlog_size' if you are using large transactions: A transaction is
  24142. written to the binary log in one piece, never split between binary logs.
  24143.  
  24144. To be able to know which different binary log files have been used,
  24145. `mysqld' also creates a binary log index file that contains the name of
  24146. all used binary log files. By default this has the same name as the
  24147. binary log file, with the extension `'.index''.  You can change the
  24148. name of the binary log index file with the
  24149. `--log-bin-index[=FILE_NAME]' option.  You should not manually edit
  24150. this file while `mysqld' is running; doing so would confuse `mysqld'.
  24151.  
  24152. You can delete all binary log files with the `RESET MASTER' statement,
  24153. or only some of them with `PURGE MASTER LOGS'.  See *Note `RESET':
  24154. RESET and *Note Replication Master SQL::.
  24155.  
  24156. You can use the following options to `mysqld' to affect what is logged
  24157. to the binary log. See also the discussion that follows this option
  24158. list.
  24159.  
  24160. `--binlog-do-db=DB_NAME'
  24161.      Tells the master that it should log updates to the binary log if
  24162.      the current database (that is, the one selected by `USE') is
  24163.      DB_NAME. All other databases that are not explicitly mentioned are
  24164.      ignored.  If you use this, you should ensure that you only do
  24165.      updates in the current database.
  24166.  
  24167.      An example of what does not work as you might expect: If the
  24168.      server is started with `binlog-do-db=sales', and you do `USE
  24169.      prices; UPDATE sales.january SET amount=amount+1000;', this
  24170.      statement will not be written into the binary log.
  24171.  
  24172. `--binlog-ignore-db=DB_NAME'
  24173.      Tells the master that updates where the current database (that is,
  24174.      the one selected by `USE') is DB_NAME should not be stored in the
  24175.      binary log.  If you use this, you should ensure that you only do
  24176.      updates in the current database.
  24177.  
  24178.      An example of what does not work as you might expect: If the
  24179.      server is started with `binlog-ignore-db=sales', and you do `USE
  24180.      prices; UPDATE sales.january SET amount=amount+1000;', this
  24181.      statement will be written into the binary log.
  24182.  
  24183. To log or ignore multiple databases, specify the appropriate option
  24184. multiple times, once for each database.
  24185.  
  24186. The rules for logging or ignoring updates to the binary log are
  24187. evaluated in the following order:
  24188.  
  24189.   1. Are there `binlog-do-db' or `binlog-ignore-db' rules?
  24190.         * No: Write the statement to the binary log and exit.
  24191.  
  24192.         * Yes: Go to the next step.
  24193.  
  24194.   2. There are some rules (`binlog-do-db' or `binlog-ignore-db' or
  24195.      both). Is there a current database (has any database been selected
  24196.      by `USE'?)?
  24197.         * No: Do _not_ write the statement, and exit.
  24198.  
  24199.         * Yes: Go to the next step.
  24200.  
  24201.   3. There is a current database. Are there some `binlog-do-db' rules?
  24202.         * Yes: Does the current database match any of the `binlog-do-db'
  24203.           rules?
  24204.              * Yes: Write the statement and exit.
  24205.  
  24206.              * No: Do _not_ write the statement, and exit.
  24207.  
  24208.         * No: Go to the next step.
  24209.  
  24210.   4. There are some `binlog-ignore-db' rules.  Does the current
  24211.      database match any of the `binlog-ignore-db' rules?
  24212.         * Yes: Do not write the statement, and exit.
  24213.  
  24214.         * No: Write the query and exit.
  24215.  
  24216. For example, a slave running with only `binlog-do-db=sales' will not
  24217. write to the binary log any statement whose current database is
  24218. different from `sales' (in other words, `binlog-do-db' can sometimes
  24219. mean "ignore other databases").
  24220.  
  24221. If you are using replication, you should not delete old binary log
  24222. files until you are sure that no slave still needs to use them.  One
  24223. way to do this is to do `mysqladmin flush-logs' once a day and then
  24224. remove any logs that are more than three days old. You can remove them
  24225. manually, or preferably using `PURGE MASTER LOGS' (*note Replication
  24226. Master SQL::), which will also safely update the binary log index file
  24227. for you  (and which can take a date argument since MySQL 4.1)
  24228.  
  24229. A client with the `SUPER' privilege can disable binary logging of its
  24230. own statements by using a `SET SQL_LOG_BIN=0' statement. *Note `SET':
  24231. SET OPTION.
  24232.  
  24233. You can examine the binary log file with the `mysqlbinlog' utility.
  24234. This can be useful when you want to reprocess statements in the log.
  24235. For example, you can update a MySQL server from the binary log as
  24236. follows:
  24237.  
  24238.      shell> mysqlbinlog log-file | mysql -h server_name
  24239.  
  24240. See *Note `mysqlbinlog': mysqlbinlog for more information on the
  24241. `mysqlbinlog' utility and how to use it.
  24242.  
  24243. If you are using transactions, you must use the MySQL binary log for
  24244. backups instead of the old update log.
  24245.  
  24246. The binary logging is done immediately after a query completes but
  24247. before any locks are released or any commit is done. This ensures that
  24248. the log will be logged in the execution order.
  24249.  
  24250. Updates to non-transactional tables are stored in the binary log
  24251. immediately after execution.  For transactional tables such as `BDB' or
  24252. `InnoDB' tables, all updates (`UPDATE', `DELETE', or `INSERT') that
  24253. change tables are cached until a `COMMIT' statement is received by the
  24254. server. At that point, `mysqld' writes the whole transaction to the
  24255. binary log before the `COMMIT' is executed.  When the thread that
  24256. handles the transaction starts, it allocates a buffer of
  24257. `binlog_cache_size' to buffer queries.  If a statement is bigger than
  24258. this, the thread opens a temporary file to store the transaction.  The
  24259. temporary file is deleted when the thread ends.
  24260.  
  24261. The `max_binlog_cache_size' (default 4GB) can be used to restrict the
  24262. total size used to cache a multiple-statement transaction.  If a
  24263. transaction is larger than this, it will fail and roll back.
  24264.  
  24265. If you are using the update log or binary log, concurrent inserts will
  24266. be converted to normal inserts when using `CREATE ... SELECT' or
  24267. `INSERT ... SELECT'.  This is to ensure that you can re-create an exact
  24268. copy of your tables by applying the log on a backup.
  24269.  
  24270. The binary log format is different in versions 3.23, 4.0, and 5.0.0.
  24271. Those format changes were required to implement enhancements to
  24272. replication.  MySQL 4.1 has the same binary log format as 4.0.  *Note
  24273. Replication Compatibility::.
  24274.  
  24275. By default, the binary log is not synchronized to disk at each write. So
  24276. if the operating system or machine (not only the MySQL server) crashes
  24277. there is a chance that the last statements of the binary log are lost.
  24278. To prevent this, you can make the binary log be synchronized to disk
  24279. after every Nth binary log write, with the `sync_binlog' global variable
  24280. (1 being the safest value, but also the slowest). *Note Server system
  24281. variables::.  Even with this set to 1, there is still the chance of an
  24282. inconsistency between the tables content and the binary log content in
  24283. case of crash. For example, if using `InnoDB' tables, and the MySQL
  24284. server processes a `COMMIT' statement, it writes the whole transaction
  24285. to the binary log and then commits this transaction into `InnoDB'. If
  24286. it crashes between those two operations, at restart the transaction
  24287. will be rolled back by InnoDB but still exist in the binary log. This
  24288. problem can be solved with the `--innodb-safe-binlog' option (available
  24289. starting from MySQL 4.1.3), which adds consistency between the content
  24290. of `InnoDB' tables and the binary log. For this option to really bring
  24291. safety to you, the MySQL server should also be configured to
  24292. synchronize to disk, at every transaction, the binary log
  24293. (`sync_binlog=1') and (which is true by default) the `InnoDB' logs.
  24294. The effect of this option is that at restart after a crash, after doing
  24295. a rollback of transactions, the MySQL server will cut rolled back
  24296. `InnoDB' transactions from the binary log. This ensures that the binary
  24297. log reflects the exact data of `InnoDB' tables, and so, that the slave
  24298. remains in sync with the master (not receiving a statement which has
  24299. been rolled back).  Note that `--innodb-safe-binlog' can be used even
  24300. if the MySQL server updates other storage engines than InnoDB. Only
  24301. statements/transactions affecting `InnoDB' tables are subject to being
  24302. removed from the binary log at `InnoDB''s crash recovery.  If at crash
  24303. recovery the MySQL server discovers that the binary log is shorter than
  24304. it should have been (that is, it lacks at least one successfully
  24305. committed `InnoDB' transaction), which should not happen if
  24306. `sync_binlog=1' and the disk/filesystem do an actual sync when they are
  24307. requested to (some don't), it will print an error message ("The binary
  24308. log <name> is shorter than its expected size"). In this case, this
  24309. binary log is not correct, replication should be restarted from a fresh
  24310. master's data snapshot.
  24311.  
  24312. The binary log format has some limitations which apply when the client
  24313. sessions change their character set and collation variables. *Note
  24314. Replication Features::.
  24315.  
  24316. The Slow Query Log
  24317. ------------------
  24318.  
  24319. When started with the `--log-slow-queries[=FILE_NAME]' option, `mysqld'
  24320. writes a log file containing all SQL statements that took more than
  24321. `long_query_time' seconds to execute. The time to acquire the initial
  24322. table locks are not counted as execution time.
  24323.  
  24324. If no FILE_NAME value is given, the default is the name of the host
  24325. machine with a suffix of `-slow.log'. If a filename is given, but
  24326. doesn't contain a path, the file is written in the data directory.
  24327.  
  24328. A statement is logged to the slow query log after it has been executed
  24329. and after all locks have been released. Log order may be different from
  24330. execution order.
  24331.  
  24332. The slow query log can be used to find queries that take a long time to
  24333. execute and are therefore candidates for optimization. However,
  24334. examining a long slow query log can become a difficult task. To make
  24335. this easier, you can pipe the slow query log through the
  24336. `mysqldumpslow' command to get a summary of the queries that appear in
  24337. the log.
  24338.  
  24339. If you also use the `--log-long-format' when logging slow queries, then
  24340. queries that are not using indexes are logged as well.  *Note Server
  24341. options::.
  24342.  
  24343. Log File Maintenance
  24344. --------------------
  24345.  
  24346. The MySQL Server can create a number of different log files that make
  24347. it easy to see what is going on. *Note Log Files::. However, you must
  24348. clean up these files regularly to ensure that the logs don't take up
  24349. too much disk space.
  24350.  
  24351. When using MySQL with logging enabled, you will want to back up and
  24352. remove old log files from time to time and tell MySQL to start logging
  24353. to new files.  *Note Backup::.
  24354.  
  24355. On a Linux (Red Hat) installation, you can use the `mysql-log-rotate'
  24356. script for this. If you installed MySQL from an RPM distribution, the
  24357. script should have been installed automatically.  You should be careful
  24358. with this script if you are using the binary log for replication! (You
  24359. should not remove binary logs until you are certain that their contents
  24360. have been processed by all slaves.)
  24361.  
  24362. On other systems, you must install a short script yourself that you
  24363. start from `cron' to handle log files.
  24364.  
  24365. You can force MySQL to start using new log files by using `mysqladmin
  24366. flush-logs' or by using the SQL statement `FLUSH LOGS'.  If you are
  24367. using MySQL 3.21, you must use `mysqladmin refresh'.
  24368.  
  24369. A log flushing operation does the following:
  24370.  
  24371.    * If standard logging (`--log') or slow query logging
  24372.      (`--log-slow-queries') is used, closes and reopens the log file
  24373.      (`mysql.log' and ``hostname`-slow.log' as default).
  24374.  
  24375.    * If update logging (`--log-update') or binary logging (`--log-bin')
  24376.      is used, closes the log and opens a new log file with a higher
  24377.      sequence number.
  24378.  
  24379. If you are using only an update log, you only have to rename the log
  24380. file and then flush the logs before making a backup. For example, you
  24381. can do something like this:
  24382.  
  24383.      shell> cd mysql-data-directory
  24384.      shell> mv mysql.log mysql.old
  24385.      shell> mysqladmin flush-logs
  24386.  
  24387. Then make a backup and remove `mysql.old'.
  24388.  
  24389. Running Multiple MySQL Servers on the Same Machine
  24390. ==================================================
  24391.  
  24392. In some cases, you might want to run multiple `mysqld' servers on the
  24393. same machine.  You might want to test a new MySQL release while leaving
  24394. your existing production setup undisturbed.  Or you may want to give
  24395. different users access to different `mysqld' servers that they manage
  24396. themselves.  (For example, you might be an Internet Service Provider
  24397. that wants to provide independent MySQL installations for different
  24398. customers.)
  24399.  
  24400. To run multiple servers on a single machine, each server must have
  24401. unique values for several operating parameters. These can be set on the
  24402. command line or in option files.  *Note Program Options::.
  24403.  
  24404. At least the following options must be different for each server:
  24405.  
  24406. `--port=PORT_NUM'
  24407.      `--port' controls the port number for TCP/IP connections.
  24408.  
  24409. `--socket=PATH'
  24410.      `--socket' controls the Unix socket file path on Unix and the name
  24411.      of the named pipe on Windows. On Windows, it's necessary to
  24412.      specify distinct pipe names only for those servers that support
  24413.      named pipe connections.
  24414.  
  24415. `--shared-memory-base-name=NAME'
  24416.      This option currently is used only on Windows.  It designates the
  24417.      shared memory name used by a Windows server to allow clients to
  24418.      connect via shared memory.  This option is new in MySQL 4.1.
  24419.  
  24420. `--pid-file=PATH'
  24421.      This option is used only on Unix.  It indicates the name of the
  24422.      file in which the server writes its process ID.
  24423.  
  24424. If you use the following log file options, they must be different for
  24425. each server:
  24426.  
  24427.    * `--log=PATH'
  24428.  
  24429.    * `--log-bin=PATH'
  24430.  
  24431.    * `--log-update=PATH'
  24432.  
  24433.    * `--log-error=PATH'
  24434.  
  24435.    * `--log-isam=PATH'
  24436.  
  24437.    * `--bdb-logdir=PATH'
  24438.  
  24439. Log file options are described in *Note Log file maintenance::.
  24440.  
  24441. If you want more performance, you can also specify the following options
  24442. differently for each server, to spread the load between several
  24443. physical disks:
  24444.  
  24445.    * `--tmpdir=PATH'
  24446.  
  24447.    * `--bdb-tmpdir=PATH'
  24448.  
  24449. Having different temporary directories is also recommended, to make it
  24450. easier to determine which MySQL server created any given temporary file.
  24451.  
  24452. Generally, each server should also use a different data directory,
  24453. which is specified using the `--datadir=path' option.
  24454.  
  24455. *Warning:* Normally you should never have two servers that update data
  24456. in the same databases!  This may lead to unpleasant surprises if your
  24457. operating system doesn't support fault-free system locking!  If
  24458. (despite this warning) you run multiple servers using the same data
  24459. directory and they have logging enabled, you must use the appropriate
  24460. options to specify log filenames that are unique to each server.
  24461. Otherwise, the servers will try to log to the same files.  Please note
  24462. that this kind of setup will only work with `ISAM', `MyISAM' and
  24463. `MERGE' tables, and not with any of the other storage engines.
  24464.  
  24465. The warning against sharing a data directory among servers also applies
  24466. in an NFS environment.  Allowing multiple MySQL servers to access a
  24467. common data directory over NFS is a _bad idea_!
  24468.  
  24469.    * The primary problem is that NFS will become the speed bottleneck.
  24470.      It is not meant for such use.
  24471.  
  24472.    * Another risk with NFS is that you will have to come up with a way
  24473.      to make sure that two or more servers do not interfere with each
  24474.      other.  Usually NFS file locking is handled by the `lockd' daemon,
  24475.      but at the moment there is no platform that will perform locking
  24476.      100% reliably in every situation.
  24477.  
  24478.  
  24479. Make it easy for yourself: Forget about sharing a data directory among
  24480. servers over NFS. A better solution is to have one computer that
  24481. contains several CPUs and use an operating system that handles threads
  24482. efficiently.
  24483.  
  24484. If you have multiple MySQL installations in different locations,
  24485. normally you can specify the base installation directory for each
  24486. server with the `--basedir=path' option to cause each server to use a
  24487. different data directory, log files, and PID file. (The defaults for
  24488. all these values are determined relative to the base directory). In
  24489. that case, the only other options you need to specify are the
  24490. `--socket' and `--port' options.  For example, suppose that you install
  24491. different versions of MySQL using `tar' file binary distributions.
  24492. These will install in different locations, so you can start the server
  24493. for each installation using the command `bin/mysqld_safe' under its
  24494. corresponding base directory.  `mysqld_safe' will determine the proper
  24495. `--basedir' option to pass to `mysqld', and you need specify only the
  24496. `--socket' and `--port' options to `mysqld_safe'.  (For versions of
  24497. MySQL older than 4.0, use `safe_mysqld' rather than `mysqld_safe'.)
  24498.  
  24499. As discussed in the following sections, it is possible to start
  24500. additional servers by setting environment variables or by specifying
  24501. appropriate command-line options.  However, if you need to run multiple
  24502. servers on a more permanent basis, it will be more convenient to use
  24503. option files to specify for each server those option values that must
  24504. be unique to it.
  24505.  
  24506. Running Multiple Servers on Windows
  24507. -----------------------------------
  24508.  
  24509. You can run multiple servers on Windows by starting them manually from
  24510. the command line, each with appropriate operating parameters. On
  24511. Windows NT-based systems, you also have the option of installing
  24512. several servers as Windows services and running them that way. General
  24513. instructions for running MySQL servers from the command line or as
  24514. services are given in *Note Windows installation::. This section
  24515. describes how to make sure that you start each server with different
  24516. values for those startup options that must be unique per server, such
  24517. as the data directory.  These options are described in *Note Multiple
  24518. servers::.
  24519.  
  24520. Starting Multiple Windows Servers at the Command Line
  24521. .....................................................
  24522.  
  24523. To start multiple servers manually from the command line, you can
  24524. specify the appropriate options on the command line or in an option
  24525. file. It's more convenient to place the options in an option file, but
  24526. it's necessary to make sure that each server gets its own set of
  24527. options. To do this, create an option file for each server and tell the
  24528. server the filename with a `--defaults-file' option when you run it.
  24529.  
  24530. Suppose that you want to run `mysqld' on port 3307 with a data
  24531. directory of `C:\mydata1', and `mysqld-max' on port 3308 with a data
  24532. directory of `C:\mydata2'. (To do this, make sure that before you start
  24533. the servers, each data directory exists and has its own copy of the
  24534. `mysql' database that contains the grant tables.)
  24535.  
  24536. Then create two option files. For example, create one file named
  24537. `C:\my-opts1.cnf' that looks like this:
  24538.  
  24539.      [mysqld]
  24540.      datadir = C:/mydata1
  24541.      port = 3307
  24542.  
  24543. Create a second file named `C:\my-opts2.cnf' that looks like this:
  24544.  
  24545.      [mysqld]
  24546.      datadir = C:/mydata2
  24547.      port = 3308
  24548.  
  24549. Then start each server with its own option file:
  24550.  
  24551.      C:\> C:\mysql\bin\mysqld --defaults-file=C:\my-opts1.cnf
  24552.      C:\> C:\mysql\bin\mysqld-max --defaults-file=C:\my-opts2.cnf
  24553.  
  24554. On NT, each server will start in the foreground (no new prompt appears
  24555. until the server exits later); you'll need to issue those two commands
  24556. in separate console windows.
  24557.  
  24558. To shut down the servers, you must connect to the appropriate port
  24559. number:
  24560.  
  24561.      C:\> C:\mysql\bin\mysqladmin --port=3307 shutdown
  24562.      C:\> C:\mysql\bin\mysqladmin --port=3308 shutdown
  24563.  
  24564. Servers configured as just described will allow clients to connect over
  24565. TCP/IP.  If your version of Windows supports named pipes and you also
  24566. want to allow named pipe connections, use the `mysqld-nt' or
  24567. `mysqld-max-nt' servers and specify options that enable the named pipe
  24568. and specify its name. Each server that supports named pipe connections
  24569. must use a unique pipe name.  For example, the `C:\my-opts1.cnf' file
  24570. might be written like this:
  24571.  
  24572.      [mysqld]
  24573.      datadir = C:/mydata1
  24574.      port = 3307
  24575.      enable-named-pipe
  24576.      socket = mypipe1
  24577.  
  24578. Then start the server this way:
  24579.  
  24580.      C:\> C:\mysql\bin\mysqld-nt --defaults-file=C:\my-opts1.cnf
  24581.  
  24582. Modify `C:\my-opts2.cnf' similarly for use by the second server.
  24583.  
  24584. Starting Multiple Windows Servers as Services
  24585. .............................................
  24586.  
  24587. On NT-based systems, a MySQL server can be run as a Windows service. The
  24588. procedures for installing, controlling, and removing a single MySQL
  24589. service are described in *Note NT start::.
  24590.  
  24591. As of MySQL 4.0.2, you can install multiple servers as services.  In
  24592. this case, you must make sure that each server uses a different service
  24593. name in addition to all the other parameters that must be unique per
  24594. server.
  24595.  
  24596. For the following instructions, assume that you want to run the
  24597. `mysqld-nt' server from two different versions of MySQL that are
  24598. installed at `C:\mysql-4.0.8' and `C:\mysql-4.0.17', respectively.
  24599. (This might be the case if you're running 4.0.8 as your production
  24600. server, but want to test 4.0.17 before upgrading to it.)
  24601.  
  24602. The following principles apply when installing a MySQL service with the
  24603. `--install' or `--install-manual' option:
  24604.  
  24605.    * If you specify no service name, the server uses the default
  24606.      service name of `MySQL' and the server reads options from the
  24607.      `[mysqld]' group in the standard option files.
  24608.  
  24609.    * If you specify a service name after the `--install' option, the
  24610.      server ignores the `[mysqld]' option group and instead reads
  24611.      options from the group that has the same name as the service. The
  24612.      server reads options from the standard option files.
  24613.  
  24614.    * If you specify a `--defaults-file' option after the service name,
  24615.      the server ignores the standard option files and reads options
  24616.      only from the `[mysqld]' group of the named file.
  24617.  
  24618.  
  24619. *Note*: Before MySQL 4.0.17, only a server installed using the default
  24620. service name (`MySQL') or one installed explicitly with a service name
  24621. of `mysqld' will read the `[mysqld]' group in the standard option
  24622. files. As of 4.0.17, all servers read the `[mysqld]' group if they read
  24623. the standard option files, even if they are installed using another
  24624. service name. This allows you to use the `[mysqld]' group for options
  24625. that should be used by all MySQL services, and an option group named
  24626. after each service for use by the server installed with that service
  24627. name.
  24628.  
  24629. Based on the preceding information, you have several ways to set up
  24630. multiple services.  The following instructions describe some examples.
  24631. Before trying any of them, be sure that you shut down and remove any
  24632. existing MySQL services first.
  24633.  
  24634.    * *Approach 1:* Specify the options for all services in one of the
  24635.      standard option files.  To do this, use a different service name
  24636.      for each server.  Suppose that you want to run the 4.0.8
  24637.      `mysqld-nt' using the service name of `mysqld1' and the 4.0.17
  24638.      `mysqld-nt' using the service name `mysqld2'.  In this case, you
  24639.      can use the `[mysqld1]' group for 4.0.8 and the `[mysqld2]' group
  24640.      for 4.0.17.  For example, you can set up `C:\my.cnf' like this:
  24641.  
  24642.           # options for mysqld1 service
  24643.           [mysqld1]
  24644.           basedir = C:/mysql-4.0.8
  24645.           port = 3307
  24646.           enable-named-pipe
  24647.           socket = mypipe1
  24648.           
  24649.           # options for mysqld2 service
  24650.           [mysqld2]
  24651.           basedir = C:/mysql-4.0.17
  24652.           port = 3308
  24653.           enable-named-pipe
  24654.           socket = mypipe2
  24655.  
  24656.      Install the services as follows, using the full server pathnames
  24657.      to ensure that Windows registers the correct executable program
  24658.      for each service:
  24659.  
  24660.           C:\> C:\mysql-4.0.8\bin\mysqld-nt --install mysqld1
  24661.           C:\> C:\mysql-4.0.17\bin\mysqld-nt --install mysqld2
  24662.  
  24663.      To start the services, use the services manager, or use `NET START'
  24664.      with the appropriate service names:
  24665.  
  24666.           C:\> NET START mysqld1
  24667.           C:\> NET START mysqld2
  24668.  
  24669.      To stop the services, use the services manager, or use `NET STOP'
  24670.      with the appropriate service names:
  24671.  
  24672.           C:\> NET STOP mysqld1
  24673.           C:\> NET STOP mysqld2
  24674.  
  24675.    * *Approach 2:* Specify options for each server in separate files
  24676.      and use `--defaults-file' when you install the services to tell
  24677.      each server what file to use.  In this case, each file should list
  24678.      options using a `[mysqld]' group.
  24679.  
  24680.      With this approach, to specify options for the 4.0.8 `mysqld-nt',
  24681.      create a file `C:\my-opts1.cnf' that looks like this:
  24682.  
  24683.           [mysqld]
  24684.           basedir = C:/mysql-4.0.8
  24685.           port = 3307
  24686.           enable-named-pipe
  24687.           socket = mypipe1
  24688.  
  24689.      For the 4.0.17 `mysqld-nt', create a file `C:\my-opts2.cnf' that
  24690.      looks like this:
  24691.  
  24692.           [mysqld]
  24693.           basedir = C:/mysql-4.0.17
  24694.           port = 3308
  24695.           enable-named-pipe
  24696.           socket = mypipe2
  24697.  
  24698.      Install the services as follows (enter each command on a single
  24699.      line):
  24700.  
  24701.           C:\> C:\mysql-4.0.8\bin\mysqld-nt --install mysqld1
  24702.                      --defaults-file=C:\my-opts1.cnf
  24703.           C:\> C:\mysql-4.0.17\bin\mysqld-nt --install mysqld2