home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / sharewar / mysql / data1.cab / Documentation / Docs / manual.txt < prev   
Encoding:
Text File  |  2001-11-02  |  1.9 MB  |  50,498 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 About MySQL
  10.   MySQL, MySQL AB, and Open Source
  11.     What Is MySQL
  12.     What Is MySQL AB
  13.     About This Manual
  14.     Conventions Used in This Manual
  15.     History of MySQL
  16.     The Main Features of MySQL
  17.     How Stable Is MySQL?
  18.     How Big Can MySQL Tables Be?
  19.     Year 2000 Compliance
  20.   MySQL Information Sources
  21.     Books About MySQL
  22.     General SQL Information and Tutorials
  23.     Useful MySQL-related Links
  24.     MySQL Mailing Lists
  25.       The MySQL Mailing Lists
  26.       Asking Questions or Reporting Bugs
  27.       How to Report Bugs or Problems
  28.       Guidelines for Answering Question on the Mailing List
  29.   MySQL Licensing and Support
  30.     MySQL Licensing Policy
  31.     Copyrights Used by MySQL
  32.       Copyright Changes
  33.     Example Licensing Situations
  34.       Selling Products that use MySQL
  35.       ISP MySQL Services
  36.       Running a Web Server Using MySQL
  37.     MySQL Licensing and Support Costs
  38.       Payment information
  39.       Contact Information
  40.     Types of Commercial Support
  41.       Basic E-mail Support
  42.       Extended E-mail Support
  43.       Login Support
  44.       Extended Login Support
  45.       Telephone Support
  46.       Support for other table handlers
  47.   How Standards-compatible Is MySQL?
  48.     MySQL Extensions to ANSI SQL92
  49.     MySQL Differences Compared to ANSI SQL92
  50.     Running MySQL in ANSI Mode
  51.     Functionality Missing from MySQL
  52.       Sub-selects
  53.       `SELECT INTO TABLE'
  54.       Transactions
  55.       Stored Procedures and Triggers
  56.       Foreign Keys
  57.       Reasons NOT to Use Foreign Keys constraints
  58.       Views
  59.       `--' as the Start of a Comment
  60.     What Standards Does MySQL Follow?
  61.     How to Cope Without `COMMIT'/`ROLLBACK'
  62.     Known errors and design deficiencies in MySQL
  63.   How MySQL Compares to Other Databases
  64.     How MySQL Compares to `mSQL'
  65.       How to Convert `mSQL' Tools for MySQL
  66.       How `mSQL' and MySQL Client/Server Communications Protocols Differ
  67.       How `mSQL' 2.0 SQL Syntax Differs from MySQL
  68.     How MySQL Compares to PostgreSQL
  69.       MySQL and PostgreSQL development strategies
  70.       Featurewise Comparison of MySQL and PostgreSQL
  71.       Benchmarking MySQL and PostgreSQL
  72.   MySQL and the future (The TODO)
  73.     Things that should be in 4.0
  74.     Things that must be done in the real near future
  75.     Things that have to be done sometime
  76.     Some things we don't have any plans to do
  77.  
  78. MySQL Installation
  79.   Quick Standard Installation of MySQL
  80.     Installing MySQL on Linux
  81.     Installing MySQL on Windows
  82.   General Installation Issues
  83.     How to Get MySQL
  84.     Operating Systems Supported by MySQL
  85.     Which MySQL Version to Use
  86.     Installation Layouts
  87.     How and When Updates Are Released
  88.     MySQL Binaries Compiled by MySQL AB
  89.   Installing a MySQL Source Distribution
  90.     Quick Installation Overview
  91.     Applying Patches
  92.     Typical `configure' Options
  93.     Installing from the Development Source Tree
  94.     Problems Compiling?
  95.     MIT-pthreads Notes
  96.   Post-installation Setup and Testing
  97.     Problems Running `mysql_install_db'
  98.     Problems Starting the MySQL Server
  99.     Starting and Stopping MySQL Automatically
  100.   Upgrading/Downgrading MySQL
  101.     Upgrading From Version 3.22 to Version 3.23
  102.     Upgrading from Version 3.21 to Version 3.22
  103.     Upgrading from Version 3.20 to Version 3.21
  104.     Upgrading to Another Architecture
  105.   Operating System Specific Notes
  106.     Linux Notes (All Linux Versions)
  107.       Linux Notes for Binary Distributions
  108.       Linux x86 Notes
  109.       Linux SPARC Notes
  110.       Linux Alpha Notes
  111.       Linux PowerPC Notes
  112.       Linux MIPS Notes
  113.       Linux IA64 Notes
  114.     Windows Notes
  115.       Starting MySQL on Windows 95 or Windows 98
  116.       Starting MySQL on Windows NT or Windows 2000
  117.       Running MySQL on Windows
  118.       Connecting to a Remote MySQL from Windows with SSH
  119.       Splitting Data Across Different Disks on Windows
  120.       Compiling MySQL Clients on Windows
  121.       MySQL-Windows Compared to Unix MySQL
  122.     Solaris Notes
  123.       Solaris 2.7/2.8 Notes
  124.       Solaris x86 Notes
  125.     BSD Notes
  126.       FreeBSD Notes
  127.       NetBSD notes
  128.       OpenBSD Notes
  129.       OpenBSD 2.5 Notes
  130.       OpenBSD 2.8 Notes
  131.       BSD/OS Notes
  132.       BSD/OS Version 2.x Notes
  133.       BSD/OS Version 3.x Notes
  134.       BSD/OS Version 4.x Notes
  135.     Mac OS X Notes
  136.       Mac OS X Public Beta
  137.       Mac OS X Server
  138.     Other Unix Notes
  139.       HP-UX Notes for Binary Distributions
  140.       HP-UX Version 10.20 Notes
  141.       HP-UX Version 11.x Notes
  142.       IBM-AIX notes
  143.       SunOS 4 Notes
  144.       Alpha-DEC-UNIX Notes (Tru64)
  145.       Alpha-DEC-OSF1 Notes
  146.       SGI Irix Notes
  147.       SCO Notes
  148.       SCO Unixware Version 7.0 Notes
  149.     OS/2 Notes
  150.     BeOS Notes
  151.     Novell Netware Notes
  152.  
  153. Introduction to MySQL: A MySQL Tutorial
  154.   Connecting to and Disconnecting from the Server
  155.   Entering Queries
  156.   Creating and Using a Database
  157.     Creating and Selecting a Database
  158.     Creating a Table
  159.     Loading Data into a Table
  160.     Retrieving Information from a Table
  161.       Selecting All Data
  162.       Selecting Particular Rows
  163.       Selecting Particular Columns
  164.       Sorting Rows
  165.       Date Calculations
  166.       Working with `NULL' Values
  167.       Pattern Matching
  168.       Counting Rows
  169.       Using More Than one Table
  170.   Getting Information About Databases and Tables
  171.   Examples of Common Queries
  172.     The Maximum Value for a Column
  173.     The Row Holding the Maximum of a Certain Column
  174.     Maximum of Column per Group
  175.     The Rows Holding the Group-wise Maximum of a Certain Field
  176.     Using user variables
  177.     Using Foreign Keys
  178.     Searching on Two Keys
  179.     Calculating visits per day
  180.   Using `mysql' in Batch Mode
  181.   Queries from Twin Project
  182.     Find all Non-distributed Twins
  183.     Show a Table on Twin Pair Status
  184.   Using MySQL with Apache
  185.  
  186. MySQL Database Administration
  187.   Configuring MySQL
  188.     mysqld Command-line Options
  189.     my.cnf Option Files
  190.     Installing Many Servers on the Same Machine
  191.     Running Multiple MySQL Servers on the Same Machine
  192.   General Security Issues and the MySQL Access Privilege System
  193.     General Security Guidelines
  194.     How to Make MySQL Secure Against Crackers
  195.     Startup Options for `mysqld' Concerning Security
  196.     What the Privilege System Does
  197.     How the Privilege System Works
  198.     Privileges Provided by MySQL
  199.     Connecting to the MySQL Server
  200.     Access Control, Stage 1: Connection Verification
  201.     Access Control, Stage 2: Request Verification
  202.     Causes of `Access denied' Errors
  203.   MySQL User Account Management
  204.     `GRANT' and `REVOKE' Syntax
  205.     MySQL User Names and Passwords
  206.     When Privilege Changes Take Effect
  207.     Setting Up the Initial MySQL Privileges
  208.     Adding New Users to MySQL
  209.     Setting Up Passwords
  210.     Keeping Your Password Secure
  211.   Disaster Prevention and Recovery
  212.     Database Backups
  213.     `BACKUP TABLE' Syntax
  214.     `RESTORE TABLE' Syntax
  215.     `CHECK TABLE' Syntax
  216.     `REPAIR TABLE' Syntax
  217.     Using `myisamchk' for Table Maintenance and Crash Recovery
  218.       `myisamchk' Invocation Syntax
  219.       General Options for `myisamchk'
  220.       Check Options for `myisamchk'
  221.       Repair Options for myisamchk
  222.       Other Options for `myisamchk'
  223.       `myisamchk' Memory Usage
  224.       Using `myisamchk' for Crash Recovery
  225.       How to Check Tables for Errors
  226.       How to Repair Tables
  227.       Table Optimization
  228.     Setting Up a Table Maintenance Regimen
  229.     Getting Information About a Table
  230.   Database Administration Language Reference
  231.     `OPTIMIZE TABLE' Syntax
  232.     `ANALYZE TABLE' Syntax
  233.     `FLUSH' Syntax
  234.     `KILL' Syntax
  235.     `SHOW' Syntax
  236.       Retrieving information about Database, Tables, Columns, and Indexes
  237.       `SHOW TABLE STATUS'
  238.       `SHOW STATUS'
  239.       `SHOW VARIABLES'
  240.       `SHOW LOGS'
  241.       `SHOW PROCESSLIST'
  242.       `SHOW GRANTS'
  243.       `SHOW CREATE TABLE'
  244.   MySQL Localization and International Usage
  245.     The Character Set Used for Data and Sorting
  246.     Non-English Error Messages
  247.     Adding a New Character Set
  248.     The character definition arrays
  249.     String Collating Support
  250.     Multi-byte Character Support
  251.   MySQL Server-Side Scripts and Utilities
  252.     Overview of the Server-Side Scripts and Utilities
  253.     safe_mysqld, the wrapper around mysqld
  254.     mysqld_multi, program for managing multiple MySQL servers
  255.     myisampack, The MySQL Compressed Read-only Table Generator
  256.     mysqld-max, An extended mysqld server
  257.   MySQL Client-Side Scripts and Utilities
  258.     Overview of the Client-Side Scripts and Utilities
  259.     The Command-line Tool
  260.     mysqladmin, Administrating a MySQL Server
  261.     Using `mysqlcheck' for Table Maintenance and Crash Recovery
  262.     mysqldump, Dumping Table Structure and Data
  263.     mysqlhotcopy, Copying MySQL Databases and Tables
  264.     mysqlimport, Importing Data from Text Files
  265.     Showing Databases, Tables, and Columns
  266.     perror, Explaining Error Codes
  267.     How to Run SQL Commands from a Text File
  268.   The MySQL Log Files
  269.     The Error Log
  270.     The General Query Log
  271.     The Update Log
  272.     The Binary Update Log
  273.     The Slow Query Log
  274.     Log File Maintenance
  275.   Replication in MySQL
  276.     Introduction
  277.     Replication Implementation Overview
  278.     How To Set Up Replication
  279.     Replication Features and Known Problems
  280.     Replication Options in my.cnf
  281.     SQL Commands Related to Replication
  282.     Replication FAQ
  283.     Troubleshooting Replication
  284.  
  285. MySQL Optimization
  286.   Optimization Overview
  287.     MySQL Design Limitations/Tradeoffs
  288.     Portability
  289.     What Have We Used MySQL For?
  290.     The MySQL Benchmark Suite
  291.     Using Your Own Benchmarks
  292.   Optimizing `SELECT's and Other Queries
  293.     `EXPLAIN' Syntax (Get Information About a `SELECT')
  294.     Estimating Query Performance
  295.     Speed of `SELECT' Queries
  296.     How MySQL Optimizes `WHERE' Clauses
  297.     How MySQL Optimizes `DISTINCT'
  298.     How MySQL Optimizes `LEFT JOIN' and `RIGHT JOIN'
  299.     How MySQL Optimizes `LIMIT'
  300.     Speed of `INSERT' Queries
  301.     Speed of `UPDATE' Queries
  302.     Speed of `DELETE' Queries
  303.     Other Optimization Tips
  304.   Locking Issues
  305.     How MySQL Locks Tables
  306.     Table Locking Issues
  307.   Optimizing Database Structure
  308.     Design Choices
  309.     Get Your Data as Small as Possible
  310.     How MySQL Uses Indexes
  311.     Column Indexes
  312.     Multiple-Column Indexes
  313.     How MySQL Opens and Closes Tables
  314.     Drawbacks to Creating Large Numbers of Tables in the Same Database
  315.     Why So Many Open tables?
  316.   Optimizing the MySQL Server
  317.     System/Compile Time and Startup Parameter Tuning
  318.     Tuning Server Parameters
  319.     How Compiling and Linking Affects the Speed of MySQL
  320.     How MySQL Uses Memory
  321.     How MySQL uses DNS
  322.     `SET' Syntax
  323.   Disk Issues
  324.     Using Symbolic Links
  325.       Using Symbolic Links for Databases
  326.       Using Symbolic Links for Tables
  327.  
  328. MySQL Language Reference
  329.   Language Structure
  330.     Literals: How to Write Strings and Numbers
  331.       Strings
  332.       Numbers
  333.       Hexadecimal Values
  334.       `NULL' Values
  335.     Database, Table, Index, Column, and Alias Names
  336.     Case Sensitivity in Names
  337.     User Variables
  338.     Comment Syntax
  339.     Is MySQL Picky About Reserved Words?
  340.   Column Types
  341.     Numeric Types
  342.     Date and Time Types
  343.       Y2K Issues and Date Types
  344.       The `DATETIME', `DATE', and `TIMESTAMP' Types
  345.       The `TIME' Type
  346.       The `YEAR' Type
  347.     String Types
  348.       The `CHAR' and `VARCHAR' Types
  349.       The `BLOB' and `TEXT' Types
  350.       The `ENUM' Type
  351.       The `SET' Type
  352.     Choosing the Right Type for a Column
  353.     Using Column Types from Other Database Engines
  354.     Column Type Storage Requirements
  355.   Functions for Use in `SELECT' and `WHERE' Clauses
  356.     Non-Type-Specific Operators and Functions
  357.       Parenthesis
  358.       Comparison Operators
  359.       Logical Operators
  360.       Control Flow Functions
  361.     String Functions
  362.       String Comparison Functions
  363.       Case Sensitivity
  364.     Numeric Functions
  365.       Arithmetic Operations
  366.       Mathematical Functions
  367.     Date and Time Functions
  368.     Other Functions
  369.       Bit Functions
  370.       Miscellaneous Functions
  371.   Data Manipulation: `SELECT', `INSERT', `UPDATE', `DELETE'
  372.     `SELECT' Syntax
  373.       `JOIN' Syntax
  374.     `INSERT' Syntax
  375.       `INSERT ... SELECT' Syntax
  376.     `INSERT DELAYED' syntax
  377.     `UPDATE' Syntax
  378.     `DELETE' Syntax
  379.     `TRUNCATE' Syntax
  380.     `REPLACE' Syntax
  381.     `LOAD DATA INFILE' Syntax
  382.   Data Definition: `CREATE', `DROP', `ALTER'
  383.     `CREATE DATABASE' Syntax
  384.     `DROP DATABASE' Syntax
  385.     `CREATE TABLE' Syntax
  386.       Silent Column Specification Changes
  387.     `ALTER TABLE' Syntax
  388.     `RENAME TABLE' Syntax
  389.     `DROP TABLE' Syntax
  390.     `CREATE INDEX' Syntax
  391.     `DROP INDEX' Syntax
  392.   Basic MySQL User Utility Commands
  393.     `USE' Syntax
  394.     `DESCRIBE' Syntax (Get Information About Columns)
  395.   MySQL Transactional and Locking Commands
  396.     `BEGIN/COMMIT/ROLLBACK' Syntax
  397.     `LOCK TABLES/UNLOCK TABLES' Syntax
  398.     `SET TRANSACTION' Syntax
  399.   MySQL Full-text Search
  400.     Fulltext restrictions
  401.     Fine-tuning MySQL Full-text Search
  402.     New Features of Full-text Search to Appear in MySQL 4.0
  403.     Full-text Search TODO
  404.  
  405. MySQL Table Types
  406.   MyISAM Tables
  407.     Space Needed for Keys
  408.     MyISAM Table Formats
  409.       Static (Fixed-length) Table Characteristics
  410.       Dynamic Table Characteristics
  411.       Compressed Table Characteristics
  412.     MyISAM table problems.
  413.       Corrupted MyISAM tables.
  414.       Clients is using or hasn't closed the table properly
  415.   MERGE Tables
  416.   ISAM Tables
  417.   HEAP Tables
  418.   BDB or Berkeley_DB Tables
  419.     Overview of BDB Tables
  420.     Installing BDB
  421.     BDB startup options
  422.     Some characteristic of `BDB' tables:
  423.     Some things we need to fix for BDB in the near future:
  424.     Operating systems supported by *BDB*
  425.     Errors You May Get When Using BDB Tables
  426.   InnoDB Tables
  427.     InnoDB tables overview
  428.     InnoDB startup options
  429.     Creating InnoDB table space
  430.       If something goes wrong in database creation
  431.     Creating InnoDB tables
  432.       Converting MyISAM tables to InnoDB
  433.     Adding and removing InnoDB data and log files
  434.     Backing up and recovering an InnoDB database
  435.       Checkpoints
  436.     Moving an InnoDB database to another machine
  437.     InnoDB transaction model
  438.       Consistent read
  439.       Locking reads
  440.       Next-key locking: avoiding the phantom problem
  441.       Locks set by different SQL statements in InnoDB
  442.       Deadlock detection and rollback
  443.       An example of how the consistent read works in InnoDB
  444.     Performance tuning tips
  445.       The InnoDB Monitor
  446.     Implementation of multiversioning
  447.     Table and index structures
  448.       Physical structure of an index
  449.       Insert buffering
  450.       Adaptive hash indexes
  451.       Physical record structure
  452.       How an auto-increment column works in InnoDB
  453.     File space management and disk i/o
  454.       Disk i/o
  455.       File space management
  456.       Defragmenting a table
  457.     Error handling
  458.     Some restrictions on InnoDB tables
  459.     InnoDB contact information
  460.  
  461. MySQL APIs
  462.   MySQL PHP API
  463.     Common Problems with MySQL and PHP
  464.   MySQL Perl API
  465.     `DBI' with `DBD::mysql'
  466.     The `DBI' Interface
  467.     More `DBI'/`DBD' Information
  468.   MySQL ODBC Support
  469.     How To Install MyODBC
  470.     How to Fill in the Various Fields in the ODBC Administrator Program
  471.     Connect parameters for MyODBC
  472.     How to Report Problems with MyODBC
  473.     Programs Known to Work with MyODBC
  474.     How to Get the Value of an `AUTO_INCREMENT' Column in ODBC
  475.     Reporting Problems with MyODBC
  476.   MySQL C API
  477.     C API Datatypes
  478.     C API Function Overview
  479.     C API Function Descriptions
  480.       `mysql_affected_rows()'
  481.       `mysql_close()'
  482.       `mysql_connect()'
  483.       `mysql_change_user()'
  484.       `mysql_character_set_name()'
  485.       `mysql_create_db()'
  486.       `mysql_data_seek()'
  487.       `mysql_debug()'
  488.       `mysql_drop_db()'
  489.       `mysql_dump_debug_info()'
  490.       `mysql_eof()'
  491.       `mysql_errno()'
  492.       `mysql_error()'
  493.       `mysql_escape_string()'
  494.       `mysql_fetch_field()'
  495.       `mysql_fetch_fields()'
  496.       `mysql_fetch_field_direct()'
  497.       `mysql_fetch_lengths()'
  498.       `mysql_fetch_row()'
  499.       `mysql_field_count()'
  500.       `mysql_field_seek()'
  501.       `mysql_field_tell()'
  502.       `mysql_free_result()'
  503.       `mysql_get_client_info()'
  504.       `mysql_get_host_info()'
  505.       `mysql_get_proto_info()'
  506.       `mysql_get_server_info()'
  507.       `mysql_info()'
  508.       `mysql_init()'
  509.       `mysql_insert_id()'
  510.       `mysql_kill()'
  511.       `mysql_list_dbs()'
  512.       `mysql_list_fields()'
  513.       `mysql_list_processes()'
  514.       `mysql_list_tables()'
  515.       `mysql_num_fields()'
  516.       `mysql_num_rows()'
  517.       `mysql_options()'
  518.       `mysql_ping()'
  519.       `mysql_query()'
  520.       `mysql_real_connect()'
  521.       `mysql_real_escape_string()'
  522.       `mysql_real_query()'
  523.       `mysql_reload()'
  524.       `mysql_row_seek()'
  525.       `mysql_row_tell()'
  526.       `mysql_select_db()'
  527.       `mysql_shutdown()'
  528.       `mysql_stat()'
  529.       `mysql_store_result()'
  530.       `mysql_thread_id()'
  531.       `mysql_use_result()'
  532.     C Threaded Function Descriptions
  533.       `my_init()'
  534.       `my_thread_init()'
  535.       `my_thread_end()'
  536.     Common questions and problems when using the C API
  537.       Why Is It that After `mysql_query()' Returns Success, `mysql_store_result()' Sometimes Returns `NULL?'
  538.       What Results Can I Get From a Query?
  539.       How Can I Get the Unique ID for the Last Inserted Row?
  540.       Problems Linking with the C API
  541.     Building Client Programs
  542.     How to Make a Threaded Client
  543.   MySQL C++ APIs
  544.     Borland C++
  545.   MySQL Java Connectivity (JDBC)
  546.   MySQL Python APIs
  547.   MySQL Tcl APIs
  548.   MySQL Eiffel wrapper
  549.  
  550. Extending MySQL
  551.   Adding New Functions to MySQL
  552.     `CREATE FUNCTION/DROP FUNCTION' Syntax
  553.     Adding a New User-definable Function
  554.       UDF Calling Sequences
  555.       Argument Processing
  556.       Return Values and Error Handling
  557.       Compiling and Installing User-definable Functions
  558.     Adding a New Native Function
  559.   Adding New Procedures to MySQL
  560.     Procedure Analyse
  561.     Writing a Procedure
  562.   MySQL Internals
  563.     MySQL Threads
  564.     MySQL Test Suite
  565.       Running the MySQL Test Suite
  566.       Extending the MySQL Test Suite
  567.       Reporting Bugs in the MySQL Test Suite
  568.  
  569. Problems and Common Errors
  570.   How to Determine What Is Causing Problems
  571.   Some Common Errors When Using MySQL
  572.     `Access denied' Error
  573.     `MySQL server has gone away' Error
  574.     `Can't connect to [local] MySQL server' error
  575.     `Host '...' is blocked' Error
  576.     `Too many connections' Error
  577.     `Some non-transactional changed tables couldn't be rolled back' Error
  578.     `Out of memory' Error
  579.     `Packet too large' Error
  580.     Communication Errors / Aborted Connection
  581.     `The table is full' Error
  582.     `Can't create/write to file' Error
  583.     `Commands out of sync' Error in Client
  584.     `Ignoring user' Error
  585.     `Table 'xxx' doesn't exist' Error
  586.     `Cant' initialize character set xxx' error.
  587.     File Not Found
  588.   Installation Related Issues
  589.     Problems When Linking with the MySQL Client Library
  590.     How to Run MySQL As a Normal User
  591.     Problems with File Permissions
  592.   Administration Related Issues
  593.     What To Do If MySQL Keeps Crashing
  594.     How to Reset a Forgotten Password
  595.     How MySQL Handles a Full Disk
  596.     Where MySQL Stores Temporary Files
  597.     How to Protect or change the MySQL socket file `/tmp/mysql.sock'
  598.     Time Zone Problems
  599.   Query Related Issues
  600.     Case Sensitivity in Searches
  601.     Problems Using `DATE' Columns
  602.     Problems with `NULL' Values
  603.     Problems with `alias'
  604.     Deleting Rows from Related Tables
  605.     Solving Problems with No Matching Rows
  606.   Table Definition Related Issues
  607.     Problems with `ALTER TABLE'.
  608.     How To Change the Order of Columns in a Table
  609.     TEMPORARY TABLE problems
  610.  
  611. Some MySQL Users
  612.   General News Sites
  613.   Some Web Search Engines
  614.   Some Information Search Engines Concentrated on Some Area
  615.   Online Magazines
  616.   Web Sites that Use MySQL as a Backend
  617.   Some Domain/Internet/Web and Related Services
  618.   Web Sites that Use `PHP' and MySQL
  619.   Some MySQL Consultants
  620.   Programming
  621.   Uncategorized Pages
  622.  
  623. MySQL customer usage
  624.  
  625. Contributed Programs
  626.   APIs
  627.   Clients
  628.   Web Tools
  629.   Performance Benchmarking Tools
  630.   Authentication Tools
  631.   Converters
  632.   Using MySQL with Other Products
  633.   Useful Tools
  634.   RPMs for Common Tools (Most Are for RedHat 6.1)
  635.   Useful Functions
  636.   Windows programs
  637.   Uncategorized
  638.  
  639. Credits
  640.   Developers at MySQL AB
  641.   Contributors to MySQL
  642.   Supporters to MySQL
  643.  
  644. MySQL change history
  645.   Changes in release 4.0.x (Development; Alpha)
  646.     Changes in release 4.0.0
  647.   Changes in release 3.23.x  (Stable)
  648.     Changes in release 3.23.44
  649.     Changes in release 3.23.43
  650.     Changes in release 3.23.42
  651.     Changes in release 3.23.41
  652.     Changes in release 3.23.40
  653.     Changes in release 3.23.39
  654.     Changes in release 3.23.38
  655.     Changes in release 3.23.37
  656.     Changes in release 3.23.36
  657.     Changes in release 3.23.35
  658.     Changes in release 3.23.34a
  659.     Changes in release 3.23.34
  660.     Changes in release 3.23.33
  661.     Changes in release 3.23.32
  662.     Changes in release 3.23.31
  663.     Changes in release 3.23.30
  664.     Changes in release 3.23.29
  665.     Changes in release 3.23.28
  666.     Changes in release 3.23.27
  667.     Changes in release 3.23.26
  668.     Changes in release 3.23.25
  669.     Changes in release 3.23.24
  670.     Changes in release 3.23.23
  671.     Changes in release 3.23.22
  672.     Changes in release 3.23.21
  673.     Changes in release 3.23.20
  674.     Changes in release 3.23.19
  675.     Changes in release 3.23.18
  676.     Changes in release 3.23.17
  677.     Changes in release 3.23.16
  678.     Changes in release 3.23.15
  679.     Changes in release 3.23.14
  680.     Changes in release 3.23.13
  681.     Changes in release 3.23.12
  682.     Changes in release 3.23.11
  683.     Changes in release 3.23.10
  684.     Changes in release 3.23.9
  685.     Changes in release 3.23.8
  686.     Changes in release 3.23.7
  687.     Changes in release 3.23.6
  688.     Changes in release 3.23.5
  689.     Changes in release 3.23.4
  690.     Changes in release 3.23.3
  691.     Changes in release 3.23.2
  692.     Changes in release 3.23.1
  693.     Changes in release 3.23.0
  694.   Changes in release 3.22.x (Older; Still supported)
  695.     Changes in release 3.22.35
  696.     Changes in release 3.22.34
  697.     Changes in release 3.22.33
  698.     Changes in release 3.22.32
  699.     Changes in release 3.22.31
  700.     Changes in release 3.22.30
  701.     Changes in release 3.22.29
  702.     Changes in release 3.22.28
  703.     Changes in release 3.22.27
  704.     Changes in release 3.22.26
  705.     Changes in release 3.22.25
  706.     Changes in release 3.22.24
  707.     Changes in release 3.22.23
  708.     Changes in release 3.22.22
  709.     Changes in release 3.22.21
  710.     Changes in release 3.22.20
  711.     Changes in release 3.22.19
  712.     Changes in release 3.22.18
  713.     Changes in release 3.22.17
  714.     Changes in release 3.22.16
  715.     Changes in release 3.22.15
  716.     Changes in release 3.22.14
  717.     Changes in release 3.22.13
  718.     Changes in release 3.22.12
  719.     Changes in release 3.22.11
  720.     Changes in release 3.22.10
  721.     Changes in release 3.22.9
  722.     Changes in release 3.22.8
  723.     Changes in release 3.22.7
  724.     Changes in release 3.22.6
  725.     Changes in release 3.22.5
  726.     Changes in release 3.22.4
  727.     Changes in release 3.22.3
  728.     Changes in release 3.22.2
  729.     Changes in release 3.22.1
  730.     Changes in release 3.22.0
  731.   Changes in release 3.21.x
  732.     Changes in release 3.21.33
  733.     Changes in release 3.21.32
  734.     Changes in release 3.21.31
  735.     Changes in release 3.21.30
  736.     Changes in release 3.21.29
  737.     Changes in release 3.21.28
  738.     Changes in release 3.21.27
  739.     Changes in release 3.21.26
  740.     Changes in release 3.21.25
  741.     Changes in release 3.21.24
  742.     Changes in release 3.21.23
  743.     Changes in release 3.21.22
  744.     Changes in release 3.21.21a
  745.     Changes in release 3.21.21
  746.     Changes in release 3.21.20
  747.     Changes in release 3.21.19
  748.     Changes in release 3.21.18
  749.     Changes in release 3.21.17
  750.     Changes in release 3.21.16
  751.     Changes in release 3.21.15
  752.     Changes in release 3.21.14b
  753.     Changes in release 3.21.14a
  754.     Changes in release 3.21.13
  755.     Changes in release 3.21.12
  756.     Changes in release 3.21.11
  757.     Changes in release 3.21.10
  758.     Changes in release 3.21.9
  759.     Changes in release 3.21.8
  760.     Changes in release 3.21.7
  761.     Changes in release 3.21.6
  762.     Changes in release 3.21.5
  763.     Changes in release 3.21.4
  764.     Changes in release 3.21.3
  765.     Changes in release 3.21.2
  766.     Changes in release 3.21.0
  767.   Changes in release 3.20.x
  768.     Changes in release 3.20.18
  769.     Changes in release 3.20.17
  770.     Changes in release 3.20.16
  771.     Changes in release 3.20.15
  772.     Changes in release 3.20.14
  773.     Changes in release 3.20.13
  774.     Changes in release 3.20.11
  775.     Changes in release 3.20.10
  776.     Changes in release 3.20.9
  777.     Changes in release 3.20.8
  778.     Changes in release 3.20.7
  779.     Changes in release 3.20.6
  780.     Changes in release 3.20.3
  781.     Changes in release 3.20.0
  782.   Changes in release 3.19.x
  783.     Changes in release 3.19.5
  784.     Changes in release 3.19.4
  785.     Changes in release 3.19.3
  786.  
  787. Comments on porting to other systems
  788.   Debugging a MySQL server
  789.     Compiling MYSQL for debugging.
  790.     Creating trace files
  791.     Debugging mysqld under gdb
  792.     Using a stack trace
  793.     Using log files to find cause of errors in mysqld
  794.     Making a test case when you experience table corruption
  795.   Debugging a MySQL client
  796.   The DBUG package.
  797.   Locking methods
  798.   Comments about RTS threads
  799.   Differences between different thread packages
  800.  
  801. Environment Variables
  802.  
  803. Description of MySQL regular expression syntax
  804.  
  805. What is Unireg?
  806.  
  807. GNU GENERAL PUBLIC LICENSE
  808.   Preamble
  809.   How to Apply These Terms to Your New Programs
  810.  
  811. GNU LESSER GENERAL PUBLIC LICENSE
  812.   Preamble
  813.   How to Apply These Terms to Your New Libraries
  814.  
  815. Pieces of the manual in transit
  816.   Installing a MySQL Binary Distribution
  817.   Perl Installation Comments
  818.     Installing Perl on Unix
  819.     Installing ActiveState Perl on Windows
  820.     Installing the MySQL Perl Distribution on Windows
  821.     Problems Using the Perl `DBI'/`DBD' Interface
  822.   Functions for Use with `GROUP BY' Clauses
  823.  
  824. SQL command, type and function index
  825.  
  826. Concept Index
  827.  
  828.  
  829. This is a manual for MySQL. This version is about the 3.23.44 version
  830. of MySQL.  You can find a manual about any older version of MySQL in
  831. the binary or source distribution for that version.
  832.  
  833. General Information About MySQL
  834. *******************************
  835.  
  836. This is the MySQL reference manual; it documents MySQL Version
  837. 3.23.44.  As MySQL is work in progress, the manual gets updated
  838. frequently.  There is a very good chance that this version is out of
  839. date, unless you are looking at it online.  The most recent version of
  840. this manual is available at `http://www.mysql.com/documentation/' in
  841. many different formats.  If you have a hard time finding information in
  842. the manual, you can try the searchable PHP version at
  843. `http://www.mysql.com/documentation/manual.php'.
  844.  
  845. MySQL is a very fast, multi-threaded, multi-user, and robust SQL
  846. (Structured Query Language) database server.
  847.  
  848. MySQL is free software.  It is licensed with the *GNU GENERAL PUBLIC
  849. LICENSE* `http://www.gnu.org/'.  *Note Licensing and Support::.
  850.  
  851. The MySQL home page (http://www.mysql.com/) provides the latest
  852. information about MySQL.
  853.  
  854. The following list describes some useful sections of the manual:
  855.  
  856.    * For information about the company behind MySQL, see *Note What is
  857.      MySQL AB::.
  858.  
  859.    * For a discussion of MySQL's capabilities, see *Note Features::.
  860.  
  861.    * For installation instructions, see *Note Installing::.
  862.  
  863.    * For tips on porting MySQL to new architectures or operating
  864.      systems, see *Note Porting::.
  865.  
  866.    * For information about upgrading from a Version 3.22 release, see
  867.      *Note Upgrading-from-3.22::.
  868.  
  869.    * For a tutorial introduction to MySQL, see *Note Tutorial::.
  870.  
  871.    * For examples of SQL and benchmarking information, see the
  872.      benchmarking directory (`sql-bench' in the distribution).
  873.  
  874.    * For a history of new features and bug fixes, see *Note News::.
  875.  
  876.    * For a list of currently known bugs and misfeatures, see *Note
  877.      Bugs::.
  878.  
  879.    * For future plans, see *Note TODO::.
  880.  
  881.    * For a list of all the contributors to this project, see *Note
  882.      Credits::.
  883.  
  884. *IMPORTANT:*
  885.  
  886. Reports of errors (often called bugs), as well as questions and
  887. comments, should be sent to the mailing list at <mysql@lists.mysql.com>.
  888. *Note Bug reports::.  The `mysqlbug' script should be used to generate
  889. bug reports.  For source distributions, the `mysqlbug' script can be
  890. found in the `scripts' directory.  For binary distributions, `mysqlbug'
  891. can be found in the `bin' directory. If you have found a sensitive
  892. security bug in MySQL, you should send an email to <security@mysql.com>.
  893.  
  894. If you have any suggestions concerning additions or corrections to this
  895. manual, please send them to the manual team at <docs@mysql.com>.
  896.  
  897. This is a reference manual; it does not provide general instruction on
  898. SQL or relational database concepts.  If you want general information
  899. about SQL, see *Note General-SQL::.  For books that focus more
  900. specifically on MySQL, see *Note MySQL-Books::.
  901.  
  902. MySQL, MySQL AB, and Open Source
  903. ================================
  904.  
  905. What Is MySQL
  906. -------------
  907.  
  908. MySQL, the most popular Open Source SQL database, is provided by MySQL
  909. AB.  MySQL AB is a commercial company that builds its business
  910. providing services around the MySQL database.  *Note What is MySQL AB::.
  911.  
  912. MySQL is a database management system.
  913.      A database is a structured collection of data.  It may be anything
  914.      from a simple shopping list to a picture gallery or the vast
  915.      amounts of information in a corporate network.  To add, access,
  916.      and process data stored in a computer database, you need a
  917.      database management system such as MySQL.  Since computers are
  918.      very good at handling large amounts of data, database management
  919.      plays a central role in computing, as stand-alone utilities, or as
  920.      parts of other applications.
  921.  
  922. MySQL is a relational database management system.
  923.      A relational database stores data in separate tables rather than
  924.      putting all the data in one big storeroom.  This adds speed and
  925.      flexibility.  The tables are linked by defined relations making it
  926.      possible to combine data from several tables on request.  The SQL
  927.      part of MySQL stands for "Structured Query Language" - the most
  928.      common standardized language used to access databases.
  929.  
  930. MySQL is Open Source Software.
  931.      Open Source means that it is possible for anyone to use and modify.
  932.      Anybody can download MySQL from the Internet and use it without
  933.      paying anything.  Anybody so inclined can study the source code
  934.      and change it to fit their needs.  MySQL uses the GPL (GNU General
  935.      Public License) `http://www.gnu.org', to define what you may and
  936.      may not do with the software in different situations.  If you feel
  937.      uncomfortable with the GPL or need to embed MySQL into a
  938.      commercial application you can buy a commercially licensed version
  939.      from us.
  940.  
  941. Why use MySQL?
  942.      MySQL is very fast, reliable, and easy to use.  If that is what
  943.      you are looking for, you should give it a try.  MySQL also has a
  944.      very practical set of features developed in very close cooperation
  945.      with our users.  You can find a performance comparison of MySQL to
  946.      some other database managers on our benchmark page.  *Note MySQL
  947.      Benchmarks::.
  948.  
  949.      MySQL was originally developed to handle very large databases much
  950.      faster than existing solutions and has been successfully used in
  951.      highly demanding production environments for several years.  Though
  952.      under constant development, MySQL today offers a rich and very
  953.      useful set of functions.  The connectivity, speed, and security
  954.      make MySQL highly suited for accessing databases on the Internet.
  955.  
  956. The technical features of MySQL
  957.      For advanced technical information, see *Note Reference::.  MySQL
  958.      is a client/server system that consists of a multi-threaded SQL
  959.      server that supports different backends, several different client
  960.      programs and libraries, administrative tools, and several
  961.      programming interfaces.
  962.  
  963.      We also provide MySQL as a multi-threaded library which you can
  964.      link into your application to get a smaller, faster, easier to
  965.      manage product.
  966.  
  967. MySQL has a lot of contributed software available.
  968.      It is very likely that you will find that your favorite
  969.      application or language already supports MySQL.
  970.  
  971. The official way to pronounce MySQL is "My Ess Que Ell" (not
  972. MY-SEQUEL). But we try to avoid correcting people who say MY-SEQUEL.
  973.  
  974. What Is MySQL AB
  975. ----------------
  976.  
  977. MySQL AB is the Swedish company owned and run by the MySQL founders and
  978. main developers.  We are dedicated to developing MySQL and spreading
  979. our database to new users.  MySQL AB owns the copyright to the MySQL
  980. server source code and the MySQL trademark.  A significant amount of
  981. revenues from our services goes to developing MySQL.  *Note What-is::.
  982.  
  983. MySQL AB has been profitable providing MySQL from the start.  We don't
  984. get any outside funding, but have earned all our money ourselves.
  985.  
  986. We are searching after partners that would like to support our
  987. development of MySQL so that we could accelerate the development pace.
  988. If you are interested in doing this, you can email <partner@mysql.com>
  989. about this!
  990.  
  991. MySQL AB has currently 20+ people
  992. (`http://www.mysql.com/development/team.html') on its payroll and is
  993. growing rapidly.
  994.  
  995. Our main sources of income are:
  996.  
  997.    * Commercial high quality support for MySQL provided by the MySQL
  998.      developers themselves.  If you are interested in purchasing a
  999.      support contract, please visit `https://order.mysql.com/' to view
  1000.      our support options or to order support.
  1001.  
  1002.    * Consulting services.  We have developers and consultants in 12
  1003.      countries and partners in many other countries that can help you
  1004.      with almost any MySQL related issues.  If you need consulting
  1005.      services, please email a good description of your needs to
  1006.      <info@mysql.com>!  If we can't handle this ourselves we can
  1007.      usually find a partner or a developer that can help you with your
  1008.      problems.
  1009.  
  1010.    * We sell licenses for using MySQL as an embedded database.  *Note
  1011.      Cost::.  If you have a commercial product for which you need a
  1012.      fast, high quality database, but you can't afford to make your
  1013.      product Open Source, you can buy the right to use the MySQL server
  1014.      under a normal commercial copyright.  If you are interested in
  1015.      this you can buy MySQL licenses at `https://order.mysql.com/' or
  1016.      contact us at <licensing@mysql.com>.
  1017.  
  1018.    * Advertising. `http://www.mysql.com/' is a very popular web site
  1019.      with more than 10,000,000 page views per months (January 2001).
  1020.      By putting a banner on this you are guaranteed to reach a lot of
  1021.      potential customers in the Open source, Linux and database
  1022.      community. If you are interested in this email
  1023.      <advertising@mysql.com>.
  1024.  
  1025.    * We are building a partner program to be able to provide MySQL
  1026.      services in every country.  If you are interested in becoming a
  1027.      partner of MySQL AB please visit
  1028.      `http://www.mysql.com/information/partners.html' or email
  1029.      <partner@mysql.com>.
  1030.  
  1031.    * We provide MySQL training through our partner programs.  For more
  1032.      information, please email <info@mysql.com>.
  1033.  
  1034.    * The MySQL brand has, since 1995, been associated with speed and
  1035.      reliability, and is known to be something you can depend upon.  If
  1036.      you are interested in using the MySQL trademark in your marketing,
  1037.      you can email <info@mysql.com> about this.
  1038.  
  1039. The MySQL core values show our dedication to MySQL and Open Source.
  1040.  
  1041. We want MySQL to be:
  1042.  
  1043.    * The best and the most used database in the world.
  1044.  
  1045.    * Available and affordable for all.
  1046.  
  1047.    * Easy to use.
  1048.  
  1049.    * Continuously improved while remaining fast and safe.
  1050.  
  1051.    * Fun to use and improve.
  1052.  
  1053.    * Free from bugs.
  1054.  
  1055. MySQL AB and the people of MySQL AB:
  1056.  
  1057.    * Promote Open Source Philosophy and support the Open Source
  1058.      Community.
  1059.  
  1060.    * Aim to be good citizens.
  1061.  
  1062.    * Prefer partners that share our values and mind-set.
  1063.  
  1064.    * Answer mail and give support.
  1065.  
  1066.    * Are a virtual company, networking with others.
  1067.  
  1068.    * Work against software patents.
  1069.  
  1070. About This Manual
  1071. -----------------
  1072.  
  1073. This manual is currently available in Texinfo, plain text, Info, HTML,
  1074. PostScript, and PDF versions.  The primary document is the Texinfo file.
  1075. The HTML version is produced automatically using a modified version of
  1076. `texi2html'.  The plain text and Info versions are produced with
  1077. `makeinfo'.  The Postscript version is produced using `texi2dvi' and
  1078. `dvips'.  The PDF version is produced with `pdftex'.
  1079.  
  1080. This manual is written and maintained by David Axmark, Michael (Monty)
  1081. Widenius, Jeremy Cole, and Paul DuBois.  For other contributors, see
  1082. *Note Credits::.
  1083.  
  1084. Conventions Used in This Manual
  1085. -------------------------------
  1086.  
  1087. This manual uses certain typographical conventions:
  1088.  
  1089. `constant'
  1090.      Constant-width font is used for command names and options; SQL
  1091.      statements; database, table and column names; C and Perl code; and
  1092.      environment variables.  Example: "To see how `mysqladmin' works,
  1093.      invoke it with the `--help' option."
  1094.  
  1095. `filename'
  1096.      Constant-width font with surrounding quotes is used for filenames
  1097.      and pathnames.  Example: "The distribution is installed under the
  1098.      `/usr/local/' directory."
  1099.  
  1100. `c'
  1101.      Constant-width font with surrounding quotes is also used to
  1102.      indicate character sequences.  Example: "To specify a wild card,
  1103.      use the `%' character."
  1104.  
  1105. _italic_
  1106.      Italic font is used for emphasis, _like this_.
  1107.  
  1108. *boldface*
  1109.      Boldface font is used for access privilege names (for example, "do
  1110.      not grant the *process* privilege lightly") and occasionally to
  1111.      convey *especially strong emphasis*.
  1112.  
  1113. When commands are shown that are meant to be executed by a particular
  1114. program, the program is indicated by a prompt shown before the command.
  1115. For example, `shell>' indicates a command that you execute from your
  1116. login shell, and `mysql>' indicates a command that you execute from the
  1117. `mysql' client program:
  1118.  
  1119.      shell> type a shell command here
  1120.      mysql> type a mysql command here
  1121.  
  1122. Shell commands are shown using Bourne shell syntax.  If you are using a
  1123. `csh'-style shell, you may need to issue commands slightly differently.
  1124. For example, the sequence to set an environment variable and run a
  1125. command looks like this in Bourne shell syntax:
  1126.  
  1127.      shell> VARNAME=value some_command
  1128.  
  1129. For `csh', you would execute the sequence like this:
  1130.  
  1131.      shell> setenv VARNAME value
  1132.      shell> some_command
  1133.  
  1134. Often, database, table, and column names must be substituted into
  1135. commands.  To indicate that such substitution is necessary, this manual
  1136. uses `db_name', `tbl_name' and `col_name'.  For example, you might see
  1137. a statement like this:
  1138.  
  1139.      mysql> SELECT col_name FROM db_name.tbl_name;
  1140.  
  1141. This means that if you were to enter a similar statement, you would
  1142. supply your own database, table, and column names, perhaps like this:
  1143.  
  1144.      mysql> SELECT author_name FROM biblio_db.author_list;
  1145.  
  1146. SQL statements may be written in uppercase or lowercase.  When this
  1147. manual shows a SQL statement, uppercase is used for particular keywords
  1148. if those keywords are under discussion (to emphasize them) and
  1149. lowercase is used for the rest of the statement.  For example, you
  1150. might see the following in a discussion of the `SELECT' statement:
  1151.  
  1152.      mysql> SELECT count(*) FROM tbl_name;
  1153.  
  1154. On the other hand, in a discussion of the `COUNT()' function, the same
  1155. statement would be written like this:
  1156.  
  1157.      mysql> select COUNT(*) from tbl_name;
  1158.  
  1159. If no particular emphasis is intended, all keywords are written
  1160. uniformly in uppercase.
  1161.  
  1162. In syntax descriptions, square brackets (`[' and `]') are used to
  1163. indicate optional words or clauses:
  1164.  
  1165.      DROP TABLE [IF EXISTS] tbl_name
  1166.  
  1167. When a syntax element consists of a number of alternatives, the
  1168. alternatives are separated by vertical bars (`|').  When one member
  1169. from a set of choices *may* be chosen, the alternatives are listed
  1170. within square brackets (`[' and `]'):
  1171.  
  1172.      TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
  1173.  
  1174. When one member from a set of choices *must* be chosen, the
  1175. alternatives are listed within braces (`{' and `}'):
  1176.  
  1177.      {DESCRIBE | DESC} tbl_name {col_name | wild}
  1178.  
  1179. History of MySQL
  1180. ----------------
  1181.  
  1182. We once started out with the intention of using `mSQL' to connect to our
  1183. tables using our own fast low-level (ISAM) routines. However, after some
  1184. testing we came to the conclusion that `mSQL' was not fast enough nor
  1185. flexible enough for our needs.  This resulted in a new SQL interface to
  1186. our database but with almost the same API interface as `mSQL'.  This
  1187. API was chosen to ease porting of third-party code.
  1188.  
  1189. The derivation of the name MySQL is not perfectly clear.  Our base
  1190. directory and a large number of our libraries and tools have had the
  1191. prefix "my" for well over 10 years.  However, Monty's daughter (some
  1192. years younger) is also named My.  Which of the two gave its name to
  1193. MySQL is still a mystery, even for us.
  1194.  
  1195. The Main Features of MySQL
  1196. --------------------------
  1197.  
  1198. The following list describes some of the important characteristics of
  1199. MySQL:
  1200.  
  1201.    * Fully multi-threaded using kernel threads.  This means it can
  1202.      easily use multiple CPUs if available.
  1203.  
  1204.    * C, C++, Eiffel, Java, Perl, PHP, Python and Tcl APIs.  *Note
  1205.      Clients::.
  1206.  
  1207.    * Works on many different platforms.  *Note Which OS::.
  1208.  
  1209.    * Many column types: signed/unsigned integers 1, 2, 3, 4, and 8 bytes
  1210.      long, `FLOAT', `DOUBLE', `CHAR', `VARCHAR', `TEXT', `BLOB',
  1211.      `DATE', `TIME', `DATETIME', `TIMESTAMP', `YEAR', `SET', and `ENUM'
  1212.      types.  *Note Column types::.
  1213.  
  1214.    * Very fast joins using an optimized one-sweep multi-join.
  1215.  
  1216.    * Full operator and function support in the `SELECT' and `WHERE'
  1217.      parts of queries.  For example:
  1218.  
  1219.           mysql> SELECT CONCAT(first_name, " ", last_name) FROM tbl_name
  1220.                      WHERE income/dependents > 10000 AND age > 30;
  1221.  
  1222.    * SQL functions are implemented through a highly optimized class
  1223.      library and should be as fast as possible!  Usually there isn't
  1224.      any memory allocation at all after query initialization.
  1225.  
  1226.    * Full support for SQL `GROUP BY' and `ORDER BY' clauses.  Support
  1227.      for group functions (`COUNT()', `COUNT(DISTINCT ...)', `AVG()',
  1228.      `STD()', `SUM()', `MAX()' and `MIN()').
  1229.  
  1230.    * Support for `LEFT OUTER JOIN' and `RIGHT OUTER JOIN' with ANSI SQL
  1231.      and ODBC syntax.
  1232.  
  1233.    * You can mix tables from different databases in the same query (as
  1234.      of Version 3.22).
  1235.  
  1236.    * A privilege and password system that is very flexible and secure,
  1237.      and allows host-based verification.  Passwords are secure because
  1238.      all password traffic is encrypted when you connect to a server.
  1239.  
  1240.    * ODBC (Open-DataBase-Connectivity) support for Win32 (with source).
  1241.      All ODBC 2.5 functions and many others.  For example, you can use
  1242.      MS Access to connect to your MySQL server.  *Note ODBC::.
  1243.  
  1244.    * Very fast B-tree disk tables with index compression.
  1245.  
  1246.    * Up to 32 indexes per table are allowed.  Each index may consist of
  1247.      1 to 16 columns or parts of columns.  The maximum index length is
  1248.      500 bytes (this may be changed when compiling MySQL).  An index
  1249.      may use a prefix of a `CHAR' or `VARCHAR' field.
  1250.  
  1251.    * Fixed-length and variable-length records.
  1252.  
  1253.    * In-memory hash tables which are used as temporary tables.
  1254.  
  1255.    * Handles large databases.  We are using MySQL with some databases
  1256.      that contain 50,000,000 records and we know of users that uses
  1257.      MySQL with 60,000 tables and about 5,000,000,000 rows
  1258.  
  1259.    * All columns have default values.  You can use `INSERT' to insert a
  1260.      subset of a table's columns; those columns that are not explicitly
  1261.      given values are set to their default values.
  1262.  
  1263.    * Uses GNU Automake, Autoconf, and Libtool for portability.
  1264.  
  1265.    * Written in C and C++.  Tested with a broad range of different
  1266.      compilers.
  1267.  
  1268.    * A very fast thread-based memory allocation system.
  1269.  
  1270.    * No memory leaks.  MySQL has been tested with Purify, a commercial
  1271.      memory leakage detector.
  1272.  
  1273.    * Includes `myisamchk', a very fast utility for table checking,
  1274.      optimization, and repair.  All of the functionality of `myisamchk'
  1275.      is also available through the SQL interface as well.  *Note MySQL
  1276.      Database Administration::.
  1277.  
  1278.    * Full support for several different character sets, including
  1279.      ISO-8859-1 (Latin1), big5, ujis, and more.  For example, the
  1280.      Scandinavian characters `a*', `a"' and `o"' are allowed in table
  1281.      and column names.
  1282.  
  1283.    * All data are saved in the chosen character set.  All comparisons
  1284.      for normal string columns are case insensitive.
  1285.  
  1286.    * Sorting is done according to the chosen character set (the Swedish
  1287.      way by default).  It is possible to change this when the MySQL
  1288.      server is started up.  To see an example of very advanced sorting,
  1289.      look at the Czech sorting code.  MySQL supports many different
  1290.      character sets that can be specified at compile and run time.
  1291.  
  1292.    * Aliases on tables and columns are allowed as in the SQL92 standard.
  1293.  
  1294.    * `DELETE', `INSERT', `REPLACE', and `UPDATE' return the number of
  1295.      rows that were changed (affected).  It is possible to return the
  1296.      number of rows matched instead by setting a flag when connecting
  1297.      to the server.
  1298.  
  1299.    * Function names do not clash with table or column names.  For
  1300.      example, `ABS' is a valid column name.  The only restriction is
  1301.      that for a function call, no spaces are allowed between the
  1302.      function name and the `(' that follows it.  *Note Reserved words::.
  1303.  
  1304.    * All MySQL programs can be invoked with the `--help' or `-?'
  1305.      options to obtain online assistance.
  1306.  
  1307.    * The server can provide error messages to clients in many languages.
  1308.      *Note Languages::.
  1309.  
  1310.    * Clients may connect to the MySQL server using TCP/IP Sockets, Unix
  1311.      Sockets (Unix), or Named Pipes (NT).
  1312.  
  1313.    * The MySQL-specific `SHOW' command can be used to retrieve
  1314.      information about databases, tables, and indexes.  The `EXPLAIN'
  1315.      command can be used to determine how the optimizer resolves a
  1316.      query.
  1317.  
  1318. How Stable Is MySQL?
  1319. --------------------
  1320.  
  1321. This section addresses the questions "How stable is MySQL?" and "Can I
  1322. depend on MySQL in this project?"  We will try to clarify some issues
  1323. and to answer some of the more important questions that seem to concern
  1324. many people.  This section has been put together from information
  1325. gathered from the mailing list (which is very active in reporting bugs).
  1326.  
  1327. At TcX, MySQL has worked without any problems in our projects since
  1328. mid-1996.  When MySQL was released to a wider public, we noticed that
  1329. there were some pieces of "untested code" that were quickly found by the
  1330. new users who made queries in a manner different than our own.  Each new
  1331. release has had fewer portability problems than the previous one (even
  1332. though each has had many new features).
  1333.  
  1334. Each release of MySQL has been usable, and there have been problems
  1335. only when users start to use code from the "gray zones."  Naturally,
  1336. outside users don't know what the gray zones are; this section attempts
  1337. to indicate those that are currently known.  The descriptions deal with
  1338. Version 3.23 of MySQL.  All known and reported bugs are fixed in the
  1339. latest version, with the exception of the bugs listed in the bugs
  1340. section, which are things that are design-related.  *Note Bugs::.
  1341.  
  1342. MySQL is written in multiple layers and different independent modules.
  1343. These modules are listed below with an indication of how well-tested
  1344. each of them is:
  1345.  
  1346. *The ISAM table handler -- Stable*
  1347.      This manages storage and retrieval of all data in MySQL Version
  1348.      3.22 and earlier.  In all MySQL releases there hasn't been a single
  1349.      (reported) bug in this code. The only known way to get a corrupted
  1350.      table is to kill the server in the middle of an update.  Even that
  1351.      is unlikely to destroy any data beyond rescue, because all data
  1352.      are flushed to disk between each query.  There hasn't been a
  1353.      single bug report about lost data because of bugs in MySQL.
  1354.  
  1355. *The MyISAM table handler -- Stable*
  1356.      This is new in MySQL Version 3.23.  It's largely based on the ISAM
  1357.      table code but has a lot of new and very useful features.
  1358.  
  1359. *The parser and lexical analyser -- Stable*
  1360.      There hasn't been a single reported bug in this system for a long
  1361.      time.
  1362.  
  1363. *The C client code -- Stable*
  1364.      No known problems.  In early Version 3.20 releases, there were
  1365.      some limitations in the send/receive buffer size.  As of Version
  1366.      3.21, the buffer size is now dynamic up to a default of 16M.
  1367.  
  1368. *Standard client programs -- Stable*
  1369.      These include `mysql', `mysqladmin', `mysqlshow', `mysqldump', and
  1370.      `mysqlimport'.
  1371.  
  1372. *Basic SQL -- Stable*
  1373.      The basic SQL function system and string classes and dynamic memory
  1374.      handling.  Not a single reported bug in this system.
  1375.  
  1376. *Query optimizer -- Stable*
  1377.  
  1378. *Range optimizer -- Stable*
  1379.  
  1380. *Join optimizer -- Stable*
  1381.  
  1382. *Locking -- Gamma*
  1383.      This is very system-dependent.  On some systems there are big
  1384.      problems using standard OS locking (`fcntl()').  In these cases,
  1385.      you should run the MySQL daemon with the `--skip-locking' flag.
  1386.      Problems are known to occur on some Linux systems, and on SunOS
  1387.      when using NFS-mounted file systems.
  1388.  
  1389. *Linux threads -- Stable*
  1390.      The major problem found has been with the `fcntl()' call, which is
  1391.      fixed by using the `--skip-locking' option to `mysqld'.  Some
  1392.      people have reported lockup problems with Version 0.5.
  1393.      LinuxThreads will need to be recompiled if you plan to use 1000+
  1394.      concurrent connections.  Although it is possible to run that many
  1395.      connections with the default LinuxThreads (however, you will never
  1396.      go above 1021), the default stack spacing of 2 MB makes the
  1397.      application unstable, and we have been able to reproduce a
  1398.      coredump after creating 1021 idle connections.  *Note Linux::.
  1399.  
  1400. *Solaris 2.5+ pthreads -- Stable*
  1401.      We use this for all our production work.
  1402.  
  1403. *MIT-pthreads (Other systems) -- Stable*
  1404.      There have been no reported bugs since Version 3.20.15 and no
  1405.      known bugs since Version 3.20.16.  On some systems, there is a
  1406.      "misfeature" where some operations are quite slow (a 1/20 second
  1407.      sleep is done between each query).  Of course, MIT-pthreads may
  1408.      slow down everything a bit, but index-based `SELECT' statements
  1409.      are usually done in one time frame so there shouldn't be a mutex
  1410.      locking/thread juggling.
  1411.  
  1412. *Other thread implementions -- Beta - Gamma*
  1413.      The ports to other systems are still very new and may have bugs,
  1414.      possibly in MySQL, but most often in the thread implementation
  1415.      itself.
  1416.  
  1417. *`LOAD DATA ...', `INSERT ... SELECT' -- Stable*
  1418.      Some people thought they had found bugs here, but these usually
  1419.      have turned out to be misunderstandings.  Please check the manual
  1420.      before reporting problems!
  1421.  
  1422. *`ALTER TABLE' -- Stable*
  1423.      Small changes in Version 3.22.12.
  1424.  
  1425. *DBD -- Stable*
  1426.      Now maintained by Jochen Wiedmann (<wiedmann@neckar-alb.de>).
  1427.      Thanks!
  1428.  
  1429. *`mysqlaccess' -- Stable*
  1430.      Written and maintained by Yves Carlier (<Yves.Carlier@rug.ac.be>).
  1431.      Thanks!
  1432.  
  1433. *`GRANT' -- Stable*
  1434.      Big changes made in MySQL Version 3.22.12.
  1435.  
  1436. **MyODBC* (uses ODBC SDK 2.5) -- Gamma*
  1437.      It seems to work well with some programs.
  1438.  
  1439. *Replication - Beta / Gamma*
  1440.      We are still working on replication, so don't expect this to be
  1441.      rock solid yet.  On the other hand, some MySQL users are already
  1442.      using this with good results.
  1443.  
  1444. *BDB Tables - Beta*
  1445.      The Berkeley DB code is very stable, but we are still improving
  1446.      the interface between MySQL and BDB tables, so it will take some
  1447.      time before this is as tested as the other table types.
  1448.  
  1449. *InnoDB Tables - Beta*
  1450.      This is a recent addition to `MySQL'. They appear to work good and
  1451.      can be used after some initial testing.
  1452.  
  1453. *Automatic recovery of MyISAM tables - Beta*
  1454.      This only affects the new code that checks if the table was closed
  1455.      properly on open and executes an automatic check/repair of the
  1456.      table if it wasn't.
  1457.  
  1458. *MERGE tables - Beta / Gamma*
  1459.      The usage of keys on `MERGE' tables is still not that tested.  The
  1460.      other part of the `MERGE' code is quite well tested.
  1461.  
  1462. *FULLTEXT - Beta*
  1463.      Text search seems to work, but is still not widely used.
  1464.  
  1465. MySQL AB provides e-mail support for paying customers, but the MySQL
  1466. mailing list usually provides answers to common questions.  Bugs are
  1467. usually fixed right away with a patch; for serious bugs, there is
  1468. almost always a new release.
  1469.  
  1470. How Big Can MySQL Tables Be?
  1471. ----------------------------
  1472.  
  1473. MySQL Version 3.22 has a 4G limit on table size. With the new `MyISAM'
  1474. in MySQL Version 3.23 the maximum table size is pushed up to 8 million
  1475. terabytes (2 ^ 63 bytes).
  1476.  
  1477. Note, however, that operating systems have their own file size limits.
  1478. Here are some examples:
  1479.  
  1480. *Operating System*                   *File Size Limit*
  1481. Linux-Intel 32 bit                   2G, 4G or more, depends on Linux
  1482.                                      version
  1483. Linux-Alpha                          8T (?)
  1484. Solaris 2.5.1                        2G (possible 4G with patch)
  1485. Solaris 2.6                          4G
  1486. Solaris 2.7 Intel                    4G
  1487. Solaris 2.7 ULTRA-SPARC              8T (?)
  1488.  
  1489. On Linux 2.2 you can get bigger tables than 2G by using the LFS patch
  1490. for the ext2 file system.  On Linux 2.4 there exists also patches for
  1491. ReiserFS to get support for big files.
  1492.  
  1493. This means that the table size for MySQL is normally limited by the
  1494. operating system.
  1495.  
  1496. By default, MySQL tables have a maximum size of about 4G.  You can
  1497. check the maximum table size for a table with the `SHOW TABLE STATUS'
  1498. command or with the `myisamchk -dv table_name'.  *Note SHOW::.
  1499.  
  1500. If you need bigger tables than 4G (and your operating system supports
  1501. this), you should set the `AVG_ROW_LENGTH' and `MAX_ROWS' parameter
  1502. when you create your table.  *Note CREATE TABLE::.  You can also set
  1503. these later with `ALTER TABLE'. *Note ALTER TABLE::.
  1504.  
  1505. If your big table is going to be read-only, you could use `myisampack'
  1506. to merge and compress many tables to one.  `myisampack' usually
  1507. compresses a table by at least 50%, so you can have, in effect, much
  1508. bigger tables.  *Note `myisampack': myisampack.
  1509.  
  1510. You can go around the operating system file limit for `MyISAM' data
  1511. files by using the `RAID' option. *Note CREATE TABLE::.
  1512.  
  1513. Another solution can be the included MERGE library, which allows you to
  1514. handle a collection of identical tables as one. *Note MERGE tables:
  1515. MERGE.
  1516.  
  1517. Year 2000 Compliance
  1518. --------------------
  1519.  
  1520. MySQL itself has no problems with Year 2000 (Y2K) compliance:
  1521.  
  1522.    * MySQL uses Unix time functions and has no problems with dates
  1523.      until `2069'; all 2-digit years are regarded to be in the range
  1524.      `1970' to `2069', which means that if you store `01' in a `year'
  1525.      column, MySQL treats it as `2001'.
  1526.  
  1527.    * All MySQL date functions are stored in one file `sql/time.cc' and
  1528.      coded very carefully to be year 2000-safe.
  1529.  
  1530.    * In MySQL Version 3.22 and later, the new `YEAR' column type can
  1531.      store years `0' and `1901' to `2155' in 1 byte and display them
  1532.      using 2 or 4 digits.
  1533.  
  1534. You may run into problems with applications that use MySQL in a way
  1535. that is not Y2K-safe.  For example, many old applications store or
  1536. manipulate years using 2-digit values (which are ambiguous) rather than
  1537. 4-digit values.  This problem may be compounded by applications that use
  1538. values such as `00' or `99' as "missing" value indicators.
  1539.  
  1540. Unfortunately, these problems may be difficult to fix, because different
  1541. applications may be written by different programmers, each of whom may
  1542. use a different set of conventions and date-handling functions.
  1543.  
  1544. Here is a simple demonstration illustrating that MySQL doesn't have any
  1545. problems with dates until the year 2030:
  1546.  
  1547.      mysql> DROP TABLE IF EXISTS y2k;
  1548.      Query OK, 0 rows affected (0.01 sec)
  1549.      
  1550.      mysql> CREATE TABLE y2k (date date, date_time datetime, time_stamp timestamp);
  1551.      Query OK, 0 rows affected (0.00 sec)
  1552.      
  1553.      mysql> INSERT INTO y2k VALUES
  1554.          -> ("1998-12-31","1998-12-31 23:59:59",19981231235959),
  1555.          -> ("1999-01-01","1999-01-01 00:00:00",19990101000000),
  1556.          -> ("1999-09-09","1999-09-09 23:59:59",19990909235959),
  1557.          -> ("2000-01-01","2000-01-01 00:00:00",20000101000000),
  1558.          -> ("2000-02-28","2000-02-28 00:00:00",20000228000000),
  1559.          -> ("2000-02-29","2000-02-29 00:00:00",20000229000000),
  1560.          -> ("2000-03-01","2000-03-01 00:00:00",20000301000000),
  1561.          -> ("2000-12-31","2000-12-31 23:59:59",20001231235959),
  1562.          -> ("2001-01-01","2001-01-01 00:00:00",20010101000000),
  1563.          -> ("2004-12-31","2004-12-31 23:59:59",20041231235959),
  1564.          -> ("2005-01-01","2005-01-01 00:00:00",20050101000000),
  1565.          -> ("2030-01-01","2030-01-01 00:00:00",20300101000000),
  1566.          -> ("2050-01-01","2050-01-01 00:00:00",20500101000000);
  1567.      Query OK, 13 rows affected (0.01 sec)
  1568.      Records: 13  Duplicates: 0  Warnings: 0
  1569.      
  1570.      mysql> SELECT * FROM y2k;
  1571.      +------------+---------------------+----------------+
  1572.      | date       | date_time           | time_stamp     |
  1573.      +------------+---------------------+----------------+
  1574.      | 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
  1575.      | 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
  1576.      | 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
  1577.      | 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
  1578.      | 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
  1579.      | 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
  1580.      | 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
  1581.      | 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
  1582.      | 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
  1583.      | 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
  1584.      | 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
  1585.      | 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
  1586.      | 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
  1587.      +------------+---------------------+----------------+
  1588.      13 rows in set (0.00 sec)
  1589.  
  1590. This shows that the `DATE' and `DATETIME' types will not give any
  1591. problems with future dates (they handle dates until the year 9999).
  1592.  
  1593. The `TIMESTAMP' type, which is used to store the current time, has a
  1594. range up to only `2030-01-01'.  `TIMESTAMP' has a range of `1970' to
  1595. `2030' on 32-bit machines (signed value).  On 64-bit machines it
  1596. handles times up to `2106' (unsigned value).
  1597.  
  1598. Even though MySQL is Y2K-compliant, it is your responsibility to
  1599. provide unambiguous input.  See *Note Y2K issues:: for MySQL's rules
  1600. for dealing with ambiguous date input data (data containing 2-digit year
  1601. values).
  1602.  
  1603. MySQL Information Sources
  1604. =========================
  1605.  
  1606. Books About MySQL
  1607. -----------------
  1608.  
  1609. For the latest book information, with user comments, please visit
  1610. `http://www.mysql.com/portal/books/html/index.html'.
  1611.  
  1612. While this manual is still the right place for up to date technical
  1613. information, its primary goal is to contain everything there is to know
  1614. about MySQL.  It is sometimes nice to have a bound book to read in bed
  1615. or while you travel.  Here is a list of books about MySQL and related
  1616. subjects (in English).
  1617.  
  1618. By purchasing a book through these hyperlinks provided herein, you are
  1619. contributing to the development of MySQL.
  1620.  
  1621. _MySQL_
  1622. Available              Barnes and Noble
  1623.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0735709211&bfmtype=book)
  1624. Publisher              New Riders
  1625. Author                 Paul DuBois
  1626. Pub Date               1st Edition December 1999
  1627. ISBN                   0735709211
  1628. Pages                  800
  1629. Price                  $49.99 US
  1630. Downloadable examples   `samp_db' distribution
  1631.                        (http://www.kitebird.com/mysql-book/)
  1632. Errata                  are available here
  1633.                        (http://www.kitebird.com/mysql-book/errata.html)
  1634.  
  1635. Foreword by Michael "Monty" Widenius, MySQL Moderator.
  1636. In _MySQL_, Paul DuBois provides you with a comprehensive guide to one
  1637. of the most popular relational database systems.  Paul has contributed
  1638. to the online documentation for MySQL and is an active member of the
  1639. MySQL community.  The principal MySQL developer, Monty Widenius, and a
  1640. network of his fellow developers reviewed the manuscript, and provided
  1641. Paul with the kind of insight no one else could supply.
  1642. Instead of merely giving you a general overview of MySQL, Paul teaches
  1643. you how to make the most of its capabilities.  Through two sample
  1644. database applications that run throughout the book, he gives you
  1645. solutions to problems you're sure to face.  He helps you integrate
  1646. MySQL efficiently with third-party tools, such as PHP and Perl,
  1647. enabling you to generate dynamic Web pages through database queries.
  1648. He teaches you to write programs that access MySQL databases, and also
  1649. provides a comprehensive set of references to column types, operators,
  1650. functions, SQL syntax, MySQL programming, C API, Perl `DBI', and PHP
  1651. API.  _MySQL_ simply gives you the kind of information you won't find
  1652. anywhere else.
  1653. If you use MySQL, this book provides you with:
  1654.    * An introduction to MySQL and SQL.
  1655.  
  1656.    * Coverage of MySQL's data types and how to use them.
  1657.  
  1658.    * Thorough treatment of how to write client programs in C.
  1659.  
  1660.    * A guide to using the Perl `DBI' and PHP APIs for developing
  1661.      command-line and Web-based applications.
  1662.  
  1663.    * Tips on administrative issues such as user accounts, backup, crash
  1664.      recovery, and security.
  1665.  
  1666.    * Help in choosing an ISP for MySQL access.
  1667.  
  1668.    * A comprehensive reference for MySQL's data types, operators,
  1669.      functions, and SQL statements and utilities.
  1670.  
  1671.    * Complete reference guides for MySQL's C API, the Perl `DBI' API,
  1672.      and PHP's MySQL-related functions.
  1673.  
  1674. _MySQL & mSQL_
  1675. Available              Barnes and Noble
  1676.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=1565924347&bfmtype=book)
  1677. Publisher              O'Reilly
  1678. Authors                Randy Jay Yarger, George Reese & Tim King
  1679. Pub Date               1st Edition July 1999
  1680. ISBN                   1-56592-434-7, Order Number: 4347
  1681. Pages                  506
  1682. Price                  $34.95
  1683.  
  1684. This book teaches you how to use MySQL and `mSQL', two popular and
  1685. robust database products that support key subsets of SQL on both Linux
  1686. and Unix systems.  Anyone who knows basic C, Java, Perl, or Python can
  1687. write a program to interact with a database, either as a stand-alone
  1688. application or through a Web page.  This book takes you through the
  1689. whole process, from installation and configuration to programming
  1690. interfaces and basic administration.  Includes plenty of tutorial
  1691. material.
  1692. _Sams' Teach Yourself MySQL in 21 Days_
  1693. Available              Barnes and Noble
  1694.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0672319144&bfmtype=book)
  1695. Publisher              Sams
  1696. Authors                Mark Maslakowski and Tony Butcher
  1697. Pub Date               June 2000
  1698. ISBN                   0672319144
  1699. Pages                  650
  1700. Price                  $39.99
  1701.  
  1702. Sams' _Teach Yourself MySQL in 21 Days_ is for intermediate Linux users
  1703. who want to move into databases.  A large share of the audience is Web
  1704. developers who need a database to store large amounts of information
  1705. that can be retrieved via the Web.
  1706.  
  1707. Sams' _Teach Yourself MySQL in 21 Days_ is a practical, step-by-step
  1708. tutorial.  The reader will learn to design and employ this open source
  1709. database technology into his or her Web site using practical, hands-on
  1710. examples to follow.
  1711. _E-Commerce Solutions with MySQL_
  1712. Available              Barnes and Noble
  1713.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0761524452&bfmtype=book)
  1714. Publisher              Prima Communications, Inc.
  1715. Authors                N/A
  1716. Pub Date               January 2000
  1717. ISBN                   0761524452
  1718. Pages                  500
  1719. Price                  $39.99
  1720.  
  1721. No description available.
  1722. _MySQL and PHP from Scratch_
  1723. Available              Barnes and Noble
  1724.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0789724405&bfmtype=book)
  1725. Publisher              Que
  1726. Authors                N/A
  1727. Pub Date               September 2000
  1728. ISBN                   0789724405
  1729. Pages                  550
  1730. Price                  $34.99
  1731.  
  1732. This book puts together information on installing, setting up, and
  1733. troubleshooting Apache, MySQL, PHP3, and IMP into one complete volume.
  1734. You also learn how each piece is part of a whole by learning,
  1735. step-by-step, how to create a web-based e-mail system.  Learn to run
  1736. the equivalent of Active Server Pages (ASP) using PHP3, set up an
  1737. e-commerce site using a database and the Apache web server, and create
  1738. a data entry system (such as sales, product quality tracking, customer
  1739. preferences, etc) that no installation in the PC.
  1740. _Professional MySQL Programming_
  1741. Available              Barnes and Noble
  1742.                        (http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=1861005164)
  1743. Publisher              Wrox Press, Inc.
  1744. Authors                N/A
  1745. Pub Date               Late 2001
  1746. ISBN                   1861005164
  1747. Pages                  1000
  1748. Price                  $49.99
  1749.  
  1750. No description available.
  1751. _Professional Linux Programming_
  1752. Available              Barnes and Noble
  1753.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=1861003013&bfmtype=book)
  1754. Publisher              Wrox Press, Inc.
  1755. Authors                N/A
  1756. Pub Date               September 2000
  1757. ISBN                   1861003013
  1758. Pages                  1155
  1759. Price                  $47.99
  1760.  
  1761. In this follow-up to the best-selling _Beginning Linux Programming_,
  1762. you will learn from the authors' real-world knowledge and experience of
  1763. developing software for Linux; you'll be taken through the development
  1764. of a sample 'DVD Store' application, with 'theme' chapters addressing
  1765. different aspects of its implementation.  Meanwhile, individual
  1766. "take-a-break" chapters cover important topics that go beyond the
  1767. bounds of the central theme.  All focus on the practical aspects of
  1768. programming, showing how crucial it is to choose the right tools for
  1769. the job, use them as they should be used, and get things right first
  1770. time.
  1771. _PHP and MySQL Web Development_
  1772. Available              Barnes and Noble
  1773.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0672317842&bfmtype=book)
  1774. Publisher              Sams
  1775. Authors                Luke Welling, Laura Thomson
  1776. Pub Date               March 2001
  1777. ISBN                   0672317842
  1778. Pages                  700
  1779. Price                  $49.99
  1780.  
  1781. _PHP and MySQL Web Development_ introduces you to the advantages of
  1782. implementing both MySQL and PHP.  These advantages are detailed through
  1783. the provision of both statistics and several case studies.  A practical
  1784. web application is developed throughout the book, providing you with
  1785. the tools necessary to implement a functional online database.  Each
  1786. function is developed separately, allowing you the choice to
  1787. incorporate only those parts that you would like to implement.
  1788. Programming concepts of the PHP language are highlighted, including
  1789. functions which tie MySQL support into a PHP script and advanced topics
  1790. regarding table manipulation.
  1791. *Books recommended by the MySQL Developers*
  1792.  
  1793. _SQL-99 Complete, Really_
  1794. Available              Barnes and Noble
  1795.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0879305681&bfmtype=book)
  1796. Publisher              CMP Books
  1797. Authors                Peter Gulutzan, Trudy Pelzer
  1798. Pub Date               April 1999
  1799. ISBN                   0879305681
  1800. Pages                  1104
  1801. Price                  $55.96
  1802.  
  1803. This book contains complete descriptions of the new standards for
  1804. syntax, data structures, and retrieval processes of SQL databases.  As
  1805. an example-based reference manual, it includes all of the CLI
  1806. functions, information, schema tables, and status codes, as well as a
  1807. working SQL database provided on the companion disk.
  1808. _C, A reference manual_
  1809. Available              Barnes and Noble
  1810.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0133262243&bfmtype=book)
  1811. Publisher              Prentice Hall
  1812. Authors                Samuel P. Harbison, Guy L. Steele
  1813. Pub Date               September 1994
  1814. ISBN                   0133262243
  1815. Pages                  480
  1816. Price                  $35.99
  1817.  
  1818. A new and improved revision of the bestselling C language reference.
  1819. This manual introduces the notion of "Clean C", writing C code that can
  1820. be compiled as a C++ program, C programming style that emphasizes
  1821. correctness, portability, maintainability, and incorporates the ISO C
  1822. Amendment 1 (1994) which specifies new facilities for writing portable,
  1823. international programs in C.
  1824. _C++ for Real Programmers_
  1825. Available              Barnes and Noble
  1826.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0120499428&bfmtype=book)
  1827. Publisher              Academic Press, Incorporated
  1828. Authors                Jeff Alger, Jim Keogh
  1829. Pub Date               February 1998
  1830. ISBN                   0120499428
  1831. Pages                  388
  1832. Price                  $39.95
  1833.  
  1834. _C++ For Real Programmers_ bridges the gap between C++ as described in
  1835. beginner and intermediate-level books and C++ as it is practiced by
  1836. experts.  Numerous valuable techniques are described, organized into
  1837. three simple themes: indirection, class hierarchies, and memory
  1838. management.  It also provides in-depth coverage of template creation,
  1839. exception handling, pointers and optimization techniques.  The focus of
  1840. the book is on ANSI C++ and, as such, is compiler independent.
  1841.  
  1842. _C++ For Real Programmers_ is a revision of _Secrets of the C++
  1843. Masters_ and includes a new appendix comparing C++ with Java.  The book
  1844. comes with a 3.5" disk for Windows with source code.
  1845. _Algorithms in C_
  1846. Available              Barnes and Noble
  1847.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0201514257&bfmtype=book)
  1848. Publisher              Addison Wesley Longman, Inc.
  1849. Authors                Robert Sedgewick
  1850. Pub Date               April 1990
  1851. ISBN                   0201514257
  1852. Pages                  648
  1853. Price                  $45.75
  1854.  
  1855. _Algorithms in C_ describes a variety of algorithms in a number of
  1856. areas of interest, including: sorting, searching, string-processing, and
  1857. geometric, graph and mathematical algorithms.  The book emphasizes
  1858. fundamental techniques, providing readers with the tools to confidently
  1859. implement, run, and debug useful algorithms.
  1860. _Multithreaded Programming with Pthreads_
  1861. Available              Barnes and Noble
  1862.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=0136807291&bfmtype=book)
  1863. Publisher              Prentice Hall
  1864. Authors                Bil Lewis, Daniel J. Berg
  1865. Pub Date               October 1997
  1866. ISBN                   0136807291
  1867. Pages                  432
  1868. Price                  $34.95
  1869.  
  1870. Based on the best-selling _Threads Primer_, _Multithreaded Programming
  1871. with Pthreads_ gives you a solid understanding of Posix threads: what
  1872. they are, how they work, when to use them, and how to optimize them. It
  1873. retains the clarity and humor of _Threads Primer_, but includes
  1874. expanded comparisons to Win32 and OS/2 implementations.  Code examples
  1875. tested on all of the major UNIX platforms are featured along with
  1876. detailed explanations of how and why they use threads.
  1877. _Programming the PERL DBI: Database Programming with PERL_
  1878. Available              Barnes and Noble
  1879.                        (http://service.bfast.com/bfast/click?bfmid=2181&sourceid=34233559&bfpid=1565926994&bfmtype=book)
  1880. Publisher              O'Reilly & Associates, Incorporated
  1881. Authors                Alligator Descartes, Tim Bunce
  1882. Pub Date               February 2000
  1883. ISBN                   1565926994
  1884. Pages                  400
  1885. Price                  $27.96
  1886.  
  1887. _Programming the Perl DBI_ is coauthored by Alligator Descartes, one of
  1888. the most active members of the DBI community, and by Tim Bunce, the
  1889. inventor of DBI.  For the uninitiated, the book explains the
  1890. architecture of DBI and shows you how to write DBI-based programs.  For
  1891. the experienced DBI dabbler, this book explains DBI's nuances and the
  1892. peculiarities of each individual DBD.
  1893.  
  1894. The book includes:
  1895.    * An introduction to DBI and its design.
  1896.  
  1897.    * How to construct queries and bind parameters.
  1898.  
  1899.    * Working with database, driver, and statement handles.
  1900.  
  1901.    * Debugging techniques.
  1902.  
  1903.    * Coverage of each existing DBD.
  1904.  
  1905.    * A complete reference to DBI.
  1906.  
  1907. General SQL Information and Tutorials
  1908. -------------------------------------
  1909.  
  1910. The following book has been recommended by several people on the MySQL
  1911. mailing list:
  1912.  
  1913.      Judith S. Bowman, Sandra L. Emerson and Marcy Darnovsky
  1914.      _The Practical SQL Handbook: Using Structured Query Language_
  1915.      Second Edition
  1916.      Addison-Wesley
  1917.      ISBN 0-201-62623-3
  1918.      http://www.awl.com
  1919.  
  1920. The following book has also received some recommendations by MySQL
  1921. users:
  1922.  
  1923.      Martin Gruber
  1924.      _Understanding SQL_
  1925.      ISBN 0-89588-644-8
  1926.      Publisher Sybex 510 523 8233
  1927.      Alameda, CA USA
  1928.  
  1929. A SQL tutorial is available on the net at
  1930. http://w3.one.net/~jhoffman/sqltut.htm
  1931.  
  1932. Useful MySQL-related Links
  1933. --------------------------
  1934.  
  1935. Apart from the following links, you can find and download a lot of
  1936. MySQL programs, tools and APIs from the Contrib directory
  1937. (http://www.mysql.com/Downloads/Contrib/).
  1938.  
  1939. MySQL
  1940.  
  1941. Tutorials and Manuals
  1942. ---------------------
  1943.  
  1944. MySQL Myths Debunked (http://michael.bacarella.com/research/mysqlmyths.html)
  1945.      MySQL used in the real world.
  1946.  
  1947. `http://www.4t2.com/mysql'
  1948.      Information about the German MySQL mailing list.
  1949.  
  1950. `http://www2.rent-a-database.de/mysql/'
  1951.      MySQL handbook in German.
  1952.  
  1953. `http://www.bitmover.com:8888//home/bk/mysql'
  1954.      Web access to the MySQL BitKeeper repository.
  1955.  
  1956. `http://www.analysisandsolutions.com/code/mybasic.htm'
  1957.      Beginners MySQL Tutorial on how to install and set up MySQL on a
  1958.      Windows machine.
  1959.  
  1960. `http://www.devshed.com/Server_Side/MySQL/'
  1961.      A lot of MySQL tutorials.
  1962.  
  1963. `http://mysql.hitstar.com/'
  1964.      MySQL manual in Chinese.
  1965.  
  1966. `http://www.linuxplanet.com/linuxplanet/tutorials/1046/1/'
  1967.      Setting Up a MySQL-based Web site.
  1968.  
  1969. `http://www.hotwired.com/webmonkey/backend/tutorials/tutorial1.html'
  1970.      MySQL-Perl tutorial.
  1971.  
  1972. `http://www.iserver.com/support/contrib/perl5/modules.html'
  1973.      Installing new Perl modules that require locally installed modules.
  1974.  
  1975. `http://www.hotwired.com/webmonkey/databases/tutorials/tutorial4.html'
  1976.      PHP/MySQL Tutorial.
  1977.  
  1978. `http://www.useractive.com/'
  1979.      Hands on tutorial for MySQL.
  1980.  
  1981. Porting MySQL/Using MySQL on Different Systems
  1982. ----------------------------------------------
  1983.  
  1984. `http://www.entropy.ch/software/macosx/mysql/'
  1985.      Binary of MySQL for Mac OS X Client.  Includes information of how
  1986.      to build and use MySQL on Mac OS X.
  1987.  
  1988. `http://xclave.macnn.com/MySQL/'
  1989.      The Mac OS Xclave.  Running MySQL on Mac OS X.
  1990.  
  1991. `http://www.prnet.de/RegEx/mysql.html'
  1992.      MySQL for Mac OS X Server.
  1993.  
  1994. `http://www.latencyzero.com/macosx/mysql.html'
  1995.      Building MySQL for Mac OS X.
  1996.  
  1997. `http://www.essencesw.com/Software/mysqllib.html'
  1998.      New Client libraries for the Mac OS Classic (Macintosh).
  1999.  
  2000. `http://www.lilback.com/macsql/'
  2001.      Client libraries for Mac OS Classic (Macintosh).
  2002.  
  2003. `http://sixk.maniasys.com/index_en.html'
  2004.      MySQL for Amiga
  2005.  
  2006. Perl-related Links
  2007. ------------------
  2008.  
  2009. `http://dbimysql.photoflux.com/'
  2010.      Perl DBI with MySQL FAQ.
  2011.  
  2012. MySQL Discussion Forums
  2013. -----------------------
  2014.  
  2015. `http://www.weberdev.com/'
  2016.      Examples using MySQL; (check Top 20)
  2017.  
  2018. `http://futurerealm.com/forum/futureforum.htm'
  2019.      FutureForum Web Discussion Software.
  2020.  
  2021. Commercial Applications that Support MySQL
  2022. ------------------------------------------
  2023.  
  2024. `http://www.supportwizard.com/'
  2025.      SupportWizard; Interactive helpdesk on the Web (This product
  2026.      includes a licensed copy of MySQL.)
  2027.  
  2028. `http://www.sonork.com/'
  2029.      Sonork,  Instant Messenger that is not only Internet oriented.
  2030.      It's focused on private networks and on small to medium companies.
  2031.      Client is free, server is free for up to 5 seats.
  2032.  
  2033. `http://www.stweb.org/'
  2034.      StWeb - Stratos Web and Application server - An easy-to-use, cross
  2035.      platform, Internet/Intranet development and deployment system for
  2036.      development of web-enabled applications.  The standard version of
  2037.      StWeb has a native interface to MySQL database.
  2038.  
  2039. `http://www.rightnowtech.com/'
  2040.      Right Now Web; Web automation for customer service.
  2041.  
  2042. `http://www.icaap.org/Bazaar/'
  2043.      Bazaar; Interactive Discussion Forums with Web interface.
  2044.  
  2045. `http://www.phonesweep.com/'
  2046.      PhoneSweepT is the world's first commercial Telephone Scanner.
  2047.      Many break-ins in recent years have come not through the Internet,
  2048.      but through unauthorized dial-up modems.  PhoneSweep lets you find
  2049.      these modems by repeatedly placing phone calls to every phone
  2050.      number that your organization controls.  PhoneSweep has a built-in
  2051.      expert system that can recognize more than 250 different kinds of
  2052.      remote-access programs, including Carbon Copy(TM), pcANYWHERE(TM),
  2053.      and Windows NT RAS.  All information is stored in the SQL
  2054.      database.  It then generates a comprehensive report detailing
  2055.      which services were discovered on which dial-up numbers in your
  2056.      organization.
  2057.  
  2058. SQL Clients and Report Writers
  2059. ------------------------------
  2060.  
  2061. urSQL (http://www.urbanresearch.com/software/utils/urbsql/index.html)
  2062.      SQL Editor and Query Utility. Custom syntax highlighting, editable
  2063.      results grid, exportable result-sets, basic MySQL admin functions,
  2064.      Etc.. For Windows.
  2065.  
  2066. MySQL Data Manager (http://www.edatanew.com/)
  2067.      MySQL Data Manager * is platform independent web client (written
  2068.      in perl) for MySQL server over TCP/IP.
  2069.  
  2070. `http://ksql.sourceforge.net/'
  2071.      KDE MySQL client.
  2072.  
  2073. `http://www.ecker-software.de'
  2074.      A Windows GUI client by David Ecker.
  2075.  
  2076. `http://www.icaap.org/software/kiosk/'
  2077.      Kiosk; a MySQL client for database management.  Written in Perl.
  2078.      Will be a part of Bazaar.
  2079.  
  2080. `http://www.casestudio.com/'
  2081.      Db design tool that supports MySQL 3.23.
  2082.  
  2083. `http://home.skif.net/~voland/zeos/eng/index.html'
  2084.      Zeos - A client that supports MySQL, Interbase and PostgreSQL.
  2085.  
  2086. `http://www.geocities.com/SiliconValley/Ridge/4280/GenericReportWriter/grwhome.html'
  2087.      A free report writer in Java
  2088.  
  2089. `http://www.javaframework.de'
  2090.      MySQLExport - Export of MySQL create statements and data in a lot
  2091.      of different formats (SQL, HTML, CVS, text, ZIP, GZIP...)
  2092.  
  2093. `http://dlabs.4t2.com'
  2094.      M2D, a MySQL Administration client for Windows.  M2D supports
  2095.      administration of MySQL databases, creation of new databases and
  2096.      tables, editing, and more.
  2097.  
  2098. `http://dlabs.4t2.com'
  2099.      Dexter, a small server written in Perl which can be used as a
  2100.      proxy server for MySQL or as a database extender.
  2101.  
  2102. `http://www.scibit.com/Products/Software/Utils/Mascon.asp'
  2103.      Mascon is a powerful Win32 GUI for administering MySQL databases.
  2104.  
  2105. `http://www.rtlabs.com/'
  2106.      MacSQL Monitor.  GUI for MySQL, ODBC, and JDBC databases for the
  2107.      Mac OS.
  2108.  
  2109. Distributions that Include MySQL
  2110. --------------------------------
  2111.  
  2112. `http://www.suse.com/'
  2113.      SuSE Linux (6.1 and above)
  2114.  
  2115. `http://www.redhat.com/'
  2116.      RedHat Linux (7.0 and above)
  2117.  
  2118. `http://distro.conectiva.com.br'
  2119.      Conectiva Linux (4.0 and above)
  2120.  
  2121. Web Development Tools that Support MySQL
  2122. ----------------------------------------
  2123.  
  2124. `http://www.php.net/'
  2125.      PHP: A server-side HTML-embedded scripting language.
  2126.  
  2127. `http://www.midgard-project.org'
  2128.      The Midgard Application Server; a powerful Web development
  2129.      environment based on MySQL and PHP.
  2130.  
  2131. `http://www.smartworker.org'
  2132.      SmartWorker is a platform for Web application development.
  2133.  
  2134. `http://xsp.lentus.se/'
  2135.      XSP: e(X)tendible (S)erver (P)ages and is a HTML embedded tag
  2136.      language written in Java (previously known as XTAGS.)
  2137.  
  2138. `http://www.dbServ.de/'
  2139.      dbServ is an extension to a web server to integrate database
  2140.      output into your HTML code.  You may use any HTML function in your
  2141.      output.  Only the client will stop you.  It works as standalone
  2142.      server or as Java servlet.
  2143.  
  2144. `http://www.chilisoft.com/'
  2145.      Platform independent ASP from Chili!Soft
  2146.  
  2147. `http://www.voicenet.com/~zellert/tjFM'
  2148.      A JDBC driver for MySQL.
  2149.  
  2150. `http://www.wernhart.priv.at/php/'
  2151.      MySQL + PHP demos.
  2152.  
  2153. `http://www.dbwww.com/'
  2154.      ForwardSQL: HTML interface to manipulate MySQL databases.
  2155.  
  2156. `http://www.daa.com.au/~james/www-sql/'
  2157.      WWW-SQL: Display database information.
  2158.  
  2159. `http://www.minivend.com/minivend/'
  2160.      Minivend: A Web shopping cart.
  2161.  
  2162. `http://www.heitml.com/'
  2163.      HeiTML: A server-side extension of HTML and a 4GL language at the
  2164.      same time.
  2165.  
  2166. `http://www.metahtml.com/'
  2167.      Metahtml: A Dynamic Programming Language for WWW Applications.
  2168.  
  2169. `http://www.binevolve.com/'
  2170.      VelocityGen for Perl and Tcl.
  2171.  
  2172. `http://hawkeye.net/'
  2173.      Hawkeye Internet Server Suite.
  2174.  
  2175. `http://www.fastflow.com/'
  2176.      Network Database Connection For Linux
  2177.  
  2178. `http://www.wdbi.net/'
  2179.      WDBI: Web browser as a universal front end to databases which
  2180.      supports MySQL well.
  2181.  
  2182. `http://www.webgroove.com/'
  2183.      WebGroove Script: HTML compiler and server-side scripting language.
  2184.  
  2185. `http://www.ihtml.com/'
  2186.      A server-side Web site scripting language.
  2187.  
  2188. `ftp://ftp.igc.apc.org/pub/myodbc/README'
  2189.      How to use MySQL with ColdFusion on Solaris.
  2190.  
  2191. `http://calistra.com/MySQL/'
  2192.      Calistra's ODBC MySQL Administrator.
  2193.  
  2194. `http://www.webmerger.com'
  2195.      Webmerger -  This CGI tool interprets files and generates dynamic
  2196.      output based on a set of simple tags.  Ready-to-run drivers for
  2197.      MySQL and PostgreSQL through ODBC.
  2198.  
  2199. `http://phpclub.net/'
  2200.      PHPclub - Tips and tricks for PHP.
  2201.  
  2202. `http://www.penguinservices.com/scripts'
  2203.      MySQL and Perl Scripts.
  2204.  
  2205. `http://www.widgetchuck.com'
  2206.      The Widgetchuck; Web Site Tools and Gadgets
  2207.  
  2208. `http://www.adcycle.com/'
  2209.      AdCycle - advertising management software.
  2210.  
  2211. `http://sourceforge.net/projects/pwpage/'
  2212.      pwPage - provides an extremely fast and simple approach to the
  2213.      creation of database forms.  That is, if a database table exists
  2214.      and an HTML page has been constructed using a few simple
  2215.      guidelines, pwPage can be immediately used for table data
  2216.      selections, insertions, updates, deletions and selectable table
  2217.      content reviewing.
  2218.  
  2219. `http://www.omnis-software.com/products/studio/studio.html'
  2220.      OMNIS Studio is a rapid application development (RAD) tool.
  2221.  
  2222. `http://www.webplus.com'
  2223.      talentsoft Web+ 4.6 - a powerful and comprehensive development
  2224.      language for use in creating web-based client/server applications
  2225.      without writing complicated, low-level, and time-consuming CGI
  2226.      programs.
  2227.  
  2228. Database Design Tools with MySQL Support
  2229. ----------------------------------------
  2230.  
  2231. `http://www.mysql.com/documentation/dezign/'
  2232.      "DeZign for databases" is a database development tool that uses an
  2233.      entity relationship diagram (ERD).
  2234.  
  2235. Web Servers with MySQL Tools
  2236. ----------------------------
  2237.  
  2238. `ftp://ftp.kcilink.com/pub/'
  2239.      mod_auth_mysql, An Apache authentication module.
  2240.  
  2241. `http://www.roxen.com/'
  2242.      The Roxen Challenger Web server.
  2243.  
  2244. Extensions for Other Programs
  2245. -----------------------------
  2246.  
  2247. `http://www.seawood.org/msql_bind/'
  2248.      MySQL support for BIND (The Internet Domain Name Server).
  2249.  
  2250. `http://www.inet-interactive.com/sendmail/'
  2251.      MySQL support for Sendmail and Procmail.
  2252.  
  2253. Using MySQL with Other Programs
  2254. -------------------------------
  2255.  
  2256. `http://www.iserver.com/support/addonhelp/database/mysql/msaccess.html'
  2257.      Using MySQL with Access.
  2258.  
  2259. `http://www.iserver.com/support/contrib/perl5/modules.html'
  2260.      Installing new Perl modules that require locally installed modules.
  2261.  
  2262. ODBC-related Links
  2263. ------------------
  2264.  
  2265. `http://www.iodbc.org/'
  2266.      Popular iODBC Driver Manager (libiodbc) now available as Open
  2267.      Source.
  2268.  
  2269. `http://users.ids.net/~bjepson/freeODBC/'
  2270.      The FreeODBC Pages.
  2271.  
  2272. `http://genix.net/unixODBC/'
  2273.      The unixODBC Project goals are to develop and promote unixODBC to
  2274.      be the definitive standard for ODBC on the Linux platform.  This
  2275.      is to include GUI support for KDE.
  2276.  
  2277. `http://www.sw-soft.com/products/BtrieveODBC/'
  2278.      A MySQL-based ODBC driver for Btrieve.
  2279.  
  2280. *API*-related Links
  2281. -------------------
  2282.  
  2283. `http://www.jppp.com/'
  2284.      Partially implemented TDataset-compatible components for MySQL.
  2285.  
  2286. `http://www.riverstyx.net/qpopmysql/'
  2287.      qpopmysql - A patch to allow POP3 authentication from a MySQL
  2288.      database.  There's also a link to Paul Khavkine's patch for
  2289.      Procmail to allow any MTA to deliver to users in a MySQL database.
  2290.  
  2291. `http://www.pbc.ottawa.on.ca'
  2292.      Visual Basic class generator for Active X.
  2293.  
  2294. `http://www.essencesw.com/Software/mysqllib.html'
  2295.      New Client libraries for the Mac OS Classic (Macintosh).
  2296.  
  2297. `http://www.lilback.com/macsql/'
  2298.      Client libraries for the Macintosh.
  2299.  
  2300. `http://www.essencesw.com/Plugins/mysqlplug.html'
  2301.      Plugin for REALbasic (for Macintosh)
  2302.  
  2303. `http://www.iis.ee.ethz.ch/~neeri/macintosh/gusi-qa.html'
  2304.      A library that emulates BSD sockets and pthreads on Macintosh.
  2305.      This can be used if you want to compile the MySQL client library
  2306.      on Mac.  It could probably even be sued to port MySQL to
  2307.      Macintosh, but we don't know of anyone that has tried that.
  2308.  
  2309. `http://www.dedecker.net/jessie/scmdb/'
  2310.      SCMDB - an add-on for SCM that ports the MySQL C library to scheme
  2311.      (SCM).  With this library scheme developers can make connections
  2312.      to a MySQL database and use embedded SQL in their programs.
  2313.  
  2314. Other MySQL-related Links
  2315. -------------------------
  2316.  
  2317. SAT (http://www.satisoft.com/)
  2318.      The Small Application Toolkit (SAT) is a collection of utilities
  2319.      intended to simplify the development of small, multi-user, GUI
  2320.      based applications in a (Microsoft -or- X) Windows Client / Unix
  2321.      Server environment.
  2322.  
  2323. `http://www.wix.com/mysql-hosting/'
  2324.      Registry of Web providers who support MySQL.
  2325.  
  2326. `http://www.softagency.co.jp/mysql/index.en.html'
  2327.      Links about using MySQL in Japan/Asia.
  2328.  
  2329. `http://abattoir.cc.ndsu.nodak.edu/~nem/mysql/udf/'
  2330.      MySQL UDF Registry.
  2331.  
  2332. `http://www.open.com.au/products.html'
  2333.      Commercial Web defect tracking system.
  2334.  
  2335. `http://www.stonekeep.com/pts/'
  2336.      PTS: Project Tracking System.
  2337.  
  2338. `http://tomato.nvgc.vt.edu/~hroberts/mot'
  2339.      Job and software tracking system.
  2340.  
  2341. `http://www.cynergi.net/exportsql/'
  2342.      ExportSQL: A script to export data from Access95+.
  2343.  
  2344. `http://SAL.KachinaTech.COM/H/1/MYSQL.html'
  2345.      SAL (Scientific Applications on Linux) MySQL entry.
  2346.  
  2347. `http://www.infotech-nj.com/itech/index.shtml'
  2348.      A consulting company which mentions MySQL in the right company.
  2349.  
  2350. `http://www.pmpcs.com/'
  2351.      PMP Computer Solutions.  Database developers using MySQL and
  2352.      `mSQL'.
  2353.  
  2354. `http://www.aewa.org/'
  2355.      Airborne Early Warning Association.
  2356.  
  2357. `http://www.dedserius.com/y2kmatrix/'
  2358.      Y2K tester.
  2359.  
  2360. SQL and Database Interfaces
  2361. ---------------------------
  2362.  
  2363. `http://java.sun.com/products/jdbc/'
  2364.      The JDBC database access API.
  2365.  
  2366. `http://www.gagme.com/mysql'
  2367.      Patch for `mSQL' Tcl.
  2368.  
  2369. `http://www.amsoft.ru/easysql/'
  2370.      EasySQL: An ODBC-like driver manager.
  2371.  
  2372. `http://www.lightlink.com/hessling/rexxsql.html'
  2373.      A REXX interface to SQL databases.
  2374.  
  2375. `http://www.mytcl.cx/'
  2376.      Tcl interface based on tcl-sql with many bugfixes.
  2377.  
  2378. `http://www.binevolve.com/~tdarugar/tcl-sql/'
  2379.      Tcl interface.
  2380.  
  2381. `http://www.contrib.andrew.cmu.edu/~shadow/sql.html'
  2382.      SQL Reference Page with a lot of interesting links.
  2383.  
  2384. Examples of MySQL Use
  2385. ---------------------
  2386.  
  2387. `http://www.little6.com/about/linux/'
  2388.      Little6 Inc., An online contract and job finding site that is
  2389.      powered by MySQL, PHP3, and Linux.
  2390.  
  2391. `http://www.delec.com/is/products/prep/examples/BookShelf/index.html'
  2392.      DELECis - A tool that makes it very easy to create an
  2393.      automatically generated table documentation. They have used MySQL
  2394.      as an example.
  2395.  
  2396. `http://www.worldrecords.com'
  2397.      World Records - A search engine for information about music that
  2398.      uses MySQL and PHP.
  2399.  
  2400. `http://www.webtechniques.com/archives/1998/01/note/'
  2401.      A Contact Database using MySQL and PHP.
  2402.  
  2403. `http://modems.rosenet.net/mysql/'
  2404.      Web based interface and Community Calendar with PHP.
  2405.  
  2406. `http://www.odbsoft.com/cook/sources.htm'
  2407.      Perl package to generate html from a SQL table structure and for
  2408.      generating SQL statements from an html form.
  2409.  
  2410. `http://www.gusnet.cx/proj/telsql/'
  2411.      Basic telephone database using `DBI'/`DBD'.
  2412.  
  2413. `http://tecfa.unige.ch/guides/java/staf2x/ex/jdbc/coffee-break'
  2414.      JDBC examples by Daniel K. Schneider.
  2415.  
  2416. `http://www.spade.com/linux/howto/PostgreSQL-HOWTO-41.html'
  2417.      SQL BNF
  2418.  
  2419. `http://www.ooc.com/'
  2420.      Object Oriented Concepts Inc; CORBA applications with examples in
  2421.      source.
  2422.  
  2423. `http://www.pbc.ottawa.on.ca/'
  2424.      DBWiz; Includes an example of how to manage cursors in VB.
  2425.  
  2426. `http://keilor.cs.umass.edu/pluribus/'
  2427.      Pluribus is a free search engine that learns to improve the
  2428.      quality of its results over time.  Pluribus works by recording
  2429.      which pages a user prefers among those returned for a query.  A
  2430.      user votes for a page by selecting it; Pluribus then uses that
  2431.      knowledge to improve the quality of the results when someone else
  2432.      submits the same (or similar) query.  Uses PHP and MySQL.
  2433.  
  2434. `http://www.stopbit.com/'
  2435.      Stopbit - A technology news site using MySQL and PHP.
  2436.  
  2437. `http://www.linuxsupportline.com/~kalendar/'
  2438.      KDE based calendar manager - The calendar manager has both single
  2439.      user (file based) and multi-user (MySQL database) support.
  2440.  
  2441. `http://tim.desert.net/~tim/imger/'
  2442.      Example of storing/retrieving images with MySQL and CGI.
  2443.  
  2444. `http://www.penguinservices.com/scripts'
  2445.      Online shopping cart system.
  2446.  
  2447. `http://www.city-gallery.com/album/'
  2448.      Old Photo Album - The album is a collaborative popular history of
  2449.      photography project that generates all pages from data stored in a
  2450.      MySQL database.  Pages are dynamically generated through a php3
  2451.      interface to the database content.  Users contribute images and
  2452.      descriptions.  Contributed images are stored on the web server to
  2453.      avoid storing them in the database as BLOBs.  All other
  2454.      information is stored on the shared MySQL server.
  2455.  
  2456. General Database Links
  2457. ----------------------
  2458.  
  2459. `http://www.pcslink.com/~ej/dbweb.html'
  2460.      Database Jump Site
  2461.  
  2462. `http://black.hole-in-the.net/guy/webdb/'
  2463.      Homepage of the webdb-l (Web Databases) mailing list.
  2464.  
  2465. `http://www.symbolstone.org/technology/perl/DBI/index.html'
  2466.      Perl `DBI'/`DBD' modules homepage.
  2467.  
  2468. `http://www.student.uni-koeln.de/cygwin/'
  2469.      Cygwin tools.  Unix on top of Windows.
  2470.  
  2471. `http://dbasecentral.com/'
  2472.      dbasecentral.com; Development and distribution of powerful and
  2473.      easy-to-use database applications and systems.
  2474.  
  2475. `http://www.tek-tips.com/'
  2476.      Tek-Tips Forums are 800+ independent peer-to-peer non-commercial
  2477.      support forums for Computer Professionals.  Features include
  2478.      automatic e-mail notification of responses, a links library, and
  2479.      member confidentiality guaranteed.
  2480.  
  2481. `http://www.public.asu.edu/~peterjn/btree/'
  2482.      B-Trees: Balanced Tree Data Structures.
  2483.  
  2484. `http://www.fit.qut.edu.au/~maire/baobab/lecture/sld001.htm'
  2485.      A lecture about B-Trees.
  2486.  
  2487. There are also many Web pages that use MySQL.  *Note Users::.  Send any
  2488. additions to this list to <webmaster@mysql.com>. We now require that
  2489. you show a MySQL logo somewhere if you wish your site to be added.  It
  2490. is okay to have it on a "used tools" page or something similar.
  2491.  
  2492. MySQL Mailing Lists
  2493. -------------------
  2494.  
  2495. This section introduces you to the MySQL mailing lists, and gives some
  2496. guidelines as to how to use them.
  2497.  
  2498. The MySQL Mailing Lists
  2499. .......................
  2500.  
  2501. To subscribe to the main MySQL mailing list, send a message to the
  2502. electronic mail address <mysql-subscribe@lists.mysql.com>.
  2503.  
  2504. To unsubscribe from the main MySQL mailing list, send a message to the
  2505. electronic mail address <mysql-unsubscribe@lists.mysql.com>.
  2506.  
  2507. Only the address to which you send your messages is significant.  The
  2508. subject line and the body of the message are ignored.
  2509.  
  2510. If your reply address is not valid, you can specify your address
  2511. explicitly.  Adding a hyphen to the subscribe or unsubscribe command
  2512. word, followed by your address with the `@' character in your address
  2513. replaced by a `='.  For example, to subscribe `your_name@host.domain',
  2514. send a message to
  2515. `mysql-subscribe-your_name=host.domain@lists.mysql.com'.
  2516.  
  2517. Mail to <mysql-subscribe@lists.mysql.com> or
  2518. <mysql-unsubscribe@lists.mysql.com> is handled automatically by the
  2519. ezmlm mailing list processor.  Information about ezmlm is available at
  2520. The ezmlm Website (http://www.ezmlm.org).
  2521.  
  2522. To post a message to the list itself, send your message to
  2523. `mysql@lists.mysql.com'.  However, please _do not_ send mail about
  2524. subscribing or unsubscribing to <mysql@lists.mysql.com>, because any
  2525. mail sent to that address is distributed automatically to thousands of
  2526. other users.
  2527.  
  2528. Your local site may have many subscribers to <mysql@lists.mysql.com>.
  2529. If so, it may have a local mailing list, so that messages sent from
  2530. `lists.mysql.com' to your site are propagated to the local list.  In
  2531. such cases, please contact your system administrator to be added to or
  2532. dropped from the local MySQL list.
  2533.  
  2534. If you wish to have traffic for a mailing list go to a separate mailbox
  2535. in your mail program, set up a filter based on the message headers.
  2536. You can use either the `List-ID:' or `Delivered-To:' headers to identify
  2537. list messages.
  2538.  
  2539. The following MySQL mailing lists exist:
  2540.  
  2541. `<announce-subscribe@lists.mysql.com> announce'
  2542.      This is for announcement of new versions of MySQL and related
  2543.      programs.  This is a low volume list all MySQL users should
  2544.      subscribe to.
  2545.  
  2546. `<mysql-subscribe@lists.mysql.com> mysql'
  2547.      The main list for general MySQL discussion.  Please note that some
  2548.      topics are better discussed on the more-specialized lists.  If you
  2549.      post to the wrong list, you may not get an answer!
  2550.  
  2551. `<mysql-digest-subscribe@lists.mysql.com> mysql-digest'
  2552.      The `mysql' list in digest form.  That means you get all individual
  2553.      messages, sent as one large mail message once a day.
  2554.  
  2555. `<bugs-subscribe@lists.mysql.com> bugs'
  2556.      On this list you should only post a full, repeatable bug report
  2557.      using the `mysqlbug' script (if you are running on Windows, you
  2558.      should include a description of the operating system and the MySQL
  2559.      version).  Preferably, you should test the problem using the
  2560.      latest stable or development version of MySQL before posting!
  2561.      Anyone should be able to repeat the bug by just using `mysql test
  2562.      < script' on the included test case.  All bugs posted on this list
  2563.      will be corrected or documented in the next MySQL release!  If
  2564.      there are only small code changes involved, we will also post a
  2565.      patch that fixes the problem.
  2566.  
  2567. `<bugs-digest-subscribe@lists.mysql.com> bugs-digest'
  2568.      The `bugs' list in digest form.
  2569.  
  2570. `<internals-subscribe@lists.mysql.com> internals'
  2571.      A list for people who work on the MySQL code.  On this list one
  2572.      can also discuss MySQL development and post patches.
  2573.  
  2574. `<internals-digest-subscribe@lists.mysql.com> internals-digest'
  2575.      A digest version of the `internals' list.
  2576.  
  2577. `<java-subscribe@lists.mysql.com> java'
  2578.      Discussion about MySQL and Java.  Mostly about the JDBC drivers.
  2579.  
  2580. `<java-digest-subscribe@lists.mysql.com> java-digest'
  2581.      A digest version of the `java' list.
  2582.  
  2583. `<win32-subscribe@lists.mysql.com> win32'
  2584.      All things concerning MySQL on Microsoft operating systems such as
  2585.      Win95, Win98, NT, and Win2000.
  2586.  
  2587. `<win32-digest-subscribe@lists.mysql.com> win32-digest'
  2588.      A digest version of the `win32' list.
  2589.  
  2590. `<myodbc-subscribe@lists.mysql.com> myodbc'
  2591.      All things about connecting to MySQL with ODBC.
  2592.  
  2593. `<myodbc-digest-subscribe@lists.mysql.com> myodbc-digest'
  2594.      A digest version of the `myodbc' list.
  2595.  
  2596. `<plusplus-subscribe@lists.mysql.com> plusplus'
  2597.      All things concerning programming with the C++ API to MySQL.
  2598.  
  2599. `<plusplus-digest-subscribe@lists.mysql.com> plusplus-digest'
  2600.      A digest version of the `plusplus' list.
  2601.  
  2602. `<msql-mysql-modules-subscribe@lists.mysql.com> msql-mysql-modules'
  2603.      A list about the Perl support in MySQL. msql-mysql-modules
  2604.  
  2605. `<msql-mysql-modules-digest-subscribe@lists.mysql.com> msql-mysql-modules-digest'
  2606.      A digest version of the `msql-mysql-modules' list.
  2607.  
  2608. You subscribe or unsubscribe to all lists in the same way as described
  2609. above.  In your subscribe or unsubscribe message, just put the
  2610. appropriate mailing list name rather than `mysql'.  For example, to
  2611. subscribe to or unsubscribe from the `myodbc' list, send a message to
  2612. <myodbc-subscribe@lists.mysql.com> or
  2613. <myodbc-unsubscribe@lists.mysql.com>.
  2614.  
  2615. If you can't get an answer for your questions from the mailing list, one
  2616. option is to pay for support from MySQL AB, which will put you in
  2617. direct contact with MySQL developers. *Note Support::.
  2618.  
  2619. The following table shows some MySQL mailing in other languages than
  2620. English.  Note that these are not operated by MySQL AB, so we can't
  2621. guarantee the quality on these.
  2622.  
  2623. `<mysql-france-subscribe@yahoogroups.com> A French mailing list'
  2624.  
  2625. `<list@tinc.net> A Korean mailing list'
  2626.      Email `subscribe mysql your@email.address' to this list.
  2627.  
  2628. `<mysql-de-request@lists.4t2.com> A German mailing list'
  2629.      Email `subscribe mysql-de your@email.address' to this list.  You
  2630.      can find information about this mailing list at
  2631.      `http://www.4t2.com/mysql'.
  2632.  
  2633. `<mysql-br-request@listas.linkway.com.br> A Portugese mailing list'
  2634.      Email `subscribe mysql-br your@email.address' to this list.
  2635.  
  2636. `<mysql-alta@elistas.net> A Spanish mailing list'
  2637.      Email `subscribe mysql your@email.address' to this list.
  2638.  
  2639. Asking Questions or Reporting Bugs
  2640. ..................................
  2641.  
  2642. Before posting a bug report or question, please do the following:
  2643.  
  2644.    * Start by searching the MySQL online manual at:
  2645.      `http://www.mysql.com/documentation/manual.php'
  2646.      We try to keep the manual up to date by updating it frequently with
  2647.      solutions to newly found problems!
  2648.  
  2649.    * Search the MySQL mailing list archives:
  2650.      `http://www.mysql.com/documentation/'
  2651.    * You can also use `http://www.mysql.com/search.html' to search all
  2652.      the Web pages (including the manual) that are located at
  2653.      `http://www.mysql.com/'.
  2654.  
  2655. If you can't find an answer in the manual or the archives, check with
  2656. your local MySQL expert.  If you still can't find an answer to your
  2657. question, go ahead and read the next section about how to send mail to
  2658. <mysql@lists.mysql.com>.
  2659.  
  2660. How to Report Bugs or Problems
  2661. ..............................
  2662.  
  2663. Writing a good bug report takes patience, but doing it right the first
  2664. time saves time for us and for you.  A good bug report containing a full
  2665. test case for the bug will make it very likely that we will fix it in
  2666. the next release.  This section will help you write your report
  2667. correctly so that you don't waste your time doing things that may not
  2668. help us much or at all.
  2669.  
  2670. We encourage everyone to use the `mysqlbug' script to generate a bug
  2671. report (or a report about any problem), if possible.  `mysqlbug' can be
  2672. found in the `scripts' directory in the source distribution, or, for a
  2673. binary distribution, in the `bin' directory under your MySQL
  2674. installation directory.  If you are unable to use `mysqlbug', you should
  2675. still include all the necessary information listed in this section.
  2676.  
  2677. The `mysqlbug' script helps you generate a report by determining much
  2678. of the following information automatically, but if something important
  2679. is missing, please include it with your message!  Please read this
  2680. section carefully and make sure that all the information described here
  2681. is included in your report.
  2682.  
  2683. The normal place to report bugs and problems is
  2684. <mysql@lists.mysql.com>.  If you can make a test case that clearly
  2685. demonstrates the bug, you should post it to the <bugs@lists.mysql.com>
  2686. list.  Note that on this list you should only post a full, repeatable
  2687. bug report using the `mysqlbug' script.  If you are running on Windows,
  2688. you should include a description of the operating system and the MySQL
  2689. version.  Preferably, you should test the problem using the latest
  2690. stable or development version of MySQL before posting!  Anyone should
  2691. be able to repeat the bug by just using "`mysql test < script'" on the
  2692. included test case or run the shell or perl script that is included in
  2693. the bug report.  All bugs posted on the `bugs' list will be corrected
  2694. or documented in the next MySQL release!  If there are only small code
  2695. changes involved to correct this problem, we will also post a patch
  2696. that fixes the problem.
  2697.  
  2698. Remember that it is possible to respond to a message containing too much
  2699. information, but not to one containing too little.  Often people omit
  2700. facts because they think they know the cause of a problem and assume
  2701. that some details don't matter.  A good principle is: if you are in
  2702. doubt about stating something, state it!  It is a thousand times faster
  2703. and less troublesome to write a couple of lines more in your report
  2704. than to be forced to ask again and wait for the answer because you
  2705. didn't include enough information the first time.
  2706.  
  2707. The most common errors are that people don't indicate the version
  2708. number of the MySQL distribution they are using, or don't indicate what
  2709. platform they have MySQL installed on (including the platform version
  2710. number).  This is highly relevant information, and in 99 cases out of
  2711. 100 the bug report is useless without it!  Very often we get questions
  2712. like, "Why doesn't this work for me?" then we find that the feature
  2713. requested wasn't implemented in that MySQL version, or that a bug
  2714. described in a report has been fixed already in newer MySQL versions.
  2715. Sometimes the error is platform dependent; in such cases, it is next to
  2716. impossible to fix anything without knowing the operating system and the
  2717. version number of the platform.
  2718.  
  2719. Remember also to provide information about your compiler, if it is
  2720. related to the problem.  Often people find bugs in compilers and think
  2721. the problem is MySQL-related.  Most compilers are under development all
  2722. the time and become better version by version.  To determine whether or
  2723. not your problem depends on your compiler, we need to know what
  2724. compiler is used.  Note that every compiling problem should be regarded
  2725. as a bug report and reported accordingly.
  2726.  
  2727. It is most helpful when a good description of the problem is included
  2728. in the bug report.  That is, a good example of all the things you did
  2729. that led to the problem and the problem itself exactly described.  The
  2730. best reports are those that include a full example showing how to
  2731. reproduce the bug or problem.  *Note Reproduceable test case::.
  2732.  
  2733. If a program produces an error message, it is very important to include
  2734. the message in your report!  If we try to search for something from the
  2735. archives using programs, it is better that the error message reported
  2736. exactly matches the one that the program produces.  (Even the case
  2737. should be observed!)  You should never try to remember what the error
  2738. message was; instead, copy and paste the entire message into your
  2739. report!
  2740.  
  2741. If you have a problem with MyODBC, you should try to generate a MyODBC
  2742. trace file.  *Note MyODBC bug report::.
  2743.  
  2744. Please remember that many of the people who will read your report will
  2745. do so using an 80-column display.  When generating reports or examples
  2746. using the `mysql' command line tool, you should therefore use the
  2747. `--vertical' option (or the `\G' statement terminator) for output that
  2748. would exceed the available width for such a display (for example, with
  2749. the `EXPLAIN SELECT' statement; see the example below).
  2750.  
  2751. Please include the following information in your report:
  2752.  
  2753.    * The version number of the MySQL distribution you are using (for
  2754.      example, MySQL Version 3.22.22). You can find out which version you
  2755.      are running by executing `mysqladmin version'.  `mysqladmin' can be
  2756.      found in the `bin' directory under your MySQL installation
  2757.      directory.
  2758.  
  2759.    * The manufacturer and model of the machine you are working on.
  2760.  
  2761.    * The operating system name and version.  For most operating
  2762.      systems, you can get this information by executing the Unix
  2763.      command `uname -a'.
  2764.  
  2765.    * Sometimes the amount of memory (real and virtual) is relevant. If
  2766.      in doubt, include these values.
  2767.  
  2768.    * If you are using a source distribution of MySQL, the name and
  2769.      version number of the compiler used is needed.  If you have a
  2770.      binary distribution, the distribution name is needed.
  2771.  
  2772.    * If the problem occurs during compilation, include the exact error
  2773.      message(s) and also a few lines of context around the offending
  2774.      code in the file where the error occurred.
  2775.  
  2776.    * If `mysqld' died, you should also report the query that crashed
  2777.      `mysqld'.  You can usually find this out by running `mysqld' with
  2778.      logging enabled.  *Note Using log files::.
  2779.  
  2780.    * If any database table is related to the problem, include the
  2781.      output from `mysqldump --no-data db_name tbl_name1 tbl_name2 ...'.
  2782.      This is very easy to do and is a powerful way to get information
  2783.      about any table in a database that will help us create a situation
  2784.      matching the one you have.
  2785.  
  2786.    * For speed-related bugs or problems with `SELECT' statements, you
  2787.      should always include the output of `EXPLAIN SELECT ...', and at
  2788.      least the number of rows that the `SELECT' statement produces.
  2789.      The more information you give about your situation, the more
  2790.      likely it is that someone can help you!  For example, the
  2791.      following is an example of a very good bug report (it should of
  2792.      course be posted with the `mysqlbug' script):
  2793.  
  2794.      Example run using the `mysql' command line tool (note the use of
  2795.      the `\G' statement terminator for statements whose output width
  2796.      would otherwise exceed that of an 80-column display device):
  2797.  
  2798.           mysql> SHOW VARIABLES;
  2799.           mysql> SHOW COLUMNS FROM ...\G
  2800.                  <output from SHOW COLUMNS>
  2801.           mysql> EXPLAIN SELECT ...\G
  2802.                  <output from EXPLAIN>
  2803.           mysql> FLUSH STATUS;
  2804.           mysql> SELECT ...;
  2805.                  <A short version of the output from SELECT,
  2806.                  including the time taken to run the query>
  2807.           mysql> SHOW STATUS;
  2808.                  <output from SHOW STATUS>
  2809.  
  2810.    * If a bug or problem occurs while running *mysqld*, try to provide
  2811.      an input script that will reproduce the anomaly.  This script
  2812.      should include any necessary source files.  The more closely the
  2813.      script can reproduce your situation, the better.  If you can make
  2814.      a repeatable test case, you should post this to
  2815.      <bugs@lists.mysql.com> for a high priority treatment!
  2816.  
  2817.      If you can't provide a script, you should at least include the
  2818.      output from `mysqladmin variables extended-status processlist' in
  2819.      your mail to provide some information of how your system is
  2820.      performing!
  2821.  
  2822.    * If you can't produce a test case in a few rows, or if the test
  2823.      table is too big to be mailed to the mailing list (more than 10
  2824.      rows), you should dump your tables using `mysqldump' and create a
  2825.      `README' file that describes your problem.
  2826.  
  2827.      Create a compressed archive of your files using `tar' and `gzip'
  2828.      or `zip', and use `ftp' to transfer the archive to
  2829.      `ftp://support.mysql.com/pub/mysql/secret/'.  Then send a short
  2830.      description of the problem to <bugs@lists.mysql.com>.
  2831.  
  2832.    * If you think that MySQL produces a strange result from a query,
  2833.      include not only the result, but also your opinion of what the
  2834.      result should be, and an account describing the basis for your
  2835.      opinion.
  2836.  
  2837.    * When giving an example of the problem, it's better to use the
  2838.      variable names, table names, etc., that exist in your actual
  2839.      situation than to come up with new names.  The problem could be
  2840.      related to the name of a variable or table!  These cases are rare,
  2841.      perhaps, but it is better to be safe than sorry.  After all, it
  2842.      should be easier for you to provide an example that uses your
  2843.      actual situation, and it is by all means better for us.  In case
  2844.      you have data you don't want to show to others, you can use `ftp'
  2845.      to transfer it to `ftp://support.mysql.com/pub/mysql/secret/'.  If
  2846.      the data are really top secret and you don't want to show them
  2847.      even to us, then go ahead and provide an example using other
  2848.      names, but please regard this as the last choice.
  2849.  
  2850.    * Include all the options given to the relevant programs, if
  2851.      possible.  For example, indicate the options that you use when you
  2852.      start the `mysqld' daemon and that you use to run any MySQL client
  2853.      programs.  The options to programs like `mysqld' and `mysql', and
  2854.      to the `configure' script, are often keys to answers and are very
  2855.      relevant!  It is never a bad idea to include them anyway!  If you
  2856.      use any modules, such as Perl or PHP, please include the version
  2857.      number(s) of those as well.
  2858.  
  2859.    * If your question is related to the privilege system, please
  2860.      include the output of `mysqlaccess', the output of `mysqladmin
  2861.      reload', and all the error messages you get when trying to
  2862.      connect!  When you test your privileges, you should first run
  2863.      `mysqlaccess'.  After this, execute `mysqladmin reload version'
  2864.      and try to connect with the program that gives you trouble.
  2865.      `mysqlaccess' can be found in the `bin' directory under your MySQL
  2866.      installation directory.
  2867.  
  2868.    * If you have a patch for a bug, that is good, but don't assume the
  2869.      patch is all we need, or that we will use it, if you don't provide
  2870.      some necessary information, such as test cases showing the bug
  2871.      that your patch fixes.  We might find problems with your patch or
  2872.      we might not understand it at all; if so, we can't use it.
  2873.  
  2874.      If we can't verify exactly what the patch is meant for, we won't
  2875.      use it.  Test cases will help us here.  Show that the patch will
  2876.      handle all the situations that may occur.  If we find a borderline
  2877.      case (even a rare one) where the patch won't work, it may be
  2878.      useless.
  2879.  
  2880.    * Guesses about what the bug is, why it occurs, or what it depends
  2881.      on, are usually wrong.  Even the MySQL team can't guess such things
  2882.      without first using a debugger to determine the real cause of a
  2883.      bug.
  2884.  
  2885.    * Indicate in your mail message that you have checked the reference
  2886.      manual and mail archive so others know that you have tried to
  2887.      solve the problem yourself.
  2888.  
  2889.    * If you get a `parse error', please check your syntax closely!  If
  2890.      you can't find something wrong with it, it's extremely likely that
  2891.      your current version of MySQL doesn't support the query you are
  2892.      using.  If you are using the current version and the manual at
  2893.      `http://www.mysql.com/documentation/manual.php' doesn't cover the
  2894.      syntax you are using, MySQL doesn't support your query.  In this
  2895.      case, your only options are to implement the syntax yourself or
  2896.      e-mail <mysql-licensing@mysql.com> and ask for an offer to
  2897.      implement it!
  2898.  
  2899.      If the manual covers the syntax you are using, but you have an
  2900.      older version of MySQL, you should check the MySQL change history
  2901.      to see when the syntax was implemented.  In this case, you have
  2902.      the option of upgrading to a newer version of MySQL.  *Note News::.
  2903.  
  2904.    * If you have a problem such that your data appears corrupt or you
  2905.      get errors when you access some particular table, you should first
  2906.      check and then try repairing your tables with `myisamchk' or
  2907.      `CHECK TABLE' and `REPAIR TABLE'.  *Note MySQL Database
  2908.      Administration::.
  2909.  
  2910.    * If you often get corrupted tables you should try to find out when
  2911.      and why this happens!  In this case, the
  2912.      `mysql-data-directory/'hostname'.err' file may contain some
  2913.      information about what happened.  *Note Error log::.  Please
  2914.      include any relevant information from this file in your bug
  2915.      report!  Normally `mysqld' should *NEVER* crash a table if nothing
  2916.      killed it in the middle of an update!  If you can find the cause
  2917.      of `mysqld' dying, it's much easier for us to provide you with a
  2918.      fix for the problem!  *Note What is crashing::.
  2919.  
  2920.    * If possible, download and install the most recent version of MySQL
  2921.      and check whether or not it solves your problem.  All versions of
  2922.      MySQL are thoroughly tested and should work without problems!  We
  2923.      believe in making everything as backward compatible as possible,
  2924.      and you should be able to switch MySQL versions in minutes!  *Note
  2925.      Which version::.
  2926.  
  2927. If you are a support customer, please cross-post the bug report to
  2928. <mysql-support@mysql.com> for higher priority treatment, as well as to
  2929. the appropriate mailing list to see if someone else has experienced (and
  2930. perhaps solved) the problem.
  2931.  
  2932. For information on reporting bugs in *MyODBC*, see *Note ODBC
  2933. Problems::.
  2934.  
  2935. For solutions to some common problems, see *Note Problems::.
  2936.  
  2937. When answers are sent to you individually and not to the mailing list,
  2938. it is considered good etiquette to summarize the answers and send the
  2939. summary to the mailing list so that others may have the benefit of
  2940. responses you received that helped you solve your problem!
  2941.  
  2942. Guidelines for Answering Question on the Mailing List
  2943. .....................................................
  2944.  
  2945. If you consider your answer to have broad interest, you may want to
  2946. post it to the mailing list instead of replying directly to the
  2947. individual who asked.  Try to make your answer general enough that
  2948. people other than the original poster may benefit from it.  When you
  2949. post to the list, please make sure that your answer is not a
  2950. duplication of a previous answer.
  2951.  
  2952. Try to summarize the essential part of the question in your reply;
  2953. don't feel obliged to quote the entire original message.
  2954.  
  2955. Please don't post mail messages from your browser with HTML mode turned
  2956. on!  Many users don't read mail with a browser!
  2957.  
  2958. MySQL Licensing and Support
  2959. ===========================
  2960.  
  2961. This section describes MySQL support and licensing arrangements:
  2962.  
  2963.    * The copyrights under which MySQL is distributed (*note Copyright::)
  2964.  
  2965.    * Sample situations illustrating when a license is required (*note
  2966.      Licensing examples::)
  2967.  
  2968.    * Support costs (*note Cost::) and support benefits (*note Support::)
  2969.  
  2970.    * Commercial licensing costs
  2971.  
  2972. MySQL Licensing Policy
  2973. ----------------------
  2974.  
  2975. The formal terms of the GPL license can be found at *Note GPL license::.
  2976. Basically, our licensing policy and interpretation of the GPL is as
  2977. follows:
  2978.  
  2979. Note that older versions of MySQL are still using a more strict license
  2980. (http://www.mysql.com/support/arrangements/mypl.html).  See the
  2981. documentation for that version for more information. If you need a
  2982. commercial MySQL license, because the GPL license doesn't suit your
  2983. application, you can buy one at `https://order.mysql.com/'.
  2984.  
  2985. For normal internal use, MySQL costs nothing.  You do not have to pay
  2986. us if you do not want to.
  2987.  
  2988. A license is required if:
  2989.  
  2990.    - You link a program, that is not free software, with code from the
  2991.      MySQL server or clients that has the GPL copyright. This happens
  2992.      for example when you use MySQL as an embedded server in your
  2993.      applications or when you add not free extensions to the MySQL
  2994.      server.  In this case your application/code would also become GPL
  2995.      through the GPL license that acts as a virus.  By licensing MySQL
  2996.      server from MySQL AB under a commercial license you will avoid
  2997.      this problem.  See `http://www.gnu.org/copyleft/gpl-faq.html'.
  2998.  
  2999.    - You have a commercial application that ONLY works with MySQL and
  3000.      ships the application with the MySQL server.  This is because we
  3001.      view this as linking even if it is done over the network.
  3002.  
  3003.    - You have a distribution of MySQL and you don't provide the source
  3004.      code for your copy of the MySQL server, as defined in the GPL
  3005.      license.
  3006.  
  3007. A license is *NOT* required if:
  3008.  
  3009.    - You do not need a license to include the client code in commercial
  3010.      programs.  The client part of MySQL licensed with the LGPL `GNU
  3011.      Library General Public License'.  The `mysql' command-line client
  3012.      includes code from the `readline' library that is under the `GPL'.
  3013.  
  3014.    - If your use of MySQL does not require a license, but you like
  3015.      MySQL and want to encourage further development, you are certainly
  3016.      welcome to purchase a license or MySQL support anyway.
  3017.  
  3018.    - If you use MySQL in a commercial context such that you profit by
  3019.      its use, we ask that you further the development of MySQL by
  3020.      purchasing some level of support.  We feel that if MySQL helps
  3021.      your business, it is reasonable to ask that you help MySQL.
  3022.      (Otherwise, if you ask us support questions, you are not only
  3023.      using for free something into which we've put a lot a work, you're
  3024.      asking us to provide free support, too.)
  3025.  
  3026. For circumstances under which a MySQL license is required, you need a
  3027. license per machine that runs the `mysqld' server.  However, a
  3028. multiple-CPU machine counts as a single machine, and there is no
  3029. restriction on the number of MySQL servers that run on one machine, or
  3030. on the number of clients concurrently connected to a server running on
  3031. that machine!
  3032.  
  3033. If you have any questions as to whether or not a license is required for
  3034. your particular use of MySQL, please read this again and then contact
  3035. us.  *Note Contact information::.
  3036.  
  3037. If you require a MySQL license, the easiest way to pay for it is to use
  3038. the license form on MySQL's secure server at
  3039. `https://order.mysql.com/'.  Other forms of payment are discussed in
  3040. *Note Payment information::.
  3041.  
  3042. Copyrights Used by MySQL
  3043. ------------------------
  3044.  
  3045. There are several different copyrights on the MySQL distribution:
  3046.  
  3047.   1. The MySQL-specific source needed to build the `mysqlclient'
  3048.      library is licensed under the `LGPL' and programs in the `client'
  3049.      directory is GPL. Each file has a header that shows which
  3050.      copyright is used for that file.
  3051.  
  3052.   2. The client library and the (GNU `getopt') library are covered by
  3053.      the "GNU LIBRARY GENERAL PUBLIC LICENSE."  *Note LGPL license::.
  3054.  
  3055.   3. Some parts of the source (the `regexp' library) are covered by a
  3056.      Berkeley-style copyright.
  3057.  
  3058.   4. All the source in the server and the (GNU `readline') library is
  3059.      covered by the "GNU GENERAL PUBLIC LICENSE."  *Note GPL license::.
  3060.      This is also available as the file `COPYING' in the distributions.
  3061.  
  3062.  
  3063. One goal is that the SQL client library should be free enough that it is
  3064. possible to add MySQL support into commercial products without a
  3065. license.  For this reason, we chose the LGPL license for the client
  3066. code.
  3067.  
  3068. This means that you can use MySQL for free with any program that uses
  3069. any of the free software licenses.  MySQL is also free for any end user
  3070. for his own or company usage.
  3071.  
  3072. However, if you use MySQL for something important to you, you may want
  3073. to help secure its development by purchasing licenses or a support
  3074. contract.  *Note Support::.
  3075.  
  3076. Copyright Changes
  3077. .................
  3078.  
  3079. Version 3.22 of MySQL is still using a more strict license.  See the
  3080. documentation for that version for more information.
  3081.  
  3082. Example Licensing Situations
  3083. ----------------------------
  3084.  
  3085. This section describes some situations illustrating whether or not you
  3086. must license the MySQL server.  Generally these examples involve
  3087. providing MySQL as an integral part of a product.
  3088.  
  3089. Note that a single MySQL license covers any number of CPUs and `mysqld'
  3090. servers on a machine!  There is no artificial limit on the number of
  3091. clients that connect to the server in any way.
  3092.  
  3093. Selling Products that use MySQL
  3094. ...............................
  3095.  
  3096. To determine whether or not you need a MySQL license when selling your
  3097. application, you should ask whether the proper functioning of your
  3098. application is dependent on the use of MySQL and whether you include
  3099. the MySQL server with your product.  There are several cases to
  3100. consider:
  3101.  
  3102.    * Does your application require MySQL to function properly?
  3103.  
  3104.    * If your product requires MySQL, you need a license for any machine
  3105.      that runs the `mysqld' server.  For example, if you've designed
  3106.      your application around MySQL, then you've really made a
  3107.      commercial product that requires the engine, so you need a license.
  3108.  
  3109.    * If your application does not require MySQL, you do not need to
  3110.      obtain a license.  For example, if using MySQL just adds some new
  3111.      optional features to your product (such as adding logging to a
  3112.      database if MySQL is used rather than logging to a text file), it
  3113.      should fall within normal use, and a license would not be required.
  3114.  
  3115.    * In other words, you need a license if you sell a product designed
  3116.      specifically for use with MySQL or that requires the MySQL server
  3117.      to function at all.  This is true whether or not you provide MySQL
  3118.      for your client as part of your product distribution.
  3119.  
  3120.    * It also depends on what you're doing for the client.  Do you plan
  3121.      to provide your client with detailed instructions on installing
  3122.      MySQL with your software?  Then your product may be contingent on
  3123.      the use of MySQL; if so, you need to buy a license.  If you are
  3124.      simply tying into a database that you expect already to have been
  3125.      installed by the time your software is purchased, then you probably
  3126.      don't need a license.
  3127.  
  3128.  
  3129. ISP MySQL Services
  3130. ..................
  3131.  
  3132. Internet Service Providers (ISPs) often host MySQL servers for their
  3133. customers.  With the GPL license this does not require a license.
  3134.  
  3135. On the other hand, we do encourage people to use ISPs that have MySQL
  3136. support, as this will give them the confidence that if they have some
  3137. problem with their MySQL installation, their ISP will be able to solve
  3138. the problem for them (in some cases with the help from the MySQL
  3139. development team).
  3140.  
  3141. All ISPs that want to keep themselves up-to-date should subscribe to
  3142. our `announce' mailing list so that they can be aware of fatal issues
  3143. that may be relevant for their MySQL installations.
  3144.  
  3145. Note that if the ISP doesn't have a license for MySQL, it should give
  3146. its customers at least read access to the source of the MySQL
  3147. installation so that its customer can verify that it is patched
  3148. correctly.
  3149.  
  3150. Running a Web Server Using MySQL
  3151. ................................
  3152.  
  3153. If you use MySQL in conjunction with a Web server on Unix, you don't
  3154. have to pay for a license.
  3155.  
  3156. This is true even if you run a commercial Web server that uses MySQL,
  3157. because you are not selling an embedded MySQL version yourself.
  3158. However, in this case we would like you to purchase MySQL support,
  3159. because MySQL is helping your enterprise.
  3160.  
  3161. MySQL Licensing and Support Costs
  3162. ---------------------------------
  3163.  
  3164. Our current license prices are shown below. To make a purchase, please
  3165. visit `https://order.mysql.com/'.
  3166.  
  3167. If you pay by credit card, the currency is EURO (European Union Euro)
  3168. so the prices will differ slightly.
  3169.  
  3170. *Number of licenses*   *Per copy*             
  3171. 1-9                    230 EURO               
  3172. 10-24                  138 EURO               
  3173. 25-49                  117 EURO               
  3174. 50-99                  102 EURO               
  3175. 100-249                91 EURO                
  3176. 250-499                76 EURO                
  3177. 500-999                66 EURO                
  3178.  
  3179. For high volume (OEM) purchases, please contact <sales@mysql.com>.
  3180.  
  3181. For OEM purchases, you must act as the middle-man for eventual problems
  3182. or extension requests from your users.  We also require that OEM
  3183. customers have at least an extended e-mail support contract.  Note that
  3184. OEM licenses only apply for products where the user doesn't have direct
  3185. access to the MySQL server (embedded system).  In other words, the
  3186. MySQL server should only be used with the application that was supplied
  3187. you.
  3188.  
  3189. If you have a low-margin, high-volume product, you can always talk to us
  3190. about other terms (for example, a percent of the sale price).  If you
  3191. do, please be informative about your product, pricing, market, and any
  3192. other information that may be relevant.
  3193.  
  3194. A full-price license is not a support agreement and includes very
  3195. minimal support.  This means that we try to answer any relevant
  3196. questions.  If the answer is in the documentation, we will direct you
  3197. to the appropriate section.  If you have not purchased a license or
  3198. support, we probably will not answer at all.
  3199.  
  3200. If you discover what we consider a real bug, we are likely to fix it in
  3201. any case.  But if you pay for support we will notify you about the fix
  3202. status instead of just fixing it in a later release.
  3203.  
  3204. More comprehensive support is sold separately.  Descriptions of what
  3205. each level of support includes are given in *Note Support::.  Costs for
  3206. the various types of commercial support are shown below.  Support level
  3207. prices are in EURO (European Union Euro).  One EURO is about 1.06 USD.
  3208.  
  3209. *Type of support*                    *Cost per year*
  3210. Basic e-mail support. *Note Basic    EURO 200
  3211. email support::.                     
  3212. Extended e-mail support *Note        EURO 1000
  3213. Extended email support::.            
  3214. Login support *Note Login            EURO 2000
  3215. support::.                           
  3216. Extended login support *Note         EURO 5000
  3217. Extended login support::.            
  3218. Telephone support *Note Telephone    EURO 12000
  3219. support::.                           
  3220.  
  3221. You may upgrade from any lower level of support to a higher level of
  3222. support for the difference in price between the two support levels.
  3223.  
  3224. We do also provide telephone support (mostly emergency support but also
  3225. 24/7 support).  This support option doesn't however have a fixed price
  3226. but is negotiated for case to case.  If you are interested in this
  3227. option you can email <sales@mysql.com> and tell us about your needs.
  3228.  
  3229. Note that as our sales staff is very busy, it may take some time until
  3230. your request is handled.  Our support staff does however always answer
  3231. promptly to support questions!
  3232.  
  3233. Payment information
  3234. ...................
  3235.  
  3236. Currently we can take SWIFT payments, checks, or credit cards.
  3237.  
  3238. Payment should be made to:
  3239.  
  3240.      Postgirot Bank AB
  3241.      105 06 STOCKHOLM, SWEDEN
  3242.      
  3243.      MySQL AB
  3244.      BOX 6434
  3245.      11382 STOCKHOLM, SWEDEN
  3246.      
  3247.      SWIFT address: PGSI SESS
  3248.      Account number: 96 77 06 - 3
  3249.  
  3250. Specify: license and/or support and your name and e-mail address.
  3251.  
  3252. In Europe and Japan you can use EuroGiro (that should be less
  3253. expensive) to the same account.
  3254.  
  3255. If you want to pay by check, make it payable to "MySQL Finland AB" and
  3256. mail it to the address below:
  3257.  
  3258.      MySQL AB
  3259.      BOX 6434, Torsgatan 21
  3260.      11382 STOCKHOLM, SWEDEN
  3261.  
  3262. If you want to pay by credit card over the Internet, you can use MySQL
  3263. AB's secure license form (https://order.mysql.com/).
  3264.  
  3265. You can also print a copy of the license form, fill it in, and send it
  3266. by fax to:
  3267.  
  3268. +46-8-729 69 05
  3269.  
  3270. If you want us to bill you, you can use the license form and write "bill
  3271. us" in the comment field.  You can also mail a message to
  3272. <sales@mysql.com> (*not* `mysql@lists.mysql.com'!)  with your company
  3273. information and ask us to bill you.
  3274.  
  3275. Contact Information
  3276. ...................
  3277.  
  3278. For commercial licensing, please contact the MySQL licensing team.  The
  3279. much preferred method is by e-mail to <licensing@mysql.com>.  Fax is
  3280. also possible but handling of these may take much longer (Fax +46-8-729
  3281. 69 05).
  3282.  
  3283. If you represent a business that is interested in partnering with
  3284. MySQL, please send e-mail to <partner@mysql.com>.
  3285.  
  3286. For timely, precise answers to technical questions about MySQL you
  3287. should order (https://order.mysql.com/) one of our support contracts
  3288. (http://www.mysql.com/support/arrangements/types.html).  MySQL support
  3289. is provided by the MySQL developers so the standard is extremely high.
  3290.  
  3291. If you are interested in placing a banner advertisement on our Web site,
  3292. please send e-mail to <advertising@mysql.com>.
  3293.  
  3294. If you are interested in any of the jobs listed in our jobs
  3295. (http://www.mysql.com/development/jobs/) section, please send e-mail to
  3296. <jobs@mysql.com>.
  3297.  
  3298. For general discussion amongst our many users, please direct your
  3299. attention to the appropriate mailing list
  3300. (http://www.mysql.com/documentation/lists.html).
  3301.  
  3302. For general information inquires, please send e-mail to
  3303. <info@mysql.com>.
  3304.  
  3305. For questions or comments about the workings or content of the Web site,
  3306. please send e-mail to <webmaster@mysql.com>.
  3307.  
  3308. Types of Commercial Support
  3309. ---------------------------
  3310.  
  3311. The following is true of all support options:
  3312.  
  3313.    * The support is per year.
  3314.  
  3315.    * We will fix, or provide a reasonable workaround for any repeatable
  3316.      bug.
  3317.  
  3318.    * We will give a reasonable effort to find and fix any other MySQL
  3319.      related bug.
  3320.  
  3321.    * The higher level of support contract the more effort we will put
  3322.      into finding a solution to your problems.
  3323.  
  3324.    * The following is true for all support contracts except Basic email
  3325.      support:
  3326.  
  3327.      For non-bug related things, like helping you optimize your queries
  3328.      or your system, extending MySQL with new functionality, etc., we
  3329.      charge 200 EURO/hour, which is deducted from your support
  3330.      contract.  In other words, if you have login support (2000 EURO),
  3331.      you can expect us to work up to 10 hours to help you with things
  3332.      like this.
  3333.  
  3334. Basic E-mail Support
  3335. ....................
  3336.  
  3337. Basic e-mail support is a very inexpensive support option and should be
  3338. thought of more as a way to support our development of MySQL than as a
  3339. real support option.  We at MySQL do give a lot of free support in all
  3340. the different MySQL lists, and the money we get from basic e-mail
  3341. support is largely used to make this possible.
  3342.  
  3343. At this support level, the MySQL mailing lists are the preferred means
  3344. of communication.  Questions normally should be mailed to the primary
  3345. mailing list (<mysql@lists.mysql.com>) or one of the other regular
  3346. lists (for example, <win32@lists.mysql.com> for Windows-related MySQL
  3347. questions), as someone else already may have experienced and solved the
  3348. problem you have.  *Note Asking questions::.
  3349.  
  3350. However, by purchasing basic e-mail support, you also have access to the
  3351. support address <mysql-support@mysql.com>, which is not available as
  3352. part of the minimal support that you get by purchasing a MySQL license.
  3353. This means that for especially critical questions, you can cross-post
  3354. your message to <mysql-support@mysql.com>.  (If the message contains
  3355. sensitive data, you should post only to <mysql-support@mysql.com>.)
  3356.  
  3357. *REMEMBER!* to ALWAYS include your registration number and expiration
  3358. date when you send a message to <mysql-support@mysql.com>.
  3359.  
  3360. Note that if you have encountered a critical, repeatable bug, and follow
  3361. the rules outlined in the manual section of how to report bugs and send
  3362. it to <bugs@lists.mysql.com>, we promise to try to fix this as soon as
  3363. possible, regardless of your support level!  *Note Bug reports::.
  3364.  
  3365. Basic e-mail support includes the following types of service:
  3366.  
  3367.    * If your question is already answered in the manual, we will inform
  3368.      you of the correct section in which you can find the answer.  If
  3369.      the answer is not in the manual, we will point you in the right
  3370.      direction to solve your problem.
  3371.  
  3372.    * We guarantee a timely answer for your e-mail messages.  We can't
  3373.      guarantee that we can solve any problem, but at least you will
  3374.      receive an answer if we can contact you by e-mail.
  3375.  
  3376.    * We will help with unexpected problems when you install MySQL from a
  3377.      binary distribution on supported platforms.  This level of support
  3378.      does not cover installing MySQL from a source distribution.
  3379.      Supported platforms are those for which MySQL is known to work.
  3380.      *Note Which OS::.
  3381.  
  3382.    * We will help you with bugs and missing features.  Any bugs that
  3383.      are found are fixed for the next MySQL release.  If the bug is
  3384.      critical for you, we will mail you a patch for it as soon the bug
  3385.      is fixed.  Critical bugs always have the highest priority for us,
  3386.      and we ensure that they are fixed as soon as possible.
  3387.  
  3388.    * Your suggestions for the further development of MySQL will be
  3389.      taken into consideration.  By taking email support you have already
  3390.      helped the further development of MySQL.  If you want to have more
  3391.      input, upgrade to a higher level of support.
  3392.  
  3393.    * If you want us to help optimize your system, you must upgrade to a
  3394.      higher level of support.
  3395.  
  3396. Extended E-mail Support
  3397. .......................
  3398.  
  3399. Extended e-mail support includes everything in basic e-mail support with
  3400. these additions:
  3401.  
  3402.    * Your e-mail will be dealt with before mail from basic e-mail
  3403.      support users and non-registered users.
  3404.  
  3405.    * Your suggestions for the further development of MySQL will receive
  3406.      strong consideration.  Simple extensions that suit the basic goals
  3407.      of MySQL are implemented in a matter of days.  By taking extended
  3408.      e-mail support you have already helped the further development of
  3409.      MySQL.
  3410.  
  3411.    * Typical situations that are covered by extended e-mail support are:
  3412.  
  3413.         - We will answer and (within reason) solve questions that
  3414.           relate to possible bugs in MySQL.  As soon as the bug is
  3415.           found and corrected, we will mail a patch for it.
  3416.  
  3417.         - We will help with unexpected problems when you install MySQL
  3418.           from a source or binary distribution on supported platforms.
  3419.  
  3420.         - We will answer questions about missing features and offer
  3421.           hints how to work around them.
  3422.  
  3423.         - We will provide hints on optimizing `mysqld' for your
  3424.           situation.
  3425.  
  3426.    * You are allowed to influence the priority of items on the MySQL
  3427.      TODO List.  *Note TODO::.  This will ensure that the features you
  3428.      really need will be implemented sooner than they might be
  3429.      otherwise.
  3430.  
  3431. Login Support
  3432. .............
  3433.  
  3434. Login support includes everything in extended e-mail support with these
  3435. additions:
  3436.  
  3437.    * Your e-mail will be dealt with even before e-mail from extended
  3438.      e-mail support users.
  3439.  
  3440.    * Your suggestions for the further development of MySQL will be
  3441.      taken into very high consideration.  Realistic extensions that can
  3442.      be implemented in a couple of hours and that suit the basic goals
  3443.      of MySQL will be implemented as soon as possible.
  3444.  
  3445.    * If you have a very specific problem, we can try to log in on your
  3446.      system to solve the problem "in place."
  3447.  
  3448.    * Like any database vendor, we can't guarantee that we can rescue
  3449.      any data from crashed tables, but if the worst happens, we will
  3450.      help you rescue as much as possible.  MySQL has proven itself very
  3451.      reliable, but anything is possible due to circumstances beyond our
  3452.      control (for example, if your system crashes or someone kills the
  3453.      server by executing a `kill -9' command).
  3454.  
  3455.    * We will provide hints on optimizing your system and your queries.
  3456.  
  3457.    * You are allowed to call a MySQL developer (in moderation) and
  3458.      discuss your MySQL-related problems.  This option is however only
  3459.      to be used as a last result during an emergency after we have
  3460.      failed to grasp the total problem with email.  To make efficient
  3461.      use of our time we need to first get all facts about the problem,
  3462.      before talking on phone, to be able to work as efficiently as
  3463.      possible on solving the problem.
  3464.  
  3465. Extended Login Support
  3466. ......................
  3467.  
  3468. Extended login support includes everything in login support with these
  3469. additions:
  3470.  
  3471.    * Your e-mail has the highest possible priority.
  3472.  
  3473.    * We will actively examine your system and help you optimize it and
  3474.      your queries.  We may also optimize and/or extend MySQL to better
  3475.      suit your needs.
  3476.  
  3477.    * You may also request special extensions just for you.  For example:
  3478.           mysql> select MY_FUNC(col1,col2) from table;
  3479.  
  3480.    * We will provide a binary distribution of all important MySQL
  3481.      releases for your system, as long as we can get an account on a
  3482.      similar system.  In the worst case, we may require access to your
  3483.      system to be able to create a binary distribution.
  3484.  
  3485.    * If you can provide accommodations and pay for traveler fares, you
  3486.      can even get a MySQL developer to visit you and offer you help with
  3487.      your troubles.  Extended login support entitles you to one personal
  3488.      encounter per year, but we are always very flexible towards our
  3489.      customers!  If the visit takes 16 hours or more, the first 8 hours
  3490.      is without charge.  For the hours above 8 hours, you will be
  3491.      charged with a rate that is at least 20 % less than our standard
  3492.      rates.
  3493.  
  3494. Telephone Support
  3495. .................
  3496.  
  3497. Telephone support includes everything in extended login support with
  3498. these additions:
  3499.  
  3500.    * We will provide you with a dynamic web page showing the current
  3501.      list of `MySQL' developers that you can phone when you have a
  3502.      critical problem.
  3503.  
  3504.    * For non critical problem, you can request a MySQL developer to
  3505.      phone back within 48 hours to discuss `MySQL' related issues.
  3506.  
  3507. Support for other table handlers
  3508. ................................
  3509.  
  3510. To get support for `BDB' tables, `InnoDB' tables you have to pay an
  3511. additional 30% on the standard support price for each of the table
  3512. handlers you would like to have support for.
  3513.  
  3514. We at `MySQL AB' will help you create a proper bug report for the table
  3515. handler and submit it to the developers for the specific table handler.
  3516. We will also do our best to ensure that you will get a timely answer
  3517. or solution from the developers of the table handler.
  3518.  
  3519. Even if we are quite confident that we can solve most problems within a
  3520. timely manner, we can't guarantee a quick solution for any problems you
  3521. can get with the different table handlers.  We will however do our best
  3522. to help you get the problem solved.
  3523.  
  3524. How Standards-compatible Is MySQL?
  3525. ==================================
  3526.  
  3527. This section describes how MySQL relates to the ANSI SQL standards.
  3528. MySQL has many extensions to the ANSI SQL standards, and here you will
  3529. find out what they are, and how to use them.  You will also find
  3530. information about functionality missing from MySQL, and how to work
  3531. around some differences.
  3532.  
  3533. MySQL Extensions to ANSI SQL92
  3534. ------------------------------
  3535.  
  3536. MySQL includes some extensions that you probably will not find in other
  3537. SQL databases.  Be warned that if you use them, your code will not be
  3538. portable to other SQL servers.  In some cases, you can write code that
  3539. includes MySQL extensions, but is still portable, by using comments of
  3540. the form `/*! ... */'.  In this case, MySQL will parse and execute the
  3541. code within the comment as it would any other MySQL statement, but
  3542. other SQL servers will ignore the extensions.  For example:
  3543.  
  3544.      SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
  3545.  
  3546. If you add a version number after the `'!'', the syntax will only be
  3547. executed if the MySQL version is equal to or newer than the used
  3548. version number:
  3549.  
  3550.      CREATE /*!32302 TEMPORARY */ TABLE (a int);
  3551.  
  3552. The above means that if you have Version 3.23.02 or newer, then MySQL
  3553. will use the `TEMPORARY' keyword.
  3554.  
  3555. MySQL extensions are listed below:
  3556.  
  3557.    * The field types `MEDIUMINT', `SET', `ENUM', and the different
  3558.      `BLOB' and `TEXT' types.
  3559.  
  3560.    * The field attributes `AUTO_INCREMENT', `BINARY', `NULL',
  3561.      `UNSIGNED', and `ZEROFILL'.
  3562.  
  3563.    * All string comparisons are case insensitive by default, with sort
  3564.      ordering determined by the current character set (ISO-8859-1
  3565.      Latin1 by default).  If you don't like this, you should declare
  3566.      your columns with the `BINARY' attribute or use the `BINARY' cast,
  3567.      which causes comparisons to be done according to the ASCII order
  3568.      used on the MySQL server host.
  3569.  
  3570.    * MySQL maps each database to a directory under the MySQL data
  3571.      directory, and tables within a database to filenames in the
  3572.      database directory.
  3573.  
  3574.      This has a few implications:
  3575.  
  3576.         - Database names and table names are case sensitive in MySQL on
  3577.           operating systems that have case-sensitive filenames (like
  3578.           most Unix systems). *Note Name case sensitivity::.
  3579.  
  3580.         - Database, table, index, column, or alias names may begin with
  3581.           a digit (but may not consist solely of digits).
  3582.  
  3583.         - You can use standard system commands to backup, rename, move,
  3584.           delete, and copy tables.  For example, to rename a table,
  3585.           rename the `.MYD', `.MYI', and `.frm' files to which the
  3586.           table corresponds.
  3587.  
  3588.    * In SQL statements, you can access tables from different databases
  3589.      with the `db_name.tbl_name' syntax.  Some SQL servers provide the
  3590.      same functionality but call this `User space'.  MySQL doesn't
  3591.      support tablespaces as in: `create table ralph.my_table...IN
  3592.      my_tablespace'.
  3593.  
  3594.    * `LIKE' is allowed on numeric columns.
  3595.  
  3596.    * Use of `INTO OUTFILE' and `STRAIGHT_JOIN' in a `SELECT' statement.
  3597.      *Note `SELECT': SELECT.
  3598.  
  3599.    * The `SQL_SMALL_RESULT' option in a `SELECT' statement.
  3600.  
  3601.    * `EXPLAIN SELECT' to get a description on how tables are joined.
  3602.  
  3603.    * Use of index names, indexes on a prefix of a field, and use of
  3604.      `INDEX' or `KEY' in a `CREATE TABLE' statement. *Note `CREATE
  3605.      TABLE': CREATE TABLE.
  3606.  
  3607.    * Use of `TEMPORARY' or `IF NOT EXISTS' with `CREATE TABLE'.
  3608.  
  3609.    * Use of `COUNT(DISTINCT list)' where 'list' is more than one
  3610.      element.
  3611.  
  3612.    * Use of `CHANGE col_name', `DROP col_name', or `DROP INDEX',
  3613.      `IGNORE' or `RENAME' in an `ALTER TABLE' statement. *Note `ALTER
  3614.      TABLE': ALTER TABLE.
  3615.  
  3616.    * Use of `RENAME TABLE'. *Note `RENAME TABLE': RENAME TABLE.
  3617.  
  3618.    * Use of multiple `ADD', `ALTER', `DROP', or `CHANGE' clauses in an
  3619.      `ALTER TABLE' statement.
  3620.  
  3621.    * Use of `DROP TABLE' with the keywords `IF EXISTS'.
  3622.  
  3623.    * You can drop multiple tables with a single `DROP TABLE' statement.
  3624.  
  3625.    * The `LIMIT' clause of the `DELETE' statement.
  3626.  
  3627.    * The `DELAYED' clause of the `INSERT' and `REPLACE' statements.
  3628.  
  3629.    * The `LOW_PRIORITY' clause of the `INSERT', `REPLACE', `DELETE',
  3630.      and `UPDATE' statements.
  3631.  
  3632.    * Use of `LOAD DATA INFILE'. In many cases, this syntax is
  3633.      compatible with Oracle's `LOAD DATA INFILE'. *Note `LOAD DATA':
  3634.      LOAD DATA.
  3635.  
  3636.    * The `ANALYZE TABLE', `CHECK TABLE', `OPTIMIZE TABLE', and `REPAIR
  3637.      TABLE' statements.
  3638.  
  3639.    * The `SHOW' statement.  *Note `SHOW': SHOW.
  3640.  
  3641.    * Strings may be enclosed by either `"' or `'', not just by `''.
  3642.  
  3643.    * Use of the escape `\' character.
  3644.  
  3645.    * The `SET OPTION' statement. *Note `SET OPTION': SET OPTION.
  3646.  
  3647.    * You don't need to name all selected columns in the `GROUP BY' part.
  3648.      This gives better performance for some very specific, but quite
  3649.      normal queries.  *Note Group by functions::.
  3650.  
  3651.    * One can specify `ASC' and `DESC' with `GROUP BY'.
  3652.  
  3653.    * To make it easier for users who come from other SQL environments,
  3654.      MySQL supports aliases for many functions. For example, all string
  3655.      functions support both ANSI SQL syntax and ODBC syntax.
  3656.  
  3657.    * MySQL understands the `||' and `&&' operators to mean logical OR
  3658.      and AND, as in the C programming language.  In MySQL, `||' and
  3659.      `OR' are synonyms, as are `&&' and `AND'.  Because of this nice
  3660.      syntax, MySQL doesn't support the ANSI SQL `||' operator for
  3661.      string concatenation; use `CONCAT()' instead. Because `CONCAT()'
  3662.      takes any number of arguments, it's easy to convert use of the
  3663.      `||' operator to MySQL.
  3664.  
  3665.    * `CREATE DATABASE' or `DROP DATABASE'.  *Note `CREATE DATABASE':
  3666.      CREATE DATABASE.
  3667.  
  3668.    * The `%' operator is a synonym for `MOD()'.  That is, `N % M' is
  3669.      equivalent to `MOD(N,M)'.  `%' is supported for C programmers and
  3670.      for compatibility with PostgreSQL.
  3671.  
  3672.    * The `=', `<>', `<=' ,`<', `>=',`>', `<<', `>>', `<=>', `AND',
  3673.      `OR', or `LIKE' operators may be used in column comparisons to the
  3674.      left of the `FROM' in `SELECT' statements.  For example:
  3675.  
  3676.           mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
  3677.  
  3678.    * The `LAST_INSERT_ID()' function.  *Note `mysql_insert_id()':
  3679.      mysql_insert_id.
  3680.  
  3681.    * The `REGEXP' and `NOT REGEXP' extended regular expression
  3682.      operators.
  3683.  
  3684.    * `CONCAT()' or `CHAR()' with one argument or more than two
  3685.      arguments.  (In MySQL, these functions can take any number of
  3686.      arguments.)
  3687.  
  3688.    * The `BIT_COUNT()', `CASE', `ELT()', `FROM_DAYS()', `FORMAT()',
  3689.      `IF()', `PASSWORD()', `ENCRYPT()', `md5()', `ENCODE()', `DECODE()',
  3690.      `PERIOD_ADD()', `PERIOD_DIFF()', `TO_DAYS()', or `WEEKDAY()'
  3691.      functions.
  3692.  
  3693.    * Use of `TRIM()' to trim substrings. ANSI SQL only supports removal
  3694.      of single characters.
  3695.  
  3696.    * The `GROUP BY' functions `STD()', `BIT_OR()', and `BIT_AND()'.
  3697.  
  3698.    * Use of `REPLACE' instead of `DELETE' + `INSERT'.  *Note `REPLACE':
  3699.      REPLACE.
  3700.  
  3701.    * The `FLUSH flush_option' statement.
  3702.  
  3703.    * The possibility to set variables in a statement with `:=':
  3704.           SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg FROM test_table;
  3705.           SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  3706.  
  3707.  
  3708. MySQL Differences Compared to ANSI SQL92
  3709. ----------------------------------------
  3710.  
  3711. We try to make MySQL follow the ANSI SQL standard and the ODBC SQL
  3712. standard, but in some cases MySQL does some things differently:
  3713.  
  3714.    * `--' is only a comment if followed by a white space. *Note Missing
  3715.      comments::.
  3716.  
  3717.    * For `VARCHAR' columns, trailing spaces are removed when the value
  3718.      is stored. *Note Bugs::.
  3719.  
  3720.    * In some cases, `CHAR' columns are silently changed to `VARCHAR'
  3721.      columns. *Note Silent column changes::.
  3722.  
  3723.    * Privileges for a table are not automatically revoked when you
  3724.      delete a table. You must explicitly issue a `REVOKE' to revoke
  3725.      privileges for a table. *Note `GRANT': GRANT.
  3726.  
  3727.    * `NULL AND FALSE' will evaluate to `NULL' and not to `FALSE'.  This
  3728.      is because we don't think it's good to have to evaluate a lot of
  3729.      extra conditions in this case.
  3730.  
  3731. Running MySQL in ANSI Mode
  3732. --------------------------
  3733.  
  3734. If you start `mysqld' with the `--ansi' option, the following behavior
  3735. of MySQL changes:
  3736.  
  3737.    * `||' is string concatenation instead of `OR'.
  3738.  
  3739.    * You can have any number of spaces between a function name and the
  3740.      `('.  This forces all function names to be treated as reserved
  3741.      words.
  3742.  
  3743.    * `"' will be an identifier quote character (like the MySQL ``'
  3744.      quote character) and not a string quote character.
  3745.  
  3746.    * `REAL' will be a synonym for `FLOAT' instead of a synonym of
  3747.      `DOUBLE'.
  3748.  
  3749.    * The default transaction isolation level is `SERIALIZABLE'.  *Note
  3750.      SET TRANSACTION::.
  3751.  
  3752. This is the same as using
  3753. `--sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,SERIALIZE,ONLY_FULL_GROUP_BY'.
  3754.  
  3755. Functionality Missing from MySQL
  3756. --------------------------------
  3757.  
  3758. The following functionality is missing in the current version of MySQL.
  3759. For a prioritized list indicating when new extensions may be added to
  3760. MySQL, you should consult the online MySQL TODO list
  3761. (http://www.mysql.com/documentation/manual.php?section=TODO). That is
  3762. the latest version of the TODO list in this manual. *Note TODO::.
  3763.  
  3764. Sub-selects
  3765. ...........
  3766.  
  3767. MySQL currently only supports sub selects of the form `INSERT ...
  3768. SELECT ...' and `REPLACE ... SELECT ...'. You can however use the
  3769. function `IN()' in other contexts.
  3770.  
  3771. In many cases you can rewrite the query without a sub-select:
  3772.  
  3773.      SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
  3774.  
  3775. This can be re-written as:
  3776.  
  3777.      SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
  3778.  
  3779. The queries:
  3780.      SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
  3781.      SELECT * FROM table1 WHERE NOT EXISTS (SELECT id FROM table2 where table1.id=table2.id);
  3782.  
  3783. Can be rewritten as:
  3784.  
  3785.      SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
  3786.  
  3787. For more complicated subqueries you can often create temporary tables
  3788. to hold the subquery.  In some cases, however this option will not
  3789. work. The most frequently encountered of these cases arises with
  3790. `DELETE' statements, for which standard SQL does not support joins
  3791. (except in sub-selects).  For this situation there are two options
  3792. available until subqueries are supported by MySQL.
  3793.  
  3794. The first option is to use a procedural programming language (such as
  3795. Perl or PHP) to submit a `SELECT' query to obtain the primary keys for
  3796. the records to be deleted, and then use these values to construct the
  3797. `DELETE' statement (`DELETE FROM ... WHERE ... IN (key1, key2, ...)').
  3798.  
  3799. The second option is to use interactive SQL to contruct a set of
  3800. `DELETE' statements automatically, using the MySQL extension `CONCAT()'
  3801. (in lieu of the standard `||' operator).  For example:
  3802.  
  3803.      SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', tab1.pkid, ';')
  3804.        FROM tab1, tab2
  3805.       WHERE tab1.col1 = tab2.col2;
  3806.  
  3807. You can place this query in a script file and redirect input from it to
  3808. the `mysql' command-line interpreter, piping its output back to a
  3809. second instance of the interpreter:
  3810.  
  3811.      prompt> mysql --skip-column-names mydb < myscript.sql | mysql mydb
  3812.  
  3813. MySQL 4.0 supports multi-table deletes that can be used to efficiently
  3814. delete rows based on information from one table or even from many tables
  3815. at the same time.
  3816.  
  3817. `SELECT INTO TABLE'
  3818. ...................
  3819.  
  3820. MySQL doesn't yet support the Oracle SQL extension: `SELECT ... INTO
  3821. TABLE ...'.  MySQL supports instead the ANSI SQL syntax `INSERT INTO
  3822. ... SELECT ...', which is basically the same thing. *Note INSERT
  3823. SELECT::.
  3824.  
  3825.      INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID FROM tblTemp1 WHERE
  3826.      tblTemp1.fldOrder_ID > 100;
  3827.  
  3828. Alternatively, you can use `SELECT INTO OUTFILE...' or `CREATE TABLE
  3829. ... SELECT' to solve your problem.
  3830.  
  3831. Transactions
  3832. ............
  3833.  
  3834. As MySQL does nowadays support transactions, the following discussion
  3835. is only valid if you are only using the non-transaction-safe table
  3836. types. *Note COMMIT::.
  3837.  
  3838. The question is often asked, by the curious and the critical, "Why is
  3839. MySQL not a transactional database?" or "Why does MySQL not support
  3840. transactions?"
  3841.  
  3842. MySQL has made a conscious decision to support another paradigm for
  3843. data integrity, "atomic operations." It is our thinking and experience
  3844. that atomic operations offer equal or even better integrity with much
  3845. better performance. We, nonetheless, appreciate and understand the
  3846. transactional database paradigm and plan, within the next few releases,
  3847. to introduce transaction-safe tables on a per table basis. We will be
  3848. giving our users the possibility to decide if they need the speed of
  3849. atomic operations or if they need to use transactional features in their
  3850. applications.
  3851.  
  3852. How does one use the features of MySQL to maintain rigorous integrity
  3853. and how do these features compare with the transactional paradigm?
  3854.  
  3855. First, in the transactional paradigm, if your applications are written
  3856. in a way that is dependent on the calling of "rollback" instead of
  3857. "commit" in critical situations, then transactions are more convenient.
  3858. Moreover, transactions ensure that unfinished updates or corrupting
  3859. activities are not committed to the database; the server is given the
  3860. opportunity to do an automatic rollback and your database is saved.
  3861.  
  3862. MySQL, in almost all cases, allows you to solve for potential problems
  3863. by including simple checks before updates and by running simple scripts
  3864. that check the databases for inconsistencies and automatically repair
  3865. or warn if such occurs. Note that just by using the MySQL log or even
  3866. adding one extra log, one can normally fix tables perfectly with no
  3867. data integrity loss.
  3868.  
  3869. Moreover, fatal transactional updates can be rewritten to be atomic. In
  3870. fact,we will go so far as to say that all integrity problems that
  3871. transactions solve can be done with `LOCK TABLES' or atomic updates,
  3872. ensuring that you never will get an automatic abort from the database,
  3873. which is a common problem with transactional databases.
  3874.  
  3875. Not even transactions can prevent all loss if the server goes down.  In
  3876. such cases even a transactional system can lose data.  The difference
  3877. between different systems lies in just how small the time-lap is where
  3878. they could lose data. No system is 100% secure, only "secure enough."
  3879. Even Oracle, reputed to be the safest of transactional databases, is
  3880. reported to sometimes lose data in such situations.
  3881.  
  3882. To be safe with MySQL, you only need to have backups and have the
  3883. update logging turned on.  With this you can recover from any situation
  3884. that you could with any transactional database.  It is, of course,
  3885. always good to have backups, independent of which database you use.
  3886.  
  3887. The transactional paradigm has its benefits and its drawbacks. Many
  3888. users and application developers depend on the ease with which they can
  3889. code around problems where an abort appears to be, or is necessary, and
  3890. they may have to do a little more work with MySQL to either think
  3891. differently or write more. If you are new to the atomic operations
  3892. paradigm, or more familiar or more comfortable with transactions, do not
  3893. jump to the conclusion that MySQL has not addressed these issues.
  3894. Reliability and integrity are foremost in our minds.  Recent estimates
  3895. indicate that there are more than 1,000,000 `mysqld' servers currently
  3896. running, many of which are in production environments.  We hear very,
  3897. very seldom from our users that they have lost any data, and in almost
  3898. all of those cases user error is involved. This is, in our opinion, the
  3899. best proof of MySQL's stability and reliability.
  3900.  
  3901. Lastly, in situations where integrity is of highest importance, MySQL's
  3902. current features allow for transaction-level or better reliability and
  3903. integrity. If you lock tables with `LOCK TABLES', all updates will
  3904. stall until any integrity checks are made.  If you only obtain a read
  3905. lock (as opposed to a write lock), then reads and inserts are still
  3906. allowed to happen.  The new inserted records will not be seen by any of
  3907. the clients that have a `READ' lock until they release their read
  3908. locks.  With `INSERT DELAYED' you can queue inserts into a local queue,
  3909. until the locks are released, without having the client wait for the
  3910. insert to complete. *Note INSERT DELAYED::.
  3911.  
  3912. "Atomic," in the sense that we mean it, is nothing magical. It only
  3913. means that you can be sure that while each specific update is running,
  3914. no other user can interfere with it, and there will never be an
  3915. automatic rollback (which can happen on transaction based systems if
  3916. you are not very careful).  MySQL also guarantees that there will not be
  3917. any dirty reads.  You can find some example of how to write atomic
  3918. updates in the commit-rollback section. *Note Commit-rollback::.
  3919.  
  3920. We have thought quite a bit about integrity and performance, and we
  3921. believe that our atomic operations paradigm allows for both high
  3922. reliability and extremely high performance, on the order of three to
  3923. five times the speed of the fastest and most optimally tuned of
  3924. transactional databases. We didn't leave out transactions because they
  3925. are hard to do. The main reason we went with atomic operations as
  3926. opposed to transactions is that by doing this we could apply many speed
  3927. optimizations that would not otherwise have been possible.
  3928.  
  3929. Many of our users who have speed foremost in their minds are not at all
  3930. concerned about transactions. For them transactions are not an issue.
  3931. For those of our users who are concerned with or have wondered about
  3932. transactions vis-a-vis MySQL, there is a "MySQL way" as we have
  3933. outlined above.  For those where safety is more important than speed,
  3934. we recommend them to use the `BDB', or `InnoDB' tables for all their
  3935. critical data. *Note Table types::.
  3936.  
  3937. One final note: We are currently working on a safe replication schema
  3938. that we believe to be better than any commercial replication system we
  3939. know of. This system will work most reliably under the atomic
  3940. operations, non-transactional, paradigm. Stay tuned.
  3941.  
  3942. Stored Procedures and Triggers
  3943. ..............................
  3944.  
  3945. A stored procedure is a set of SQL commands that can be compiled and
  3946. stored in the server. Once this has been done, clients don't need to
  3947. keep reissuing the entire query but can refer to the stored procedure.
  3948. This provides better performance because the query has to be parsed
  3949. only once, and less information needs to be sent between the server and
  3950. the client. You can also raise the conceptual level by having libraries
  3951. of functions in the server.
  3952.  
  3953. A trigger is a stored procedure that is invoked when a particular event
  3954. occurs.  For example, you can install a stored procedure that is
  3955. triggered each time a record is deleted from a transaction table and
  3956. that automatically deletes the corresponding customer from a customer
  3957. table when all his transactions are deleted.
  3958.  
  3959. The planned update language will be able to handle stored procedures,
  3960. but without triggers. Triggers usually slow down everything, even
  3961. queries for which they are not needed.
  3962.  
  3963. To see when MySQL might get stored procedures, see *Note TODO::.
  3964.  
  3965. Foreign Keys
  3966. ............
  3967.  
  3968. Note that foreign keys in SQL are not used to join tables, but are used
  3969. mostly for checking referential integrity (foreign key constraints).  If
  3970. you want to get results from multiple tables from a `SELECT' statement,
  3971. you do this by joining tables:
  3972.  
  3973.      SELECT * from table1,table2 where table1.id = table2.id;
  3974.  
  3975. *Note `JOIN': JOIN. *Note example-Foreign keys::.
  3976.  
  3977. The `FOREIGN KEY' syntax in MySQL exists only for compatibility with
  3978. other SQL vendors' `CREATE TABLE' commands; it doesn't do anything.
  3979. The `FOREIGN KEY' syntax without `ON DELETE ...' is mostly used for
  3980. documentation purposes. Some ODBC applications may use this to produce
  3981. automatic `WHERE' clauses, but this is usually easy to override.
  3982. `FOREIGN KEY' is sometimes used as a constraint check, but this check
  3983. is unnecessary in practice if rows are inserted into the tables in the
  3984. right order. MySQL only supports these clauses because some
  3985. applications require them to exist (regardless of whether or not they
  3986. work).
  3987.  
  3988. In MySQL, you can work around the problem of `ON DELETE ...' not being
  3989. implemented by adding the appropriate `DELETE' statement to an
  3990. application when you delete records from a table that has a foreign key.
  3991. In practice this is as quick (in some cases quicker) and much more
  3992. portable than using foreign keys.
  3993.  
  3994. In the near future we will extend the `FOREIGN KEY' implementation so
  3995. that at least the information will be saved in the table specification
  3996. file and may be retrieved by `mysqldump' and ODBC. At a later stage we
  3997. will implement the foreign key constraints for application that can't
  3998. easily be coded to avoid them.
  3999.  
  4000. Reasons NOT to Use Foreign Keys constraints
  4001. ...........................................
  4002.  
  4003. There are so many problems with foreign key constraints that we don't
  4004. know where to start:
  4005.  
  4006.    * Foreign key constraints make life very complicated, because the
  4007.      foreign key definitions must be stored in a database and
  4008.      implementing them would destroy the whole "nice approach" of using
  4009.      files that can be moved, copied, and removed.
  4010.  
  4011.    * The speed impact is terrible for `INSERT' and `UPDATE' statements,
  4012.      and in this case almost all `FOREIGN KEY' constraint checks are
  4013.      useless because you usually insert records in the right tables in
  4014.      the right order, anyway.
  4015.  
  4016.    * There is also a need to hold locks on many more tables when
  4017.      updating one table, because the side effects can cascade through
  4018.      the entire database. It's MUCH faster to delete records from one
  4019.      table first and subsequently delete them from the other tables.
  4020.  
  4021.    * You can no longer restore a table by doing a full delete from the
  4022.      table and then restoring all records (from a new source or from a
  4023.      backup).
  4024.  
  4025.    * If you use foreign key constraints you can't dump and restore
  4026.      tables unless you do so in a very specific order.
  4027.  
  4028.    * It's very easy to do "allowed" circular definitions that make the
  4029.      tables impossible to re-create each table with a single create
  4030.      statement, even if the definition works and is usable.
  4031.  
  4032.    * It's very easy to overlook `FOREIGN KEY ... ON DELETE' rules when
  4033.      one codes an application. It's not unusual that one loses a lot of
  4034.      important information just because a wrong or misused `ON DELETE'
  4035.      rule.
  4036.  
  4037. The only nice aspect of `FOREIGN KEY' is that it gives ODBC and some
  4038. other client programs the ability to see how a table is connected and
  4039. to use this to show connection diagrams and to help in building
  4040. applications.
  4041.  
  4042. MySQL will soon store `FOREIGN KEY' definitions so that a client can
  4043. ask for and receive an answer about how the original connection was
  4044. made. The current `.frm' file format does not have any place for it.
  4045. At a later stage we will implement the foreign key constraints for
  4046. application that can't easily be coded to avoid them.
  4047.  
  4048. Views
  4049. .....
  4050.  
  4051. MySQL doesn't yet support views, but we plan to implement these to
  4052. about 4.1.
  4053.  
  4054. Views are mostly useful for letting users access a set of relations as
  4055. one table (in read-only mode).  Many SQL databases don't allow one to
  4056. update any rows in a view, but you have to do the updates in the
  4057. separate tables.
  4058.  
  4059. As MySQL is mostly used in applications and on web system where the
  4060. application writer has full control on the database usage, most of our
  4061. users haven't regarded views to be very important. (At least no one has
  4062. been interested enough in this to be prepared to finance the
  4063. implementation of views).
  4064.  
  4065. One doesn't need views in MySQL to restrict access to columns as MySQL
  4066. has a very sophisticated privilege system. *Note Privilege system::.
  4067.  
  4068. `--' as the Start of a Comment
  4069. ..............................
  4070.  
  4071. Some other SQL databases use `--' to start comments. MySQL has `#' as
  4072. the start comment character, even if the `mysql' command-line tool
  4073. removes all lines that start with `--'.  You can also use the C comment
  4074. style `/* this is a comment */' with MySQL.  *Note Comments::.
  4075.  
  4076. MySQL Version 3.23.3 and above supports the `--' comment style only if
  4077. the comment is followed by a space.  This is because this degenerate
  4078. comment style has caused many problems with automatically generated SQL
  4079. queries that have used something like the following code, where we
  4080. automatically insert the value of the payment for `!payment!':
  4081.  
  4082.      UPDATE tbl_name SET credit=credit-!payment!
  4083.  
  4084. What do you think will happen when the value of `payment' is negative?
  4085.  
  4086. Because `1--1' is legal in SQL, we think it is terrible that `--' means
  4087. start comment.
  4088.  
  4089. In MySQL Version 3.23 you can, however, use: `1-- This is a comment'
  4090.  
  4091. The following discussion only concerns you if you are running a MySQL
  4092. version earlier than Version 3.23:
  4093.  
  4094. If you have a SQL program in a text file that contains `--' comments
  4095. you should use:
  4096.  
  4097.      shell> replace " --" " #" < text-file-with-funny-comments.sql \
  4098.               | mysql database
  4099.  
  4100. instead of the usual:
  4101.  
  4102.      shell> mysql database < text-file-with-funny-comments.sql
  4103.  
  4104. You can also edit the command file "in place" to change the `--'
  4105. comments to `#' comments:
  4106.  
  4107.      shell> replace " --" " #" -- text-file-with-funny-comments.sql
  4108.  
  4109. Change them back with this command:
  4110.  
  4111.      shell> replace " #" " --" -- text-file-with-funny-comments.sql
  4112.  
  4113. What Standards Does MySQL Follow?
  4114. ---------------------------------
  4115.  
  4116. Entry level SQL92. ODBC levels 0-2.
  4117.  
  4118. How to Cope Without `COMMIT'/`ROLLBACK'
  4119. ---------------------------------------
  4120.  
  4121. The following mostly applies only for `ISAM', `MyISAM', and `HEAP'
  4122. tables. If you only use transaction-safe tables (`BDB', or `InnoDB'
  4123. tables) in an an update, you can do `COMMIT' and `ROLLBACK' also with
  4124. MySQL.  *Note COMMIT::.
  4125.  
  4126. The problem with handling `COMMIT'-`ROLLBACK' efficiently with the
  4127. above table types would require a completely different table layout
  4128. than MySQL uses today.  The table type would also need extra threads
  4129. that do automatic cleanups on the tables, and the disk usage would be
  4130. much higher. This would make these table types about 2-4 times slower
  4131. than they are today.
  4132.  
  4133. For the moment, we prefer implementing the SQL server language
  4134. (something like stored procedures). With this you would very seldom
  4135. really need `COMMIT'-`ROLLBACK.' This would also give much better
  4136. performance.
  4137.  
  4138. Loops that need transactions normally can be coded with the help of
  4139. `LOCK TABLES', and you don't need cursors when you can update records
  4140. on the fly.
  4141.  
  4142. We at TcX had a greater need for a real fast database than a 100%
  4143. general database. Whenever we find a way to implement these features
  4144. without any speed loss, we will probably do it. For the moment, there
  4145. are many more important things to do. Check the TODO for how we
  4146. prioritize things at the moment. (Customers with higher levels of
  4147. support can alter this, so things may be reprioritized.)
  4148.  
  4149. The current problem is actually `ROLLBACK'. Without `ROLLBACK', you can
  4150. do any kind of `COMMIT' action with `LOCK TABLES'. To support
  4151. `ROLLBACK' with the above table types, MySQL would have to be changed
  4152. to store all old records that were updated and revert everything back
  4153. to the starting point if `ROLLBACK' was issued. For simple cases, this
  4154. isn't that hard to do (the current `isamlog' could be used for this
  4155. purpose), but it would be much more difficult to implement `ROLLBACK'
  4156. for `ALTER/DROP/CREATE TABLE'.
  4157.  
  4158. To avoid using `ROLLBACK', you can use the following strategy:
  4159.  
  4160.   1. Use `LOCK TABLES ...' to lock all the tables you want to access.
  4161.  
  4162.   2. Test conditions.
  4163.  
  4164.   3. Update if everything is okay.
  4165.  
  4166.   4. Use `UNLOCK TABLES' to release your locks.
  4167.  
  4168. This is usually a much faster method than using transactions with
  4169. possible `ROLLBACK's, although not always. The only situation this
  4170. solution doesn't handle is when someone kills the threads in the middle
  4171. of an update. In this case, all locks will be released but some of the
  4172. updates may not have been executed.
  4173.  
  4174. You can also use functions to update records in a single operation.
  4175. You can get a very efficient application by using the following
  4176. techniques:
  4177.  
  4178.    * Modify fields relative to their current value.
  4179.  
  4180.    * Update only those fields that actually have changed.
  4181.  
  4182. For example, when we are doing updates to some customer information, we
  4183. update only the customer data that has changed and test only that none
  4184. of the changed data, or data that depend on the changed data, has
  4185. changed compared to the original row. The test for changed data is done
  4186. with the `WHERE' clause in the `UPDATE' statement. If the record wasn't
  4187. updated, we give the client a message: "Some of the data you have
  4188. changed have been changed by another user". Then we show the old row
  4189. versus the new row in a window, so the user can decide which version of
  4190. the customer record he should use.
  4191.  
  4192. This gives us something that is similar to column locking but is
  4193. actually even better, because we only update some of the columns, using
  4194. values that are relative to their current values.  This means that
  4195. typical `UPDATE' statements look something like these:
  4196.  
  4197.      UPDATE tablename SET pay_back=pay_back+'relative change';
  4198.      
  4199.      UPDATE customer
  4200.        SET
  4201.          customer_date='current_date',
  4202.          address='new address',
  4203.          phone='new phone',
  4204.          money_he_owes_us=money_he_owes_us+'new_money'
  4205.        WHERE
  4206.          customer_id=id AND address='old address' AND phone='old phone';
  4207.  
  4208. As you can see, this is very efficient and works even if another client
  4209. has changed the values in the `pay_back' or `money_he_owes_us' columns.
  4210.  
  4211. In many cases, users have wanted `ROLLBACK' and/or `LOCK TABLES' for
  4212. the purpose of managing unique identifiers for some tables. This can be
  4213. handled much more efficiently by using an `AUTO_INCREMENT' column and
  4214. either the SQL function `LAST_INSERT_ID()' or the C API function
  4215. `mysql_insert_id()'. *Note `mysql_insert_id()': mysql_insert_id.
  4216.  
  4217. At MySQL AB, we have never had any need for row-level locking because
  4218. we have always been able to code around it. Some cases really need row
  4219. locking, but they are very few. If you want row-level locking, you can
  4220. use a flag column in the table and do something like this:
  4221.  
  4222.      UPDATE tbl_name SET row_flag=1 WHERE id=ID;
  4223.  
  4224. MySQL returns 1 for the number of affected rows if the row was found
  4225. and `row_flag' wasn't already 1 in the original row.
  4226.  
  4227. You can think of it as MySQL changed the above query to:
  4228.  
  4229.      UPDATE tbl_name SET row_flag=1 WHERE id=ID and row_flag <> 1;
  4230.  
  4231. Known errors and design deficiencies in MySQL
  4232. ---------------------------------------------
  4233.  
  4234. The following problems are known and have a very high priority to get
  4235. fixed:
  4236.  
  4237.    * `ANALYZE TABLE' on a BDB table may in some case make the table
  4238.      unusable until one has restarted `mysqld'.  When this happens you
  4239.      will see errors like the following in the MySQL error file:
  4240.  
  4241.           001207 22:07:56  bdb:  log_flush: LSN past current end-of-log
  4242.  
  4243.    * Don't execute `ALTER TABLE' on a `BDB' table on which you are
  4244.      running not completed multi-statement transactions. (The
  4245.      transaction will probably be ignored).
  4246.  
  4247.    * `ANALYZE TABLE', `OPTIMIZE TABLE' and `REPAIR TABLE' may cause
  4248.      problems on tables for which you are using `INSERT DELAYED'.
  4249.  
  4250.    * Doing a `LOCK TABLE ..' and `FLUSH TABLES ..' doesn't guarantee
  4251.      that there isn't a half-finished transaction in progress on the
  4252.      table.
  4253.  
  4254.    * BDB tables are a bit slow to open. If you have many BDB tables in a
  4255.      database, it will take a long time to use the `mysql' client on the
  4256.      database if you are not using the `-A' option or if you are using
  4257.      `rehash'. This is especially notable when you have a big table
  4258.      cache.
  4259.  
  4260.    * Th current replication protocol cannot deal with `LOAD DATA INFILE'
  4261.      and line terminator characters of more than 1 character.
  4262.  
  4263. The following problems are known and will be fixed in due time:
  4264.  
  4265.    * For the moment `MATCH' only works with `SELECT' statements.
  4266.  
  4267.    * When using `SET CHARACTER SET', one can't use translated
  4268.      characters in database, table and column names.
  4269.  
  4270.    * `DELETE FROM merge_table' used without a `WHERE' will only clear
  4271.      the mapping for the table, not delete everything in the mapped
  4272.      tables
  4273.  
  4274.    * You cannot build in another directory when using MIT-pthreads.
  4275.      Because this requires changes to MIT-pthreads, we are not likely
  4276.      to fix this.
  4277.  
  4278.    * `BLOB' values can't "reliably" be used in `GROUP BY' or `ORDER BY'
  4279.      or `DISTINCT'. Only the first `max_sort_length' bytes (default
  4280.      1024) are used when comparing `BLOB'bs in these cases.  This can
  4281.      be changed with the `-O max_sort_length' option to `mysqld'. A
  4282.      workaround for most cases is to use a substring: `SELECT DISTINCT
  4283.      LEFT(blob,2048) FROM tbl_name'.
  4284.  
  4285.    * Calculation is done with `BIGINT' or `DOUBLE' (both are normally
  4286.      64 bits long). It depends on the function which precision one
  4287.      gets. The general rule is that bit functions are done with `BIGINT'
  4288.      precision, `IF', and `ELT()' with `BIGINT' or `DOUBLE' precision
  4289.      and the rest with `DOUBLE' precision.  One should try to avoid
  4290.      using bigger unsigned long long values than 63 bits
  4291.      (9223372036854775807) for anything else than bit fields!
  4292.  
  4293.    * All string columns, except `BLOB' and `TEXT' columns, automatically
  4294.      have all trailing spaces removed when retrieved. For `CHAR' types
  4295.      this is okay, and may be regarded as a feature according to ANSI
  4296.      SQL92. The bug is that in MySQL, `VARCHAR' columns are treated the
  4297.      same way.
  4298.  
  4299.    * You can only have up to 255 `ENUM' and `SET' columns in one table.
  4300.  
  4301.    * `safe_mysqld' re-directs all messages from `mysqld' to the
  4302.      `mysqld' log.  One problem with this is that if you execute
  4303.      `mysqladmin refresh' to close and reopen the log, `stdout' and
  4304.      `stderr' are still redirected to the old log.  If you use `--log'
  4305.      extensively, you should edit `safe_mysqld' to log to
  4306.      `'hostname'.err' instead of `'hostname'.log' so you can easily
  4307.      reclaim the space for the old log by deleting the old one and
  4308.      executing `mysqladmin refresh'.
  4309.  
  4310.    * In the `UPDATE' statement, columns are updated from left to right.
  4311.      If you refer to an updated column, you will get the updated value
  4312.      instead of the original value. For example:
  4313.  
  4314.           mysql> UPDATE tbl_name SET KEY=KEY+1,KEY=KEY+1;
  4315.  
  4316.      This will update `KEY' with `2' instead of with `1'.
  4317.  
  4318.    * You can't use temporary tables more than once in the same query.
  4319.      For example, the following doesn't work.
  4320.  
  4321.           select * from temporary_table, temporary_table as t2;
  4322.  
  4323.    * `RENAME' doesn't work with `TEMPORARY' tables.
  4324.  
  4325.    * The optimizer may handle `DISTINCT' differently if you are using
  4326.      'hidden' columns in a join or not.  In a join, hidden columns are
  4327.      counted as part of the result (even if they are not shown) while in
  4328.      normal queries hidden columns doesn't participate in the `DISTINCT'
  4329.      comparison.  We will probably change this in the future to never
  4330.      compare the hidden columns when executing `DISTINCT'
  4331.  
  4332.      An example of this is:
  4333.  
  4334.           SELECT DISTINCT mp3id FROM band_downloads WHERE userid = 9 ORDER BY id
  4335.           DESC;
  4336.  
  4337.      and
  4338.  
  4339.           SELECT DISTINCT band_downloads.mp3id, FROM band_downloads,band_mp3
  4340.           WHERE band_downloads.userid = 9 AND band_mp3.id = band_downloads.mp3id
  4341.           ORDER BY band_downloads.id DESC;
  4342.  
  4343.      In the second case you may in MySQL 3.23.x get two identical rows
  4344.      in the result set (because the hidden 'id' column may differ).
  4345.  
  4346.      Note that the this only happens for queries where you don't have
  4347.      the ORDER BY columns in the result, something that is you are not
  4348.      allowed to do in ANSI SQL.
  4349.  
  4350.    * Because MySQL allows you to work with table types that doesn't
  4351.      support transactions (and thus can't `rollback' data) some things
  4352.      behaves a little different in MySQL than in other SQL servers:
  4353.      (This is just to ensure that MySQL never need to do a rollback for
  4354.      a SQL command).  This may be a little awkward at times as column
  4355.      Because MySQL allows you to work with table types that don't
  4356.      support transactions, and thus can't `rollback' data, some things
  4357.      behave a little differently in MySQL than in other SQL servers.
  4358.      This is just to ensure that MySQL never need to do a rollback for
  4359.      a SQL command.  This may be a little awkward at times as column
  4360.      values must be checked in the application, but this will actually
  4361.      give you a nice speed increase as it allows MySQL to do some
  4362.      optimizations that otherwise would be very hard to do.
  4363.  
  4364.      If you set a column to an incorrect value, MySQL will, instead of
  4365.      doing a rollback, store the `best possible value' in the column:
  4366.  
  4367.         - If you try to store a value outside the range in a numerical
  4368.           column, MySQL will instead store the smallest or biggest
  4369.           possible value in the column.
  4370.  
  4371.         - If you try to store a string that doesn't start with a number
  4372.           into a numerical column, MySQL will store 0 into it.
  4373.  
  4374.         - If you try to store `NULL' into a column that doesn't take
  4375.           `NULL' values, MySQL will store 0 or `''' (empty string) in
  4376.           it instead. (This behavior can, however, be changed with the
  4377.           -DDONT_USE_DEFAULT_FIELDS compile option).
  4378.  
  4379.         - MySQL allows you to store some wrong date values into `DATE'
  4380.           and `DATETIME' columns. (Like 2000-02-31 or 2000-02-00).  If
  4381.           the date is totally wrong, MySQL will store the special
  4382.           0000-00-00 date value in the column.
  4383.  
  4384.         - If you set an `enum' to an unsupported value, it will be set
  4385.           to the error value 'empty string', with numeric value 0.
  4386.  
  4387.    * If you execute a `PROCEDURE' on a query that returns an empty set,
  4388.      in some cases the `PROCEDURE' will not transform the columns.
  4389.  
  4390.    * Creation of a table of type `MERGE' doesn't check if the underlying
  4391.      tables are of compatible types.
  4392.  
  4393.    * MySQL can't yet handle `NaN', `-Inf' and `Inf' values in double.
  4394.      Using these will cause problems when trying to export and import
  4395.      data. We should as an intermediate solution change `NaN' to `NULL'
  4396.      (if possible) and `-Inf' and `Inf' to the Minimum respective
  4397.      maximum possible `double' value.
  4398.  
  4399.    * `LIMIT' on negative numbers are treated as big positive numbers.
  4400.  
  4401.    * If you use `ALTER TABLE' to first add an `UNIQUE' index to a table
  4402.      used in a `MERGE' table and then use `ALTER TABLE' to add a normal
  4403.      index on the `MERGE' table, the key order will be different for
  4404.      the tables if there was an old not-unique key in the table. This
  4405.      is because `ALTER TABLE' puts `UNIQUE' keys before normal keys to
  4406.      be able to detect duplicate keys as early as possible.
  4407.  
  4408. The following are known bugs in earlier versions of MySQL:
  4409.  
  4410.    * You can get a hung thread if you do a `DROP TABLE' on a table that
  4411.      is one among many tables that is locked with `LOCK TABLES'.
  4412.  
  4413.    * In the following case you can get a core dump:
  4414.  
  4415.         - Delayed insert handler has pending inserts to a table.
  4416.  
  4417.         - `LOCK table' with `WRITE'
  4418.  
  4419.         - `FLUSH TABLES'
  4420.  
  4421.    * Before MySQL Version 3.23.2 an `UPDATE' that updated a key with a
  4422.      `WHERE' on the same key may have failed because the key was used to
  4423.      search for records and the same row may have been found multiple
  4424.      times:
  4425.  
  4426.           UPDATE tbl_name SET KEY=KEY+1 WHERE KEY > 100;
  4427.  
  4428.      A workaround is to use:
  4429.  
  4430.           mysql> UPDATE tbl_name SET KEY=KEY+1 WHERE KEY+0 > 100;
  4431.  
  4432.      This will work because MySQL will not use index on expressions in
  4433.      the `WHERE' clause.
  4434.  
  4435.    * Before MySQL Version 3.23, all numeric types where treated as
  4436.      fixed-point fields. That means you had to specify how many
  4437.      decimals a floating-point field shall have. All results were
  4438.      returned with the correct number of decimals.
  4439.  
  4440. For platform-specific bugs, see the sections about compiling and
  4441. porting.
  4442.  
  4443. How MySQL Compares to Other Databases
  4444. =====================================
  4445.  
  4446. This section compares MySQL to other popular databases.
  4447.  
  4448. This section has been written by the MySQL developers, so it should be
  4449. read with that in mind.  There are no factual errors contained in this
  4450. section that we know of.  If you find something which you believe to be
  4451. an error, please contact us about it at <docs@mysql.com>.
  4452.  
  4453. For a list of all supported limits, functions, and types, see the
  4454. `crash-me' Web page at `http://www.mysql.com/information/crash-me.php'.
  4455.  
  4456. How MySQL Compares to `mSQL'
  4457. ----------------------------
  4458.  
  4459. *Performance*
  4460.      For a true comparison of speed, consult the growing MySQL benchmark
  4461.      suite. *Note MySQL Benchmarks::.
  4462.  
  4463.      Because there is no thread creation overhead, a small parser, few
  4464.      features, and simple security, `mSQL' should be quicker at:
  4465.  
  4466.         * Tests that perform repeated connects and disconnects, running
  4467.           a very simple query during each connection.
  4468.  
  4469.         * `INSERT' operations into very simple tables with few columns
  4470.           and keys.
  4471.  
  4472.         * `CREATE TABLE' and `DROP TABLE'.
  4473.  
  4474.         * `SELECT' on something that isn't an index. (A table scan is
  4475.           very easy.)
  4476.  
  4477.      Because these operations are so simple, it is hard to be better at
  4478.      them when you have a higher startup overhead. After the connection
  4479.      is established, MySQL should perform much better.
  4480.  
  4481.      On the other hand, MySQL is much faster than `mSQL' (and most
  4482.      other SQL implementations) on the following:
  4483.  
  4484.         * Complex `SELECT' operations.
  4485.  
  4486.         * Retrieving large results (MySQL has a better, faster, and
  4487.           safer protocol).
  4488.  
  4489.         * Tables with variable-length strings, because MySQL has more
  4490.           efficient handling and can have indexes on `VARCHAR' columns.
  4491.  
  4492.         * Handling tables with many columns.
  4493.  
  4494.         * Handling tables with large record lengths.
  4495.  
  4496.         * `SELECT' with many expressions.
  4497.  
  4498.         * `SELECT' on large tables.
  4499.  
  4500.         * Handling many connections at the same time. MySQL is fully
  4501.           multi-threaded. Each connection has its own thread, which
  4502.           means that no thread has to wait for another (unless a thread
  4503.           is modifying a table another thread wants to access). In
  4504.           `mSQL', once one connection is established, all others must
  4505.           wait until the first has finished, regardless of whether the
  4506.           connection is running a query that is short or long. When the
  4507.           first connection terminates, the next can be served, while
  4508.           all the others wait again, etc.
  4509.  
  4510.         * Joins.  `mSQL' can become pathologically slow if you change
  4511.           the order of tables in a `SELECT'. In the benchmark suite, a
  4512.           time more than 15000 times slower than MySQL was seen.  This
  4513.           is due to `mSQL''s lack of a join optimizer to order tables
  4514.           in the optimal order. However, if you put the tables in
  4515.           exactly the right order in `mSQL'2 and the `WHERE' is simple
  4516.           and uses index columns, the join will be relatively fast!
  4517.           *Note MySQL Benchmarks::.
  4518.  
  4519.         * `ORDER BY' and `GROUP BY'.
  4520.  
  4521.         * `DISTINCT'.
  4522.  
  4523.         * Using `TEXT' or `BLOB' columns.
  4524.  
  4525. *SQL Features*
  4526.         * `GROUP BY' and `HAVING'.  `mSQL' does not support `GROUP BY'
  4527.           at all.  MySQL supports a full `GROUP BY' with both `HAVING'
  4528.           and the following functions: `COUNT()', `AVG()', `MIN()',
  4529.           `MAX()', `SUM()', and `STD()'.  `COUNT(*)' is optimized to
  4530.           return very quickly if the `SELECT' retrieves from one table,
  4531.           no other columns are retrieved, and there is no `WHERE'
  4532.           clause.  `MIN()' and `MAX()' may take string arguments.
  4533.  
  4534.         * `INSERT' and `UPDATE' with calculations.  MySQL can do
  4535.           calculations in an `INSERT' or `UPDATE'.  For example:
  4536.  
  4537.                mysql> UPDATE SET x=x*10+y WHERE x<20;
  4538.  
  4539.         * Aliasing.  MySQL has column aliasing.
  4540.  
  4541.         * Qualifying column names.  In MySQL, if a column name is
  4542.           unique among the tables used in a query, you do not have to
  4543.           use the full qualifier.
  4544.  
  4545.         * `SELECT' with functions.  MySQL has many functions (too many
  4546.           to list here; see *Note Functions::).
  4547.  
  4548.  
  4549. *Disk Space Efficiency*
  4550.      That is, how small can you make your tables?
  4551.  
  4552.      MySQL has very precise types, so you can create tables that take
  4553.      very little space. An example of a useful MySQL datatype is the
  4554.      `MEDIUMINT' that is 3 bytes long. If you have 100,000,000 records,
  4555.      saving even one byte per record is very important.
  4556.  
  4557.      `mSQL2' has a more limited set of column types, so it is more
  4558.      difficult to get small tables.
  4559.  
  4560. *Stability*
  4561.      This is harder to judge objectively. For a discussion of MySQL
  4562.      stability, see *Note Stability::.
  4563.  
  4564.      We have no experience with `mSQL' stability, so we cannot say
  4565.      anything about that.
  4566.  
  4567. *Price*
  4568.      Another important issue is the license. MySQL has a more flexible
  4569.      license than `mSQL', and is also less expensive than `mSQL'.
  4570.      Whichever product you choose to use, remember to at least consider
  4571.      paying for a license or e-mail support.  (You are required to get
  4572.      a license if you include MySQL with a product that you sell, of
  4573.      course.)
  4574.  
  4575. *Perl Interfaces*
  4576.      MySQL has basically the same interfaces to Perl as `mSQL' with
  4577.      some added features.
  4578.  
  4579. *JDBC (Java)*
  4580.      MySQL currently has a lot of different JDBC drivers:
  4581.  
  4582.         * The mm driver: A type 4 JDBC driver by Mark Matthews
  4583.           <mmatthew@ecn.purdue.edu>.  This is released under the LGPL.
  4584.  
  4585.         * The Resin driver. This is a commercial JDBC driver released
  4586.           under open source.
  4587.           `http://www.caucho.com/projects/jdbc-mysql/index.xtp'
  4588.  
  4589.         * The gwe driver: A Java interface by GWE technologies (not
  4590.           supported anymore).
  4591.  
  4592.         * The jms driver: An improved gwe driver by Xiaokun Kelvin ZHU
  4593.           <X.Zhu@brad.ac.uk> (not supported anymore).
  4594.  
  4595.         * The twz driver: A type 4 JDBC driver by Terrence W. Zellers
  4596.           <zellert@voicenet.com>.  This is commercial but is free for
  4597.           private and educational use (not supported anymore).
  4598.  
  4599.      The recommended driver is the mm driver. The Resin driver may also
  4600.      be good (at least the benchmarks looks good), but we haven't
  4601.      received that much information about this yet.
  4602.  
  4603.      We know that `mSQL' has a JDBC driver, but we have too little
  4604.      experience with it to compare.
  4605.  
  4606. *Rate of Development*
  4607.      MySQL has a very small team of developers, but we are quite used
  4608.      to coding C and C++ very rapidly. Because threads, functions,
  4609.      `GROUP BY', and so on are still not implemented in `mSQL', it has
  4610.      a lot of catching up to do. To get some perspective on this, you
  4611.      can view the `mSQL' `HISTORY' file for the last year and compare
  4612.      it with the News section of the MySQL Reference Manual (*note
  4613.      News::). It should be pretty obvious which one has developed most
  4614.      rapidly.
  4615.  
  4616. *Utility Programs*
  4617.      Both `mSQL' and MySQL have many interesting third-party tools.
  4618.      Because it is very easy to port upward (from `mSQL' to MySQL),
  4619.      almost all the interesting applications that are available for
  4620.      `mSQL' are also available for MySQL.
  4621.  
  4622.      MySQL comes with a simple `msql2mysql' program that fixes
  4623.      differences in spelling between `mSQL' and MySQL for the most-used
  4624.      C API functions.  For example, it changes instances of
  4625.      `msqlConnect()' to `mysql_connect()'. Converting a client program
  4626.      from `mSQL' to MySQL usually takes a couple of minutes.
  4627.  
  4628. How to Convert `mSQL' Tools for MySQL
  4629. .....................................
  4630.  
  4631. According to our experience, it would just take a few hours to convert
  4632. tools such as `msql-tcl' and `msqljava' that use the `mSQL' C API so
  4633. that they work with the MySQL C API.
  4634.  
  4635. The conversion procedure is:
  4636.  
  4637.   1. Run the shell script `msql2mysql' on the source. This requires the
  4638.      `replace' program, which is distributed with MySQL.
  4639.  
  4640.   2. Compile.
  4641.  
  4642.   3. Fix all compiler errors.
  4643.  
  4644. Differences between the `mSQL' C API and the MySQL C API are:
  4645.  
  4646.    * MySQL uses a `MYSQL' structure as a connection type (`mSQL' uses
  4647.      an `int').
  4648.  
  4649.    * `mysql_connect()' takes a pointer to a `MYSQL' structure as a
  4650.      parameter.  It is easy to define one globally or to use `malloc()'
  4651.      to get one.  `mysql_connect()' also takes two parameters for
  4652.      specifying the user and password.  You may set these to `NULL,
  4653.      NULL' for default use.
  4654.  
  4655.    * `mysql_error()' takes the `MYSQL' structure as a parameter. Just
  4656.      add the parameter to your old `msql_error()' code if you are
  4657.      porting old code.
  4658.  
  4659.    * MySQL returns an error number and a text error message for all
  4660.      errors. `mSQL' returns only a text error message.
  4661.  
  4662.    * Some incompatibilities exist as a result of MySQL supporting
  4663.      multiple connections to the server from the same process.
  4664.  
  4665. How `mSQL' and MySQL Client/Server Communications Protocols Differ
  4666. ..................................................................
  4667.  
  4668. There are enough differences that it is impossible (or at least not
  4669. easy) to support both.
  4670.  
  4671. The most significant ways in which the MySQL protocol differs from the
  4672. `mSQL' protocol are listed below:
  4673.  
  4674.    * A message buffer may contain many result rows.
  4675.  
  4676.    * The message buffers are dynamically enlarged if the query or the
  4677.      result is bigger than the current buffer, up to a configurable
  4678.      server and client limit.
  4679.  
  4680.    * All packets are numbered to catch duplicated or missing packets.
  4681.  
  4682.    * All column values are sent in ASCII. The lengths of columns and
  4683.      rows are sent in packed binary coding (1, 2, or 3 bytes).
  4684.  
  4685.    * MySQL can read in the result unbuffered (without having to store
  4686.      the full set in the client).
  4687.  
  4688.    * If a single read/write takes more than 30 seconds, the server
  4689.      closes the connection.
  4690.  
  4691.    * If a connection is idle for 8 hours, the server closes the
  4692.      connection.
  4693.  
  4694. How `mSQL' 2.0 SQL Syntax Differs from MySQL
  4695. ............................................
  4696.  
  4697. *Column types*
  4698.  
  4699. `MySQL'
  4700.      Has the following additional types (among others; *note `CREATE
  4701.      TABLE': CREATE TABLE.):
  4702.         * `ENUM' type for one of a set of strings.
  4703.  
  4704.         * `SET' type for many of a set of strings.
  4705.  
  4706.         * `BIGINT' type for 64-bit integers.
  4707.  
  4708. `'
  4709.      MySQL also supports the following additional type attributes:
  4710.         * `UNSIGNED' option for integer columns.
  4711.  
  4712.         * `ZEROFILL' option for integer columns.
  4713.  
  4714.         * `AUTO_INCREMENT' option for integer columns that are a
  4715.           `PRIMARY KEY'.  *Note `mysql_insert_id()': mysql_insert_id.
  4716.  
  4717.         * `DEFAULT' value for all columns.
  4718.  
  4719. `mSQL2'
  4720.      `mSQL' column types correspond to the MySQL types shown below:
  4721.      `mSQL'     *Corresponding MySQL type*
  4722.      *type*     
  4723.      `CHAR(len)'`CHAR(len)'
  4724.      `TEXT(len)'`TEXT(len)'. `len' is the maximal length.  And `LIKE'
  4725.                 works.
  4726.      `INT'      `INT'. With many more options!
  4727.      `REAL'     `REAL'. Or `FLOAT'. Both 4- and 8-byte versions are
  4728.                 available.
  4729.      `UINT'     `INT UNSIGNED'
  4730.      `DATE'     `DATE'. Uses ANSI SQL format rather than `mSQL''s own
  4731.                 format.
  4732.      `TIME'     `TIME'
  4733.      `MONEY'    `DECIMAL(12,2)'. A fixed-point value with two decimals.
  4734.  
  4735. *Index Creation*
  4736.  
  4737. `MySQL'
  4738.      Indexes may be specified at table creation time with the `CREATE
  4739.      TABLE' statement.
  4740.  
  4741. `mSQL'
  4742.      Indexes must be created after the table has been created, with
  4743.      separate `CREATE INDEX' statements.
  4744.  
  4745. *To Insert a Unique Identifier into a Table*
  4746.  
  4747. `MySQL'
  4748.      Use `AUTO_INCREMENT' as a column type specifier.  *Note
  4749.      `mysql_insert_id()': mysql_insert_id.
  4750.  
  4751. `mSQL'
  4752.      Create a `SEQUENCE' on a table and select the `_seq' column.
  4753.  
  4754. *To Obtain a Unique Identifier for a Row*
  4755.  
  4756. `MySQL'
  4757.      Add a `PRIMARY KEY' or `UNIQUE' key to the table and use this.
  4758.      New in Version 3.23.11: If the `PRIMARY' or `UNIQUE' key consists
  4759.      of only one column and this is of type integer, one can also refer
  4760.      to it as `_rowid'.
  4761.  
  4762. `mSQL'
  4763.      Use the `_rowid' column. Observe that `_rowid' may change over time
  4764.      depending on many factors.
  4765.  
  4766. *To Get the Time a Column Was Last Modified*
  4767.  
  4768. `MySQL'
  4769.      Add a `TIMESTAMP' column to the table. This column is
  4770.      automatically set to the current date and time for `INSERT' or
  4771.      `UPDATE' statements if you don't give the column a value or if you
  4772.      give it a `NULL' value.
  4773.  
  4774. `mSQL'
  4775.      Use the `_timestamp' column.
  4776.  
  4777. *`NULL' Value Comparisons*
  4778.  
  4779. `MySQL'
  4780.      MySQL follows ANSI SQL, and a comparison with `NULL' is always
  4781.      `NULL'.
  4782.  
  4783. `mSQL'
  4784.      In `mSQL', `NULL = NULL' is TRUE.  You must change `=NULL' to `IS
  4785.      NULL' and `<>NULL' to `IS NOT NULL' when porting old code from
  4786.      `mSQL' to MySQL.
  4787.  
  4788. *String Comparisons*
  4789.  
  4790. `MySQL'
  4791.      Normally, string comparisons are performed in case-independent
  4792.      fashion with the sort order determined by the current character
  4793.      set (ISO-8859-1 Latin1 by default).  If you don't like this,
  4794.      declare your columns with the `BINARY' attribute, which causes
  4795.      comparisons to be done according to the ASCII order used on the
  4796.      MySQL server host.
  4797.  
  4798. `mSQL'
  4799.      All string comparisons are performed in case-sensitive fashion with
  4800.      sorting in ASCII order.
  4801.  
  4802. *Case-insensitive Searching*
  4803.  
  4804. `MySQL'
  4805.      `LIKE' is a case-insensitive or case-sensitive operator, depending
  4806.      on the columns involved. If possible, MySQL uses indexes if the
  4807.      `LIKE' argument doesn't start with a wild-card character.
  4808.  
  4809. `mSQL'
  4810.      Use `CLIKE'.
  4811.  
  4812. *Handling of Trailing Spaces*
  4813.  
  4814. `MySQL'
  4815.      Strips all spaces at the end of `CHAR' and `VARCHAR' columns. Use
  4816.      a `TEXT' column if this behavior is not desired.
  4817.  
  4818. `mSQL'
  4819.      Retains trailing space.
  4820.  
  4821. *`WHERE' Clauses*
  4822.  
  4823. `MySQL'
  4824.      MySQL correctly prioritizes everything (`AND' is evaluated before
  4825.      `OR'). To get `mSQL' behavior in MySQL, use parentheses (as shown
  4826.      in an example below).
  4827.  
  4828. `mSQL'
  4829.      Evaluates everything from left to right. This means that some
  4830.      logical calculations with more than three arguments cannot be
  4831.      expressed in any way. It also means you must change some queries
  4832.      when you upgrade to MySQL. You do this easily by adding
  4833.      parentheses.  Suppose you have the following `mSQL' query:
  4834.           mysql> SELECT * FROM table WHERE a=1 AND b=2 OR a=3 AND b=4;
  4835.      To make MySQL evaluate this the way that `mSQL' would, you must
  4836.      add parentheses:
  4837.           mysql> SELECT * FROM table WHERE (a=1 AND (b=2 OR (a=3 AND (b=4))));
  4838.  
  4839. *Access Control*
  4840.  
  4841. `MySQL'
  4842.      Has tables to store grant (permission) options per user, host, and
  4843.      database. *Note Privileges::.
  4844.  
  4845. `mSQL'
  4846.      Has a file `mSQL.acl' in which you can grant read/write privileges
  4847.      for users.
  4848.  
  4849. `'
  4850. How MySQL Compares to PostgreSQL
  4851. --------------------------------
  4852.  
  4853. When reading the following, please note that both products are
  4854. continually evolving.  We at MySQL AB and the PostgreSQL developers are
  4855. both working on making our respective database as good as possible, so
  4856. we are both a serious choice to any commercial database.
  4857.  
  4858. The following comparison is made by us at MySQL AB.  We have tried to be
  4859. as accurate and fair as possible, but because we don't have a full
  4860. knowledge of all PostgreSQL features while we know MySQL througly, we
  4861. may have got some things wrong.  We will however correct these when they
  4862. come to our attention.
  4863.  
  4864. We would first like to note that PostgreSQL and MySQL are both widely
  4865. used products, but with different design goals, even if we are both
  4866. striving to be ANSI SQL compatible.  This means that for some
  4867. applications MySQL is more suited, while for others PostgreSQL is more
  4868. suited.  When choosing which database to use, you should first check if
  4869. the database's feature set satisfies your application.  If you need raw
  4870. speed, MySQL is probably your best choice.  If you need some of the
  4871. extra features that only PostgreSQL can offer, you should use
  4872. `PostgreSQL'.
  4873.  
  4874. MySQL and PostgreSQL development strategies
  4875. ...........................................
  4876.  
  4877. When adding things to MySQL we take pride to do an optimal, definite
  4878. solution.  The code should be so good that we shouldn't have any need to
  4879. change it in the foreseeable future.  We also do not like to sacrifice
  4880. speed for features but instead will do our utmost to find a solution
  4881. that will give maximal throughput.  This means that development will
  4882. take a little longer, but the end result will be well worth this.  This
  4883. kind of development is only possible because all server code are
  4884. checked by one of a few (currently two) persons before it's included in
  4885. the MySQL server.
  4886.  
  4887. We at MySQL AB believe in frequent releases to be able to push out new
  4888. features quickly to our users.  Because of this we do a new small
  4889. release about every three weeks, and a major branch every year.  All
  4890. releases are throughly tested with our testing tools on a lot of
  4891. different platforms.
  4892.  
  4893. PostgreSQL is based on a kernel with lots of contributors. In this setup
  4894. it makes sense to prioritize adding a lot of new features, instead of
  4895. implementing them optimally, because one can always optimize things
  4896. later if there arises a need for this.
  4897.  
  4898. Another big difference between MySQL and PostgreSQL is that nearly all
  4899. of the code in the MySQL server are coded by developers that are
  4900. employed by MySQL AB and are still working on the server code. The
  4901. exceptions are the transaction engines, and the regexp library.
  4902.  
  4903. This is in sharp contrast to the PostgreSQL code where the majority of
  4904. the code is coded by a big group of people with different backgrounds.
  4905. It was only recently that the PostgreSQL developers announced that their
  4906. current developer group had finally had time to take a look at all the
  4907. code in the current PostgreSQL release.
  4908.  
  4909. Both of the above development methods has it's own merits and drawbacks.
  4910. We here at MySQL AB think of course that our model is better because our
  4911. model gives better code consistency, more optimal and reusable code, and
  4912. in our opinion, fewer bugs.  Because we are the authors of the MySQL
  4913. server code, we are better able to coordinate new features and releases.
  4914.  
  4915. Featurewise Comparison of MySQL and PostgreSQL
  4916. ..............................................
  4917.  
  4918. On the crash-me (http://www.mysql.com/information/crash-me.php) page
  4919. you can find a list of those database constructs and limits that one
  4920. can detect automatically with a program.  Note however that a lot of
  4921. the numerical limits may be changed with startup options for respective
  4922. database.  The above web page is however extremely useful when you want
  4923. to ensure that your applications works with many different databases or
  4924. when you want to convert your application from one datbase to another.
  4925.  
  4926. MySQL offers the following advantages over PostgreSQL:
  4927.  
  4928.    * `MySQL' is generally much faster than PostgreSQL.  *Note
  4929.      MySQL-PostgreSQL benchmarks::.
  4930.  
  4931.    * MySQL has a much larger user base than PostgreSQL, therefor the
  4932.      code is more tested and has historically been more stable than
  4933.      PostgreSQL.  MySQL is the much more used in production
  4934.      environments than PostgreSQL, mostly thanks to that MySQL AB,
  4935.      formerly TCX DataKonsult AB, has provided top quality commercial
  4936.      support for MySQL from the day it was released, whereas until
  4937.      recently PostgreSQL was unsupported.
  4938.  
  4939.    * MySQL works better on Windows than PostgreSQL does.  MySQL runs as
  4940.      a native Windows application (a service on NT/Win2000/WinXP), while
  4941.      PostgreSQL is run under the cygwin emulation.  We have heard that
  4942.      PostgreSQL is not yet that stable on Windows but we haven't been
  4943.      able to verify this ourselves.
  4944.  
  4945.    * MySQL has more APIs to other languages and is supported by more
  4946.      existing programs than PostgreSQL.  *Note Contrib::.
  4947.  
  4948.    * MySQL works on 24/7 heavy duty systems.  In most circumstances you
  4949.      never have to run any cleanups on MySQL.  PostgreSQL doesn't yet
  4950.      support 24/7 systems because you have to run `VACUUM()' once in a
  4951.      while to reclaim space from `UPDATE' and `DELETE' commands and to
  4952.      perform statistics analyzes that are critical to get good
  4953.      performance with PostgreSQL.  `VACUUM()' is also needed after
  4954.      adding a lot of new rows to a table.  On a busy system with lots
  4955.      of changes, `VACUUM()' must be run very frequently, in the worst
  4956.      cases even many times a day.  During the `VACUUM()' run, which may
  4957.      take hours if the database is big, the database is from a
  4958.      production standpoint, practically dead.  The PostgreSQL team has
  4959.      fixing this on their TODO, but we assume that this is not an easy
  4960.      thing to fix permanently.
  4961.  
  4962.    * A working, tested replication feature used by sites like:
  4963.         - Yahoo Finance (`http://finance.yahoo.com')
  4964.  
  4965.         - Mobile.de (`http://www.mobile.de/')
  4966.  
  4967.         - Slashdot (`http://www.slashdot.org')
  4968.  
  4969.    * Included in the MySQL distribution are two different testing
  4970.      suites, `mysql-test-run' and crash-me
  4971.      (http://www.mysql.com/information/crash-me.php), as well as a
  4972.      benchmark suite.  The test system is actively updated with code to
  4973.      test each new feature and almost all repeatable bugs that have
  4974.      come to our attention.  We test MySQL with these on a lot of
  4975.      platforms before every release.  These tests are more
  4976.      sophisticated than anything we have seen from PostgreSQL, and they
  4977.      ensures that the MySQL is kept to a high standard.
  4978.  
  4979.    * There are far more books in print about MySQL than about
  4980.      PostgreSQL.  O'Reilly, Sams, Que, and New Riders are all major
  4981.      publishers with books about MySQL.  All MySQL features are also
  4982.      documented in the MySQL on-line manual, because when a new feature
  4983.      is implemented, the MySQL developers are required to document it
  4984.      before it's included in the source.
  4985.  
  4986.    * MySQL supports more of the standard ODBC functions than
  4987.      `PostgreSQL'.
  4988.  
  4989.    * MySQL has a much more sophisticated `ALTER TABLE'.
  4990.  
  4991.    * MySQL has support for tables without transactions for applications
  4992.      that need all speed they can get. The tables may be memory based,
  4993.      `HEAP' tables or disk based `MyISAM'.  *Note Table types::.
  4994.  
  4995.    * MySQL has support for two different table handlers that support
  4996.      transactions, `BerkeleyDB' and `InnoDB'.  Because every
  4997.      transaction engine performs differently under different
  4998.      conditions, this gives the application writer more options to find
  4999.      an optimal solution for his or her setup.  *Note Table types::.
  5000.  
  5001.    * `MERGE' tables gives you a unique way to instantly make a view over
  5002.      a set of identical tables and use these as one.  This is perfect
  5003.      for systems where you have log files that you order for example by
  5004.      month.  *Note MERGE::.
  5005.  
  5006.    * The option to compress read-only tables, but still have direct
  5007.      access to the rows in the table, gives you better performance by
  5008.      minimizing disk reads.  This is very useful when you are archiving
  5009.      things.  *Note myisampack::.
  5010.  
  5011.    * MySQL has internal support for fulltext search. *Note Fulltext
  5012.      Search::.
  5013.  
  5014.    * You can access many databases from the same connection (depending
  5015.      of course on your privileges).
  5016.  
  5017.    * MySQL is coded from the start to be multi-threaded while
  5018.      PostgreSQL uses processes.  Context switching and access to common
  5019.      storage areas is much faster between threads than between separate
  5020.      processes, this gives MySQL a big speed advantage in multi-user
  5021.      applications and also makes it easier for MySQL to take full
  5022.      advantage of symmetric multiprocessor (SMP) systems.
  5023.  
  5024.    * MySQL has a much more sophisticated privilege system than
  5025.      PostgreSQL.  While PostgreSQL only supports `INSERT', `SELECT', and
  5026.      `UPDATE/DELETE' grants per user on a database or a table, MySQL
  5027.      allows you to define a full set of different privileges on
  5028.      database, table and column level.  MySQL also allows you to
  5029.      specify the privilege on host and user combinations.  *Note
  5030.      GRANT::.
  5031.  
  5032.    * MySQL supports a compressed client/server protocol which improves
  5033.      performance over slow links.
  5034.  
  5035.    * MySQL employs a "table handler" concept, and is the only relational
  5036.      database we know of built around this concept.  This allows
  5037.      different low-level table types to be swapped into the SQL engine,
  5038.      and each table type can be optimized for different performance
  5039.      characteristics.
  5040.  
  5041.    * All MySQL table types (except *InnoDB*) are implemented as files
  5042.      (one table per file), which makes it really easy to backup, move,
  5043.      delete and even symlink databases and tables, even when the server
  5044.      is down.
  5045.  
  5046.    * Tools to repair and optimize *MyISAM* tables (the most common
  5047.      MySQL table type).  A repair tool is only needed when a physical
  5048.      corruption of a data file happens, usually from a hardware
  5049.      failure.  It allows a majority of the data to be recovered.
  5050.  
  5051.    * Upgrading MySQL is painless.  When you are upgrading MySQL, you
  5052.      don't need to dump/restore your data, as you have to do with most
  5053.      PostgreSQL upgrades.
  5054.  
  5055. Drawbacks with MySQL compared to PostgreSQL:
  5056.  
  5057.    * The transaction support in MySQL is not yet as well tested as
  5058.      PostgreSQL's system.
  5059.  
  5060.    * Because MySQL uses threads, which are not yet flawless on many
  5061.      OSes, one must either use binaries from
  5062.      `http://www.mysql.com/downloads', or carefully follow our
  5063.      instructions on
  5064.      `http://www.mysql.com/doc/I/n/Installing_source.html' to get an
  5065.      optimal binary that works in all cases.
  5066.  
  5067.    * Table locking, as used by the non-transactional `MyISAM' tables, is
  5068.      in many cases faster than page locks, row locks or versioning.  The
  5069.      drawback however is that if one doesn't take into account how table
  5070.      locks work, a single long-running query can block a table for
  5071.      updates for a long time. This can usable be avoided when designing
  5072.      the application.  If not, one can always switch the trouble table
  5073.      to use one of the transactional table types. *Note Table locking::.
  5074.  
  5075.    * With UDF (user defined functions) one can extend MySQL with both
  5076.      normal SQL functions and aggregates, but this is not yet as easy
  5077.      or as flexible as in PostgreSQL.  *Note Adding functions::.
  5078.  
  5079.    * Updates and deletes that run over multiple tables is harder to do
  5080.      in MySQL. This will, hoever, be fixed in MySQL 4.0 with multi-table
  5081.      `DELETE' and multi-table `UPDATE' and in MySQL 4.1 with subselects.
  5082.  
  5083. PostgreSQL currently offers the following advantages over MySQL:
  5084.  
  5085. Note that because we know the MySQL road map, we have included in the
  5086. following table the version when MySQL should support this feature.
  5087. Unfortunately we couldn't do this for previous comparison, because we
  5088. don't know the PostgreSQL roadmap.
  5089.  
  5090. *Feature*                                          *MySQL version*
  5091. Subselects                                         4.1
  5092. Foreign keys                                       4.0 and 4.1
  5093. Views                                              4.2
  5094. Stored procedures                                  4.1
  5095. Extensible type system                             Not planned
  5096. Unions                                             4.0
  5097. Full join                                          4.0 or 4.1
  5098. Triggers                                           4.1
  5099. Constrainst                                        4.1
  5100. Cursors                                            4.1 or 4.2
  5101. Extensible index types like R-trees                R-trees are planned
  5102.                                                    for 4.2
  5103. Inherited tables                                   Not planned
  5104.  
  5105. Other reasons to use PostgreSQL:
  5106.  
  5107.    * Standard usage in PostgreSQL is closer to ANSI SQL in some cases.
  5108.  
  5109.    * One can speed up PostgreSQL by coding things as stored procedures.
  5110.  
  5111.    * PostgreSQL has a bigger team of developers that contribute to the
  5112.      server.
  5113.  
  5114. Drawbacks with PostgreSQL compared to MySQL:
  5115.  
  5116.    * `VACUUM()' makes PostgreSQL hard to use in a 24/7 environment.
  5117.  
  5118.    * Only transactional tables.
  5119.  
  5120.    * Much slower `INSERT', `DELETE', and `UPDATE'.
  5121.  
  5122. For a complete list of drawbacks, you should also examine the first
  5123. table in this section.
  5124.  
  5125. Benchmarking MySQL and PostgreSQL
  5126. .................................
  5127.  
  5128. The only open source benchmark that we know of that can be used to
  5129. benchmark MySQL and PostgreSQL (and other databases) is our own. It can
  5130. be found at `http://www.mysql.com/information/benchmarks.html'.
  5131.  
  5132. We have many times asked the PostgreSQL developers and some PostgreSQL
  5133. users to help us extend this benchmark to make it the definitive
  5134. benchmark for databases, but unfortunately we haven't gotten any
  5135. feedback for this.
  5136.  
  5137. We the MySQL developers have, because of this, spent a lot of hours to
  5138. get maximum performance from PostgreSQL for the benchmarks, but because
  5139. we don't know PostgreSQL intimately, we are sure that there are things
  5140. that we have missed.  We have on the benchmark page documented exactly
  5141. how we did run the benchmark so that it should be easy for anyone to
  5142. repeat and verify our results.
  5143.  
  5144. The benchmarks are usually run with and without the `--fast' option.
  5145. When run with `--fast' we are trying to use every trick the server can
  5146. do to get the code to execute as fast as possible.  The idea is that the
  5147. normal run should show how the server would work in a default setup and
  5148. the `--fast' run shows how the server would do if the application
  5149. developer would use extensions in the server to make his application run
  5150. faster.
  5151.  
  5152. When running with PostgreSQL and `--fast' we do a `VACUUM()' after
  5153. every major table `UPDATE' and `DROP TABLE' to make the database in
  5154. perfect shape for the following `SELECT's.  The time for `VACUUM()' is
  5155. measured separately.
  5156.  
  5157. When running with PostgreSQL 7.1.1 we could, however, not run with
  5158. `--fast' because during the `INSERT' test, the postmaster (the
  5159. PostgreSQL deamon) died and the database was so corrupted that it was
  5160. impossible to restart postmaster.   After this happened twice, we
  5161. decided to postpone the `--fast' test until next PostgreSQL release.
  5162. The details about the machine we run the benchmark can be found on the
  5163. benchmark page.
  5164.  
  5165. Before going to the other benchmarks we know of, we would like to give
  5166. some background on benchmarks:
  5167.  
  5168. It's very easy to write a test that shows ANY database to be best
  5169. database in the world, by just restricting the test to something the
  5170. database is very good at and not test anything that the database is not
  5171. good at.  If one after this publishes the result with a single figure,
  5172. things are even easier.
  5173.  
  5174. This would be like us measuring the speed of MySQL compared to
  5175. PostgreSQL by looking at the summary time of the MySQL benchmarks on
  5176. our web page.  Based on this MySQL would be more than 40 times faster
  5177. than PostgreSQL, something that is of course not true.  We could make
  5178. things even worse by just taking the test where PostgreSQL performs
  5179. worst and claim that MySQL is more than 2000 times faster than
  5180. PostgreSQL.
  5181.  
  5182. The case is that MySQL does a lot of optimizations that PostgreSQL
  5183. doesn't do. This is of course also true the other way around.  An SQL
  5184. optimizer is a very complex thing, and a company could spend years on
  5185. just making the optimizer faster and faster.
  5186.  
  5187. When looking at the benchmark results you should look for things that
  5188. you do in your application and just use these results to decide which
  5189. database would be best suited for your application.  The benchmark
  5190. results also shows things a particular database is not good at and
  5191. should give you a notion about things to avoid and what you may have to
  5192. do in other ways.
  5193.  
  5194. We know of two benchmark tests that claims that PostgreSQL performs
  5195. better than MySQL.  These both where multi-user tests, a test that we
  5196. here at MySQL AB haven't had time to write and include in the benchmark
  5197. suite, mainly because it's a big task to do this in a manner that is
  5198. fair against all databases.
  5199.  
  5200. One is the benchmark paid for by Great Bridge, which you can read about
  5201. at: `http://www.greatbridge.com/about/press.php?content_id=4'.
  5202.  
  5203. This is the probably worst benchmark we have ever seen anyone conduct.
  5204. This was not only tuned to only test what PostgreSQL is absolutely best
  5205. at, it was also totally unfair against every other database involved in
  5206. the test.
  5207.  
  5208. *NOTE*:  We know that not even some of the main PostgreSQL developers
  5209. did like the way Great Bridge conducted the benchmark, so we don't
  5210. blame them for the way the benchmark was made.
  5211.  
  5212. This benchmark has been condemned in a lot of postings and newsgroups so
  5213. we will here just shortly repeat some things that where wrong with it.
  5214.  
  5215.    * The tests were run with an expensive commercial tool, that makes it
  5216.      impossible for an open source company like us to verify the
  5217.      benchmarks, or even check how the benchmarks were really done.
  5218.      The tool is not even a true benchmark tool, but an
  5219.      application/setup testing tool.  To refer this as a "standard"
  5220.      benchmark tool is to stretch the truth a long way.
  5221.  
  5222.    * Great Bridge admitted that they had optimized the PostgreSQL
  5223.      database (with `VACUUM()' before the test) and tuned the startup
  5224.      for the tests, something they hadn't done for any of the other
  5225.      databases involved.  To say "This process optimizes indexes and
  5226.      frees up disk space a bit.  The optimized indexes boost
  5227.      performance by some margin."  Our benchmarks clearly indicate that
  5228.      the difference in running a lot of selects on a database with and
  5229.      without `VACUUM()' can easily differ by a factor of ten.
  5230.  
  5231.    * The test results were also strange.  The AS3AP test documentation
  5232.      mentions that the test does "selections, simple joins, projections,
  5233.      aggregates, one-tuple updates, and bulk updates".
  5234.  
  5235.      PostgreSQL is good at doing `SELECT's and `JOIN's (especially
  5236.      after a `VACUUM()'), but doesn't perform as well on `INSERT's or
  5237.      `UPDATE's.  The benchmarks seem to indicate that only `SELECT's
  5238.      were done (or very few updates).  This could easily explain they
  5239.      good results for PostgreSQL in this test.  The bad results for
  5240.      MySQL will be obvious a bit down in this document.
  5241.  
  5242.    * They did run the so-called benchmark from a Windows machine
  5243.      against a Linux machine over ODBC, a setup that no normal database
  5244.      user would ever do when running a heavy multi-user application.
  5245.      This tested more the ODBC driver and the Windows protocol used
  5246.      between the clients than the database itself.
  5247.  
  5248.    * When running the database against Oracle and MS-SQL (Great Bridge
  5249.      has indirectly indicated that the databases they used in the
  5250.      test), they didn't use the native protocol but instead ODBC.
  5251.      Anyone that has ever used Oracle knows that all real application
  5252.      uses the native interface instead of ODBC.  Doing a test through
  5253.      ODBC and claiming that the results had anything to do with using
  5254.      the database in a real-world situation can't be regarded as fair.
  5255.      They should have done two tests with and without ODBC to provide
  5256.      the right facts (after having got experts to tune all involved
  5257.      databases of course).
  5258.  
  5259.    * They refer to the TPC-C tests, but they don't mention anywhere
  5260.      that the test they did was not a true TPC-C test and they were not
  5261.      even allowed to call it a TPC-C test.  A TPC-C test can only be
  5262.      conducted by the rules approved by the TPC Council
  5263.      (`http://www.tpc.org'). Great Bridge didn't do that.  By doing
  5264.      this they have both violated the TPC trademark and miscredited
  5265.      their own benchmarks.  The rules set by the TPC Council are very
  5266.      strict to ensure that no one can produce false results or make
  5267.      unprovable statements.  Apparently Great Bridge wasn't interested
  5268.      in doing this.
  5269.  
  5270.    * After the first test, we contacted Great Bridge and mentioned to
  5271.      them some of the obvious mistakes they had done with MySQL:
  5272.  
  5273.         - Running with a debug version of our ODBC driver
  5274.  
  5275.         - Running on a Linux system that wasn't optimized for threads
  5276.  
  5277.         - Using an old MySQL version when there was a recommended newer
  5278.           one available
  5279.  
  5280.         - Not starting MySQL with the right options for heavy
  5281.           multi-user use (the default installation of MySQL is tuned
  5282.           for minimal resource use).
  5283.  
  5284.      Great Bridge did run a new test, with our optimized ODBC driver
  5285.      and with better startup options for MySQL, but refused to either
  5286.      use our updated glibc library or our standard binary (used by 80%
  5287.      of our users), which was statically linked with a fixed glibc
  5288.      library.
  5289.  
  5290.      According to what we know, Great Bridge did nothing to ensure that
  5291.      the other databases were set up correctly to run well in their test
  5292.      environment.  We are sure however that they didn't contact Oracle
  5293.      or Microsoft to ask for their advice in this matter ;)
  5294.  
  5295.    * The benchmark was paid for by Great Bridge, and they decided to
  5296.      publish only partial, chosen results (instead of publishing it
  5297.      all).
  5298.  
  5299. Tim Perdue, a long time PostgreSQL fan and a reluctant MySQL user
  5300. published a comparison on phpbuider
  5301. (http://www.phpbuilder.com/columns/tim20001112.php3).
  5302.  
  5303. When we became aware of the comparison, we phoned Tim Perdue about this
  5304. because there were a lot of strange things in his results.  For example,
  5305. he claimed that MySQL had a problem with five users in his tests, when
  5306. we know that there are users with similar machines as his that are using
  5307. MySQL with 2000 simultaneous connections doing 400 queries per second.
  5308. (In this case the limit was the web bandwidth, not the database.)
  5309.  
  5310. It sounded like he was using a Linux kernel that either had some
  5311. problems with many threads, such as kernels before 2.4, which had a
  5312. problem with many threads on multi-CPU machines. We have documented in
  5313. this manual how to fix this and Tim should be aware of this problem.
  5314.  
  5315. The other possible problem could have been an old glibc library and
  5316. that Tim didn't use a MySQL binary from our site, which is linked with
  5317. a corrected glibc library, but had compiled a version of his own with.
  5318. In any of the above cases, the symptom would have been exactly what Tim
  5319. had measured.
  5320.  
  5321. We asked Tim if we could get access to his data so that we could repeat
  5322. the benchmark and if he could check the MySQL version on the machine to
  5323. find out what was wrong and he promised to come back to us about this.
  5324. He has not done that yet.
  5325.  
  5326. Because of this we can't put any trust in this benchmark either :(
  5327.  
  5328. Over time things also changes and the above benchmarks are not that
  5329. relevant anymore.  MySQL now have a couple of different table handlers
  5330. with different speed/concurrency tradeoffs.  *Note Table types::. It
  5331. would be interesting to see how the above tests would run with the
  5332. different transactional table types in MySQL.  PostgreSQL has of course
  5333. also got new features since the test was made.  As the above test are
  5334. not publicly available there is no way for us to know how the database
  5335. would preform in the same tests today.
  5336.  
  5337. Conclusion:
  5338.  
  5339. The only benchmarks that exist today that anyone can download and run
  5340. against MySQL and PostgreSQL is the MySQL benchmarks.  We here at MySQL
  5341. believe that open source databases should be tested with open source
  5342. tools!  This is the only way to ensure that no one does tests that
  5343. nobody can reproduce and use this to claim that a database is better
  5344. than another.  Without knowing all the facts it's impossible to answer
  5345. the claims of the tester.
  5346.  
  5347. The thing we find strange is that every test we have seen about
  5348. PostgreSQL, that is impossible to reproduce, claims that PostgreSQL is
  5349. better in most cases while our tests, which anyone can reproduce,
  5350. clearly shows otherwise.  With this we don't want to say that PostgreSQL
  5351. isn't good at many things (it is!) or that it isn't faster than MySQL
  5352. under certain conditions.  We would just like to see a fair test where
  5353. they are very good so that we could get some friendly competition going!
  5354.  
  5355. For more information about our benchmarks suite *Note MySQL
  5356. Benchmarks::.
  5357.  
  5358. We are working on an even better benchmark suite, including multi user
  5359. tests, and a better documentation of what the individual tests really
  5360. do and how to add more tests to the suite.
  5361.  
  5362. MySQL and the future (The TODO)
  5363. ===============================
  5364.  
  5365. This appendix lists the features that we plan to implement in MySQL.
  5366.  
  5367. Everything in this list is approximately in the order it will be done.
  5368. If you want to affect the priority order, please register a license or
  5369. support us and tell us what you want to have done more quickly. *Note
  5370. Licensing and Support::.
  5371.  
  5372. The plan is that we in the future will support the full ANSI SQL99
  5373. standard, but with a lot of useful extensions. The challenge is to do
  5374. this without sacrifying the speed or compromise the code.
  5375.  
  5376. Things that should be in 4.0
  5377. ----------------------------
  5378.  
  5379. We plan to make MySQL Version 4.0 a "quick" release where we only add
  5380. some new stuff to enable others to help us with developing new features
  5381. into Version 4.1.  The MySQL 4.0 version should only take us about a
  5382. month to make after which we want to stabilize it and start working on
  5383. Version 4.1.  Version 4.0 should have the following new features:
  5384.  
  5385. The news section for 4.0 includes a list of the features we have already
  5386. implemented in the 4.0 tree. *Note News-4.0.x::.
  5387.  
  5388.    * New table definition file format (`.frm' files) This will enable us
  5389.      to not run out of bits when adding more table options.  One will
  5390.      still be able to use the old `.frm' file format with 4.0.  All
  5391.      newly created tables will, however, use the new format.
  5392.  
  5393.      The new file format will enable us to add new column types, more
  5394.      options for keys and `FOREIGN KEY' support.
  5395.  
  5396.    * `mysqld' as a library.  This will have the same interface as the
  5397.      standard MySQL client (with an extra function to just set up
  5398.      startup parameters) but will be faster (no TCP/IP or socket
  5399.      overhead), smaller and much easier to use for embedded products.
  5400.  
  5401.      One will be able to define at link time if one wants to use the
  5402.      client/server model or a stand-alone application just by defining
  5403.      which library to link with.
  5404.  
  5405.      The `mysqld' will support all standard MySQL features and one can
  5406.      use it in a threaded client to run different queries in each
  5407.      thread.
  5408.  
  5409.    * Replication should work with `RAND()' and user variables `@var'.
  5410.  
  5411.    * Online backup with very low performance penalty.  The online
  5412.      backup will make it easy to add a new replication slave without
  5413.      taking down the master.
  5414.  
  5415.    * `DELETE FROM table_name' will return the number of deleted rows.
  5416.      For fast execution one should use `TRUNCATE table_name'.
  5417.  
  5418.    * Allow `DELETE' on `MyISAM' tables to use the record cache.  To do
  5419.      this, we need to update the threads record cache when we update
  5420.      the `.MYD' file.
  5421.  
  5422.    * Better replication.
  5423.  
  5424.    * More functions for full-text search.  *Note Fulltext Features to
  5425.      Appear in MySQL 4.0::.
  5426.  
  5427.    * Character set casts and syntax for handling multiple character
  5428.      sets.
  5429.  
  5430.    * Allow users to change startup options without taking down the
  5431.      server.
  5432.  
  5433.    * Help for all commands from the client.
  5434.  
  5435.    * Secure connections (with SSL).
  5436.  
  5437.    * Extend the optimizer to be able to optimize some `ORDER BY
  5438.      key_name DESC' queries.
  5439.  
  5440.    * `SHOW COLUMNS FROM table_name' (used by `mysql' client to allow
  5441.      expansions of column names) should not open the table, but only the
  5442.      definition file. This will require less memory and be much faster.
  5443.  
  5444.    * New key cache
  5445.  
  5446.    * When using `SET CHARACTER SET' we should translate the whole query
  5447.      at once and not only strings. This will enable users to use the
  5448.      translated characters in database, table and column names.
  5449.  
  5450.    * Add a portable interface over `gethostbyaddr_r()' so that we can
  5451.      change `ip_to_hostname()' to not block other threads while doing
  5452.      DNS lookups.
  5453.  
  5454.    * Add `record_in_range()' method to `MERGE' tables to be able to
  5455.      choose the right index when there is many to choose from. We should
  5456.      also extend the info interface to get the key distribution for
  5457.      each index, of `analyze' is run on all sub tables.
  5458.  
  5459.    * `SET SQL_DEFAULT_TABLE_TYPE=[MyISAM | INNODB | BDB | HEAP]'.
  5460.  
  5461. Things that must be done in the real near future
  5462. ------------------------------------------------
  5463.  
  5464.    * Fail safe replication.
  5465.  
  5466.    * Subqueries.  `select id from t where grp in (select grp from g
  5467.      where u > 100)'
  5468.  
  5469.    * Derived tables.
  5470.           select a.col1, b.col2 from (select max(col1) as col1 from root_table ) a,
  5471.           other_table b where a.col1=b.col1
  5472.  
  5473.      This could be done by automatically creating temporary tables for
  5474.      the derived tables for the duration of the query.
  5475.  
  5476.    * Add `PREPARE' of statements and sending of parameters to `mysqld'.
  5477.  
  5478.    * Extend the server/client protocol to support warnings.
  5479.  
  5480.    * Add options to the server/protocol protocol to get progress notes
  5481.      for long running commands.
  5482.  
  5483.    * Add database and real table name (in case of alias) to the
  5484.      MYSQL_FIELD structure.
  5485.  
  5486.    * Don't allow more than a defined number of threads to run MyISAM
  5487.      recover at the same time.
  5488.  
  5489.    * Change `INSERT ... SELECT' to optionally use concurrent inserts.
  5490.  
  5491.    * Implement `RENAME DATABASE'. To make this safe for all table
  5492.      handlers, it should work as follows:
  5493.         * Create the new database.
  5494.  
  5495.         * For every table do a rename of the table to another database,
  5496.           as we do with the `RENAME' command.
  5497.  
  5498.         * Drop the old database.
  5499.  
  5500.    * Return the original field types() when doing `SELECT MIN(column)
  5501.      ... GROUP BY'.
  5502.  
  5503.    * Multiple result sets.
  5504.  
  5505.    * Change the protocol to allow binary transfer of values. To do this
  5506.      efficiently, we need to add an API to allow binding of variables.
  5507.  
  5508.    * Make it possible to specify `long_query_time' with a granularity
  5509.      in microseconds.
  5510.  
  5511.    * Add a configurable prompt to the `mysql' command line client, with
  5512.      options like database in use, time and date...
  5513.  
  5514.    * Add range checking to `MERGE' tables.
  5515.  
  5516.    * Link the `myisampack' code into the server.
  5517.  
  5518.    * Port of MySQL to BeOS.
  5519.  
  5520.    * Port of the MySQL clients to LynxOS.
  5521.  
  5522.    * Add a temporary key buffer cache during `INSERT/DELETE/UPDATE' so
  5523.      that we can gracefully recover if the index file gets full.
  5524.  
  5525.    * If you perform an `ALTER TABLE' on a table that is symlinked to
  5526.      another disk, create temporary tables on this disk.
  5527.  
  5528.    * Implement a `DATE/DATETIME' type that handles time zone information
  5529.      properly, so that dealing with dates in different time zones is
  5530.      easier.
  5531.  
  5532.    * FreeBSD and MIT-pthreads;  Do sleeping threads take CPU?
  5533.  
  5534.    * Check if locked threads take any CPU.
  5535.  
  5536.    * Fix configure so that one can compile all libraries (like `MyISAM')
  5537.      without threads.
  5538.  
  5539.    * Add an option to periodically flush key pages for tables with
  5540.      delayed keys if they haven't been used in a while.
  5541.  
  5542.    * Allow join on key parts (optimization issue).
  5543.  
  5544.    * `INSERT SQL_CONCURRENT' and `mysqld --concurrent-insert' to do a
  5545.      concurrent insert at the end of the file if the file is
  5546.      read-locked.
  5547.  
  5548.    * Remember `FOREIGN' key definitions in the `.frm' file.
  5549.  
  5550.    * Cascading `DELETE'
  5551.  
  5552.    * Server side cursors.
  5553.  
  5554.    * Check if `lockd' works with modern Linux kernels; If not, we have
  5555.      to fix `lockd'!  To test this, start `mysqld' with
  5556.      `--enable-locking' and run the different fork* test suits. They
  5557.      shouldn't give any errors if `lockd' works.
  5558.  
  5559.    * Allow SQL variables in `LIMIT', like in `LIMIT @a,@b'.
  5560.  
  5561.    * Allow update of variables in `UPDATE' statements. For example:
  5562.      `UPDATE TABLE foo SET @a=a+b,a=@a, b=@a+c'
  5563.  
  5564.    * Change when user variables are updated so that one can use them
  5565.      with `GROUP BY', as in the following example: `SELECT id,
  5566.      @a:=count(*), sum(sum_col)/@a FROM table_name GROUP BY id'.
  5567.  
  5568.    * Don't add automatic `DEFAULT' values to columns.  Give an error
  5569.      when using an `INSERT' that doesn't contain a column that doesn't
  5570.      have a `DEFAULT'.
  5571.  
  5572.    * Caching of queries and results. This should be done as a separated
  5573.      module that examines each query and if this is query is in the
  5574.      cache the cached result should be returned.  When one updates a
  5575.      table one should remove as few queries as possible from the cache.
  5576.      This should give a big speed bost on machines with much RAM where
  5577.      queries are often repeated (like WWW applications).  One idea
  5578.      would be to only cache queries of type: `SELECT CACHED ...'
  5579.  
  5580.    * Fix `libmysql.c' to allow two `mysql_query()' commands in a row
  5581.      without reading results or give a nice error message when one does
  5582.      this.
  5583.  
  5584.    * Optimize `BIT' type to take 1 bit (now `BIT' takes 1 char).
  5585.  
  5586.    * Check why MIT-pthreads `ctime()' doesn't work on some FreeBSD
  5587.      systems.
  5588.  
  5589.    * Add an `IMAGE' option to `LOAD DATA INFILE' to not update
  5590.      `TIMESTAMP' and `AUTO_INCREMENT' fields.
  5591.  
  5592.    * Added `LOAD DATE INFILE.. UPDATE' syntax.
  5593.         * For tables with primary keys, if the data contains the
  5594.           primary key, entries matching that primary key are updated
  5595.           from the remainder of the columns. However, columns MISSING
  5596.           from the incoming data feed are not touched.
  5597.  
  5598.         * For tables tables with primary keys that are missing some
  5599.           part of the key in the incoming data stream, or that have no
  5600.           primary key, the feed is treated as a `LOAD DATA INFILE ...
  5601.           REPLACE INTO' is now.
  5602.  
  5603.    * Make `LOAD DATA INFILE' understand syntax like:
  5604.           LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name
  5605.           TEXT_FIELDS (text_field1, text_field2, text_field3)
  5606.           SET table_field1=concatenate(text_field1, text_field2), table_field3=23
  5607.           IGNORE text_field3
  5608.           
  5609.           This can be used to skip over extra columns in the text file, or update columns
  5610.           based on expressions of the read data...
  5611.  
  5612.    * `LOAD DATA INFILE 'file_name' INTO TABLE 'table_name' ERRORS TO
  5613.      err_table_name' This would cause any errors and warnings to be
  5614.      logged into the err_table_name table. That table would have a
  5615.      structure like:
  5616.  
  5617.           line_number    - line number in data file
  5618.           error_message  - the error/warning message
  5619.           and maybe
  5620.           data_line      - the line from the data file
  5621.  
  5622.    * Add true `VARCHAR' support (There is already support for this in
  5623.      MyISAM).
  5624.  
  5625.    * Automatic output from `mysql' to netscape.
  5626.  
  5627.    * `LOCK DATABASES'. (with various options)
  5628.  
  5629.    * Change sort to allocate memory in "hunks" to get better memory
  5630.      utilization.
  5631.  
  5632.    * `DECIMAL' and `NUMERIC' types can't read exponential numbers;
  5633.      `Field_decimal::store(const char *from,uint len)' must be recoded
  5634.      to fix this.
  5635.  
  5636.    * Functions: ADD_TO_SET(value,set) and REMOVE_FROM_SET(value,set)
  5637.  
  5638.    * Add use of `t1 JOIN t2 ON ...' and `t1 JOIN t2 USING ...'
  5639.      Currently, you can only use this syntax with `LEFT JOIN'.
  5640.  
  5641.    * Add full support for `unsigned long long' type.
  5642.  
  5643.    * Many more variables for `show status'.  Counts for:
  5644.      `INSERT'/`DELETE'/`UPDATE' statements. Records reads and updated.
  5645.      Selects on 1 table and selects with joins.  Mean number of tables
  5646.      in select. Number of `ORDER BY' and `GROUP BY' queries.
  5647.  
  5648.    * If you abort `mysql' in the middle of a query, you should open
  5649.      another connection and kill the old running query.  Alternatively,
  5650.      an attempt should be made to detect this in the server.
  5651.  
  5652.    * Add a handler interface for table information so you can use it as
  5653.      a system table. This would be a bit slow if you requested
  5654.      information about all tables, but very flexible.  `SHOW INFO FROM
  5655.      tbl_name' for basic table information should be implemented.
  5656.  
  5657.    * Add support for UNICODE.
  5658.  
  5659.    * `NATURAL JOIN' and `UNION JOIN'
  5660.  
  5661.    * Allow `select a from crash_me left join crash_me2 using (a)'; In
  5662.      this case a is assumed to come from the crash_me table.
  5663.  
  5664.    * Fix that `ON' and `USING' works with the `JOIN' join type.
  5665.  
  5666.    * Oracle like `CONNECT BY PRIOR ...' to search hierarchy structures.
  5667.  
  5668.    * `mysqladmin copy database new-database'. - Requires COPY command
  5669.      to be added to `mysqld'
  5670.  
  5671.    * Processlist should show number of queries/thread.
  5672.  
  5673.    * `SHOW HOSTS' for printing information about the hostname cache.
  5674.  
  5675.    * `DELETE' and `REPLACE' options to the `UPDATE' statement (this
  5676.      will delete rows when one gets a duplicate key error while
  5677.      updating).
  5678.  
  5679.    * Change the format of `DATETIME' to store fractions of seconds.
  5680.  
  5681.    * Add all missing ANSI92 and ODBC 3.0 types.
  5682.  
  5683.    * Change table names from empty strings to `NULL' for calculated
  5684.      columns.
  5685.  
  5686.    * Don't use 'Item_copy_string' on numerical values to avoid
  5687.      number->string->number conversion in case of: `SELECT
  5688.      COUNT(*)*(id+0) FROM table_name GROUP BY id'
  5689.  
  5690.    * Make it possible to use the new GNU regexp library instead of the
  5691.      current one (The GNU library should be much faster than the old
  5692.      one).
  5693.  
  5694.    * Change that `ALTER TABLE' doesn't abort clients that executes
  5695.      `INSERT DELAYED'.
  5696.  
  5697.    * Fix that when columns referenced in an `UPDATE' clause contains
  5698.      the old values before the update started.
  5699.  
  5700.    * `myisamchk', `REPAIR' and `OPTIMIZE TABLE' should be able to
  5701.      handle cases where the data and/or index files are symbolic links.
  5702.  
  5703.    * Add simulation of `pread()'/`pwrite()' on Windows to enable
  5704.      concurrent inserts.
  5705.  
  5706.    * A logfile analyzer that could parsed out information about which
  5707.      tables are hit most often, how often multi-table joins are
  5708.      executed, etc.  It should help users identify areas or table
  5709.      design that could be optimized to execute much more efficient
  5710.      queries.
  5711.  
  5712.    * Add `SUM(DISTINCT)'
  5713.  
  5714.    * Add `ANY()',`EVERY()' and `SOME()' group functions. In ANSI SQL
  5715.      these only works on boolean columns, but we can extend these to
  5716.      work on any columns/expressions by applying: value == 0 -> FALSE
  5717.      and value <> 0 -> TRUE.
  5718.  
  5719.    * Fix that the type for `MAX(column)' is the same as the column type.
  5720.           create table t1 (a DATE);
  5721.           insert into t1 values (now());
  5722.           create table t2 select max(a) from t1;
  5723.           show columns from t2;
  5724.  
  5725.    * Come up with a nice syntax for a statement that will `UPDATE' the
  5726.      row if it exists and `INSERT' a new row if the row didn't exist.
  5727.      (Like `REPLACE' works with `INSERT' / `DELETE')
  5728.  
  5729. Things that have to be done sometime
  5730. ------------------------------------
  5731.  
  5732.    * Implement function: `get_changed_tables(timeout,table1,table2,...)'
  5733.  
  5734.    * Atomic multi-table updates, eg `update items,month set
  5735.      items.price=month.price where items.id=month.id;';
  5736.  
  5737.    * Change reading through tables to use memmap when possible. Now only
  5738.      compressed tables use memmap.
  5739.  
  5740.    * Add a new privilege *'Show_priv'* for `SHOW' commands.
  5741.  
  5742.    * Make the automatic timestamp code nicer.  Add timestamps to the
  5743.      update log with `SET TIMESTAMP=#;'
  5744.  
  5745.    * Use read/write mutex in some places to get more speed.
  5746.  
  5747.    * Full foreign key support. One probably wants to implement a
  5748.      procedural language first.
  5749.  
  5750.    * Simple views (first on one table, later on any expression).
  5751.  
  5752.    * Automatically close some tables if a table, temporary table or
  5753.      temporary files gets error 23 (not enough open files).
  5754.  
  5755.    * When one finds a field=#, change all occurrences of field to #.
  5756.      Now this is only done for some simple cases.
  5757.  
  5758.    * Change all const expressions with calculated expressions if
  5759.      possible.
  5760.  
  5761.    * Optimize key = expression. At the moment only key = field or key =
  5762.      constant are optimized.
  5763.  
  5764.    * Join some of the copy functions for nicer code.
  5765.  
  5766.    * Change `sql_yacc.yy' to an inline parser to reduce its size and get
  5767.      better error messages (5 days).
  5768.  
  5769.    * Change the parser to use only one rule per different number of
  5770.      arguments in function.
  5771.  
  5772.    * Use of full calculation names in the order part. (For ACCESS97)
  5773.  
  5774.    * `UNION', `MINUS', `INTERSECT' and `FULL OUTER JOIN'.  (Currently
  5775.      only `LEFT OUTER JOIN' is supported)
  5776.  
  5777.    * Allow `UNIQUE' on fields that can be `NULL'.
  5778.  
  5779.    * `SQL_OPTION MAX_SELECT_TIME=#' to put a time limit on a query.
  5780.  
  5781.    * Make the update log to a database.
  5782.  
  5783.    * Negative `LIMIT' to retrieve data from the end.
  5784.  
  5785.    * Alarm around client connect/read/write functions.
  5786.  
  5787.    * Please note the changes to `safe_mysqld': according to FSSTND
  5788.      (which Debian tries to follow) PID files should go into
  5789.      `/var/run/<progname>.pid' and log files into `/var/log'. It would
  5790.      be nice if you could put the "DATADIR" in the first declaration of
  5791.      "pidfile" and "log", so the placement of these files can be
  5792.      changed with a single statement.
  5793.  
  5794.    * Allow a client to request logging.
  5795.  
  5796.    * Add use of `zlib()' for `gzip'-ed files to `LOAD DATA INFILE'.
  5797.  
  5798.    * Fix sorting and grouping of `BLOB' columns (partly solved now).
  5799.  
  5800.    * Stored procedures.  This is currently not regarded to be very
  5801.      important as stored procedures are not very standardized yet.
  5802.      Another problem is that true stored procedures make it much harder
  5803.      for the optimizer and in many cases the result is slower than
  5804.      before We will, on the other hand, add a simple (atomic) update
  5805.      language that can be used to write loops and such in the MySQL
  5806.      server.
  5807.  
  5808.    * Change to use semaphores when counting threads.  One should first
  5809.      implement a semaphore library to MIT-pthreads.
  5810.  
  5811.    * Don't assign a new `AUTO_INCREMENT' value when one sets a column
  5812.      to 0.  Use `NULL' instead.
  5813.  
  5814.    * Add full support for `JOIN' with parentheses.
  5815.  
  5816.    * As an alternative for one thread / connection manage a pool of
  5817.      threads to handle the queries.
  5818.  
  5819.    * Allow one to get more than one lock with `GET_LOCK'.  When doing
  5820.      this, one must also handle the possible deadlocks this change will
  5821.      introduce.
  5822.  
  5823. Time is given according to amount of work, not real time.
  5824.  
  5825. Some things we don't have any plans to do
  5826. -----------------------------------------
  5827.  
  5828.    * Nothing;  In the long run we plan to be fully ANSI 92 / ANSI 99
  5829.      compliant.
  5830.  
  5831. MySQL Installation
  5832. ******************
  5833.  
  5834. This chapter describes how to obtain and install MySQL:
  5835.  
  5836.    * For a list of sites from which you can obtain MySQL, see *Note
  5837.      Getting MySQL: Getting MySQL.
  5838.  
  5839.    * To see which platforms are supported, see *Note Which OS::. Please
  5840.      note that not all supported system are equally good for running
  5841.      MySQL on them.  On some it is much more robust and efficient than
  5842.      others - see  *Note Which OS:: for details.
  5843.  
  5844.    * Several versions of MySQL are available in both binary and source
  5845.      distributions.  We also provide public access to our current
  5846.      source tree for those who want to see our most recent developments
  5847.      and help us test new code.  To determine which version and type of
  5848.      distribution you should use, see *Note Which version::. When in
  5849.      doubt, use the binary distribution.
  5850.  
  5851.    * Installation instructions for binary and source distributions are
  5852.      described in *Note Installing binary:: and *Note Installing
  5853.      source::.  Each set of instructions includes a section on
  5854.      system-specific problems you may run into.
  5855.  
  5856.    * For post-installation procedures, see *Note Post-installation::.
  5857.      These procedures apply whether you install MySQL using a binary or
  5858.      source distribution.
  5859.  
  5860. Quick Standard Installation of MySQL
  5861. ====================================
  5862.  
  5863. Installing MySQL on Linux
  5864. -------------------------
  5865.  
  5866. The recommended way to install MySQL on Linux is by using an RPM file.
  5867. The MySQL RPMs are currently being built on a RedHat Version 6.2 system
  5868. but should work on other versions of Linux that support `rpm' and use
  5869. `glibc'.
  5870.  
  5871. If you have problems with an RPM file, for example, if you receive the
  5872. error "`Sorry, the host 'xxxx' could not be looked up'", see *Note
  5873. Binary notes-Linux::.
  5874.  
  5875. The RPM files you may want to use are:
  5876.  
  5877.    * `MySQL-VERSION.i386.rpm'
  5878.  
  5879.      The MySQL server.  You will need this unless you only want to
  5880.      connect to a MySQL server running on another machine.
  5881.  
  5882.    * `MySQL-client-VERSION.i386.rpm'
  5883.  
  5884.      The standard MySQL client programs. You probably always want to
  5885.      install this package.
  5886.  
  5887.    * `MySQL-bench-VERSION.i386.rpm'
  5888.  
  5889.      Tests and benchmarks. Requires Perl and msql-mysql-modules RPMs.
  5890.  
  5891.    * `MySQL-devel-VERSION.i386.rpm'
  5892.  
  5893.      Libraries and include files needed if you want to compile other
  5894.      MySQL clients, such as the Perl modules.
  5895.  
  5896.    * `MySQL-VERSION.src.rpm'
  5897.  
  5898.      This contains the source code for all of the above packages. It
  5899.      can also be used to try to build RPMs for other architectures (for
  5900.      example, Alpha or SPARC).
  5901.  
  5902. To see all files in an RPM package, run:
  5903.      shell> rpm -qpl MySQL-VERSION.i386.rpm
  5904.  
  5905. To perform a standard minimal installation, run:
  5906.  
  5907.      shell> rpm -i MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
  5908.  
  5909. To install just the client package, run:
  5910.  
  5911.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  5912.  
  5913. The RPM places data in `/var/lib/mysql'. The RPM also creates the
  5914. appropriate entries in `/etc/rc.d/' to start the server automatically
  5915. at boot time.  (This means that if you have performed a previous
  5916. installation, you may want to make a copy of your previously installed
  5917. MySQL startup file if you made any changes to it, so you don't lose
  5918. your changes.)
  5919.  
  5920. After installing the RPM file(s), the `mysqld' daemon should be running
  5921. and you should now be able to start using MySQL.  *Note
  5922. Post-installation::.
  5923.  
  5924. If something goes wrong, you can find more information in the binary
  5925. installation chapter. *Note Installing binary::.
  5926.  
  5927. Installing MySQL on Windows
  5928. ---------------------------
  5929.  
  5930. The following instructions apply to precompiled binary distributions.
  5931. If you download a source distribution, you will have to compile and
  5932. install it yourself.
  5933.  
  5934. If you don't have a copy of the MySQL distribution, you should first
  5935. download one from `http://www.mysql.com/downloads/mysql-3.23.html'.
  5936.  
  5937. If you plan to connect to MySQL from some other program, you will
  5938. probably also need the *MyODBC* driver. You can find this at the
  5939. *MyODBC* download page
  5940. (`http://www.mysql.com/downloads/api-myodbc.html').
  5941.  
  5942. To install either distribution, unzip it in some empty directory and
  5943. run the `Setup.exe' program.
  5944.  
  5945. By default, MySQL-Windows is configured to be installed in `C:\mysql'.
  5946. If you want to install MySQL elsewhere, install it in `C:\mysql' first,
  5947. then move the installation to where you want it.  If you do move MySQL,
  5948. you must indicate where everything is located by supplying a
  5949. `--basedir' option when you start the server.  For example, if you have
  5950. moved the MySQL distribution to `D:\programs\mysql', you must start
  5951. `mysqld' like this:
  5952.  
  5953.      C:\> D:\programs\mysql\bin\mysqld --basedir D:\programs\mysql
  5954.  
  5955. Use `mysqld --help' to display all the options that `mysqld'
  5956. understands!
  5957.  
  5958. With all newer MySQL versions, you can also create a `C:\my.cnf' file
  5959. that holds any default options for the MySQL server.  Copy the file
  5960. `\mysql\my-xxxxx.cnf' to `C:\my.cnf' and edit it to suit your setup.
  5961. Note that you should specify all paths with `/' instead of `\'. If you
  5962. use `\', you need to specify it twice, because `\' is the escape
  5963. character in MySQL.  *Note Option files::.
  5964.  
  5965. Starting with MySQL 3.23.38, the Windows distribution includes both the
  5966. normal and the *MySQL-Max* binaries.  The main benefit of using the
  5967. normal `mysqld.exe' binary is that it's a little faster and uses less
  5968. resources.
  5969.  
  5970. Here is a list of the different MySQL servers you can use:
  5971.  
  5972. `mysqld'            Compiled with full debugging and automatic memory
  5973.                    allocation checking, symbolic links, BDB and InnoDB
  5974.                    tables.
  5975. `mysqld-opt'        Optimized binary with no support for transactional
  5976.                    tables.
  5977. `mysqld-nt'         Optimized binary for NT with support for named
  5978.                    pipes. You can run this version on Win98, but in this
  5979.                    case no named pipes are created and you must have
  5980.                    TCP/IP installed.
  5981. `mysqld-max'        Optimized binary with support for symbolic links,
  5982.                    BDB and InnoDB tables.
  5983. `mysqld-max-nt'     Like `mysqld-max', but compiled with support for
  5984.                    named pipes.
  5985.  
  5986. All of the above binaries are optimized for the Pentium Pro processor
  5987. but should work on any Intel processor >= i386.
  5988.  
  5989. NOTE: If you want to use InnoDB tables, there are certain startup
  5990. options that must be specified in your `my.ini' file! *Note InnoDB
  5991. start::.
  5992.  
  5993. General Installation Issues
  5994. ===========================
  5995.  
  5996. How to Get MySQL
  5997. ----------------
  5998.  
  5999. Check the MySQL home page (http://www.mysql.com/) for information about
  6000. the current version and for downloading instructions.
  6001.  
  6002. Our main download mirror is located at:
  6003.  
  6004. `http://download.sourceforge.net/mirrors/mysql/'
  6005.  
  6006. If you are interested in becoming a MySQL mirror site, you may
  6007. anonymously rsync with: `rsync://download.sourceforge.net/mysql/'.
  6008. Please send e-mail to <webmaster@mysql.com> notifying us of your mirror
  6009. to be added to the list below.
  6010.  
  6011. If you have problems downloading from our main site, try using one of
  6012. the mirrors listed below.
  6013.  
  6014. Please report bad or out-of-date mirrors to <webmaster@mysql.com>.
  6015.  
  6016. *Europe:*
  6017.  
  6018.    *  Austria [Univ. of Technology/Vienna]  WWW
  6019.      (http://gd.tuwien.ac.at/db/mysql/) FTP
  6020.      (ftp://gd.tuwien.ac.at/db/mysql/)
  6021.  
  6022.    *  Bulgaria [online.bg/Sofia]  WWW (http://mysql.online.bg/) FTP
  6023.      (ftp://mysql.online.bg/)
  6024.  
  6025.    *  Czech Republic [Masaryk University in Brno]  WWW
  6026.      (http://mysql.linux.cz/index.html) FTP
  6027.      (ftp://ftp.fi.muni.cz/pub/mysql/)
  6028.  
  6029.    *  Czech Republic [www.sopik.cz]  WWW (http://www.mysql.cz/)
  6030.  
  6031.    *  Czech Republic [www.gin.cz]  WWW (http://mysql.gin.cz/) FTP
  6032.      (ftp://ftp.gin.cz/pub/MIRRORS/www.mysql.com/)
  6033.  
  6034.    *  Denmark [Borsen]  WWW (http://mysql.borsen.dk/)
  6035.  
  6036.    *  Denmark [SunSITE]  WWW (http://mirrors.sunsite.dk/mysql/) FTP
  6037.      (ftp://sunsite.dk/mirrors/mysql/)
  6038.  
  6039.    *  Estonia [OKinteractive]  WWW (http://mysql.mirror.ok.ee)
  6040.  
  6041.    *  France [mtesa.net]  WWW (http://mysql.mtesa.net/)
  6042.  
  6043.    *  France [fastorama.com, Chatenois]  WWW
  6044.      (http://mysql.fastorama.com/) FTP
  6045.      (ftp://ftp.fastorama.com/unix/mysql/)
  6046.  
  6047.    *  Finland [tonnikala.net]  WWW (http://mysql.tonnikala.org/)
  6048.  
  6049.    *  Germany [Kernelnotes.de, Bonn]  WWW
  6050.      (http://www.kernelnotes.de/mysql/) FTP
  6051.      (ftp://ftp.kernelnotes.de/pub/mirror/mysql.org/)
  6052.  
  6053.    *  Germany [Wolfenbuettel]  WWW
  6054.      (http://www.fh-wolfenbuettel.de/ftp/pub/database/mysql/) FTP
  6055.      (ftp://ftp.fh-wolfenbuettel.de/pub/database/mysql/)
  6056.  
  6057.    *  Greece [NTUA, Athens]  WWW (http://www.ntua.gr/mysql/) FTP
  6058.      (ftp://ftp.ntua.gr/pub/databases/mysql/)
  6059.  
  6060.    *  Hungary [Xenia]  WWW (http://mysql.sote.hu/) FTP
  6061.      (ftp://xenia.sote.hu/pub/mirrors/www.mysql.com/)
  6062.  
  6063.    *  Hungary [TiszaneT]  WWW (http://mysql.tiszanet.hu/) FTP
  6064.      (ftp://mysql.tiszanet.hu/pub/mirrors/mysql/)
  6065.  
  6066.    *  Hungary [stop.hu]  WWW (http://mysql.mirror.stop.hu/)
  6067.  
  6068.    *  Iceland [GM]  WWW (http://mysql.gm.is/) FTP
  6069.      (ftp://ftp.gm.is/pub/mysql/)
  6070.  
  6071.    *  Italy [feelinglinux.com]  WWW (http://mysql.feelinglinux.com/)
  6072.  
  6073.    *  Italy [Teta Srl]  WWW (http://www.teta.it/mysql/)
  6074.  
  6075.    *  Italy [tzone.it]  WWW (http://mysql.tzone.it/)
  6076.  
  6077.    *  Ireland [Esat Net]  WWW
  6078.      (http://ftp.esat.net/mirrors/download.sourceforge.net/pub/mirrors/mysql/)
  6079.      FTP
  6080.      (ftp://ftp.esat.net/mirrors/download.sourceforge.net/pub/mirrors/mysql/)
  6081.  
  6082.    *  Latvia [linux.lv]  FTP (ftp://ftp.linux.lv/pub/software/mysql/)
  6083.  
  6084.    *  Netherlands [Silverpoint]  WWW (http://mysql.silverpoint.nl/)
  6085.  
  6086.    *  Netherlands [Widexs BV]  WWW (http://mysql.widexs.nl/) FTP
  6087.      (ftp://mysql.widexs.nl/pub/mysql/)
  6088.  
  6089.    *  Netherlands [ProServe]  WWW (http://mysql.proserve.nl/)
  6090.  
  6091.    *  Poland [Sunsite]  WWW (http://sunsite.icm.edu.pl/mysql/) FTP
  6092.      (ftp://sunsite.icm.edu.pl/pub/unix/mysql/)
  6093.  
  6094.    *  Poland [ncservice.com/Gdansk]  WWW (http://mysql.service.net.pl/)
  6095.  
  6096.    *  Portugal [Netc]  WWW (http://ftp.netc.pt/pub/mysql/) FTP
  6097.      (ftp://ftp.netc.pt/pub/mysql/)
  6098.  
  6099.    *  Romania [roedu.net/Bucharest]  FTP
  6100.      (ftp://ftp.roedu.net/pub/mirrors/ftp.mysql.com/)
  6101.  
  6102.    *  Russia [DirectNet]  WWW (http://mysql.directnet.ru/) FTP
  6103.      (ftp://ftp.dn.ru/pub/MySQL/)
  6104.  
  6105.    *  Russia [Scientific Center/Chernogolovka]  FTP
  6106.      (ftp://ftp.chg.ru/pub/databases/mysql/)
  6107.  
  6108.    *  Sweden [Sunet]  WWW
  6109.      (http://ftp.sunet.se/pub/unix/databases/relational/mysql/) FTP
  6110.      (ftp://ftp.sunet.se/pub/unix/databases/relational/mysql/)
  6111.  
  6112.    *  Switzerland [Sunsite]  WWW
  6113.      (http://sunsite.cnlab-switch.ch/ftp/mirror/mysql/) FTP
  6114.      (ftp://sunsite.cnlab-switch.ch/mirror/mysql/)
  6115.  
  6116.    *  UK [PLiG/UK]  WWW (http://ftp.plig.org/pub/mysql/) FTP
  6117.      (ftp://ftp.plig.org/pub/mysql/)
  6118.  
  6119.    *  Ukraine [PACO]  WWW (http://mysql.paco.net.ua) FTP
  6120.      (ftp://mysql.paco.net.ua/)
  6121.  
  6122.    *  Ukraine [ISP Alkar Teleport/Dnepropetrovsk]  WWW
  6123.      (http://mysql.dp.ua/)
  6124.  
  6125.    *  Yugoslavia [bolex.co.yu]  WWW (http://mysql.boa.org.yu/) FTP
  6126.      (ftp://ftp.linux.org.yu/pub/MySQL/)
  6127.  
  6128.  
  6129. *North America:*
  6130.  
  6131.    *  Canada [Tryc]  WWW (http://web.tryc.on.ca/mysql/)
  6132.  
  6133.    *  USA [Hurricane Electric/San Jose]  WWW (http://mysql.he.net/)
  6134.  
  6135.    *  USA [ValueClick, Los Angeles CA]  WWW
  6136.      (http://mysql.valueclick.com/) FTP
  6137.      (ftp://mysql.valueclick.com/pub/mysql/Downloads/)
  6138.  
  6139.    *  USA [Wisconsin University/Wisconsin]  WWW
  6140.      (http://mirror.sit.wisc.edu/mysql/) FTP
  6141.      (ftp://mirror.sit.wisc.edu/mirrors/mysql/)
  6142.  
  6143.    *  USA [LinuxWired/Scottsdale, AZ]  WWW
  6144.      (http://mysql.linuxwired.net/) FTP
  6145.      (ftp://ftp.linuxwired.net/pub/mirrors/mysql/)
  6146.  
  6147.    *  USA [adgrafix.com/Boston, MA]  WWW (http://mysql.adgrafix.com/)
  6148.  
  6149.    *  USA [netNumina/Cambridge, MA]  WWW
  6150.      (http://mysql.mirrors.netnumina.com/)
  6151.  
  6152.    *  USA [Ahaza Systems/Seattle, WA]  WWW
  6153.      (http://mysql.mirrortree.com/) FTP
  6154.      (ftp://mysql.mirrortree.com/pub/mysql/)
  6155.  
  6156.  
  6157. *South America:*
  6158.  
  6159.    *  Argentina [bannerlandia.com]  WWW
  6160.      (http://mysql.bannerlandia.com.ar/) FTP
  6161.      (ftp://mysql.bannerlandia.com.ar/mirrors/mysql/)
  6162.  
  6163.    *  Chile [Vision]  WWW (http://mysql.vision.cl/)
  6164.  
  6165.    *  Chile [PSINet]  WWW (http://mysql.psinet.cl/) FTP
  6166.      (ftp://ftp.psinet.cl/pub/database/mysql/)
  6167.  
  6168.    *  Chile [Tecnoera]  WWW (http://mysql.tecnoera.com/)
  6169.  
  6170.  
  6171. *Asia:*
  6172.  
  6173.    *  China [linuxforum.net]  WWW
  6174.      (http://www2.linuxforum.net/mirror/mysql/)
  6175.  
  6176.    *  China [HKLPG/Hong Kong]  WWW (http://mysql.hklpg.org)
  6177.  
  6178.    *  China [Gremlins/Hong Kong]  WWW (http://mysql.gremlins.com.hk/)
  6179.      FTP (ftp://ftp.mirrors.gremlins.com.hk/mysql/)
  6180.  
  6181.    *  China [shellhung.org/Hong Kong]  WWW (http://mysql.shellhung.org/)
  6182.      FTP (ftp://ftp.shellhung.org/pub/Mirror/mysql/)
  6183.  
  6184.    *  Indonesia [incaf.net]  WWW (http://mysql.incaf.net/)
  6185.  
  6186.    *  Indonesia [web.id]  WWW (http://mysql.itb.web.id/) FTP
  6187.      (ftp://mysql.itb.web.id/pub/MySQL/)
  6188.  
  6189.    *  Japan [Soft Agency]  WWW (http://www.softagency.co.jp/MySQL)
  6190.  
  6191.    *  Japan [u-aizu.ac.jp/Aizu]  FTP
  6192.      (ftp://ftp.u-aizu.ac.jp/ftp/pub/dbms/mysql/mysql.com)
  6193.  
  6194.    *  South Korea [Webiiz]  WWW (http://mysql.webiiz.com/)
  6195.  
  6196.    *  South Korea [PanworldNet]  WWW (http://mysql.holywar.net/)
  6197.  
  6198.    *  Singapore [HJC]  WWW (http://mysql.hjc.edu.sg) FTP
  6199.      (ftp://ftp.hjc.edu.sg/mysql)
  6200.  
  6201.    *  Taiwan [TTN]  WWW (http://mysql.ttn.net)
  6202.  
  6203.    *  Taiwan [nctu.edu/HsinChu]  WWW (http://mysql.nctu.edu.tw/)
  6204.  
  6205.  
  6206. *Africa:*
  6207.  
  6208.    *  South-Africa [Mweb]  WWW (http://www.mysql.mweb.co.za/)
  6209.  
  6210.    *  South Africa [The Internet Solution/Johannesburg]  FTP
  6211.      (ftp://ftp.is.co.za/linux/mysql/)
  6212.  
  6213.  
  6214. Operating Systems Supported by MySQL
  6215. ------------------------------------
  6216.  
  6217. We use GNU Autoconf, so it is possible to port MySQL to all modern
  6218. systems with working Posix threads and a C++ compiler.  (To compile
  6219. only the client code, a C++ compiler is required but not threads.)  We
  6220. use and develop the software ourselves primarily on Sun Solaris
  6221. (Versions 2.5 - 2.7) and SuSE Linux Version 7.x.
  6222.  
  6223. Note that for many operating systems, the native thread support works
  6224. only in the latest versions. MySQL has been reported to compile
  6225. successfully on the following operating system/thread package
  6226. combinations:
  6227.  
  6228.    * AIX 4.x with native threads.  *Note IBM-AIX::.
  6229.  
  6230.    * Amiga.
  6231.  
  6232.    * BSDI 2.x with the included MIT-pthreads package.  *Note BSDI::.
  6233.  
  6234.    * BSDI 3.0, 3.1 and 4.x with native threads.  *Note BSDI::.
  6235.  
  6236.    * DEC Unix 4.x with native threads.  *Note Alpha-DEC-UNIX::.
  6237.  
  6238.    * FreeBSD 2.x with the included MIT-pthreads package.  *Note
  6239.      FreeBSD::.
  6240.  
  6241.    * FreeBSD 3.x and 4.x with native threads.  *Note FreeBSD::.
  6242.  
  6243.    * HP-UX 10.20 with the included MIT-pthreads package.  *Note HP-UX
  6244.      10.20::.
  6245.  
  6246.    * HP-UX 11.x with the native threads.  *Note HP-UX 11.x::.
  6247.  
  6248.    * Linux 2.0+ with LinuxThreads 0.7.1+ or `glibc' 2.0.7+.  *Note
  6249.      Linux::.
  6250.  
  6251.    * Mac OS X Server.  *Note Mac OS X::.
  6252.  
  6253.    * NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (Requires GNU make).
  6254.      *Note NetBSD::.
  6255.  
  6256.    * OpenBSD > 2.5 with native therads. OpenBSD < 2.5 with the included
  6257.      MIT-pthreads package.  *Note OpenBSD::.
  6258.  
  6259.    * OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4.  *Note OS/2::.
  6260.  
  6261.    * SGI Irix 6.x with native threads.  *Note SGI-Irix::.
  6262.  
  6263.    * Solaris 2.5 and above with native threads on SPARC and x86.  *Note
  6264.      Solaris::.
  6265.  
  6266.    * SunOS 4.x with the included MIT-pthreads package.  *Note Solaris::.
  6267.  
  6268.    * SCO OpenServer with a recent port of the FSU Pthreads package.
  6269.      *Note SCO::.
  6270.  
  6271.    * SCO UnixWare 7.0.1.  *Note SCO Unixware::.
  6272.  
  6273.    * Tru64 Unix
  6274.  
  6275.    * Win95, Win98, NT, and Win2000.  *Note Windows::.
  6276.  
  6277. Note that not all platforms are suited equally well for running MySQL.
  6278. How well a certain platform is suited for a high-load mission critical
  6279. MySQL server is determined by the following factors:
  6280.  
  6281.    * General stability of the thread library. A platform may have
  6282.      excellent reputation otherwise, but if the thread library is
  6283.      unstable in the code that is called by MySQL, even if everything
  6284.      else is perfect, MySQL will be only as stable as the thread
  6285.      library.
  6286.  
  6287.    * The ability of the kernel and/or thread library to take advantage
  6288.      of *SMP* on multi-processor systems. In other words, when a process
  6289.      creates a thread, it should be possible for that thread to run on
  6290.      a different CPU than the original process.
  6291.  
  6292.    * The ability of the kernel and/or the thread library to run many
  6293.      threads which acquire/release a mutex over a short critical region
  6294.      frequently without excessive context switches. In other words, if
  6295.      the implementation of `pthread_mutex_lock()' is too anxious to
  6296.      yield CPU, this will hurt MySQL tremendously. If this issue is not
  6297.      taken care of, adding extra CPUs will actually make MySQL slower.
  6298.  
  6299.    * General file system stability/performance.
  6300.  
  6301.    * Ability of the file system to deal with large files at all and
  6302.      deal with them efficiently, if your tables are big.
  6303.  
  6304.    * Our level of expertise here at MySQL AB with the platform. If we
  6305.      know a platform well, we introduce platform-specific
  6306.      optimizations/fixes enabled at compile time. We can also provide
  6307.      advice on configuring your system optimally for MySQL.
  6308.  
  6309.    * The amount of testing of similar configurations we have done
  6310.      internally.
  6311.  
  6312.    * The number of users that have successfully run MySQL on that
  6313.      platform in similar configurations. If this number is high, the
  6314.      chances of hitting some platform-specific surprise are much
  6315.      smaller.
  6316.  
  6317. Based on the above criteria, the best platforms for running MySQL at
  6318. this point are x86 with SuSE Linux 7.1, 2.4 kernel and ReiserFS (or any
  6319. similar Linux distribution) and Sparc with Solaris 2.7 or 2.8. FreeBSD
  6320. comes third, but we really hope it will join the top club once the
  6321. thread library is improved. We also hope that at some point we will be
  6322. able to include all other platforms on which MySQL compiles, runs ok,
  6323. but not quite with the same level of stability and performance, into
  6324. the top category. This will require some effort on our part in
  6325. cooperation with the developers of the OS/library components MySQL
  6326. depends upon. If you are interested in making one of those components
  6327. better, are in a position to influence their development, and need more
  6328. detailed instructions on what MySQL needs to run better, send an e-mail
  6329. to <internals@lists.mysql.com>.
  6330.  
  6331. Please note that the comparison above is not to say that one OS is
  6332. better or worse than the other in general. We are talking about
  6333. choosing a particular OS for a dedicated purpose - running MySQL, and
  6334. compare platforms in that regard only. With this in mind, the result of
  6335. this comparison would be different if we included more issues into it.
  6336. And in some cases, the reason one OS is better than the other could
  6337. simply be that we have put forth more effort into testing on and
  6338. optimizing for that particular platform.  We are just stating our
  6339. observations to help you make a decision on which platform to use MySQL
  6340. on in your setup.
  6341.  
  6342. Which MySQL Version to Use
  6343. --------------------------
  6344.  
  6345. The first decision to make is whether you want to use the latest
  6346. development release or the last stable release:
  6347.  
  6348.    * Normally, if you are beginning to use MySQL for the first time or
  6349.      trying to port it to some system for which there is no binary
  6350.      distribution, we recommend going with the stable release (currently
  6351.      Version 3.23.44.  Note that all MySQL releases are checked with
  6352.      the MySQL benchmarks and an extensive test suite before each
  6353.      release.
  6354.  
  6355.    * Otherwise, if you are running an old system and want to upgrade,
  6356.      but don't want to take chances with a non-seamless upgrade, you
  6357.      should upgrade to the latest in the same branch you are using
  6358.      (where only the last version number is newer than yours).  We have
  6359.      tried to fix only fatal bugs and make small, relatively safe
  6360.      changes to that version.
  6361.  
  6362. The second decision to make is whether you want to use a source
  6363. distribution or a binary distribution.  In most cases you should
  6364. probably use a binary distribution, if one exists for your platform, as
  6365. this generally will be easier to install than a source distribution.
  6366.  
  6367. In the following cases you probably will be better off with a source
  6368. installation:
  6369.  
  6370.    * If you want to install MySQL at some explicit location.  (The
  6371.      standard binary distributions are "ready to run" at any place, but
  6372.      you may want to get even more flexibility).
  6373.  
  6374.    * To be able to satisfy different user requirements, we are
  6375.      providing two different binary versions; One compiled with the
  6376.      non-transactional table handlers, (a small, fast binary), and one
  6377.      configured with the most important extended options like
  6378.      transaction-safe tables.  Both versions are compiled from the same
  6379.      source distribution.  All native `MySQL' clients can connect to
  6380.      both MySQL versions.
  6381.  
  6382.      The extended MySQL binary distribution is marked with the `-max'
  6383.      suffix and is configured with the same options as `mysqld-max'.
  6384.      *Note `mysqld-max': mysqld-max.
  6385.  
  6386.      If you want to use the `MySQL-Max' RPM, you must first install the
  6387.      standard `MySQL' RPM.
  6388.  
  6389.    * If you want to configure `mysqld' with some extra features that are
  6390.      NOT in the standard binary distributions.  Here is a list of the
  6391.      most common extra options that you may want to use:
  6392.  
  6393.         * `--with-berkeley-db'
  6394.  
  6395.         * `--with-innodb'
  6396.  
  6397.         * `--with-raid'
  6398.  
  6399.         * `--with-libwrap'
  6400.  
  6401.         * `--with-named-z-lib  (This is done for some of the binaries)'
  6402.  
  6403.         * `--with-debug[=full]'
  6404.  
  6405.    * The default binary distribution is normally compiled with support
  6406.      for all characters sets and should work on a variety of processors
  6407.      from the same processor family.
  6408.  
  6409.      If you want a faster MySQL server you may want to recompile it
  6410.      with support for only the character sets you need, use a better
  6411.      compiler (like `pgcc') or use compiler options that are better
  6412.      optimized for your processor.
  6413.  
  6414.    * If you have found a bug and reported it to the MySQL development
  6415.      team you will probably receive a patch that you need to apply to
  6416.      the source distribution to get the bug fixed.
  6417.  
  6418.    * If you want to read (and/or modify) the C and C++ code that makes
  6419.      up MySQL, you should get a source distribution.  The source code is
  6420.      always the ultimate manual.  Source distributions also contain more
  6421.      tests and examples than binary distributions.
  6422.  
  6423. The MySQL naming scheme uses release numbers that consist of three
  6424. numbers and a suffix.  For example, a release name like
  6425. `mysql-3.21.17-beta' is interpreted like this:
  6426.  
  6427.    * The first number (`3') describes the file format.  All Version 3
  6428.      releases have the same file format.
  6429.  
  6430.    * The second number (`21') is the release level.  Normally there are
  6431.      two to choose from. One is the release/stable branch (currently
  6432.      `23') and the other is the development branch (currently `4.0').
  6433.      Normally both are stable, but the development version may have
  6434.      quirks, missing documentation on new features, or may fail to
  6435.      compile on some systems.
  6436.  
  6437.    * The third number (`17') is the version number within the release
  6438.      level.  This is incremented for each new distribution.  Usually you
  6439.      want the latest version for the release level you have chosen.
  6440.  
  6441.    * The suffix (`beta') indicates the stability level of the release.
  6442.      The possible suffixes are:
  6443.  
  6444.         - `alpha' indicates that the release contains some large
  6445.           section of new code that hasn't been 100% tested.  Known bugs
  6446.           (usually there are none) should be documented in the News
  6447.           section.  *Note News::.  There are also new commands and
  6448.           extensions in most alpha releases.  Active development that
  6449.           may involve major code changes can occur on an alpha release,
  6450.           but everything will be tested before doing a release.  There
  6451.           should be no known bugs in any MySQL release.
  6452.  
  6453.         - `beta' means that all new code has been tested.  No major new
  6454.           features that could cause corruption on old code are added.
  6455.           There should be no known bugs.  A version changes from alpha
  6456.           to beta when there haven't been any reported fatal bugs
  6457.           within an alpha version for at least a month and we don't
  6458.           plan to add any features that could make any old command more
  6459.           unreliable.
  6460.  
  6461.         - `gamma' is a beta that has been around a while and seems to
  6462.           work fine.  Only minor fixes are added.  This is what many
  6463.           other companies call a release.
  6464.  
  6465.         - If there is no suffix, it means that the version has been run
  6466.           for a while at many different sites with no reports of bugs
  6467.           other than platform-specific bugs.  Only critical bug fixes
  6468.           are applied to the release. This is what we call a stable
  6469.           release.
  6470.  
  6471. All versions of MySQL are run through our standard tests and benchmarks
  6472. to ensure that they are relatively safe to use.  Because the standard
  6473. tests are extended over time to check for all previously found bugs,
  6474. the test suite keeps getting better.
  6475.  
  6476. Note that all releases have been tested at least with:
  6477.  
  6478. An internal test suite
  6479.      This is part of a production system for a customer.  It has many
  6480.      tables with hundreds of megabytes of data.
  6481.  
  6482. The MySQL benchmark suite
  6483.      This runs a range of common queries.  It is also a test to see
  6484.      whether the latest batch of optimizations actually made the code
  6485.      faster.  *Note MySQL Benchmarks::.
  6486.  
  6487. The `crash-me' test
  6488.      This tries to determine what features the database supports and
  6489.      what its capabilities and limitations are.  *Note MySQL
  6490.      Benchmarks::.
  6491.  
  6492. Another test is that we use the newest MySQL version in our internal
  6493. production environment, on at least one machine.  We have more than 100
  6494. gigabytes of data to work with.
  6495.  
  6496. Installation Layouts
  6497. --------------------
  6498.  
  6499. This section describes the default layout of the directories created by
  6500. installing binary and source distributions.
  6501.  
  6502. A binary distribution is installed by unpacking it at the installation
  6503. location you choose (typically `/usr/local/mysql') and creates the
  6504. following directories in that location:
  6505.  
  6506. *Directory*            *Contents of directory*
  6507. `bin'                  Client programs and the `mysqld' server
  6508. `data'                 Log files, databases
  6509. `include'              Include (header) files
  6510. `lib'                  Libraries
  6511. `scripts'              `mysql_install_db'
  6512. `share/mysql'          Error message files
  6513. `sql-bench'            Benchmarks
  6514.  
  6515. A source distribution is installed after you configure and compile it.
  6516. By default, the installation step installs files under `/usr/local', in
  6517. the following subdirectories:
  6518.  
  6519. *Directory*            *Contents of directory*
  6520. `bin'                  Client programs and scripts
  6521. `include/mysql'        Include (header) files
  6522. `info'                 Documentation in Info format
  6523. `lib/mysql'            Libraries
  6524. `libexec'              The `mysqld' server
  6525. `share/mysql'          Error message files
  6526. `sql-bench'            Benchmarks and `crash-me' test
  6527. `var'                  Databases and log files
  6528.  
  6529. Within an installation directory, the layout of a source installation
  6530. differs from that of a binary installation in the following ways:
  6531.  
  6532.    * The `mysqld' server is installed in the `libexec' directory rather
  6533.      than in the `bin' directory.
  6534.  
  6535.    * The data directory is `var' rather than `data'.
  6536.  
  6537.    * `mysql_install_db' is installed in the `/usr/local/bin' directory
  6538.      rather than in `/usr/local/mysql/scripts'.
  6539.  
  6540.    * The header file and library directories are `include/mysql' and
  6541.      `lib/mysql' rather than `include' and `lib'.
  6542.  
  6543. You can create your own binary installation from a compiled source
  6544. distribution by executing the script `scripts/make_binary_distribution'.
  6545.  
  6546. How and When Updates Are Released
  6547. ---------------------------------
  6548.  
  6549. MySQL is evolving quite rapidly here at MySQL AB and we want to share
  6550. this with other MySQL users.  We try to make a release when we have
  6551. very useful features that others seem to have a need for.
  6552.  
  6553. We also try to help out users who request features that are easy to
  6554. implement.  We take note of what our licensed users want to have, and
  6555. we especially take note of what our extended e-mail supported customers
  6556. want and try to help them out.
  6557.  
  6558. No one has to download a new release.  The News section will tell you if
  6559. the new release has something you really want.  *Note News::.
  6560.  
  6561. We use the following policy when updating MySQL:
  6562.  
  6563.    * For each minor update, the last number in the version string is
  6564.      incremented.  When there are major new features or minor
  6565.      incompatibilities with previous versions, the second number in the
  6566.      version string is incremented.  When the file format changes, the
  6567.      first number is increased.
  6568.  
  6569.    * Stable tested releases are meant to appear about 1-2 times a year,
  6570.      but if small bugs are found, a release with only bug fixes will be
  6571.      released.
  6572.  
  6573.    * Working releases are meant to appear about every 1-8 weeks.
  6574.  
  6575.    * Binary distributions for some platforms will be made by us for
  6576.      major releases.  Other people may make binary distributions for
  6577.      other systems but probably less frequently.
  6578.  
  6579.    * We usually make patches available as soon as we have located and
  6580.      fixed small bugs.
  6581.  
  6582.    * For non-critical but annoying bugs, we will make patches available
  6583.      if they are sent to us.  Otherwise we will combine many of them
  6584.      into a larger patch.
  6585.  
  6586.    * If there is, by any chance, a fatal bug in a release we will make
  6587.      a new release as soon as possible.  We would like other companies
  6588.      to do this, too.
  6589.  
  6590. The current stable release is Version 3.23; We have already moved active
  6591. development to Version 4.0.  Bugs will still be fixed in the stable
  6592. version.  We don't believe in a complete freeze, as this also leaves
  6593. out bug fixes and things that "must be done."  "Somewhat frozen" means
  6594. that we may add small things that "almost surely will not affect
  6595. anything that's already working."
  6596.  
  6597. MySQL Binaries Compiled by MySQL AB
  6598. -----------------------------------
  6599.  
  6600. As a service, we at MySQL AB provide a set of binary distributions of
  6601. MySQL that are compiled at our site or at sites where customers kindly
  6602. have given us access to their machines.
  6603.  
  6604. These distributions are generated with
  6605. `scripts/make_binary_distribution' and are configured with the
  6606. following compilers and options:
  6607.  
  6608. SunOS 4.1.4 2 sun4c with `gcc' 2.7.2.1
  6609.      `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors" ./configure
  6610.      --prefix=/usr/local/mysql --disable-shared
  6611.      --with-extra-charsets=complex --enable-assembler'
  6612.  
  6613. SunOS 5.5.1 (and above) sun4u with `egcs' 1.0.3a or 2.90.27 or gcc 2.95.2 and newer
  6614.      `CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors
  6615.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  6616.      --with-low-memory --with-extra-charsets=complex --enable-assembler'
  6617.  
  6618. SunOS 5.6 i86pc with `gcc' 2.8.1
  6619.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6620.      --with-low-memory --with-extra-charsets=complex'
  6621.  
  6622. Linux 2.0.33 i386 with `pgcc' 2.90.29 (`egcs' 1.0.3a)
  6623.      `CFLAGS="-O3 -mpentium -mstack-align-double" CXX=gcc CXXFLAGS="-O3
  6624.      -mpentium -mstack-align-double -felide-constructors
  6625.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  6626.      --enable-assembler --with-mysqld-ldflags=-all-static
  6627.      --with-extra-charsets=complex'
  6628.  
  6629. Linux 2.2.x with x686 with `gcc' 2.95.2
  6630.      `CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  6631.      -felide-constructors -fno-exceptions -fno-rtti" ./configure
  6632.      --prefix=/usr/local/mysql --enable-assembler
  6633.      --with-mysqld-ldflags=-all-static --disable-shared
  6634.      --with-extra-charset=complex'
  6635.  
  6636. SCO 3.2v5.0.4 i386 with `gcc' 2.7-95q4
  6637.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6638.      --with-extra-charsets=complex'
  6639.  
  6640. AIX 2 4 with `gcc' 2.7.2.2
  6641.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6642.      --with-extra-charsets=complex'
  6643.  
  6644. OSF1 V4.0 564 alpha with `gcc' 2.8.1
  6645.      `CC=gcc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 ./configure
  6646.      --prefix=/usr/local/mysql --with-low-memory
  6647.      --with-extra-charsets=complex'
  6648.  
  6649. Irix 6.3 IP32 with `gcc' 2.8.0
  6650.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6651.      --with-extra-charsets=complex'
  6652.  
  6653. BSDI BSD/OS 3.1 i386 with `gcc' 2.7.2.1
  6654.      `CC=gcc CXX=gcc CXXFLAGS=-O ./configure --prefix=/usr/local/mysql
  6655.      --with-extra-charsets=complex'
  6656.  
  6657. BSDI BSD/OS 2.1 i386 with `gcc' 2.7.2
  6658.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6659.      --with-extra-charsets=complex'
  6660.  
  6661. Anyone who has more optimal options for any of the configurations listed
  6662. above can always mail them to the developer's mailing list at
  6663. <internals@lists.mysql.com>.
  6664.  
  6665. RPM distributions prior to MySQL Version 3.22 are user-contributed.
  6666. Beginning with Version 3.22, the RPMs are generated by us at MySQL AB.
  6667.  
  6668. If you want to compile a debug version of MySQL, you should add
  6669. `--with-debug' or `--with-debug=full' to the above configure lines and
  6670. remove any `-fomit-frame-pointer' options.
  6671.  
  6672. Installing a MySQL Source Distribution
  6673. ======================================
  6674.  
  6675. Before you proceed with the source installation, check first to see if
  6676. our binary is available for your platform and if it will work for you.
  6677. We put in a lot of effort into making sure that our binaries are built
  6678. with the best possible options.
  6679.  
  6680. You need the following tools to build and install MySQL from source:
  6681.  
  6682.    * GNU `gunzip' to uncompress the distribution.
  6683.  
  6684.    * A reasonable `tar' to unpack the distribution.  GNU `tar' is known
  6685.      to work.  Sun `tar' is known to have problems.
  6686.  
  6687.    * A working ANSI C++ compiler.  `gcc' >= 2.95.2, `egcs' >= 1.0.2 or
  6688.      `egcs 2.91.66', SGI C++, and SunPro C++ are some of the compilers
  6689.      that are known to work.  `libg++' is not needed when using `gcc'.
  6690.      `gcc' 2.7.x has a bug that makes it impossible to compile some
  6691.      perfectly legal C++ files, such as `sql/sql_base.cc'.  If you only
  6692.      have `gcc' 2.7.x, you must upgrade your `gcc' to be able to
  6693.      compile MySQL. `gcc' 2.8.1 is also known to have problems on some
  6694.      platforms so it should be avoided if there exists a new compiler
  6695.      for the platform..
  6696.  
  6697.      `gcc' >= 2.95.2 is recommended when compiling MySQL Version 3.23.x.
  6698.  
  6699.    * A good `make' program.  GNU `make' is always recommended and is
  6700.      sometimes required.  If you have problems, we recommend trying GNU
  6701.      `make' 3.75 or newer.
  6702.  
  6703. If you are using a recent version of *gcc*, recent enough to understand
  6704. `-fno-exceptions' option, it is *VERY IMPORTANT* that you use it.
  6705. Otherwise, you may compile a binary that crashes randomly. We also
  6706. recommend that you use `-felide-contructors' and `-fno-rtti' along with
  6707. `-fno-exceptions'. When in doubt, do the following:
  6708.  
  6709.  
  6710.      CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static
  6711.  
  6712. On most systems this will give you a fast and stable binary.
  6713.  
  6714. If you run into problems, *PLEASE ALWAYS USE `mysqlbug'* when posting
  6715. questions to <mysql@lists.mysql.com>.  Even if the problem isn't a bug,
  6716. `mysqlbug' gathers system information that will help others solve your
  6717. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  6718. a solution to your problem!  You will find `mysqlbug' in the `scripts'
  6719. directory after you unpack the distribution.  *Note Bug reports::.
  6720.  
  6721. Quick Installation Overview
  6722. ---------------------------
  6723.  
  6724. The basic commands you must execute to install a MySQL source
  6725. distribution are:
  6726.  
  6727.      shell> groupadd mysql
  6728.      shell> useradd -g mysql mysql
  6729.      shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
  6730.      shell> cd mysql-VERSION
  6731.      shell> ./configure --prefix=/usr/local/mysql
  6732.      shell> make
  6733.      shell> make install
  6734.      shell> scripts/mysql_install_db
  6735.      shell> chown -R root  /usr/local/mysql
  6736.      shell> chown -R mysql /usr/local/mysql/var
  6737.      shell> chgrp -R mysql /usr/local/mysql
  6738.      shell> cp support-files/my-medium.cnf /etc/my.cnf
  6739.      shell> /usr/local/mysql/bin/safe_mysqld --user=mysql &
  6740.  
  6741. If you want have support for InnoDB tables, you should edit the
  6742. `/etc/my.cnf' file and remove the `#' character before the parameters
  6743. that starts with `innodb_...'. *Note Option files::. *Note InnoDB
  6744. start::.
  6745.  
  6746. If you start from a source RPM, then do the following:
  6747.  
  6748.      shell> rpm --rebuild MySQL-VERSION.src.rpm
  6749.  
  6750. This will make a binary RPM that you can install.
  6751.  
  6752. You can add new users using the `bin/mysql_setpermission' script if you
  6753. install the `DBI' and `Msql-Mysql-modules' Perl modules.
  6754.  
  6755. A more detailed description follows.
  6756.  
  6757. To install a source distribution, follow the steps below, then proceed
  6758. to *Note Post-installation::, for post-installation initialization and
  6759. testing:
  6760.  
  6761.   1. Pick the directory under which you want to unpack the
  6762.      distribution, and move into it.
  6763.  
  6764.   2. Obtain a distribution file from one of the sites listed in *Note
  6765.      Getting MySQL: Getting MySQL.
  6766.  
  6767.   3. If you are interested in using Berkeley DB tables with MySQL, you
  6768.      will need to obtain a patched version of the Berkeley DB source
  6769.      code.  Please read the chapter on Berkeley DB tables before
  6770.      proceeding.  *Note BDB::.
  6771.  
  6772.      MySQL source distributions are provided as compressed `tar'
  6773.      archives and have names like `mysql-VERSION.tar.gz', where
  6774.      `VERSION' is a number like 3.23.44.
  6775.  
  6776.   4. Add a user and group for `mysqld' to run as:
  6777.  
  6778.           shell> groupadd mysql
  6779.           shell> useradd -g mysql mysql
  6780.  
  6781.      These commands add the `mysql' group, and the `mysql' user.  The
  6782.      syntax for `useradd' and `groupadd' may differ slightly on
  6783.      different versions of Unix.  They may also be called `adduser' and
  6784.      `addgroup'.  You may wish to call the user and group something
  6785.      else instead of `mysql'.
  6786.  
  6787.   5. Unpack the distribution into the current directory:
  6788.           shell> gunzip < /path/to/mysql-VERSION.tar.gz | tar xvf -
  6789.  
  6790.      This command creates a directory named `mysql-VERSION'.
  6791.  
  6792.   6. Change into the top-level directory of the unpacked distribution:
  6793.  
  6794.           shell> cd mysql-VERSION
  6795.  
  6796.      Note that currently you must configure and build MySQL from this
  6797.      top-level directory.  You can not build it in a different
  6798.      directory.
  6799.  
  6800.   7. Configure the release and compile everything:
  6801.  
  6802.           shell> ./configure --prefix=/usr/local/mysql
  6803.           shell> make
  6804.  
  6805.      When you run `configure', you might want to specify some options.
  6806.      Run `./configure --help' for a list of options.  *Note `configure'
  6807.      options: configure options, discusses some of the more useful
  6808.      options.
  6809.  
  6810.      If `configure' fails, and you are going to send mail to
  6811.      <mysql@lists.mysql.com> to ask for assistance, please include any
  6812.      lines from `config.log' that you think can help solve the problem.
  6813.      Also include the last couple of lines of output from `configure'
  6814.      if `configure' aborts.  Post the bug report using the `mysqlbug'
  6815.      script.  *Note Bug reports::.
  6816.  
  6817.      If the compile fails, see *Note Compilation problems::, for help
  6818.      with a number of common problems.
  6819.  
  6820.   8. Install everything:
  6821.  
  6822.           shell> make install
  6823.  
  6824.      You might need to run this command as `root'.
  6825.  
  6826.   9. Create the MySQL grant tables (necessary only if you haven't
  6827.      installed MySQL before):
  6828.  
  6829.           shell> scripts/mysql_install_db
  6830.  
  6831.      Note that MySQL versions older than Version 3.22.10 started the
  6832.      MySQL server when you run `mysql_install_db'.  This is no longer
  6833.      true!
  6834.  
  6835.  10. Change ownership of binaries to `root' and ownership of the data
  6836.      directory to the user that you will run `mysqld' as:
  6837.  
  6838.           shell> chown -R root  /usr/local/mysql
  6839.           shell> chown -R mysql /usr/local/mysql/var
  6840.           shell> chgrp -R mysql /usr/local/mysql
  6841.  
  6842.      The first command changes the `owner' attribute of the files to the
  6843.      `root' user, the second one changes the `owner' attribute of the
  6844.      data directory to the `mysql' user, and the third one changes the
  6845.      `group' attribute to the `mysql' group.
  6846.  
  6847.  11. If you want to install support for the Perl `DBI'/`DBD' interface,
  6848.      see *Note Perl support::.
  6849.  
  6850.  12. If you would like MySQL to start automatically when you boot your
  6851.      machine, you can copy `support-files/mysql.server' to the location
  6852.      where your system has its startup files.  More information can be
  6853.      found in the `support-files/mysql.server' script itself and in
  6854.      *Note Automatic start::.
  6855.  
  6856. After everything has been installed, you should initialize and test your
  6857. distribution:
  6858.  
  6859.      shell> /usr/local/mysql/bin/safe_mysqld --user=mysql &
  6860.  
  6861. If that command fails immediately with `mysqld daemon ended' then you
  6862. can find some information in the file
  6863. `mysql-data-directory/'hostname'.err'.  The likely reason is that you
  6864. already have another `mysqld' server running.  *Note Multiple servers::.
  6865.  
  6866. *Note Post-installation::.
  6867.  
  6868. Applying Patches
  6869. ----------------
  6870.  
  6871. Sometimes patches appear on the mailing list or are placed in the
  6872. patches area (http://www.mysql.com/Downloads/Patches) of the MySQL Web
  6873. site.
  6874.  
  6875. To apply a patch from the mailing list, save the message in which the
  6876. patch appears in a file, change into the top-level directory of your
  6877. MySQL source tree, and run these commands:
  6878.  
  6879.      shell> patch -p1 < patch-file-name
  6880.      shell> rm config.cache
  6881.      shell> make clean
  6882.  
  6883. Patches from the FTP site are distributed as plain text files or as
  6884. files compressed with `gzip'.  Apply a plain patch as shown above for
  6885. mailing list patches.  To apply a compressed patch, change into the
  6886. top-level directory of your MySQL source tree and run these commands:
  6887.  
  6888.      shell> gunzip < patch-file-name.gz | patch -p1
  6889.      shell> rm config.cache
  6890.      shell> make clean
  6891.  
  6892. After applying a patch, follow the instructions for a normal source
  6893. install, beginning with the `./configure' step.  After running the `make
  6894. install' step, restart your MySQL server.
  6895.  
  6896. You may need to bring down any currently running server before you run
  6897. `make install'.  (Use `mysqladmin shutdown' to do this.)  Some systems
  6898. do not allow you to install a new version of a program if it replaces
  6899. the version that is currently executing.
  6900.  
  6901. Typical `configure' Options
  6902. ---------------------------
  6903.  
  6904. The `configure' script gives you a great deal of control over how you
  6905. configure your MySQL distribution.  Typically you do this using options
  6906. on the `configure' command line.  You can also affect `configure' using
  6907. certain environment variables.  *Note Environment variables::.  For a
  6908. list of options supported by `configure', run this command:
  6909.  
  6910.      shell> ./configure --help
  6911.  
  6912. Some of the more commonly-used `configure' options are described below:
  6913.  
  6914.    * To compile just the MySQL client libraries and client programs and
  6915.      not the server, use the `--without-server' option:
  6916.  
  6917.           shell> ./configure --without-server
  6918.  
  6919.      If you don't have a C++ compiler, `mysql' will not compile (it is
  6920.      the one client program that requires C++).  In this case, you can
  6921.      remove the code in `configure' that tests for the C++ compiler and
  6922.      then run `./configure' with the `--without-server' option. The
  6923.      compile step will still try to build `mysql', but you can ignore
  6924.      any warnings about `mysql.cc'.  (If `make' stops, try `make -k' to
  6925.      tell it to continue with the rest of the build even if errors
  6926.      occur.)
  6927.  
  6928.    * If you don't want your log files and database directories located
  6929.      under `/usr/local/var', use a `configure' command, something like
  6930.      one of these:
  6931.  
  6932.           shell> ./configure --prefix=/usr/local/mysql
  6933.           shell> ./configure --prefix=/usr/local \
  6934.                      --localstatedir=/usr/local/mysql/data
  6935.  
  6936.      The first command changes the installation prefix so that
  6937.      everything is installed under `/usr/local/mysql' rather than the
  6938.      default of `/usr/local'.  The second command preserves the default
  6939.      installation prefix, but overrides the default location for
  6940.      database directories (normally `/usr/local/var') and changes it to
  6941.      `/usr/local/mysql/data'.
  6942.  
  6943.    * If you are using Unix and you want the MySQL socket located
  6944.      somewhere other than the default location (normally in the
  6945.      directory `/tmp' or `/var/run') use a `configure' command like
  6946.      this:
  6947.  
  6948.           shell> ./configure --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
  6949.  
  6950.      Note that the given file must be an absolute pathname!  You can
  6951.      also later change the location `mysql.sock' by using the MySQL
  6952.      option files. *Note Problems with mysql.sock::.
  6953.  
  6954.    * If you want to compile statically linked programs (for example, to
  6955.      make a binary distribution, to get more speed, or to work around
  6956.      problems with some RedHat Linux distributions), run `configure'
  6957.      like this:
  6958.  
  6959.           shell> ./configure --with-client-ldflags=-all-static \
  6960.                      --with-mysqld-ldflags=-all-static
  6961.  
  6962.    * If you are using `gcc' and don't have `libg++' or `libstdc++'
  6963.      installed, you can tell `configure' to use `gcc' as your C++
  6964.      compiler:
  6965.  
  6966.           shell> CC=gcc CXX=gcc ./configure
  6967.  
  6968.      When you use `gcc' as your C++ compiler, it will not attempt to
  6969.      link in `libg++' or `libstdc++'.
  6970.  
  6971.      Here is some common environment variables to set depending on the
  6972.      compiler you are using:
  6973.  
  6974.      gcc 2.7.2.1    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"
  6975.      egcs 1.0.3a    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors
  6976.                    -fno-exceptions -fno-rtti"
  6977.      gcc 2.95.2     CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3
  6978.                    -mpentiumpro -felide-constructors -fno-exceptions
  6979.                    -fno-rtti"
  6980.      pgcc 2.90.29   CFLAGS="-O3 -mpentiumpro -mstack-align-double"
  6981.      or newer      CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  6982.                    -mstack-align-double -felide-constructors
  6983.                    -fno-exceptions -fno-rtti"
  6984.  
  6985.      In most cases you can get a reasonably optimal MySQL binary by
  6986.      using the options from the above and adding the following options
  6987.      to the configure line:
  6988.  
  6989.           --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static
  6990.  
  6991.      The full configure line would in other words be something like the
  6992.      following for all recent gcc versions:
  6993.  
  6994.           CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static
  6995.  
  6996.      The binaries we provide on the MySQL Web site at
  6997.      `http://www.mysql.com' are all compiled with full optimization and
  6998.      should be perfect for most users.  *Note MySQL binaries::.  There
  6999.      are some things you can tweak to make an even faster binary, but
  7000.      this is only for advanced users.  *Note Compile and link options::.
  7001.  
  7002.      If the build fails and produces errors about your compiler or
  7003.      linker not being able to create the shared library
  7004.      `libmysqlclient.so.#' (`#' is a version number), you can work
  7005.      around this problem by giving the `--disable-shared' option to
  7006.      `configure'.  In this case, `configure' will not build a shared
  7007.      `libmysqlclient.so.#' library.
  7008.  
  7009.    * You can configure MySQL not to use `DEFAULT' column values for
  7010.      non-`NULL' columns (that is, columns that are not allowed to be
  7011.      `NULL').  This causes `INSERT' statements to generate an error
  7012.      unless you explicitly specify values for all columns that require a
  7013.      non-`NULL' value.  To suppress use of default values, run
  7014.      `configure' like this:
  7015.  
  7016.           shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure
  7017.  
  7018.    * By default, MySQL uses the ISO-8859-1 (Latin1) character set. To
  7019.      change the default set, use the `--with-charset' option:
  7020.           shell> ./configure --with-charset=CHARSET
  7021.      `CHARSET' may be one of `big5', `cp1251', `cp1257', `czech',
  7022.      `danish', `dec8', `dos', `euc_kr', `gb2312', `gbk', `german1',
  7023.      `hebrew', `hp8', `hungarian', `koi8_ru', `koi8_ukr', `latin1',
  7024.      `latin2', `sjis', `swe7', `tis620', `ujis', `usa7', or
  7025.      `win1251ukr'.  *Note Character sets::.
  7026.  
  7027.      If you want to convert characters between the server and the
  7028.      client, you should take a look at the `SET OPTION CHARACTER SET'
  7029.      command.  *Note `SET OPTION': SET OPTION.
  7030.  
  7031.      *Warning:* If you change character sets after having created any
  7032.      tables, you will have to run `myisamchk -r -q' on every table. Your
  7033.      indexes may be sorted incorrectly otherwise.  (This can happen if
  7034.      you install MySQL, create some tables, then reconfigure MySQL to
  7035.      use a different character set and reinstall it.)
  7036.  
  7037.      With the option `--with-extra-charset=LIST' you can define which
  7038.      additional character sets should be incompiled in the server.
  7039.  
  7040.      Here `LIST' is either a list of character set separated with space,
  7041.      `complex' to include all characters that can't be dynamically
  7042.      loaded or `all' to include all character sets into the binaries.
  7043.  
  7044.    * To configure MySQL with debugging code, use the `--with-debug'
  7045.      option:
  7046.           shell> ./configure --with-debug
  7047.      This causes a safe memory allocator to be included that can find
  7048.      some errors and that provides output about what is happening.
  7049.      *Note Debugging server::.
  7050.  
  7051.    * If your client programs are using threads, you need to also
  7052.      compile a thread-safe version of the MySQL client library with the
  7053.      `--enable-thread-safe-client' configure options. This will create a
  7054.      `libmysqlclient_r' library with which you should link your threaded
  7055.      applications.  *Note Threaded clients::.
  7056.  
  7057.    * Options that pertain to particular systems can be found in the
  7058.      system-specific section of this manual.  *Note Operating System
  7059.      Specific Notes::.
  7060.  
  7061. Installing from the Development Source Tree
  7062. -------------------------------------------
  7063.  
  7064. *CAUTION:* You should read this section only if you are interested in
  7065. helping us test our new code. If you just want to get MySQL up and
  7066. running on your system, you should use a standard release distribution
  7067. (either a source or binary distribution will do).
  7068.  
  7069. To obtain our most recent development source tree, use these
  7070. instructions:
  7071.  
  7072.   1. Download *BitKeeper* from
  7073.      `http://www.bitmover.com/cgi-bin/download.cgi'.  You will need
  7074.      *Bitkeeper* 2.0 or newer to access our repository.
  7075.  
  7076.   2. Follow the instructions to install it.
  7077.  
  7078.   3. After *BitKeeper* is installed, use this command if you want to
  7079.      clone the MySQL 3.23 branch:
  7080.  
  7081.           shell> bk clone bk://work.mysql.com:7000 mysql
  7082.  
  7083.      To clone the 4.0 branch, use this command instead:
  7084.  
  7085.           shell> bk clone bk://work.mysql.com:7001 mysql-4.0
  7086.  
  7087.      The initial download of the source tree may take a while,
  7088.      depending on the speed of your connection; be patient.
  7089.  
  7090.   4. You will need GNU `autoconf', `automake', `libtool', and `m4' to
  7091.      run the next set of commands.  If you get some strange error
  7092.      during this stage, check that you really have `libtool' installed!
  7093.  
  7094.           shell> cd mysql
  7095.           shell> bk -r edit
  7096.           shell> aclocal; autoheader; autoconf;  automake;
  7097.           shell> ./configure  # Add your favorite options here
  7098.           shell> make
  7099.  
  7100.      A collection of our standard configure scripts is located in the
  7101.      `BUILD/' subdirectory.  If you are lazy, you can use
  7102.      `BUILD/compile-pentium-debug'. To compile on a different
  7103.      architecture, modify the script removing flags that are
  7104.      Pentium-specific.
  7105.  
  7106.   5. When the build is done, run `make install'.  Be careful with this
  7107.      on a production machine; the command may overwrite your live
  7108.      release installation.  If you have another installation of MySQL,
  7109.      we recommand that you run `./configure' with different values for
  7110.      the `prefix', `tcp-port', and `unix-socket-path' options than
  7111.      those used for your production server.
  7112.  
  7113.   6. Play hard with your new installation and try to make the new
  7114.      features crash.  Start by running `make test'.  *Note MySQL test
  7115.      suite::.
  7116.  
  7117.   7. If you have gotten to the `make' stage and the distribution does
  7118.      not compile, please report it to <bugs@lists.mysql.com>.  If you
  7119.      have installed the latest versions of the required GNU tools, and
  7120.      they crash trying to process our configuration files, please
  7121.      report that also.  However, if you execute `aclocal' and get a
  7122.      `command not found' error or a similar problem, do not report it.
  7123.      Instead, make sure all the necessary tools are installed and that
  7124.      your `PATH' variable is set correctly so your shell can find them.
  7125.  
  7126.   8. After the initial `bk clone' operation to get the source tree, you
  7127.      should run `bk pull' periodically to get the updates.
  7128.  
  7129.   9. You can examine the change history for the tree with all the diffs
  7130.      by using `bk sccstool'.  If you see some funny diffs or code that
  7131.      you have a question about, do not hesitate to send e-mail to
  7132.      <internals@lists.mysql.com>.  Also, if you think you have a better
  7133.      idea on how to do something, send an email to the same address
  7134.      with a patch.  `bk diffs' will produce a patch for you after you
  7135.      have made changes to the source. If you do not have the time to
  7136.      code your idea, just send a description.
  7137.  
  7138.  10. *BitKeeper* has a nice help utility that you can access via `bk
  7139.      helptool'.
  7140.  
  7141.  
  7142. Problems Compiling?
  7143. -------------------
  7144.  
  7145. All MySQL programs compile cleanly for us with no warnings on Solaris
  7146. using `gcc'.  On other systems, warnings may occur due to differences
  7147. in system include files.  See *Note MIT-pthreads:: for warnings that
  7148. may occur when using MIT-pthreads.  For other problems, check the list
  7149. below.
  7150.  
  7151. The solution to many problems involves reconfiguring.  If you do need to
  7152. reconfigure, take note of the following:
  7153.  
  7154.    * If `configure' is run after it already has been run, it may use
  7155.      information that was gathered during its previous invocation.  This
  7156.      information is stored in `config.cache'.  When `configure' starts
  7157.      up, it looks for that file and reads its contents if it exists, on
  7158.      the assumption that the information is still correct.  That
  7159.      assumption is invalid when you reconfigure.
  7160.  
  7161.    * Each time you run `configure', you must run `make' again to
  7162.      recompile.  However, you may want to remove old object files from
  7163.      previous builds first, because they were compiled using different
  7164.      configuration options.
  7165.  
  7166. To prevent old configuration information or object files from being
  7167. used, run these commands before rerunning `configure':
  7168.  
  7169.      shell> rm config.cache
  7170.      shell> make clean
  7171.  
  7172. Alternatively, you can run `make distclean'.
  7173.  
  7174. The list below describes some of the problems compiling MySQL that have
  7175. been found to occur most often:
  7176.  
  7177.    * If you get errors when compiling `sql_yacc.cc', such as the ones
  7178.      shown below, you have probably run out of memory or swap space:
  7179.  
  7180.           Internal compiler error: program cc1plus got fatal signal 11
  7181.             or
  7182.           Out of virtual memory
  7183.             or
  7184.           Virtual memory exhausted
  7185.  
  7186.      The problem is that `gcc' requires huge amounts of memory to
  7187.      compile `sql_yacc.cc' with inline functions.  Try running
  7188.      `configure' with the `--with-low-memory' option:
  7189.  
  7190.           shell> ./configure --with-low-memory
  7191.  
  7192.      This option causes `-fno-inline' to be added to the compile line
  7193.      if you are using `gcc' and `-O0' if you are using something else.
  7194.      You should try the `--with-low-memory' option even if you have so
  7195.      much memory and swap space that you think you can't possibly have
  7196.      run out.  This problem has been observed to occur even on systems
  7197.      with generous hardware configurations, and the `--with-low-memory'
  7198.      option usually fixes it.
  7199.  
  7200.    * By default, `configure' picks `c++' as the compiler name and GNU
  7201.      `c++' links with `-lg++'.  If you are using `gcc', that behavior
  7202.      can cause problems during configuration such as this:
  7203.  
  7204.           configure: error: installation or configuration problem:
  7205.           C++ compiler cannot create executables.
  7206.  
  7207.      You might also observe problems during compilation related to
  7208.      `g++', `libg++', or `libstdc++'.
  7209.  
  7210.      One cause of these problems is that you may not have `g++', or you
  7211.      may have `g++' but not `libg++', or `libstdc++'.  Take a look at
  7212.      the `config.log' file.  It should contain the exact reason why
  7213.      your c++ compiler didn't work!  To work around these problems, you
  7214.      can use `gcc' as your C++ compiler.  Try setting the environment
  7215.      variable `CXX' to `"gcc -O3"'.  For example:
  7216.  
  7217.           shell> CXX="gcc -O3" ./configure
  7218.  
  7219.      This works because `gcc' compiles C++ sources as well as `g++'
  7220.      does, but does not link in `libg++' or `libstdc++' by default.
  7221.  
  7222.      Another way to fix these problems, of course, is to install `g++',
  7223.      `libg++' and `libstdc++'.
  7224.  
  7225.    * If your compile fails with errors, such as any of the following,
  7226.      you must upgrade your version of `make' to GNU `make':
  7227.  
  7228.           making all in mit-pthreads
  7229.           make: Fatal error in reader: Makefile, line 18:
  7230.           Badly formed macro assignment
  7231.             or
  7232.           make: file `Makefile' line 18: Must be a separator (:
  7233.             or
  7234.           pthread.h: No such file or directory
  7235.  
  7236.      Solaris and FreeBSD are known to have troublesome `make' programs.
  7237.  
  7238.      GNU `make' Version 3.75 is known to work.
  7239.  
  7240.    * If you want to define flags to be used by your C or C++ compilers,
  7241.      do so by adding the flags to the `CFLAGS' and `CXXFLAGS'
  7242.      environment variables.  You can also specify the compiler names
  7243.      this way using `CC' and `CXX'.  For example:
  7244.  
  7245.           shell> CC=gcc
  7246.           shell> CFLAGS=-O3
  7247.           shell> CXX=gcc
  7248.           shell> CXXFLAGS=-O3
  7249.           shell> export CC CFLAGS CXX CXXFLAGS
  7250.  
  7251.      See *Note MySQL binaries::, for a list of flag definitions that
  7252.      have been found to be useful on various systems.
  7253.  
  7254.    * If you get an error message like this, you need to upgrade your
  7255.      `gcc' compiler:
  7256.  
  7257.           client/libmysql.c:273: parse error before `__attribute__'
  7258.  
  7259.      `gcc' 2.8.1 is known to work, but we recommend using `gcc' 2.95.2
  7260.      or `egcs' 1.0.3a instead.
  7261.  
  7262.    * If you get errors such as those shown below when compiling
  7263.      `mysqld', `configure' didn't correctly detect the type of the last
  7264.      argument to `accept()', `getsockname()', or `getpeername()':
  7265.  
  7266.           cxx: Error: mysqld.cc, line 645: In this statement, the referenced
  7267.                type of the pointer value "&length" is "unsigned long", which
  7268.                is not compatible with "int".
  7269.           new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
  7270.  
  7271.      To fix this, edit the `config.h' file (which is generated by
  7272.      `configure').  Look for these lines:
  7273.  
  7274.           /* Define as the base type of the last arg to accept */
  7275.           #define SOCKET_SIZE_TYPE XXX
  7276.  
  7277.      Change `XXX' to `size_t' or `int', depending on your operating
  7278.      system.  (Note that you will have to do this each time you run
  7279.      `configure', because `configure' regenerates `config.h'.)
  7280.  
  7281.    * The `sql_yacc.cc' file is generated from `sql_yacc.yy'.  Normally
  7282.      the build process doesn't need to create `sql_yacc.cc', because
  7283.      MySQL comes with an already-generated copy.  However, if you do
  7284.      need to re-create it, you might encounter this error:
  7285.  
  7286.           "sql_yacc.yy", line xxx fatal: default action causes potential...
  7287.  
  7288.      This is a sign that your version of `yacc' is deficient.  You
  7289.      probably need to install `bison' (the GNU version of `yacc') and
  7290.      use that instead.
  7291.  
  7292.    * If you need to debug `mysqld' or a MySQL client, run `configure'
  7293.      with the `--with-debug' option, then recompile and link your
  7294.      clients with the new client library.  *Note Debugging client::.
  7295.  
  7296. MIT-pthreads Notes
  7297. ------------------
  7298.  
  7299. This section describes some of the issues involved in using
  7300. MIT-pthreads.
  7301.  
  7302. Note that on Linux you should NOT use MIT-pthreads but install
  7303. LinuxThreads!  *Note Linux::.
  7304.  
  7305. If your system does not provide native thread support, you will need to
  7306. build MySQL using the MIT-pthreads package.  This includes older
  7307. FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others.
  7308. *Note Which OS::.
  7309.  
  7310.    * On most systems, you can force MIT-pthreads to be used by running
  7311.      `configure' with the `--with-mit-threads' option:
  7312.  
  7313.           shell> ./configure --with-mit-threads
  7314.  
  7315.      Building in a non-source directory is not supported when using
  7316.      MIT-pthreads, because we want to minimize our changes to this code.
  7317.  
  7318.    * The checks that determine whether or not to use MIT-pthreads occur
  7319.      only during the part of the configuration process that deals with
  7320.      the server code.  If you have configured the distribution using
  7321.      `--without-server' to build only the client code, clients will not
  7322.      know whether or not MIT-pthreads is being used and will use Unix
  7323.      socket connections by default.  Because Unix sockets do not work
  7324.      under MIT-pthreads, this means you will need to use `-h' or
  7325.      `--host' when you run client programs.
  7326.  
  7327.    * When MySQL is compiled using MIT-pthreads, system locking is
  7328.      disabled by default for performance reasons.  You can tell the
  7329.      server to use system locking with the `--use-locking' option.
  7330.  
  7331.    * Sometimes the pthread `bind()' command fails to bind to a socket
  7332.      without any error message (at least on Solaris).  The result is
  7333.      that all connections to the server fail.  For example:
  7334.  
  7335.           shell> mysqladmin version
  7336.           mysqladmin: connect to server at '' failed;
  7337.           error: 'Can't connect to mysql server on localhost (146)'
  7338.  
  7339.      The solution to this is to kill the `mysqld' server and restart it.
  7340.      This has only happened to us when we have forced the server down
  7341.      and done a restart immediately.
  7342.  
  7343.    * With MIT-pthreads, the `sleep()' system call isn't interruptible
  7344.      with `SIGINT' (break).  This is only noticeable when you run
  7345.      `mysqladmin --sleep'.  You must wait for the `sleep()' call to
  7346.      terminate before the interrupt is served and the process stops.
  7347.  
  7348.    * When linking, you may receive warning messages like these (at
  7349.      least on Solaris); they can be ignored:
  7350.  
  7351.           ld: warning: symbol `_iob' has differing sizes:
  7352.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  7353.           file /usr/lib/libc.so value=0x140);
  7354.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  7355.           ld: warning: symbol `__iob' has differing sizes:
  7356.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  7357.           file /usr/lib/libc.so value=0x140);
  7358.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  7359.  
  7360.    * Some other warnings also can be ignored:
  7361.  
  7362.           implicit declaration of function `int strtoll(...)'
  7363.           implicit declaration of function `int strtoul(...)'
  7364.  
  7365.    * We haven't gotten `readline' to work with MIT-pthreads.  (This
  7366.      isn't needed, but may be interesting for someone.)
  7367.  
  7368. Post-installation Setup and Testing
  7369. ===================================
  7370.  
  7371. Once you've installed MySQL (from either a binary or source
  7372. distribution), you need to initialize the grant tables, start the
  7373. server, and make sure that the server works okay.  You may also wish to
  7374. arrange for the server to be started and stopped automatically when
  7375. your system starts up and shuts down.
  7376.  
  7377. Normally you install the grant tables and start the server like this
  7378. for installation from a source distribution:
  7379.  
  7380.      shell> ./scripts/mysql_install_db
  7381.      shell> cd mysql_installation_directory
  7382.      shell> ./bin/safe_mysqld --user=mysql &
  7383.  
  7384. For a binary distribution (not RPM or pkg packages), do this:
  7385.  
  7386.      shell> cd mysql_installation_directory
  7387.      shell> ./bin/mysql_install_db
  7388.      shell> ./bin/safe_mysqld --user=mysql &
  7389.  
  7390. This creates the `mysql' database which will hold all database
  7391. privileges, the `test' database which you can use to test MySQL and
  7392. also privilege entries for the user that run `mysql_install_db' and a
  7393. `root' user (without any passwords).  This also starts the `mysqld'
  7394. server.
  7395.  
  7396. `mysql_install_db' will not overwrite any old privilege tables, so it
  7397. should be safe to run in any circumstances.  If you don't want to have
  7398. the `test' database you can remove it with `mysqladmin -u root drop
  7399. test'.
  7400.  
  7401. Testing is most easily done from the top-level directory of the MySQL
  7402. distribution.  For a binary distribution, this is your installation
  7403. directory (typically something like `/usr/local/mysql').  For a source
  7404. distribution, this is the main directory of your MySQL source tree.
  7405.  
  7406. In the commands shown below in this section and in the following
  7407. subsections, `BINDIR' is the path to the location in which programs
  7408. like `mysqladmin' and `safe_mysqld' are installed.  For a binary
  7409. distribution, this is the `bin' directory within the distribution.  For
  7410. a source distribution, `BINDIR' is probably `/usr/local/bin', unless
  7411. you specified an installation directory other than `/usr/local' when
  7412. you ran `configure'.  `EXECDIR' is the location in which the `mysqld'
  7413. server is installed.  For a binary distribution, this is the same as
  7414. `BINDIR'.  For a source distribution, `EXECDIR' is probably
  7415. `/usr/local/libexec'.
  7416.  
  7417. Testing is described in detail below:
  7418.  
  7419.   1. If necessary, start the `mysqld' server and set up the initial
  7420.      MySQL grant tables containing the privileges that determine how
  7421.      users are allowed to connect to the server.  This is normally done
  7422.      with the `mysql_install_db' script:
  7423.  
  7424.           shell> scripts/mysql_install_db
  7425.  
  7426.      Typically, `mysql_install_db' needs to be run only the first time
  7427.      you install MySQL.  Therefore, if you are upgrading an existing
  7428.      installation, you can skip this step.  (However,
  7429.      `mysql_install_db' is quite safe to use and will not update any
  7430.      tables that already exist, so if you are unsure of what to do, you
  7431.      can always run `mysql_install_db'.)
  7432.  
  7433.      `mysql_install_db' creates six tables (`user', `db', `host',
  7434.      `tables_priv', `columns_priv', and `func') in the `mysql'
  7435.      database.  A description of the initial privileges is given in
  7436.      *Note Default privileges::.  Briefly, these privileges allow the
  7437.      MySQL `root' user to do anything, and allow anybody to create or
  7438.      use databases with a name of `'test'' or starting with `'test_''.
  7439.  
  7440.      If you don't set up the grant tables, the following error will
  7441.      appear in the log file when you start the server:
  7442.  
  7443.           mysqld: Can't find file: 'host.frm'
  7444.  
  7445.      The above may also happen with a binary MySQL distribution if you
  7446.      don't start MySQL by executing exactly `./bin/safe_mysqld'!  *Note
  7447.      `safe_mysqld': safe_mysqld.
  7448.  
  7449.      You might need to run `mysql_install_db' as `root'.  However, if
  7450.      you prefer, you can run the MySQL server as an unprivileged
  7451.      (non-`root') user, provided that user can read and write files in
  7452.      the database directory.  Instructions for running MySQL as an
  7453.      unprivileged user are given in *Note Changing MySQL user: Changing
  7454.      MySQL user.
  7455.  
  7456.      If you have problems with `mysql_install_db', see *Note
  7457.      `mysql_install_db': mysql_install_db.
  7458.  
  7459.      There are some alternatives to running the `mysql_install_db'
  7460.      script as it is provided in the MySQL distribution:
  7461.  
  7462.         * You may want to edit `mysql_install_db' before running it, to
  7463.           change the initial privileges that are installed into the
  7464.           grant tables.  This is useful if you want to install MySQL on
  7465.           a lot of machines with the same privileges.  In this case you
  7466.           probably should need only to add a few extra `INSERT'
  7467.           statements to the `mysql.user' and `mysql.db' tables!
  7468.  
  7469.         * If you want to change things in the grant tables after
  7470.           installing them, you can run `mysql_install_db', then use
  7471.           `mysql -u root mysql' to connect to the grant tables as the
  7472.           MySQL `root' user and issue SQL statements to modify the
  7473.           grant tables directly.
  7474.  
  7475.         * It is possible to re-create the grant tables completely after
  7476.           they have already been created.  You might want to do this if
  7477.           you've already installed the tables but then want to
  7478.           re-create them after editing `mysql_install_db'.
  7479.  
  7480.      For more information about these alternatives, see *Note Default
  7481.      privileges::.
  7482.  
  7483.   2. Start the MySQL server like this:
  7484.  
  7485.           shell> cd mysql_installation_directory
  7486.           shell> bin/safe_mysqld &
  7487.  
  7488.      If you have problems starting the server, see *Note Starting
  7489.      server::.
  7490.  
  7491.   3. Use `mysqladmin' to verify that the server is running.  The
  7492.      following commands provide a simple test to check that the server
  7493.      is up and responding to connections:
  7494.  
  7495.           shell> BINDIR/mysqladmin version
  7496.           shell> BINDIR/mysqladmin variables
  7497.  
  7498.      The output from `mysqladmin version' varies slightly depending on
  7499.      your platform and version of MySQL, but should be similar to that
  7500.      shown below:
  7501.  
  7502.           shell> BINDIR/mysqladmin version
  7503.           mysqladmin  Ver 8.14 Distrib 3.23.32, for linux on i586
  7504.           Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  7505.           This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  7506.           and you are welcome to modify and redistribute it under the GPL license
  7507.           
  7508.           Server version          3.23.32-debug
  7509.           Protocol version        10
  7510.           Connection              Localhost via Unix socket
  7511.           TCP port                3306
  7512.           UNIX socket             /tmp/mysql.sock
  7513.           Uptime:                 16 sec
  7514.           
  7515.           Threads: 1  Questions: 9  Slow queries: 0  Opens: 7  Flush tables: 2  Open tables: 0 Queries per second avg: 0.000  Memory in use: 132K  Max memory used: 16773K
  7516.  
  7517.      To get a feeling for what else you can do with `BINDIR/mysqladmin',
  7518.      invoke it with the `--help' option.
  7519.  
  7520.   4. Verify that you can shut down the server:
  7521.  
  7522.           shell> BINDIR/mysqladmin -u root shutdown
  7523.  
  7524.   5. Verify that you can restart the server.  Do this using
  7525.      `safe_mysqld' or by invoking `mysqld' directly.  For example:
  7526.  
  7527.           shell> BINDIR/safe_mysqld --log &
  7528.  
  7529.      If `safe_mysqld' fails, try running it from the MySQL installation
  7530.      directory (if you are not already there).  If that doesn't work,
  7531.      see *Note Starting server::.
  7532.  
  7533.   6. Run some simple tests to verify that the server is working.  The
  7534.      output should be similar to what is shown below:
  7535.  
  7536.           shell> BINDIR/mysqlshow
  7537.           +-----------+
  7538.           | Databases |
  7539.           +-----------+
  7540.           | mysql     |
  7541.           +-----------+
  7542.           
  7543.           shell> BINDIR/mysqlshow mysql
  7544.           Database: mysql
  7545.           +--------------+
  7546.           |    Tables    |
  7547.           +--------------+
  7548.           | columns_priv |
  7549.           | db           |
  7550.           | func         |
  7551.           | host         |
  7552.           | tables_priv  |
  7553.           | user         |
  7554.           +--------------+
  7555.           
  7556.           shell> BINDIR/mysql -e "select host,db,user from db" mysql
  7557.           +------+--------+------+
  7558.           | host | db     | user |
  7559.           +------+--------+------+
  7560.           | %    | test   |      |
  7561.           | %    | test_% |      |
  7562.           +------+--------+------+
  7563.  
  7564.      There is also a benchmark suite in the `sql-bench' directory
  7565.      (under the MySQL installation directory) that you can use to
  7566.      compare how MySQL performs on different platforms.  The
  7567.      `sql-bench/Results' directory contains the results from many runs
  7568.      against different databases and platforms.  To run all tests,
  7569.      execute these commands:
  7570.  
  7571.           shell> cd sql-bench
  7572.           shell> run-all-tests
  7573.  
  7574.      If you don't have the `sql-bench' directory, you are probably
  7575.      using an RPM for a binary distribution.  (Source distribution RPMs
  7576.      include the benchmark directory.)  In this case, you must first
  7577.      install the benchmark suite before you can use it.  Beginning with
  7578.      MySQL Version 3.22, there are benchmark RPM files named
  7579.      `mysql-bench-VERSION-i386.rpm' that contain benchmark code and
  7580.      data.
  7581.  
  7582.      If you have a source distribution, you can also run the tests in
  7583.      the `tests' subdirectory. For example, to run
  7584.      `auto_increment.tst', do this:
  7585.  
  7586.           shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst
  7587.  
  7588.      The expected results are shown in the `./tests/auto_increment.res'
  7589.      file.
  7590.  
  7591. Problems Running `mysql_install_db'
  7592. -----------------------------------
  7593.  
  7594. The purpose of the `mysql_install_db' script is to generate new MySQL
  7595. privilege tables.  It will not affect any other data!  It will also not
  7596. do anything if you already have MySQL privilege tables installed!
  7597.  
  7598. If you want to re-create your privilege tables, you should take down
  7599. the `mysqld' server, if it's running, and then do something like:
  7600.  
  7601.      mv mysql-data-directory/mysql mysql-data-directory/mysql-old
  7602.      mysql_install_db
  7603.  
  7604. This section lists problems you might encounter when you run
  7605. `mysql_install_db':
  7606.  
  7607. *`mysql_install_db' doesn't install the grant tables*
  7608.      You may find that `mysql_install_db' fails to install the grant
  7609.      tables and terminates after displaying the following messages:
  7610.  
  7611.           starting mysqld daemon with databases from XXXXXX
  7612.           mysql daemon ended
  7613.  
  7614.      In this case, you should examine the log file very carefully!  The
  7615.      log should be located in the directory `XXXXXX' named by the error
  7616.      message, and should indicate why `mysqld' didn't start.  If you
  7617.      don't understand what happened, include the log when you post a
  7618.      bug report using `mysqlbug'!  *Note Bug reports::.
  7619.  
  7620. *There is already a `mysqld' daemon running*
  7621.      In this case, you probably don't have to run `mysql_install_db' at
  7622.      all.  You have to run `mysql_install_db' only once, when you
  7623.      install MySQL the first time.
  7624.  
  7625. *Installing a second `mysqld' daemon doesn't work when one daemon is running*
  7626.      This can happen when you already have an existing MySQL
  7627.      installation, but want to put a new installation in a different
  7628.      place (for example, for testing, or perhaps you simply want to run
  7629.      two installations at the same time).  Generally the problem that
  7630.      occurs when you try to run the second server is that it tries to
  7631.      use the same socket and port as the old one.  In this case you
  7632.      will get the error message: `Can't start server: Bind on TCP/IP
  7633.      port: Address already in use' or `Can't start server : Bind on
  7634.      unix socket...'. *Note Installing many servers::.
  7635.  
  7636. *You don't have write access to `/tmp'*
  7637.      If you don't have write access to create a socket file at the
  7638.      default place (in `/tmp') or permission to create temporary files
  7639.      in `/tmp,' you will get an error when running `mysql_install_db'
  7640.      or when starting or using `mysqld'.
  7641.  
  7642.      You can specify a different socket and temporary directory as
  7643.      follows:
  7644.  
  7645.           shell> TMPDIR=/some_tmp_dir/
  7646.           shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysqld.sock
  7647.           shell> export TMPDIR MYSQL_UNIX_PORT
  7648.  
  7649.      *Note Problems with mysql.sock::.
  7650.  
  7651.      `some_tmp_dir' should be the path to some directory for which you
  7652.      have write permission. *Note Environment variables::.
  7653.  
  7654.      After this you should be able to run `mysql_install_db' and start
  7655.      the server with these commands:
  7656.  
  7657.           shell> scripts/mysql_install_db
  7658.           shell> BINDIR/safe_mysqld &
  7659.  
  7660. *`mysqld' crashes immediately*
  7661.      If you are running RedHat Version 5.0 with a version of `glibc'
  7662.      older than 2.0.7-5, you should make sure you have installed all
  7663.      `glibc' patches!  There is a lot of information about this in the
  7664.      MySQL mail archives.  Links to the mail archives are available
  7665.      online at `http://www.mysql.com/documentation/'.  Also, see *Note
  7666.      Linux::.
  7667.  
  7668.      You can also start `mysqld' manually using the
  7669.      `--skip-grant-tables' option and add the privilege information
  7670.      yourself using `mysql':
  7671.  
  7672.           shell> BINDIR/safe_mysqld --skip-grant-tables &
  7673.           shell> BINDIR/mysql -u root mysql
  7674.  
  7675.      From `mysql', manually execute the SQL commands in
  7676.      `mysql_install_db'.  Make sure you run `mysqladmin
  7677.      flush-privileges' or `mysqladmin reload' afterward to tell the
  7678.      server to reload the grant tables.
  7679.  
  7680. Problems Starting the MySQL Server
  7681. ----------------------------------
  7682.  
  7683. If you are going to use tables that support transactions (BDB, InnoDB),
  7684. you should first create a my.cnf file and set startup options for the
  7685. table types you plan to use. *Note Table types::.
  7686.  
  7687. Generally, you start the `mysqld' server in one of three ways:
  7688.  
  7689.    * By invoking `mysql.server'.  This script is used primarily at
  7690.      system startup and shutdown, and is described more fully in *Note
  7691.      Automatic start::.
  7692.  
  7693.    * By invoking `safe_mysqld', which tries to determine the proper
  7694.      options for `mysqld' and then runs it with those options. *Note
  7695.      `safe_mysqld': safe_mysqld.
  7696.  
  7697.    * On NT you should install `mysqld' as a service as follows:
  7698.           bin\mysqld-nt --install               # Install MySQL as a service
  7699.  
  7700.      You can now start/stop `mysqld' as follows:
  7701.           NET START mysql
  7702.           NET STOP mysql
  7703.  
  7704.      Note that in this case you can't use any other options for
  7705.      `mysqld'!
  7706.  
  7707.      You can remove the service as follows:
  7708.           bin\mysqld-nt --remove                # remove MySQL as a service
  7709.  
  7710.    * By invoking `mysqld' directly.
  7711.  
  7712. When the `mysqld' daemon starts up, it changes directory to the data
  7713. directory.  This is where it expects to write log files and the pid
  7714. (process ID) file, and where it expects to find databases.
  7715.  
  7716. The data directory location is hardwired in when the distribution is
  7717. compiled.  However, if `mysqld' expects to find the data directory
  7718. somewhere other than where it really is on your system, it will not work
  7719. properly.  If you have problems with incorrect paths, you can find out
  7720. what options `mysqld' allows and what the default path settings are by
  7721. invoking `mysqld' with the `--help' option.  You can override the
  7722. defaults by specifying the correct pathnames as command-line arguments
  7723. to `mysqld'.  (These options can be used with `safe_mysqld' as well.)
  7724.  
  7725. Normally you should need to tell `mysqld' only the base directory under
  7726. which MySQL is installed.  You can do this with the `--basedir' option.
  7727. You can also use `--help' to check the effect of changing path options
  7728. (note that `--help' _must_ be the final option of the `mysqld'
  7729. command).  For example:
  7730.  
  7731.      shell> EXECDIR/mysqld --basedir=/usr/local --help
  7732.  
  7733. Once you determine the path settings you want, start the server without
  7734. the `--help' option.
  7735.  
  7736. Whichever method you use to start the server, if it fails to start up
  7737. correctly, check the log file to see if you can find out why.  Log files
  7738. are located in the data directory (typically `/usr/local/mysql/data'
  7739. for a binary distribution, `/usr/local/var' for a source distribution,
  7740. `\mysql\data\mysql.err' on Windows.)  Look in the data directory for
  7741. files with names of the form `host_name.err' and `host_name.log' where
  7742. `host_name' is the name of your server host.  Then check the last few
  7743. lines of these files:
  7744.  
  7745.      shell> tail host_name.err
  7746.      shell> tail host_name.log
  7747.  
  7748. If you find something like the following in the log file:
  7749.      000729 14:50:10  bdb:  Recovery function for LSN 1 27595 failed
  7750.      000729 14:50:10  bdb:  warning: ./test/t1.db: No such file or directory
  7751.      000729 14:50:10  Can't init databases
  7752.  
  7753. This means that you didn't start `mysqld' with `--bdb-no-recover' and
  7754. Berkeley DB found something wrong with its log files when it tried to
  7755. recover your databases.  To be able to continue, you should move away
  7756. the old Berkeley DB log file from the database directory to some other
  7757. place, where you can later examine these.  The log files are named
  7758. `log.0000000001', where the number will increase over time.
  7759.  
  7760. If you are running `mysqld' with BDB table support and `mysqld' core
  7761. dumps at start this could be because of some problems with the BDB
  7762. recover log.  In this case you can try starting `mysqld' with
  7763. `--bdb-no-recover'.  If this helps, then you should remove all `log.*'
  7764. files from the data directory and try starting `mysqld' again.
  7765.  
  7766. If you get the following error, it means that some other program (or
  7767. another `mysqld' server) is already using the TCP/IP port or socket
  7768. `mysqld' is trying to use:
  7769.  
  7770.      Can't start server: Bind on TCP/IP port: Address already in use
  7771.        or
  7772.      Can't start server : Bind on unix socket...
  7773.  
  7774. Use `ps' to make sure that you don't have another `mysqld' server
  7775. running.  If you can't find another server running, you can try to
  7776. execute the command `telnet your-host-name tcp-ip-port-number' and press
  7777. `RETURN' a couple of times.  If you don't get an error message like
  7778. `telnet: Unable to connect to remote host: Connection refused',
  7779. something is using the TCP/IP port `mysqld' is trying to use.  See
  7780. *Note mysql_install_db:: and *Note Multiple servers::.
  7781.  
  7782. If `mysqld' is currently running, you can find out what path settings
  7783. it is using by executing this command:
  7784.  
  7785.      shell> mysqladmin variables
  7786.  
  7787. or
  7788.  
  7789.      shell> mysqladmin -h 'your-host-name' variables
  7790.  
  7791. If `safe_mysqld' starts the server but you can't connect to it, you
  7792. should make sure you have an entry in `/etc/hosts' that looks like this:
  7793.  
  7794.      127.0.0.1       localhost
  7795.  
  7796. This problem occurs only on systems that don't have a working thread
  7797. library and for which MySQL must be configured to use MIT-pthreads.
  7798.  
  7799. If you can't get `mysqld' to start you can try to make a trace file to
  7800. find the problem. *Note Making trace files::.
  7801.  
  7802. If you are using InnoDB tables, refer to the InnoDB-specific startup
  7803. options.  *Note InnoDB start::.
  7804.  
  7805. If you are using BDB (Berkeley DB) tables, you should familiarize
  7806. yourself with the different BDB specific startup options.  *Note BDB
  7807. start::.
  7808.  
  7809. Starting and Stopping MySQL Automatically
  7810. -----------------------------------------
  7811.  
  7812. The `mysql.server' and `safe_mysqld' scripts can be used to start the
  7813. server automatically at system startup time. `mysql.server' can also be
  7814. used to stop the server.
  7815.  
  7816. The `mysql.server' script can be used to start or stop the server by
  7817. invoking it with `start' or `stop' arguments:
  7818.  
  7819.      shell> mysql.server start
  7820.      shell> mysql.server stop
  7821.  
  7822. `mysql.server' can be found in the `share/mysql' directory under the
  7823. MySQL installation directory or in the `support-files' directory of the
  7824. MySQL source tree.
  7825.  
  7826. Before `mysql.server' starts the server, it changes directory to the
  7827. MySQL installation directory, then invokes `safe_mysqld'.  You might
  7828. need to edit `mysql.server' if you have a binary distribution that
  7829. you've installed in a non-standard location.  Modify it to `cd' into
  7830. the proper directory before it runs `safe_mysqld'. If you want the
  7831. server to run as some specific user, add an appropriate `user' line to
  7832. the `/etc/my.cnf' file, as shown later in this section.
  7833.  
  7834. `mysql.server stop' brings down the server by sending a signal to it.
  7835. You can take down the server manually by executing `mysqladmin
  7836. shutdown'.
  7837.  
  7838. You might want to add these start and stop commands to the appropriate
  7839. places in your `/etc/rc*' files when you start using MySQL for
  7840. production applications.  Note that if you modify `mysql.server', then
  7841. upgrade MySQL sometime, your modified version will be overwritten, so
  7842. you should make a copy of your edited version that you can reinstall.
  7843.  
  7844. If your system uses `/etc/rc.local' to start external scripts, you
  7845. should append the following to it:
  7846.      /bin/sh -c 'cd /usr/local/mysql ; ./bin/safe_mysqld --user=mysql &'
  7847.  
  7848. You can also add options for `mysql.server' in a global `/etc/my.cnf'
  7849. file.  A typical `/etc/my.cnf' file might look like this:
  7850.  
  7851.      [mysqld]
  7852.      datadir=/usr/local/mysql/var
  7853.      socket=/var/tmp/mysql.sock
  7854.      port=3306
  7855.      user=mysql
  7856.      
  7857.      [mysql.server]
  7858.      basedir=/usr/local/mysql
  7859.  
  7860. The `mysql.server' script understands the following options: `datadir',
  7861. `basedir', and `pid-file'.
  7862.  
  7863. The following table shows which option groups each of the startup
  7864. scripts read from option files:
  7865.  
  7866. *Script*       *Option groups*
  7867. `mysqld'       `mysqld' and `server'
  7868. `mysql.server' `mysql.server', `mysqld', and `server'
  7869. `safe_mysqld'  `mysql.server', `mysqld', and `server'
  7870.  
  7871. *Note Option files::.
  7872.  
  7873. Upgrading/Downgrading MySQL
  7874. ===========================
  7875.  
  7876. You can always move the MySQL form and data files between different
  7877. versions on the same architecture as long as you have the same base
  7878. version of MySQL. The current base version is 3. If you change the
  7879. character set when running MySQL (which may also change the sort
  7880. order), you must run `myisamchk -r -q' on all tables.  Otherwise your
  7881. indexes may not be ordered correctly.
  7882.  
  7883. If you are afraid of new versions, you can always rename your old
  7884. `mysqld' to something like `mysqld'-'old-version-number'.  If your new
  7885. `mysqld' then does something unexpected, you can simply shut it down
  7886. and restart with your old `mysqld'!
  7887.  
  7888. When you do an upgrade you should also back up your old databases, of
  7889. course.
  7890.  
  7891. If after an upgrade, you experience problems with recompiled client
  7892. programs, like `Commands out of sync' or unexpected core dumps, you
  7893. probably have used an old header or library file when compiling your
  7894. programs.  In this case you should check the date for your `mysql.h'
  7895. file and `libmysqlclient.a' library to verify that they are from the new
  7896. MySQL distribution.  If not, please recompile your programs!
  7897.  
  7898. If you get some problems that the new `mysqld' server doesn't want to
  7899. start or that you can't connect without a password, check that you don't
  7900. have some old `my.cnf' file from your old installation!  You can check
  7901. this with: `program-name --print-defaults'.  If this outputs anything
  7902. other than the program name, you have an active `my.cnf' file that will
  7903. affect things!
  7904.  
  7905. It is a good idea to rebuild and reinstall the `Msql-Mysql-modules'
  7906. distribution whenever you install a new release of MySQL, particularly
  7907. if you notice symptoms such as all your `DBI' scripts dumping core
  7908. after you upgrade MySQL.
  7909.  
  7910. Upgrading From Version 3.22 to Version 3.23
  7911. -------------------------------------------
  7912.  
  7913. MySQL Version 3.23 supports tables of the new `MyISAM' type and the old
  7914. `ISAM' type.  You don't have to convert your old tables to use these
  7915. with Version 3.23.  By default, all new tables will be created with
  7916. type `MyISAM' (unless you start `mysqld' with the
  7917. `--default-table-type=isam' option). You can change an `ISAM' table to
  7918. a `MyISAM' table with `ALTER TABLE table_name TYPE=MyISAM' or the Perl
  7919. script `mysql_convert_table_format'.
  7920.  
  7921. Version 3.22 and 3.21 clients will work without any problems with a
  7922. Version 3.23 server.
  7923.  
  7924. The following lists tell what you have to watch out for when upgrading
  7925. to Version 3.23:
  7926.  
  7927.    * All tables that uses the `tis620' character set must be fixed with
  7928.      `myisamchk -r' or `REPAIR TABLE'.
  7929.  
  7930.    * If you do a `DROP DATABASE' on a symbolic linked database, both the
  7931.      link and the original database is deleted.  (This didn't happen in
  7932.      3.22 because configure didn't detect the `readlink' system call).
  7933.  
  7934.    * `OPTIMIZE TABLE' now only works for *MyISAM* tables.  For other
  7935.      table types, you can use `ALTER TABLE' to optimize the table.
  7936.      During `OPTIMIZE TABLE' the table is now locked from other threads.
  7937.  
  7938.    * The MySQL client `mysql' is now by default started with the option
  7939.      `--no-named-commands (-g)'. This option can be disabled with
  7940.      `--enable-named-commands (-G)'. This may cause incompatibility
  7941.      problems in some cases, for example in SQL scripts that use named
  7942.      commands without a semicolon!  Long format commands still work
  7943.      from the first line.
  7944.  
  7945.    * If you are using the `german' character sort order, you must repair
  7946.      all your tables with `isamchk -r', as we have made some changes in
  7947.      the sort order!
  7948.  
  7949.    * The default return type of `IF' will now depend on both arguments
  7950.      and not only the first argument.
  7951.  
  7952.    * `AUTO_INCREMENT' will not work with negative numbers. The reason
  7953.      for this is that negative numbers caused problems when wrapping
  7954.      from -1 to 0.  `AUTO_INCREMENT' is now for MyISAM tables handled
  7955.      at a lower level and is much faster than before. For MyISAM tables
  7956.      old numbers are also not reused anymore, even if you delete some
  7957.      rows from the table.
  7958.  
  7959.    * `CASE', `DELAYED', `ELSE', `END', `FULLTEXT', `INNER', `RIGHT',
  7960.      `THEN' and `WHEN' are now reserved words.
  7961.  
  7962.    * `FLOAT(X)' is now a true floating-point type and not a value with a
  7963.      fixed number of decimals.
  7964.  
  7965.    * When declaring `DECIMAL(length,dec)' the length argument no longer
  7966.      includes a place for the sign or the decimal point.
  7967.  
  7968.    * A `TIME' string must now be of one of the following formats:
  7969.      `[[[DAYS] [H]H:]MM:]SS[.fraction]' or
  7970.      `[[[[[H]H]H]H]MM]SS[.fraction]'
  7971.  
  7972.    * `LIKE' now compares strings using the same character comparison
  7973.      rules as `'=''.  If you require the old behavior, you can compile
  7974.      MySQL with the `CXXFLAGS=-DLIKE_CMP_TOUPPER' flag.
  7975.  
  7976.    * `REGEXP' is now case insensitive for normal (not binary) strings.
  7977.  
  7978.    * When you check/repair tables you should use `CHECK TABLE' or
  7979.      `myisamchk' for `MyISAM' tables (`.MYI') and `isamchk' for ISAM
  7980.      (`.ISM') tables.
  7981.  
  7982.    * If you want your `mysqldump' files to be compatible between MySQL
  7983.      Version 3.22 and Version 3.23, you should not use the `--opt' or
  7984.      `--full' option to `mysqldump'.
  7985.  
  7986.    * Check all your calls to `DATE_FORMAT()' to make sure there is a
  7987.      `%' before each format character.  (Later MySQL Version 3.22 did
  7988.      allow this syntax.)
  7989.  
  7990.    * `mysql_fetch_fields_direct' is now a function (it was a macro) and
  7991.      it returns a pointer to a `MYSQL_FIELD' instead of a `MYSQL_FIELD'.
  7992.  
  7993.    * `mysql_num_fields()' can no longer be used on a `MYSQL*' object
  7994.      (it's now a function that takes `MYSQL_RES*' as an argument. You
  7995.      should now use `mysql_field_count()' instead.
  7996.  
  7997.    * In MySQL Version 3.22, the output of `SELECT DISTINCT ...' was
  7998.      almost always sorted.  In Version 3.23, you must use `GROUP BY' or
  7999.      `ORDER BY' to obtain sorted output.
  8000.  
  8001.    * `SUM()' now returns `NULL', instead of 0, if there is no matching
  8002.      rows. This is according to ANSI SQL.
  8003.  
  8004.    * An `AND' or `OR' with `NULL' values will now return `NULL' instead
  8005.      of 0. This mostly affects queries that use `NOT' on an `AND/OR'
  8006.      expression as `NOT NULL' = `NULL'.  `LPAD()' and `RPAD()' will
  8007.      shorten the result string if it's longer than the length argument.
  8008.  
  8009. Upgrading from Version 3.21 to Version 3.22
  8010. -------------------------------------------
  8011.  
  8012. Nothing that affects compatibility has changed between Version 3.21 and
  8013. 3.22.  The only pitfall is that new tables that are created with `DATE'
  8014. type columns will use the new way to store the date. You can't access
  8015. these new fields from an old version of `mysqld'.
  8016.  
  8017. After installing MySQL Version 3.22, you should start the new server
  8018. and then run the `mysql_fix_privilege_tables' script. This will add the
  8019. new privileges that you need to use the `GRANT' command.  If you forget
  8020. this, you will get `Access denied' when you try to use `ALTER TABLE',
  8021. `CREATE INDEX', or `DROP INDEX'. If your MySQL root user requires a
  8022. password, you should give this as an argument to
  8023. `mysql_fix_privilege_tables'.
  8024.  
  8025. The C API interface to `mysql_real_connect()' has changed.  If you have
  8026. an old client program that calls this function, you must place a `0' for
  8027. the new `db' argument (or recode the client to send the `db' element
  8028. for faster connections).  You must also call `mysql_init()' before
  8029. calling `mysql_real_connect()'!  This change was done to allow the new
  8030. `mysql_options()' function to save options in the `MYSQL' handler
  8031. structure.
  8032.  
  8033. The `mysqld' variable `key_buffer' has changed names to
  8034. `key_buffer_size', but you can still use the old name in your startup
  8035. files.
  8036.  
  8037. Upgrading from Version 3.20 to Version 3.21
  8038. -------------------------------------------
  8039.  
  8040. If you are running a version older than Version 3.20.28 and want to
  8041. switch to Version 3.21, you need to do the following:
  8042.  
  8043. You can start the `mysqld' Version 3.21 server with `safe_mysqld
  8044. --old-protocol' to use it with clients from a Version 3.20 distribution.
  8045. In this case, the new client function `mysql_errno()' will not return
  8046. any server error, only `CR_UNKNOWN_ERROR' (but it works for client
  8047. errors), and the server uses the old `password()' checking rather than
  8048. the new one.
  8049.  
  8050. If you are *NOT* using the `--old-protocol' option to `mysqld', you
  8051. will need to make the following changes:
  8052.  
  8053.    * All client code must be recompiled. If you are using ODBC, you
  8054.      must get the new *MyODBC* 2.x driver.
  8055.  
  8056.    * The script `scripts/add_long_password' must be run to convert the
  8057.      `Password' field in the `mysql.user' table to `CHAR(16)'.
  8058.  
  8059.    * All passwords must be reassigned in the `mysql.user' table (to get
  8060.      62-bit rather than 31-bit passwords).
  8061.  
  8062.    * The table format hasn't changed, so you don't have to convert any
  8063.      tables.
  8064.  
  8065. MySQL Version 3.20.28 and above can handle the new `user' table format
  8066. without affecting clients. If you have a MySQL version earlier than
  8067. Version 3.20.28, passwords will no longer work with it if you convert
  8068. the `user' table. So to be safe, you should first upgrade to at least
  8069. Version 3.20.28 and then upgrade to Version 3.21.
  8070.  
  8071. The new client code works with a 3.20.x `mysqld' server, so if you
  8072. experience problems with 3.21.x, you can use the old 3.20.x server
  8073. without having to recompile the clients again.
  8074.  
  8075. If you are not using the `--old-protocol' option to `mysqld', old
  8076. clients will issue the error message:
  8077.  
  8078.      ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
  8079.  
  8080. The new Perl `DBI'/`DBD' interface also supports the old `mysqlperl'
  8081. interface.  The only change you have to make if you use `mysqlperl' is
  8082. to change the arguments to the `connect()' function.  The new arguments
  8083. are: `host', `database', `user', `password' (the `user' and `password'
  8084. arguments have changed places).  *Note Perl `DBI' Class: Perl DBI Class.
  8085.  
  8086. The following changes may affect queries in old applications:
  8087.  
  8088.    * `HAVING' must now be specified before any `ORDER BY' clause.
  8089.  
  8090.    * The parameters to `LOCATE()' have been swapped.
  8091.  
  8092.    * There are some new reserved words. The most notable are `DATE',
  8093.      `TIME', and `TIMESTAMP'.
  8094.  
  8095. Upgrading to Another Architecture
  8096. ---------------------------------
  8097.  
  8098. If you are using MySQL Version 3.23, you can copy the `.frm', `.MYI',
  8099. and `.MYD' files between different architectures that support the same
  8100. floating-point format.  (MySQL takes care of any byte swapping issues.)
  8101.  
  8102. The MySQL `ISAM' data and index files (`.ISD' and `*.ISM',
  8103. respectively) are architecture-dependent and in some cases
  8104. OS-dependent.  If you want to move your applications to another machine
  8105. that has a different architecture or OS than your current machine, you
  8106. should not try to move a database by simply copying the files to the
  8107. other machine. Use `mysqldump' instead.
  8108.  
  8109. By default, `mysqldump' will create a file full of SQL statements.  You
  8110. can then transfer the file to the other machine and feed it as input to
  8111. the `mysql' client.
  8112.  
  8113. Try `mysqldump --help' to see what options are available.  If you are
  8114. moving the data to a newer version of MySQL, you should use `mysqldump
  8115. --opt' with the newer version to get a fast, compact dump.
  8116.  
  8117. The easiest (although not the fastest) way to move a database between
  8118. two machines is to run the following commands on the machine on which
  8119. the database is located:
  8120.  
  8121.      shell> mysqladmin -h 'other hostname' create db_name
  8122.      shell> mysqldump --opt db_name \
  8123.              | mysql -h 'other hostname' db_name
  8124.  
  8125. If you want to copy a database from a remote machine over a slow
  8126. network, you can use:
  8127.  
  8128.      shell> mysqladmin create db_name
  8129.      shell> mysqldump -h 'other hostname' --opt --compress db_name \
  8130.              | mysql db_name
  8131.  
  8132. You can also store the result in a file, then transfer the file to the
  8133. target machine and load the file into the database there.  For example,
  8134. you can dump a database to a file on the source machine like this:
  8135.  
  8136.      shell> mysqldump --quick db_name | gzip > db_name.contents.gz
  8137.  
  8138. (The file created in this example is compressed.) Transfer the file
  8139. containing the database contents to the target machine and run these
  8140. commands there:
  8141.  
  8142.      shell> mysqladmin create db_name
  8143.      shell> gunzip < db_name.contents.gz | mysql db_name
  8144.  
  8145. You can also use `mysqldump' and `mysqlimport' to accomplish the
  8146. database transfer.  For big tables, this is much faster than simply
  8147. using `mysqldump'.  In the commands shown below, `DUMPDIR' represents
  8148. the full pathname of the directory you use to store the output from
  8149. `mysqldump'.
  8150.  
  8151. First, create the directory for the output files and dump the database:
  8152.  
  8153.      shell> mkdir DUMPDIR
  8154.      shell> mysqldump --tab=DUMPDIR db_name
  8155.  
  8156. Then transfer the files in the `DUMPDIR' directory to some corresponding
  8157. directory on the target machine and load the files into MySQL there:
  8158.  
  8159.      shell> mysqladmin create db_name           # create database
  8160.      shell> cat DUMPDIR/*.sql | mysql db_name   # create tables in database
  8161.      shell> mysqlimport db_name DUMPDIR/*.txt   # load data into tables
  8162.  
  8163. Also, don't forget to copy the `mysql' database, because that's where
  8164. the grant tables (`user', `db', `host') are stored.  You may have to
  8165. run commands as the MySQL `root' user on the new machine until you have
  8166. the `mysql' database in place.
  8167.  
  8168. After you import the `mysql' database on the new machine, execute
  8169. `mysqladmin flush-privileges' so that the server reloads the grant table
  8170. information.
  8171.  
  8172. Operating System Specific Notes
  8173. ===============================
  8174.  
  8175. Linux Notes (All Linux Versions)
  8176. --------------------------------
  8177.  
  8178. The notes below regarding *glibc* apply only to the situation when you
  8179. build MySQL yourself. If you are running Linux on an x86 machine, in
  8180. most cases it is much better for you to just use our binary. We link
  8181. our binaries against the best patched version of *glibc* we can come up
  8182. with and with the best compiler options, in an attempt to make it
  8183. suitable for a high-load server. So if you read the text below, and are
  8184. in doubt about what you should do, try our binary first to see if it
  8185. meets your needs, and worry about your own build only after you have
  8186. discovered that our binary is not good enough. In that case, we would
  8187. appreciate a note about it, so we can build a better binary next time.
  8188. For a typical user, even for setups with a lot of concurrent
  8189. connections and/or tables exceeding 2GB limit, our binary in most cases
  8190. is the best choice.
  8191.  
  8192. MySQL uses LinuxThreads on Linux.  If you are using an old Linux
  8193. version that doesn't have `glibc2', you must install LinuxThreads
  8194. before trying to compile MySQL.   You can get LinuxThreads at
  8195. `http://www.mysql.com/Downloads/Linux'.
  8196.  
  8197. *NOTE:* We have seen some strange problems with Linux 2.2.14 and MySQL
  8198. on SMP systems; If you have a SMP system, we recommend you to upgrade
  8199. to Linux 2.4 ASAP!  Your system will be faster and more stable by doing
  8200. this!
  8201.  
  8202. Note that `glibc' versions before and including Version 2.1.1 have a
  8203. fatal bug in `pthread_mutex_timedwait' handling, which is used when you
  8204. do `INSERT DELAYED'.  We recommend you to not use `INSERT DELAYED'
  8205. before upgrading glibc.
  8206.  
  8207. If you plan to have 1000+ concurrent connections, you will need to make
  8208. some changes to LinuxThreads, recompile it, and relink MySQL against
  8209. the new `libpthread.a'.  Increase `PTHREAD_THREADS_MAX' in
  8210. `sysdeps/unix/sysv/linux/bits/local_lim.h' to 4096 and decrease
  8211. `STACK_SIZE' in `linuxthreads/internals.h' to 256 KB. The paths are
  8212. relative to the root of `glibc' Note that MySQL will not be stable with
  8213. around 600-1000 connections if `STACK_SIZE' is the default of 2 MB.
  8214.  
  8215. If you have a problem with that MySQL can't open enough files, or
  8216. connections, it may be that you haven't configured Linux to handle
  8217. enough files.
  8218.  
  8219. In Linux 2.2 and forwards, you can check the number of allocated file
  8220. handlers by doing:
  8221.  
  8222.      cat /proc/sys/fs/file-max
  8223.      cat /proc/sys/fs/dquot-max
  8224.      cat /proc/sys/fs/super-max
  8225.  
  8226. If you have more than 16M of memory, you should add something like the
  8227. following in your boot script (`/etc/rc/boot.local' on SuSE):
  8228.  
  8229.      echo 65536 > /proc/sys/fs/file-max
  8230.      echo 8192 > /proc/sys/fs/dquot-max
  8231.      echo 1024 > /proc/sys/fs/super-max
  8232.  
  8233. You can also run the above from the command line as root, but in this
  8234. case your old limits will be used next time your computer reboots.
  8235.  
  8236. You should also add /etc/my.cnf:
  8237.  
  8238.      [safe_mysqld]
  8239.      open-files-limit=8192
  8240.  
  8241. The above should allow MySQL to create up to 8192 connections + files.
  8242.  
  8243. The `STACK_SIZE' constant in LinuxThreads controls the spacing of thread
  8244. stacks in the address space.  It needs to be large enough so that there
  8245. will be plenty of room for the stack of each individual thread, but
  8246. small enough to keep the stack of some thread from running into the
  8247. global `mysqld' data.  Unfortunately, the Linux implementation of
  8248. `mmap()', as we have experimentally discovered, will successfully unmap
  8249. an already mapped region if you ask it to map out an address already in
  8250. use, zeroing out the data on the entire page, instead of returning an
  8251. error.  So, the safety of `mysqld' or any other threaded application
  8252. depends on the "gentleman" behavior of the code that creates threads.
  8253. The user must take measures to make sure the number of running threads
  8254. at any time is sufficiently low for thread stacks to stay away from the
  8255. global heap.  With `mysqld', you should enforce this "gentleman"
  8256. behavior by setting a reasonable value for the `max_connections'
  8257. variable.
  8258.  
  8259. If you build MySQL yourself and do not want to mess with patching
  8260. LinuxThreads, you should set `max_connections' to a value no higher
  8261. than 500.  It should be even less if you have a large key buffer,  large
  8262. heap tables, or some other things that make `mysqld' allocate a lot of
  8263. memory or if you are running a 2.2 kernel with a 2GB patch. If you are
  8264. using our binary or RPM version 3.23.25 or later, you can safely set
  8265. `max_connections' at 1500, assuming no large key buffer or heap tables
  8266. with lots of data.  The more you reduce `STACK_SIZE' in LinuxThreads
  8267. the more threads you can safely create.  We recommend the values between
  8268. 128K and 256K.
  8269.  
  8270. If you use a lot of concurrent connections, you may suffer from a
  8271. "feature" in the 2.2 kernel that penalizes a process for forking or
  8272. cloning a child in an attempt to prevent a fork bomb attack.  This will
  8273. cause MySQL not to scale well as you increase the number of concurrent
  8274. clients.  On single CPU systems, we have seen this manifested in a very
  8275. slow thread creation, which means it may take a long time to connect to
  8276. MySQL (as long as 1 minute), and it may take just as long to shut it
  8277. down.  On multiple CPU systems, we have observed a gradual drop in
  8278. query speed as the number of clients increases.  In the process of
  8279. trying to find a solution, we have received a kernel patch from one of
  8280. our users, who claimed it made a lot of difference for his site.  The
  8281. patch is available here
  8282. (`http://www.mysql.com/Downloads/Patches/linux-fork.patch'). We have
  8283. now done rather extensive testing of this patch on both development and
  8284. production systems.  It has significantly improved `MySQL' performance
  8285. without causing any problems and we now recommend it to our users who
  8286. are still running high-load servers on 2.2 kernels.  This issue has
  8287. been fixed in the 2.4 kernel, so if you are not satisfied with the
  8288. current performance of your system, rather than patching your 2.2
  8289. kernel, it might be easier to just upgrade to 2.4, which will also give
  8290. you a nice SMP boost in addition to fixing this fairness bug.
  8291.  
  8292. We have tested MySQL on the 2.4 kernel on a 2 CPU machine and found
  8293. MySQL scales MUCH better - there was virtually no slowdown on query
  8294. throughput all the way up to 1000 clients, and MySQL scaling factor (
  8295. computed as the ratio of maximum throughput to the throughput with one
  8296. client) was 180%.  We have observed similar results on a 4-CPU system -
  8297. virtually no slowdown as the number of clients was increased up to
  8298. 1000, and 300% scaling factor. So for a high-load SMP server we would
  8299. definitely recommend the 2.4 kernel at this point. We have discovered
  8300. that it is essential to run `mysqld' process with the highest possible
  8301. priority on the 2.4 kernel to achieve maximum performance.  This can be
  8302. done by adding `renice -20 $$' command to `safe_mysqld'. In our testing
  8303. on a 4-CPU machine, increasing the priority gave 60% increase in
  8304. throughput with 400 clients.
  8305.  
  8306. We are currently also trying to collect more info on how well `MySQL'
  8307. performs on 2.4 kernel on 4-way and 8-way systems. If you have access
  8308. such a system and have done some benchmarks, please send a mail to
  8309. <docs@mysql.com> with the results - we will include them in the manual.
  8310.  
  8311. There is another issue that greatly hurts MySQL performance, especially
  8312. on SMP systems.  The implementation of mutex in LinuxThreads in
  8313. *glibc-2.1* is very bad for programs with many threads that only hold
  8314. the mutex for a short time. On an SMP system, ironic as it is, if you
  8315. link MySQL against unmodified *LinuxThreads*, removing processors from
  8316. the machine improves MySQL performance in many cases.  We have made a
  8317. patch available for *glibc 2.1.3*, linuxthreads-2.1-patch
  8318. (http://www.mysql.com/Downloads/Linux/linuxthreads-2.1-patch) to
  8319. correct this behavior.
  8320.  
  8321. With *glibc-2.2.2* MySQL version 3.23.36 will use the adaptive mutex,
  8322. which is much better than even the patched one in *glibc-2.1.3*. Be
  8323. warned, however, that under some conditions, the current mutex code in
  8324. *glibc-2.2.2* overspins, which hurts MySQL performance. The chance of
  8325. this condition can be reduced by renicing `mysqld' process to the
  8326. highest priority. We have also been able to correct the overspin
  8327. behavior with a patch, available here
  8328. (http://www.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch). It
  8329. combines the correction of overspin, maximum number of threads, and
  8330. stack spacing all in one. You will need to apply it in the
  8331. `linuxthreads' directory with `patch -p0
  8332. </tmp/linuxthreads-2.2.2.patch'.  We hope it will be included in some
  8333. form in to the future releases of `glibc-2.2'. In any case, if you link
  8334. against `glibc-2.2.2' you still need to correct `STACK_SIZE' and
  8335. `PTHREAD_THREADS_MAX'. We hope that the defaults will be corrected to
  8336. some more acceptable values for high-load MySQL setup in the future, so
  8337. that your own build can be reduced to `./configure; make; make install'.
  8338.  
  8339. We recommend that you use the above patches to build a special static
  8340. version of `libpthread.a' and use it only for statically linking
  8341. against `MySQL'. We know that the patches are safe for `MySQL' and
  8342. significantly improve its performance, but we cannot say anything about
  8343. other applications. If you link other applications against the patched
  8344. version of the library, or build a patched shared version and install
  8345. it on your system, you are doing it at your own risk with regard to
  8346. other applications that depend on `LinuxThreads'.
  8347.  
  8348. If you experience any strange problems during the installation of
  8349. MySQL, or with some common utilties hanging, it is very likely that
  8350. they are either library or compiler related. If this is the case, using
  8351. our binary will resolve them.
  8352.  
  8353. One known problem with the binary distribution is that with older Linux
  8354. systems that use `libc' (like RedHat 4.x or Slackware), you will get
  8355. some non-fatal problems with hostname resolution.  *Note Binary
  8356. notes-Linux::.
  8357.  
  8358. When using LinuxThreads you will see a minimum of three processes
  8359. running.  These are in fact threads.  There will be one thread for the
  8360. LinuxThreads manager, one thread to handle connections, and one thread
  8361. to handle alarms and signals.
  8362.  
  8363. Note that the Linux kernel and the LinuxThread library can by default
  8364. only have 1024 threads.  This means that you can only have up to 1021
  8365. connections to MySQL on an unpatched system.  The page
  8366. `http://www.volano.com/linuxnotes.html' contains information how to go
  8367. around this limit.
  8368.  
  8369. If you see a dead `mysqld' daemon process with `ps', this usually means
  8370. that you have found a bug in MySQL or you have a corrupted table. *Note
  8371. Crashing::.
  8372.  
  8373. To get a core dump on Linux if `mysqld' dies with a SIGSEGV signal, you
  8374. can start `mysqld' with the `--core-file' option.  Note that you also
  8375. probably need to raise the `core file size' by adding `ulimit -c
  8376. 1000000' to `safe_mysqld' or starting `safe_mysqld' with
  8377. `--core-file-sizes=1000000'. *Note `safe_mysqld': safe_mysqld.
  8378.  
  8379. To get a core dump on Linux if `mysqld' dies with a SIGSEGV signal, you
  8380. can start `mysqld' with the `--core-file' option.  Note that you also
  8381. probably need to raise the `core file size' by adding `ulimit -c
  8382. 1000000' to `safe_mysqld' or starting `safe_mysqld' with
  8383. `--core-file-sizes=1000000'.  *Note `safe_mysqld': safe_mysqld.
  8384.  
  8385. If you are linking your own MySQL client and get the error:
  8386.  
  8387.      ld.so.1: ./my: fatal: libmysqlclient.so.4: open failed: No such file or directory
  8388.  
  8389. When executing them, the problem can be avoided by one of the following
  8390. methods:
  8391.  
  8392.    * Link the client with the following flag (instead of `-Lpath'):
  8393.      `-Wl,r/path-libmysqlclient.so'.
  8394.  
  8395.    * Copy `libmysqclient.so' to `/usr/lib'.
  8396.  
  8397.    * Add the pathname of the directory where `libmysqlclient.so' is
  8398.      located to the `LD_RUN_PATH' environment variable before running
  8399.      your client.
  8400.  
  8401. If you are using the Fujitsu compiler `(fcc / FCC)' you will have some
  8402. problems compiling MySQL because the Linux header files are very `gcc'
  8403. oriented.
  8404.  
  8405. The following `configure' line should work with `fcc/FCC':
  8406.  
  8407.      CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE -DCONST=const -DNO_STRTOLL_PROTO" CXX=FCC CXXFLAGS="-O -K fast -K lib  -K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE -DCONST=const -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO '-D_EXTERN_INLINE=static __inline'" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --with-low-memory
  8408.  
  8409. Linux Notes for Binary Distributions
  8410. ....................................
  8411.  
  8412. MySQL needs at least Linux Version 2.0.
  8413.  
  8414. The binary release is linked with `-static', which means you do not
  8415. normally need to worry about which version of the system libraries you
  8416. have. You need not install LinuxThreads, either.  A program linked with
  8417. `-static' is slightly bigger than a dynamically linked program but also
  8418. slightly faster (3-5%).  One problem, however, is that you can't use
  8419. user-definable functions (UDFs) with a statically linked program.  If
  8420. you are going to write or use UDF functions (this is something only for
  8421. C or C++ programmers), you must compile MySQL yourself, using dynamic
  8422. linking.
  8423.  
  8424. If you are using a `libc'-based system (instead of a `glibc2' system),
  8425. you will probably get some problems with hostname resolving and
  8426. `getpwnam()' with the binary release. (This is because `glibc'
  8427. unfortunately depends on some external libraries to resolve hostnames
  8428. and `getpwent()', even when compiled with `-static'). In this case you
  8429. probably get the following error message when you run
  8430. `mysql_install_db':
  8431.  
  8432.      Sorry, the host 'xxxx' could not be looked up
  8433.  
  8434. or the following error when you try to run `mysqld' with the `--user'
  8435. option:
  8436.  
  8437.      getpwnam: No such file or directory
  8438.  
  8439. You can solve this problem in one of the following ways:
  8440.  
  8441.    * Get a MySQL source distribution (an RPM or the `tar.gz'
  8442.      distribution) and install this instead.
  8443.  
  8444.    * Execute `mysql_install_db --force'; This will not execute the
  8445.      `resolveip' test in `mysql_install_db'.  The downside is that you
  8446.      can't use host names in the grant tables; you must use IP numbers
  8447.      instead (except for `localhost').  If you are using an old MySQL
  8448.      release that doesn't support `--force', you have to remove the
  8449.      `resolveip' test in `mysql_install' with an editor.
  8450.  
  8451.    * Start `mysqld' with `su' instead of using `--user'.
  8452.  
  8453. The Linux-Intel binary and RPM releases of MySQL are configured for the
  8454. highest possible speed.  We are always trying to use the fastest stable
  8455. compiler available.
  8456.  
  8457. MySQL Perl support requires Version Perl 5.004_03 or newer.
  8458.  
  8459. On some Linux 2.2 versions, you may get the error `Resource temporarily
  8460. unavailable' when you do a lot of new connections to a `mysqld' server
  8461. over TCP/IP.
  8462.  
  8463. The problem is that Linux has a delay between when you close a TCP/IP
  8464. socket and until this is actually freed by the system.  As there is only
  8465. room for a finite number of TCP/IP slots, you will get the above error
  8466. if you try to do too many new TCP/IP connections during a small time,
  8467. like when you run the MySQL `test-connect' benchmark over TCP/IP.
  8468.  
  8469. We have mailed about this problem a couple of times to different Linux
  8470. mailing lists but have never been able to resolve this properly.
  8471.  
  8472. The only known 'fix' to this problem is to use persistent connections in
  8473. your clients or use sockets, if you are running the database server and
  8474. clients on the same machine.  We hope that the `Linux 2.4' kernel will
  8475. fix this problem in the future.
  8476.  
  8477. Linux x86 Notes
  8478. ...............
  8479.  
  8480. MySQL requires `libc' Version 5.4.12 or newer. It's known to work with
  8481. `libc' 5.4.46.  `glibc' Version 2.0.6 and later should also work. There
  8482. have been some problems with the `glibc' RPMs from RedHat, so if you
  8483. have problems, check whether or not there are any updates!  The `glibc'
  8484. 2.0.7-19 and 2.0.7-29 RPMs are known to work.
  8485.  
  8486. On some older Linux distributions, `configure' may produce an error
  8487. like this:
  8488.  
  8489.      Syntax error in sched.h. Change _P to __P in the /usr/include/sched.h file.
  8490.      See the Installation chapter in the Reference Manual.
  8491.  
  8492. Just do what the error message says and add an extra underscore to the
  8493. `_P' macro that has only one underscore, then try again.
  8494.  
  8495. You may get some warnings when compiling; those shown below can be
  8496. ignored:
  8497.  
  8498.      mysqld.cc -o objs-thread/mysqld.o
  8499.      mysqld.cc: In function `void init_signals()':
  8500.      mysqld.cc:315: warning: assignment of negative value `-1' to `long unsigned int'
  8501.      mysqld.cc: In function `void * signal_hand(void *)':
  8502.      mysqld.cc:346: warning: assignment of negative value `-1' to `long unsigned int'
  8503.  
  8504. In Debian GNU/Linux, if you want MySQL to start automatically when the
  8505. system boots, do the following:
  8506.  
  8507.      shell> cp support-files/mysql.server /etc/init.d/mysql.server
  8508.      shell> /usr/sbin/update-rc.d mysql.server defaults 99
  8509.  
  8510. `mysql.server' can be found in the `share/mysql' directory under the
  8511. MySQL installation directory or in the `support-files' directory of the
  8512. MySQL source tree.
  8513.  
  8514. If `mysqld' always core dumps when it starts up, the problem may be that
  8515. you have an old `/lib/libc.a'.  Try renaming it, then remove
  8516. `sql/mysqld' and do a new `make install' and try again.  This problem
  8517. has been reported on some Slackware installations.
  8518.  
  8519. If you get the following error when linking `mysqld', it means that
  8520. your `libg++.a' is not installed correctly:
  8521.  
  8522.      /usr/lib/libc.a(putc.o): In function `_IO_putc':
  8523.      putc.o(.text+0x0): multiple definition of `_IO_putc'
  8524.  
  8525. You can avoid using `libg++.a' by running `configure' like this:
  8526.  
  8527.      shell> CXX=gcc ./configure
  8528.  
  8529. Linux SPARC Notes
  8530. .................
  8531.  
  8532. In some implementations, `readdir_r()' is broken.  The symptom is that
  8533. `SHOW DATABASES' always returns an empty set.  This can be fixed by
  8534. removing `HAVE_READDIR_R' from `config.h' after configuring and before
  8535. compiling.
  8536.  
  8537. Some problems will require patching your Linux installation.  The patch
  8538. can be found at
  8539. `http://www.mysql.com/Downloads/patches/Linux-sparc-2.0.30.diff'.  This
  8540. patch is against the Linux distribution `sparclinux-2.0.30.tar.gz' that
  8541. is available at `vger.rutgers.edu' (a version of Linux that was never
  8542. merged with the official 2.0.30).  You must also install LinuxThreads
  8543. Version 0.6 or newer.
  8544.  
  8545. Linux Alpha Notes
  8546. .................
  8547.  
  8548. MySQL Version 3.23.12 is the first MySQL version that is tested on
  8549. Linux-Alpha.  If you plan to use MySQL on Linux-Alpha, you should
  8550. ensure that you have this version or newer.
  8551.  
  8552. We have tested MySQL on Alpha with our benchmarks and test suite, and
  8553. it appears to work nicely.  The main thing we haven't yet had time to
  8554. test is how things works with many concurrent users.
  8555.  
  8556. When we compiled the standard MySQL binary we are using SuSE 6.4,
  8557. kernel 2.2.13-SMP, Compaq C compiler (V6.2-504) and Compaq C++ compiler
  8558. (V6.3-005) on a Comaq DS20 machine with an Alpha EV6 processor.
  8559.  
  8560. You can find the above compilers at
  8561. `http://www.support.compaq.com/alpha-tools').  By using these compilers,
  8562. instead of gcc, we get about 9-14 % better performance with MySQL.
  8563.  
  8564. Note that the configure line optimized the binary for the current CPU;
  8565. This means you can only use our binary if you have an Alpha EV6
  8566. processor. We also compile statically to avoid library problems.
  8567.  
  8568.      CC=ccc CFLAGS="-fast" CXX=cxx CXXFLAGS="-fast -noexceptions -nortti" ./configure --prefix=/usr/local/mysql --disable-shared --with-extra-charsets=complex --enable-thread-safe-client --with-mysqld-ldflags=-non_shared --with-client-ldflags=-non_shared
  8569.  
  8570. If you want to use egcs the following configure line worked for us:
  8571.  
  8572.      CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --disable-shared
  8573.  
  8574. Some known problems when running MySQL on Linux-Alpha:
  8575.  
  8576.    * Debugging threaded applications like MySQL will not work with `gdb
  8577.      4.18'.  You should download and use gdb 5.0 instead!
  8578.  
  8579.    * If you try linking `mysqld' statically when using `gcc', the
  8580.      resulting image will core dump at start.  In other words, *DON'T*
  8581.      use `--with-mysqld-ldflags=-all-static' with `gcc'.
  8582.  
  8583. Linux PowerPC Notes
  8584. ...................
  8585.  
  8586. MySQL should work on MkLinux with the newest `glibc' package (tested
  8587. with `glibc' 2.0.7).
  8588.  
  8589. Linux MIPS Notes
  8590. ................
  8591.  
  8592. To get MySQL to work on Qube2, (Linux Mips), you need the newest
  8593. `glibc' libraries (`glibc-2.0.7-29C2' is known to work).  You must also
  8594. use the `egcs' C++ compiler (`egcs-1.0.2-9', `gcc 2.95.2' or newer).
  8595.  
  8596. Linux IA64 Notes
  8597. ................
  8598.  
  8599. To get MySQL to compile on Linux Ia64, we use the following compile
  8600. line: Using `gcc-2.96':
  8601.  
  8602.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql "--with-comment=Official MySQL binary" --with-extra-charsets=complex
  8603.  
  8604. On Ia64 the MySQL client binaries are using shared libraries. This means
  8605. that if you install our binary distribution in some other place than
  8606. `/usr/local/mysql' you need to either modify `/etc/ld.so.conf' or add
  8607. the path to the directory where you have `libmysqlclient.so' to the
  8608. `LD_LIBRARY_PATH' environment variable.
  8609.  
  8610. *Note Link errors::.
  8611.  
  8612. Windows Notes
  8613. -------------
  8614.  
  8615. This section describes installation and use of MySQL on Windows.  This
  8616. information is also provided in the `README' file that comes with the
  8617. MySQL Windows distribution.
  8618.  
  8619. Starting MySQL on Windows 95 or Windows 98
  8620. ..........................................
  8621.  
  8622. MySQL uses TCP/IP to connect a client to a server. (This will allow any
  8623. machine on your network to connect to your MySQL server.)  Because of
  8624. this, you must install TCP/IP on your machine before starting MySQL.
  8625. You can find TCP/IP on your Windows CD-ROM.
  8626.  
  8627. Note that if you are using an old Win95 release (for example OSR2), it's
  8628. likely that you have an old Winsock package!  MySQL requires Winsock 2!
  8629. You can get the newest Winsock from `http://www.microsoft.com/'.
  8630. Win98 has the new Winsock 2 library, so the above doesn't apply for
  8631. Win98.
  8632.  
  8633. To start the `mysqld' server, you should start an MS-DOS window and
  8634. type:
  8635.  
  8636.      C:\> C:\mysql\bin\mysqld
  8637.  
  8638. This will start `mysqld' in the background without a window.
  8639.  
  8640. You can kill the MySQL server by executing:
  8641.  
  8642.      C:\> C:\mysql\bin\mysqladmin -u root shutdown
  8643.  
  8644. Note that Win95 and Win98 don't support creation of named pipes.  On
  8645. Win95 and Win98, you can only use named pipes to connect to a remote
  8646. MySQL server running on a Windows NT server host.  (The MySQL server
  8647. must also support named pipes, of course. For example, using
  8648. `mysqld-opt' under NT will not allow named pipe connections.  You
  8649. should use either `mysqld-nt' or `mysqld-max-nt'.)
  8650.  
  8651. If `mysqld' doesn't start, please check the `\mysql\data\mysql.err'
  8652. file to see if the server wrote any message there to indicate the cause
  8653. of the problem.  You can also try to start the server with `mysqld
  8654. --standalone';  In this case, you may get some useful information on
  8655. the screen that may help solve the problem.
  8656.  
  8657. The last option is to start `mysqld' with `--standalone --debug'.  In
  8658. this case `mysqld' will write a log file `C:\mysqld.trace' that should
  8659. contain the reason why `mysqld' doesn't start. *Note Making trace
  8660. files::.
  8661.  
  8662. Starting MySQL on Windows NT or Windows 2000
  8663. ............................................
  8664.  
  8665. The Win95/Win98 section also applies to MySQL on NT/Win2000, with the
  8666. following differences:
  8667.  
  8668. To get MySQL to work with TCP/IP on NT, you must install service pack 3
  8669. (or newer)!
  8670.  
  8671. Note that everything in the following that applies for NT also applies
  8672. for Win2000!
  8673.  
  8674. For NT/Win2000, the server name is `mysqld-nt'.  Normally you should
  8675. install MySQL as a service on NT/Win2000:
  8676.  
  8677.      C:\> C:\mysql\bin\mysqld-nt --install
  8678.  
  8679. or
  8680.  
  8681.      C:\> C:\mysql\bin\mysqld-max-nt --install
  8682.  
  8683. (Under Windows NT, you can actually install any of the server binaries
  8684. as a service, but only those having names that end with `-nt.exe'
  8685. provide support for named pipes.)
  8686.  
  8687. You can start and stop the MySQL service with these commands:
  8688.  
  8689.      C:\> NET START mysql
  8690.      C:\> NET STOP mysql
  8691.  
  8692. Note that in this case you can't use any other options for `mysqld-nt'!
  8693.  
  8694. You can also run `mysqld-nt' as a stand-alone program on NT if you need
  8695. to start `mysqld-nt' with any options!  If you start `mysqld-nt'
  8696. without options on NT, `mysqld-nt' tries to start itself as a service
  8697. with the default service options.  If you have stopped `mysqld-nt', you
  8698. have to start it with `NET START mysql'.
  8699.  
  8700. The service is installed with the name `MySQL'. Once installed, it must
  8701. be started using the Services Control Manager (SCM) Utility found in the
  8702. Control Panel, or by using the `NET START MySQL' command.  If any
  8703. options are desired, they must be specified as "Startup parameters" in
  8704. the SCM utility before you start the MySQL service.  Once running,
  8705. `mysqld-nt' can be stopped using `mysqladmin', or from the SCM utility
  8706. or by using the command `NET STOP MySQL'. If you use SCM to stop
  8707. `mysqld-nt', there is a strange message from SCM about `mysqld shutdown
  8708. normally'.  When run as a service, `mysqld-nt' has no access to a
  8709. console and so no messages can be seen.
  8710.  
  8711. On NT you can get the following service error messages:
  8712.  
  8713. Permission Denied      Means that it cannot find `mysqld-nt.exe'.
  8714. Cannot Register        Means that the path is incorrect.
  8715. Failed to install      Means that the service is already installed or
  8716. service.               that the Service Control Manager is in bad state.
  8717.  
  8718. If you have problems installing `mysqld-nt' as a service, try starting
  8719. it with the full path:
  8720.  
  8721.      C:\> C:\mysql\bin\mysqld-nt --install
  8722.  
  8723. If this doesn't work, you can get `mysqld-nt' to start properly by
  8724. fixing the path in the registry!
  8725.  
  8726. If you don't want to start `mysqld-nt' as a service, you can start it as
  8727. follows:
  8728.  
  8729.      C:\> C:\mysql\bin\mysqld-nt --standalone
  8730.  
  8731. or
  8732.  
  8733.      C:\> C:\mysql\bin\mysqld --standalone --debug
  8734.  
  8735. The last version gives you a debug trace in `C:\mysqld.trace'.  *Note
  8736. Making trace files::.
  8737.  
  8738. Running MySQL on Windows
  8739. ........................
  8740.  
  8741. MySQL supports TCP/IP on all Windows platforms and named pipes on NT.
  8742. The default is to use named pipes for local connections on NT and
  8743. TCP/IP for all other cases if the client has TCP/IP installed.  The
  8744. host name specifies which protocol is used:
  8745.  
  8746. *Host name* *Protocol*             
  8747. NULL (none)            On NT, try named pipes first; if that doesn't
  8748.                        work, use TCP/IP. On Win95/Win98, TCP/IP is used.
  8749. .                      Named pipes
  8750. localhost              TCP/IP to current host
  8751. hostname               TCP/IP
  8752.  
  8753.  
  8754. You can force a MySQL client to use named pipes by specifying the
  8755. `--pipe' option or by specifying `.' as the host name.  Use the
  8756. `--socket' option to specify the name of the pipe.
  8757.  
  8758. You can test whether or not MySQL is working by executing the following
  8759. commands:
  8760.  
  8761.      C:\> C:\mysql\bin\mysqlshow
  8762.      C:\> C:\mysql\bin\mysqlshow -u root mysql
  8763.      C:\> C:\mysql\bin\mysqladmin version status proc
  8764.      C:\> C:\mysql\bin\mysql test
  8765.  
  8766. If `mysqld' is slow to answer to connections on Win95/Win98, there is
  8767. probably a problem with your DNS.  In this case, start `mysqld' with
  8768. `--skip-name-resolve' and use only `localhost' and IP numbers in the
  8769. MySQL grant tables.  You can also avoid DNS when connecting to a
  8770. `mysqld-nt' MySQL server running on NT by using the `--pipe' argument
  8771. to specify use of named pipes.  This works for most MySQL clients.
  8772.  
  8773. There are two versions of the MySQL command-line tool:
  8774. `mysql'            Compiled on native Windows, which offers very limited
  8775.                    text editing capabilities.
  8776. `mysqlc'           Compiled with the Cygnus GNU compiler and libraries,
  8777.                    which offers `readline' editing.
  8778.  
  8779. If you want to use `mysqlc.exe', you must copy
  8780. `C:\mysql\lib\cygwinb19.dll' to your Windows system directory
  8781. (`\windows\system' or similar place).
  8782.  
  8783. The default privileges on Windows give all local users full privileges
  8784. to all databases without specifying a password.  To make MySQL more
  8785. secure, you should set a password for all users and remove the row in
  8786. the `mysql.user' table that has `Host='localhost'' and `User='''.
  8787.  
  8788. You should also add a password for the `root' user. The following
  8789. example starts by removing the anonymous user that can be used by anyone
  8790. to access the `test' database, then sets a `root' user password:
  8791.  
  8792.      C:\> C:\mysql\bin\mysql mysql
  8793.      mysql> DELETE FROM user WHERE Host='localhost' AND User='';
  8794.      mysql> QUIT
  8795.      C:\> C:\mysql\bin\mysqladmin reload
  8796.      C:\> C:\mysql\bin\mysqladmin -u root password your_password
  8797.  
  8798. After you've set the password, if you want to take down the `mysqld'
  8799. server, you can do so using this command:
  8800.  
  8801.      C:\> mysqladmin --user=root --password=your_password shutdown
  8802.  
  8803. If you are using the old shareware version of MySQL Version 3.21 under
  8804. Windows, the above command will fail with an error: `parse error near
  8805. 'SET OPTION password''.  The fix is in to upgrade to the current MySQL
  8806. version, which is freely available.
  8807.  
  8808. With the current MySQL versions you can easily add new users and change
  8809. privileges with `GRANT' and `REVOKE' commands.  *Note GRANT::.
  8810.  
  8811. Connecting to a Remote MySQL from Windows with SSH
  8812. ..................................................
  8813.  
  8814. Here is a note about how to connect to get a secure connection to remote
  8815. MySQL server with SSH (by David Carlson <dcarlson@mplcomm.com>):
  8816.  
  8817.    * Install an SSH client on your Windows machine.  As a user, the
  8818.      best non-free one I've found is from `SecureCRT' from
  8819.      `http://www.vandyke.com/'.  Another option is `f-secure' from
  8820.      `http://www.f-secure.com/'. You can also find some free ones on
  8821.      *Google* at
  8822.      `http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cryptography/SSH/Clients/Windows/'.
  8823.  
  8824.    * Start your Windows SSH client.  Set `Host_Name =
  8825.      yourmysqlserver_URL_or_IP'.  Set `userid=your_userid' to log in to
  8826.      your server (probably not the same as your MySQL login/password.
  8827.  
  8828.    * Set up port forwarding. Either do a remote forward (Set
  8829.      `local_port: 3306', `remote_host: yourmysqlservername_or_ip',
  8830.      `remote_port: 3306' ) or a local forward (Set `port: 3306',
  8831.      `host: localhost', `remote port: 3306').
  8832.  
  8833.    * Save everything, otherwise you'll have to redo it the next time.
  8834.  
  8835.    * Log in to your server with SSH session you just created.
  8836.  
  8837.    * On your Windows machine, start some ODBC application (such as
  8838.      Access).
  8839.  
  8840.    * Create a new file in Windows and link to MySQL using the ODBC
  8841.      driver the same way you normally do, EXCEPT type in `localhost'
  8842.      for the MySQL host server -- not `yourmysqlservername'.
  8843.  
  8844. You should now have an ODBC connection to MySQL, encrypted using SSH.
  8845.  
  8846. Splitting Data Across Different Disks on Windows
  8847. ................................................
  8848.  
  8849. Beginning with MySQL Version 3.23.16, the `mysqld-max' and
  8850. `mysql-max-nt' servers in the MySQL distribution are compiled with the
  8851. `-DUSE_SYMDIR' option.  This allows you to put a database on different
  8852. disk by adding a symbolic link to it (in a manner similar to the way
  8853. that symbolic links work on Unix).
  8854.  
  8855. On Windows, you make a symbolic link to a database by creating a file
  8856. that contains the path to the destination directory and saving this in
  8857. the `mysql_data' directory under the filename `database.sym'.  Note
  8858. that the symbolic link will be used only if the directory
  8859. `mysql_data_dir\database' doesn't exist.
  8860.  
  8861. For example, if the MySQL data directory is `C:\mysql\data' and you
  8862. want to have database `foo' located at `D:\data\foo', you should create
  8863. the file `C:\mysql\data\foo.sym' that contains the text `D:\data\foo\'.
  8864. After that, all tables created in the database `foo' will be created
  8865. in `D:\data\foo'.
  8866.  
  8867. Note that because of the speed penalty you get when opening every table,
  8868. we have not enabled this by default even if you have compiled MySQL
  8869. with support for this. To enable symlinks you should put in your
  8870. `my.cnf' or `my.ini' file the following entry:
  8871.  
  8872.      [mysqld]
  8873.      use-symbolic-links
  8874.  
  8875. In MySQL 4.0 we will enable symlinks by default. Then you should
  8876. instead use the `skip-symlink' option if you want to disable this.
  8877.  
  8878. Compiling MySQL Clients on Windows
  8879. ..................................
  8880.  
  8881. In your source files, you should include `windows.h' before you include
  8882. `mysql.h':
  8883.  
  8884.      #if defined(_WIN32) || defined(_WIN64)
  8885.      #include <windows.h>
  8886.      #endif
  8887.      #include <mysql.h>
  8888.  
  8889. You can either link your code with the dynamic `libmysql.lib' library,
  8890. which is just a wrapper to load in `libmysql.dll' on demand, or link
  8891. with the static `mysqlclient.lib' library.
  8892.  
  8893. Note that as the mysqlclient libraries are compiled as threaded
  8894. libraries, you should also compile your code to be multi-threaded!
  8895.  
  8896. MySQL-Windows Compared to Unix MySQL
  8897. ....................................
  8898.  
  8899. MySQL-Windows has by now proven itself to be very stable. This version
  8900. of MySQL has the same features as the corresponding Unix version with
  8901. the following exceptions:
  8902.  
  8903. *Win95 and threads*
  8904.      Win95 leaks about 200 bytes of main memory for each thread
  8905.      creation.  Each connection in MySQL creates a new thread, so you
  8906.      shouldn't run `mysqld' for an extended time on Win95 if your
  8907.      server handles many connections!  WinNT and Win98 don't suffer
  8908.      from this bug.
  8909.  
  8910. *Concurrent reads*
  8911.      MySQL depends on the `pread()' and `pwrite()' calls to be able to
  8912.      mix `INSERT' and `SELECT'.  Currently we use mutexes to emulate
  8913.      `pread()'/`pwrite()'.  We will, in the long run, replace the file
  8914.      level interface with a virtual interface so that we can use the
  8915.      `readfile()'/`writefile()' interface on NT to get more speed.  The
  8916.      current implementation limits the number of open files MySQL can
  8917.      use to 1024, which means that you will not be able to run as many
  8918.      concurrent threads on NT as on Unix.
  8919.  
  8920. *Blocking read*
  8921.      MySQL uses a blocking read for each connection.  This means that:
  8922.  
  8923.         * A connection will not be disconnected automatically after 8
  8924.           hours, as happens with the Unix version of MySQL.
  8925.  
  8926.         * If a connection hangs, it's impossible to break it without
  8927.           killing MySQL.
  8928.  
  8929.         * `mysqladmin kill' will not work on a sleeping connection.
  8930.  
  8931.         * `mysqladmin shutdown' can't abort as long as there are
  8932.           sleeping connections.
  8933.  
  8934.      We plan to fix this problem when our Windows developers have
  8935.      figured out a nice workaround.
  8936.  
  8937. *UDF functions*
  8938.      For the moment, MySQL-Windows does not support user-definable
  8939.      functions.
  8940.  
  8941. *`DROP DATABASE'*
  8942.      You can't drop a database that is in use by some thread.
  8943.  
  8944. *Killing MySQL from the task manager*
  8945.      You can't kill MySQL from the task manager or with the shutdown
  8946.      utility in Win95.  You must take it down with `mysqladmin
  8947.      shutdown'.
  8948.  
  8949. *Case-insensitive names*
  8950.      Filenames are case insensitive on Windows, so database and table
  8951.      names are also case insensitive in MySQL for Windows.  The only
  8952.      restriction is that database and table names must be specified
  8953.      using the same case throughout a given statement.  *Note Name case
  8954.      sensitivity::.
  8955.  
  8956. *The `\' directory character*
  8957.      Pathname components in Win95 are separated by the `\' character,
  8958.      which is also the escape character in MySQL.  If you are using
  8959.      `LOAD DATA INFILE' or `SELECT ... INTO OUTFILE', you must double
  8960.      the `\' character:
  8961.  
  8962.           mysql> LOAD DATA INFILE "C:\\tmp\\skr.txt" INTO TABLE skr;
  8963.           mysql> SELECT * INTO OUTFILE 'C:\\tmp\\skr.txt' FROM skr;
  8964.  
  8965.      Alternatively, use Unix style filenames with `/' characters:
  8966.  
  8967.           mysql> LOAD DATA INFILE "C:/tmp/skr.txt" INTO TABLE skr;
  8968.           mysql> SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr;
  8969.  
  8970. *`Can't open named pipe' error*
  8971.      If you use a MySQL 3.22 version on NT with the newest mysql-clients
  8972.      you will get the following error:
  8973.  
  8974.           error 2017: can't open named pipe to host: . pipe...
  8975.  
  8976.      This is because the release version of MySQL uses named pipes on NT
  8977.      by default.  You can avoid this error by using the
  8978.      `--host=localhost' option to the new MySQL clients or create an
  8979.      option file `C:\my.cnf' that contains the following information:
  8980.  
  8981.           [client]
  8982.           host = localhost
  8983.  
  8984. *`Access denied for user' error*
  8985.      If you get the error `Access denied for user: 'some-user@unknown'
  8986.      to database 'mysql'' when accessing a MySQL server on the same
  8987.      machine, this means that MySQL can't resolve your host name
  8988.      properly.
  8989.  
  8990.      To fix this, you should create a file `\windows\hosts' with the
  8991.      following information:
  8992.  
  8993.           127.0.0.1       localhost
  8994.  
  8995. *`ALTER TABLE'*
  8996.      While you are executing an `ALTER TABLE' statement, the table is
  8997.      locked from usage by other threads.  This has to do with the fact
  8998.      that on Windows, you can't delete a file that is in use by another
  8999.      threads.  (In the future, we may find some way to work around this
  9000.      problem.)
  9001.  
  9002. *`DROP TABLE' on a table that is in use by a `MERGE' table will not work*
  9003.      The `MERGE' handler does its table mapping hidden from MySQL.
  9004.      Because Windows doesn't allow you to drop files that are open, you
  9005.      first must flush all `MERGE' tables (with `FLUSH TABLES') or drop
  9006.      the `MERGE' table before dropping the table.  We will fix this at
  9007.      the same time we introduce `VIEW's.
  9008.  
  9009. Here are some open issues for anyone who might want to help us with the
  9010. Windows release:
  9011.  
  9012.    * Make a single-user `MYSQL.DLL' server.  This should include
  9013.      everything in a standard MySQL server, except thread creation.
  9014.      This will make MySQL much easier to use in applications that don't
  9015.      need a true client/server and don't need to access the server from
  9016.      other hosts.
  9017.  
  9018.    * Add some nice start and shutdown icons to the MySQL installation.
  9019.  
  9020.    * Create a tool to manage registry entries for the MySQL startup
  9021.      options.  The registry entry reading is already coded into
  9022.      `mysqld.cc', but it should be recoded to be more parameter
  9023.      oriented.  The tool should also be able to update the `C:\my.cnf'
  9024.      option file if the user prefers to use that instead of the
  9025.      registry.
  9026.  
  9027.    * When registering `mysqld' as a service with `--install' (on NT) it
  9028.      would be nice if you could also add default options on the command
  9029.      line.  For the moment, the workaround is to list the parameters in
  9030.      the `C:\my.cnf' file instead.
  9031.  
  9032.    * It would be real nice to be able to kill `mysqld' from the task
  9033.      manager.  For the moment, you must use `mysqladmin shutdown'.
  9034.  
  9035.    * Port `readline' to Windows for use in the `mysql' command line
  9036.      tool.
  9037.  
  9038.    * GUI versions of the standard MySQL clients (`mysql', `mysqlshow',
  9039.      `mysqladmin', and `mysqldump') would be nice.
  9040.  
  9041.    * It would be nice if the socket read and write functions in `net.c'
  9042.      were interruptible. This would make it possible to kill open
  9043.      threads with `mysqladmin kill' on Windows.
  9044.  
  9045.    * `mysqld' always starts in the "C" locale and not in the default
  9046.      locale.  We would like to have `mysqld' use the current locale for
  9047.      the sort order.
  9048.  
  9049.    * Implement UDF functions with `.DLL's.
  9050.  
  9051.    * Add macros to use the faster thread-safe increment/decrement
  9052.      methods provided by Windows.
  9053.  
  9054.  
  9055. Other Windows-specific issues are described in the `README' file that
  9056. comes with the MySQL-Windows distribution.
  9057.  
  9058. Solaris Notes
  9059. -------------
  9060.  
  9061. On Solaris, you may run into trouble even before you get the MySQL
  9062. distribution unpacked!  Solaris `tar' can't handle long file names, so
  9063. you may see an error like this when you unpack MySQL:
  9064.  
  9065.      x mysql-3.22.12-beta/bench/Results/ATIS-mysql_odbc-NT_4.0-cmp-db2,informix,ms-sql,mysql,oracle,solid,sybase, 0 bytes, 0 tape blocks
  9066.      tar: directory checksum error
  9067.  
  9068. In this case, you must use GNU `tar' (`gtar') to unpack the
  9069. distribution.  You can find a precompiled copy for Solaris at
  9070. `http://www.mysql.com/Downloads/'.
  9071.  
  9072. Sun native threads work only on Solaris 2.5 and higher.  For Version
  9073. 2.4 and earlier, MySQL will automatically use MIT-pthreads.  *Note
  9074. MIT-pthreads::.
  9075.  
  9076. If you get the following error from configure:
  9077.  
  9078.      checking for restartable system calls... configure: error can not run test
  9079.      programs while cross compiling
  9080.  
  9081. This means that you have something wrong with your compiler
  9082. installation!  In this case you should upgrade your compiler to a newer
  9083. version.  You may also be able to solve this problem by inserting the
  9084. following row into the `config.cache' file:
  9085.  
  9086.      ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
  9087.  
  9088. If you are using Solaris on a SPARC, the recommended compiler is `gcc'
  9089. 2.95.2.  You can find this at `http://gcc.gnu.org/'.  Note that `egcs'
  9090. 1.1.1 and `gcc' 2.8.1 don't work reliably on SPARC!
  9091.  
  9092. The recommended `configure' line when using `gcc' 2.95.2 is:
  9093.  
  9094.      CC=gcc CFLAGS="-O3" \
  9095.      CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" \
  9096.      ./configure --prefix=/usr/local/mysql --with-low-memory --enable-assembler
  9097.  
  9098. If you have a ultra sparc, you can get 4 % more performance by adding
  9099. "-mcpu=v8 -Wa,-xarch=v8plusa" to CFLAGS and CXXFLAGS.
  9100.  
  9101. If you have Sun Workshop (Fortre) 5.3 (or newer) compiler, you can run
  9102. `configure' like this:
  9103.  
  9104.      CC=cc CFLAGS="-Xa -fast -xO4 -native -xstrconst -mt" \
  9105.      CXX=CC CXXFLAGS="-noex -xO4 -mt" \
  9106.      ./configure --prefix=/usr/local/mysql --enable-assembler
  9107.  
  9108. In the MySQL benchmarks, we got a 6 % speedup on an Ultrasparc when
  9109. using Sun Workshop 5.3 compared to using gcc with -mcpu flags.
  9110.  
  9111. If you get a problem with `fdatasync' or `sched_yield', you can fix
  9112. this by adding `LIBS=-lrt' to the configure line
  9113.  
  9114. The following paragraph is only relevant for older compilers than
  9115. WorkShop 5.3:
  9116.  
  9117. You may also have to edit the `configure' script to change this line:
  9118.  
  9119.      #if !defined(__STDC__) || __STDC__ != 1
  9120.  
  9121. to this:
  9122.  
  9123.      #if !defined(__STDC__)
  9124.  
  9125. If you turn on `__STDC__' with the `-Xc' option, the Sun compiler can't
  9126. compile with the Solaris `pthread.h' header file.  This is a Sun bug
  9127. (broken compiler or broken include file).
  9128.  
  9129. If `mysqld' issues the error message shown below when you run it, you
  9130. have tried to compile MySQL with the Sun compiler without enabling the
  9131. multi-thread option (`-mt'):
  9132.  
  9133.      libc internal error: _rmutex_unlock: rmutex not held
  9134.  
  9135. Add `-mt' to `CFLAGS' and `CXXFLAGS' and try again.
  9136.  
  9137. If you get the following error when compiling MySQL with `gcc', it
  9138. means that your `gcc' is not configured for your version of Solaris:
  9139.  
  9140.      shell> gcc -O3 -g -O2 -DDBUG_OFF  -o thr_alarm ...
  9141.      ./thr_alarm.c: In function `signal_hand':
  9142.      ./thr_alarm.c:556: too many arguments to function `sigwait'
  9143.  
  9144. The proper thing to do in this case is to get the newest version of
  9145. `gcc' and compile it with your current `gcc' compiler!  At least for
  9146. Solaris 2.5, almost all binary versions of `gcc' have old, unusable
  9147. include files that will break all programs that use threads (and
  9148. possibly other programs)!
  9149.  
  9150. Solaris doesn't provide static versions of all system libraries
  9151. (`libpthreads' and `libdl'), so you can't compile MySQL with
  9152. `--static'.  If you try to do so, you will get the error:
  9153.  
  9154.      ld: fatal: library -ldl: not found
  9155.      
  9156.      or
  9157.      
  9158.      undefined reference to `dlopen'
  9159.      
  9160.      or
  9161.      
  9162.      cannot find -lrt
  9163.  
  9164. If too many processes try to connect very rapidly to `mysqld', you will
  9165. see this error in the MySQL log:
  9166.  
  9167.      Error in accept: Protocol error
  9168.  
  9169. You might try starting the server with the `--set-variable back_log=50'
  9170. option as a workaround for this. *Note Command-line options::.
  9171.  
  9172. If you are linking your own MySQL client, you might get the following
  9173. error when you try to execute it:
  9174.  
  9175.      ld.so.1: ./my: fatal: libmysqlclient.so.#: open failed: No such file or directory
  9176.  
  9177. The problem can be avoided by one of the following methods:
  9178.  
  9179.    * Link the client with the following flag (instead of `-Lpath'):
  9180.      `-Wl,r/full-path-to-libmysqlclient.so'.
  9181.  
  9182.    * Copy `libmysqclient.so' to `/usr/lib'.
  9183.  
  9184.    * Add the pathname of the directory where `libmysqlclient.so' is
  9185.      located to the `LD_RUN_PATH' environment variable before running
  9186.      your client.
  9187.  
  9188. When using the `--with-libwrap' configure option, you must also include
  9189. the libraries that `libwrap.a' needs:
  9190.  
  9191.      --with-libwrap="/opt/NUtcpwrapper-7.6/lib/libwrap.a -lnsl -lsocket
  9192.  
  9193. If you have problems with configure trying to link with `-lz' and you
  9194. don't have `zlib' installed, you have two options:
  9195.  
  9196.    * If you want to be able to use the compressed communication
  9197.      protocol, you need to get and install zlib from ftp.gnu.org.
  9198.  
  9199.    * Configure with `--with-named-z-libs=no'.
  9200.  
  9201. If you are using gcc and have problems with loading `UDF' functions
  9202. into MySQL, try adding `-lgcc' to the link line for the `UDF' function.
  9203.  
  9204. If you would like MySQL to start automatically, you can copy
  9205. `support-files/mysql.server' to `/etc/init.d' and create a symbolic
  9206. link to it named `/etc/rc3.d/S99mysql.server'.
  9207.  
  9208. Solaris 2.7/2.8 Notes
  9209. .....................
  9210.  
  9211. You can normally use a Solaris 2.6 binary on Solaris 2.7 and 2.8.  Most
  9212. of the Solaris 2.6 issues also apply for Solaris 2.7 and 2.8.
  9213.  
  9214. Note that MySQL Version 3.23.4 and above should be able to autodetect
  9215. new versions of Solaris and enable workarounds for the following
  9216. problems!
  9217.  
  9218. Solaris 2.7 / 2.8 has some bugs in the include files.  You may see the
  9219. following error when you use `gcc':
  9220.  
  9221.      /usr/include/widec.h:42: warning: `getwc' redefined
  9222.      /usr/include/wchar.h:326: warning: this is the location of the previous
  9223.      definition
  9224.  
  9225. If this occurs, you can do the following to fix the problem:
  9226.  
  9227. Copy `/usr/include/widec.h' to `.../lib/gcc-lib/os/gcc-version/include'
  9228. and change line 41 from:
  9229.  
  9230.      #if     !defined(lint) && !defined(__lint)
  9231.      
  9232.      to
  9233.      
  9234.      #if     !defined(lint) && !defined(__lint) && !defined(getwc)
  9235.  
  9236. Alternatively, you can edit `/usr/include/widec.h' directly.  Either
  9237. way, after you make the fix, you should remove `config.cache' and run
  9238. `configure' again!
  9239.  
  9240. If you get errors like this when you run `make', it's because
  9241. `configure' didn't detect the `curses.h' file (probably because of the
  9242. error in `/usr/include/widec.h'):
  9243.  
  9244.      In file included from mysql.cc:50:
  9245.      /usr/include/term.h:1060: syntax error before `,'
  9246.      /usr/include/term.h:1081: syntax error before `;'
  9247.  
  9248. The solution to this is to do one of the following:
  9249.  
  9250.    * Configure with `CFLAGS=-DHAVE_CURSES_H CXXFLAGS=-DHAVE_CURSES_H
  9251.      ./configure'.
  9252.  
  9253.    * Edit `/usr/include/widec.h' as indicted above and rerun configure.
  9254.  
  9255.    * Remove the `#define HAVE_TERM' line from `config.h' file and run
  9256.      `make' again.
  9257.  
  9258. If you get a problem that your linker can't find `-lz' when linking
  9259. your client program, the problem is probably that your `libz.so' file is
  9260. installed in `/usr/local/lib'.  You can fix this by one of the
  9261. following methods:
  9262.  
  9263.    * Add `/usr/local/lib' to `LD_LIBRARY_PATH'.
  9264.  
  9265.    * Add a link to `libz.so' from `/lib'.
  9266.  
  9267.    * If you are using Solaris 8, you can install the optional zlib from
  9268.      your Solaris 8 CD distribution.
  9269.  
  9270.    * Configure MySQL with the `--with-named-z-libs=no' option.
  9271.  
  9272. Solaris x86 Notes
  9273. .................
  9274.  
  9275. On Solaris 2.8 on x86, `mysqld' will core dump if you run 'strip' in.
  9276.  
  9277. If you are using `gcc' or `egcs' on Solaris x86 and you experience
  9278. problems with core dumps under load, you should use the following
  9279. `configure' command:
  9280.  
  9281.      CC=gcc CFLAGS="-O3 -fomit-frame-pointer -DHAVE_CURSES_H" \
  9282.      CXX=gcc \
  9283.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti -DHAVE_CURSES_H" \
  9284.      ./configure --prefix=/usr/local/mysql
  9285.  
  9286. This will avoid problems with the `libstdc++' library and with C++
  9287. exceptions.
  9288.  
  9289. If this doesn't help, you should compile a debug version and run it
  9290. with a trace file or under `gdb'.  *Note Using gdb on mysqld::.
  9291.  
  9292. BSD Notes
  9293. ---------
  9294.  
  9295. FreeBSD Notes
  9296. .............
  9297.  
  9298. FreeBSD 3.x is recommended for running MySQL since the thread package
  9299. is much more integrated.
  9300.  
  9301. The easiest and therefor the preferred way to install is to use the
  9302. mysql-server and mysql-client ports available on
  9303. `http://www.freebsd.org'.
  9304.  
  9305. Using these gives you:
  9306.    * A working MySQL with all optimizations known to work on your
  9307.      version of FreeBSD enabled.
  9308.  
  9309.    * Automatic configuration and build.
  9310.  
  9311.    * Startup scripts installed in /usr/local/etc/rc.d.
  9312.  
  9313.    * Ability to see which files that are installed with pkg_info -L.
  9314.      And to remove them all with pkg_delete if you no longer want MySQL
  9315.      on that machine.
  9316.  
  9317. It is recommended you use MIT-pthreads on FreeBSD 2.x and native
  9318. threads on Versions 3 and up. It is possible to run with  native
  9319. threads on some late 2.2.x versions but you may encounter problems
  9320. shutting down `mysqld'.
  9321.  
  9322. The MySQL `Makefile's require GNU make (`gmake') to work.  If you want
  9323. to compile MySQL you need to install GNU `make' first.
  9324.  
  9325. Be sure to have your name resolver setup correct.  Otherwise you may
  9326. experience resolver delays or failures when connecting to `mysqld'.
  9327.  
  9328. Make sure that the `localhost' entry in the `/etc/hosts' file is
  9329. correct (otherwise you will have problems connecting to the database).
  9330. The `/etc/hosts' file should start with a line:
  9331.  
  9332.      127.0.0.1       localhost localhost.your.domain
  9333.  
  9334. If you notice that `configure' will use MIT-pthreads, you should read
  9335. the MIT-pthreads notes.  *Note MIT-pthreads::.
  9336.  
  9337. If you get an error from `make install' that it can't find
  9338. `/usr/include/pthreads', `configure' didn't detect that you need
  9339. MIT-pthreads.  This is fixed by executing these commands:
  9340.  
  9341.      shell> rm config.cache
  9342.      shell> ./configure --with-mit-threads
  9343.  
  9344. FreeBSD is also known to have a very low default file handle limit.
  9345. *Note Not enough file handles::.  Uncomment the ulimit -n section in
  9346. safe_mysqld or raise the limits for the `mysqld' user in /etc/login.conf
  9347. (and rebuild it with cap_mkdb /etc/login.conf).  Also be sure you set
  9348. the appropriate class for this user in the password file if you are not
  9349. using the default (use: chpass mysqld-user-name).  *Note `safe_mysqld':
  9350. safe_mysqld.
  9351.  
  9352. If you get problems with the current date in MySQL, setting the `TZ'
  9353. variable will probably help.  *Note Environment variables::.
  9354.  
  9355. To get a secure and stable system you should only use FreeBSD kernels
  9356. that are marked `-STABLE'.
  9357.  
  9358. NetBSD notes
  9359. ............
  9360.  
  9361. To compile on NetBSD you need GNU `make'.  Otherwise the compile will
  9362. crash when `make' tries to run `lint' on C++ files.
  9363.  
  9364. OpenBSD Notes
  9365. .............
  9366.  
  9367. OpenBSD 2.5 Notes
  9368. .................
  9369.  
  9370. On OpenBSD Version 2.5, you can compile MySQL with native threads with
  9371. the following options:
  9372.  
  9373.      CFLAGS=-pthread CXXFLAGS=-pthread ./configure --with-mit-threads=no
  9374.  
  9375. OpenBSD 2.8 Notes
  9376. .................
  9377.  
  9378. Our users have reported that OpenBSD 2.8 has a threading bug which
  9379. causes problems with MySQL.  The OpenBSD Developers have fixed the
  9380. problem, but as of January 25th, 2001, it's only available in the
  9381. "-current" branch.  The symptoms of this threading bug are: slow
  9382. response, high load, high CPU usage, and crashes.
  9383.  
  9384. BSD/OS Notes
  9385. ............
  9386.  
  9387. BSD/OS Version 2.x Notes
  9388. ........................
  9389.  
  9390. If you get the following error when compiling MySQL, your `ulimit'
  9391. value for virtual memory is too low:
  9392.  
  9393.      item_func.h: In method `Item_func_ge::Item_func_ge(const Item_func_ge &)':
  9394.      item_func.h:28: virtual memory exhausted
  9395.      make[2]: *** [item_func.o] Error 1
  9396.  
  9397. Try using `ulimit -v 80000' and run `make' again.  If this doesn't work
  9398. and you are using `bash', try switching to `csh' or `sh'; some BSDI
  9399. users have reported problems with `bash' and `ulimit'.
  9400.  
  9401. If you are using `gcc', you may also use have to use the
  9402. `--with-low-memory' flag for `configure' to be able to compile
  9403. `sql_yacc.cc'.
  9404.  
  9405. If you get problems with the current date in MySQL, setting the `TZ'
  9406. variable will probably help.  *Note Environment variables::.
  9407.  
  9408. BSD/OS Version 3.x Notes
  9409. ........................
  9410.  
  9411. Upgrade to BSD/OS Version 3.1.  If that is not possible, install
  9412. BSDIpatch M300-038.
  9413.  
  9414. Use the following command when configuring MySQL:
  9415.  
  9416.      shell> env CXX=shlicc++ CC=shlicc2 \
  9417.             ./configure \
  9418.                 --prefix=/usr/local/mysql \
  9419.                 --localstatedir=/var/mysql \
  9420.                 --without-perl \
  9421.                 --with-unix-socket-path=/var/mysql/mysql.sock
  9422.  
  9423. The following is also known to work:
  9424.  
  9425.      shell> env CC=gcc CXX=gcc CXXFLAGS=-O3 \
  9426.             ./configure \
  9427.                 --prefix=/usr/local/mysql \
  9428.                 --with-unix-socket-path=/var/mysql/mysql.sock
  9429.  
  9430. You can change the directory locations if you wish, or just use the
  9431. defaults by not specifying any locations.
  9432.  
  9433. If you have problems with performance under heavy load, try using the
  9434. `--skip-thread-priority' option to `mysqld'!  This will run all threads
  9435. with the same priority; on BSDI Version 3.1, this gives better
  9436. performance (at least until BSDI fixes their thread scheduler).
  9437.  
  9438. If you get the error `virtual memory exhausted' while compiling, you
  9439. should try using `ulimit -v 80000' and run `make' again.  If this
  9440. doesn't work and you are using `bash', try switching to `csh' or `sh';
  9441. some BSDI users have reported problems with `bash' and `ulimit'.
  9442.  
  9443. BSD/OS Version 4.x Notes
  9444. ........................
  9445.  
  9446. BSDI Version 4.x has some thread-related bugs.  If you want to use
  9447. MySQL on this, you should install all thread-related patches.  At least
  9448. M400-023 should be installed.
  9449.  
  9450. On some BSDI Version 4.x systems, you may get problems with shared
  9451. libraries.  The symptom is that you can't execute any client programs,
  9452. for example, `mysqladmin'.  In this case you need to reconfigure not to
  9453. use shared libraries with the `--disable-shared' option to configure.
  9454.  
  9455. Some customers have had problems on BSDI 4.0.1 that the `mysqld' binary
  9456. after a while can't open tables.  This is because some library/system
  9457. related bug causes `mysqld' to change current directory without asking
  9458. for this!
  9459.  
  9460. The fix is to either upgrade to 3.23.34 or after running `configure'
  9461. remove the line `#define HAVE_REALPATH' from `config.h' before running
  9462. make.
  9463.  
  9464. Note that the above means that you can't symbolic link a database
  9465. directories to another database directory or symbolic link a table to
  9466. another database on BSDI!  (Making a symbolic link to another disk is
  9467. ok).
  9468.  
  9469. Mac OS X Notes
  9470. --------------
  9471.  
  9472. Mac OS X Public Beta
  9473. ....................
  9474.  
  9475. MySQL should work without any problems on Mac OS X Public Beta
  9476. (Darwin).  You don't need the pthread patches for this OS!
  9477.  
  9478. Mac OS X Server
  9479. ...............
  9480.  
  9481. Before trying to configure MySQL on Mac OS X server you must first
  9482. install the pthread package from `http://www.prnet.de/RegEx/mysql.html'.
  9483.  
  9484. Our binary for Mac OS X is compiled on Rhapsody 5.5 with the following
  9485. configure line:
  9486.  
  9487.      CC=gcc CFLAGS="-O2 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O2 -fomit-frame-pointer" ./configure --prefix=/usr/local/mysql "--with-comment=Official MySQL binary" --with-extra-charsets=complex  --disable-shared
  9488.  
  9489. You might want to also add aliases to your shell's resource file to
  9490. access `mysql' and `mysqladmin' from the command line:
  9491.  
  9492.      alias mysql '/usr/local/mysql/bin/mysql'
  9493.      alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
  9494.  
  9495. Other Unix Notes
  9496. ----------------
  9497.  
  9498. HP-UX Notes for Binary Distributions
  9499. ....................................
  9500.  
  9501. Some of the binary distributions of MySQL for HP-UX is distributed as
  9502. an HP depot file and as a tar file.  To use the depot file you must be
  9503. running at least HP-UX 10.x to have access to HP's software depot tools.
  9504.  
  9505. The HP version of MySQL was compiled on an HP 9000/8xx server under
  9506. HP-UX 10.20, and uses MIT-pthreads.  It is known to work well under
  9507. this configuration.  MySQL Version 3.22.26 and newer can also be built
  9508. with HP's native thread package.
  9509.  
  9510. Other configurations that may work:
  9511.  
  9512.    * HP 9000/7xx running HP-UX 10.20+
  9513.  
  9514.    * HP 9000/8xx running HP-UX 10.30
  9515.  
  9516. The following configurations almost definitely won't work:
  9517.  
  9518.    * HP 9000/7xx or 8xx running HP-UX 10.x where x < 2
  9519.  
  9520.    * HP 9000/7xx or 8xx running HP-UX 9.x
  9521.  
  9522. To install the distribution, use one of the commands below, where
  9523. `/path/to/depot' is the full pathname of the depot file:
  9524.  
  9525.    * To install everything, including the server, client and
  9526.      development tools:
  9527.  
  9528.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.full
  9529.  
  9530.    * To install only the server:
  9531.  
  9532.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.server
  9533.  
  9534.    * To install only the client package:
  9535.  
  9536.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.client
  9537.  
  9538.    * To install only the development tools:
  9539.  
  9540.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.developer
  9541.  
  9542. The depot places binaries and libraries in `/opt/mysql' and data in
  9543. `/var/opt/mysql'. The depot also creates the appropriate entries in
  9544. `/etc/init.d' and `/etc/rc2.d' to start the server automatically at
  9545. boot time.  Obviously, this entails being `root' to install.
  9546.  
  9547. To install the HP-UX tar.gz distribution, you must have a copy of GNU
  9548. `tar'.
  9549.  
  9550. HP-UX Version 10.20 Notes
  9551. .........................
  9552.  
  9553. There are a couple of small problems when compiling MySQL on HP-UX.  We
  9554. recommend that you use `gcc' instead of the HP-UX native compiler,
  9555. because `gcc' produces better code!
  9556.  
  9557. We recommend using gcc 2.95 on HP-UX.  Don't use high optimization
  9558. flags (like -O6) as this may not be safe on HP-UX.
  9559.  
  9560. Note that MIT-pthreads can't be compiled with the HP-UX compiler
  9561. because it can't compile `.S' (assembler) files.
  9562.  
  9563. The following configure line should work:
  9564.  
  9565.      CFLAGS="-DHPUX -I/opt/dce/include" CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors -fno-exceptions -fno-rtti" CXX=gcc ./configure --with-pthread --with-named-thread-libs='-ldce' --prefix=/usr/local/mysql --disable-shared
  9566.  
  9567. If you are compiling `gcc' 2.95 yourself, you should NOT link it with
  9568. the DCE libraries (`libdce.a' or `libcma.a') if you want to compile
  9569. MySQL with MIT-pthreads.  If you mix the DCE and MIT-pthreads packages
  9570. you will get a `mysqld' to which you cannot connect.  Remove the DCE
  9571. libraries while you compile `gcc' 2.95!
  9572.  
  9573. HP-UX Version 11.x Notes
  9574. ........................
  9575.  
  9576. For HP-UX Version 11.x we recommend MySQL Version 3.23.15 or later.
  9577.  
  9578. Because of some critical bugs in the standard HP-UX libraries, you
  9579. should install the following patches before trying to run MySQL on
  9580. HP-UX 11.0:
  9581.  
  9582.      PHKL_22840 Streams cumulative
  9583.      PHNE_22397 ARPA cumulative
  9584.  
  9585. This will solve a problem that one gets `EWOULDBLOCK' from `recv()' and
  9586. `EBADF' from `accept()' in threaded applications.
  9587.  
  9588. If you are using `gcc' 2.95.1 on an unpatched HP-UX 11.x system, you
  9589. will get the error:
  9590.  
  9591.      In file included from /usr/include/unistd.h:11,
  9592.                       from ../include/global.h:125,
  9593.                       from mysql_priv.h:15,
  9594.                       from item.cc:19:
  9595.      /usr/include/sys/unistd.h:184: declaration of C function ...
  9596.      /usr/include/sys/pthread.h:440: previous declaration ...
  9597.      In file included from item.h:306,
  9598.                       from mysql_priv.h:158,
  9599.                       from item.cc:19:
  9600.  
  9601. The problem is that HP-UX doesn't define `pthreads_atfork()'
  9602. consistently.  It has conflicting prototypes in
  9603. `/usr/include/sys/unistd.h':184 and `/usr/include/sys/pthread.h':440
  9604. (details below).
  9605.  
  9606. One solution is to copy `/usr/include/sys/unistd.h' into
  9607. `mysql/include' and edit `unistd.h' and change it to match the
  9608. definition in `pthread.h'.  Here's the diff:
  9609.  
  9610.      183,184c183,184
  9611.      <      extern int pthread_atfork(void (*prepare)(), void (*parent)(),
  9612.      <                                                void (*child)());
  9613.      ---
  9614.      >      extern int pthread_atfork(void (*prepare)(void), void (*parent)(void),
  9615.      >                                                void (*child)(void));
  9616.  
  9617. After this, the following configure line should work:
  9618.  
  9619.      CFLAGS="-fomit-frame-pointer -O3 -fpic" CXX=gcc CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -O3" ./configure --prefix=/usr/local/mysql --disable-shared
  9620.  
  9621. Here is some information that a HP-UX Version 11.x user sent us about
  9622. compiling MySQL with HP-UX:x compiler:
  9623.  
  9624.       Environment:
  9625.            proper compilers.
  9626.               setenv CC cc
  9627.               setenv CXX aCC
  9628.            flags
  9629.               setenv CFLAGS -D_REENTRANT
  9630.               setenv CXXFLAGS -D_REENTRANT
  9631.               setenv CPPFLAGS -D_REENTRANT
  9632.           % aCC -V
  9633.           aCC: HP ANSI C++ B3910B X.03.14.06
  9634.           % cc -V /tmp/empty.c
  9635.           cpp.ansi: HP92453-01 A.11.02.00 HP C Preprocessor (ANSI)
  9636.           ccom: HP92453-01 A.11.01.00 HP C Compiler
  9637.           cc: "/tmp/empty.c", line 1: warning 501: Empty source file.
  9638.      
  9639.        configuration:
  9640.           ./configure  --with-pthread        \
  9641.           --prefix=/source-control/mysql     \
  9642.           --with-named-thread-libs=-lpthread \
  9643.           --with-low-memory
  9644.      
  9645.          added '#define _CTYPE_INCLUDED' to include/m_ctype.h. This
  9646.          symbol is the one defined in HP's /usr/include/ctype.h:
  9647.      
  9648.           /* Don't include std ctype.h when this is included */
  9649.           #define _CTYPE_H
  9650.           #define __CTYPE_INCLUDED
  9651.           #define _CTYPE_INCLUDED
  9652.           #define _CTYPE_USING   /* Don't put names in global namespace. */
  9653.  
  9654.    * I had to use the compile-time flag `-D_REENTRANT' to get the
  9655.      compiler to recognize the prototype for `localtime_r'.
  9656.      Alternatively I could have supplied the prototype for
  9657.      `localtime_r'. But I wanted to catch other bugs without needing to
  9658.      run into them.  I wasn't sure where I needed it, so I added it to
  9659.      all flags.
  9660.  
  9661.    * The optimization flags used by MySQL (-O3) are not recognized by
  9662.      HP's compilers.  I did not change the flags.
  9663.  
  9664. If you get the following error from `configure'
  9665.  
  9666.      checking for cc option to accept ANSI C... no
  9667.      configure: error: MySQL requires a ANSI C compiler (and a C++ compiler). Try gcc. See the Installation chapter in the Reference Manual.
  9668.  
  9669. Check that you don't have the path to the K&R compiler before the path
  9670. to the HP-UX C and C++ compiler.
  9671.  
  9672. IBM-AIX notes
  9673. .............
  9674.  
  9675. Automatic detection of `xlC' is missing from Autoconf, so a `configure'
  9676. command something like this is needed when compiling MySQL (This
  9677. example uses the IBM compiler):
  9678.  
  9679.      export CC="xlc_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192 "
  9680.      export CXX="xlC_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192"
  9681.      export CFLAGS="-I /usr/local/include"
  9682.      export LDLFAGS="-L /usr/local/lib"
  9683.      export CPPFLAGS=$CFLAGS
  9684.      export CXXFLAGS=$CFLAGS
  9685.      
  9686.      ./configure --prefix=/usr/local \
  9687.              --localstatedir=/var/mysql \
  9688.              --sysconfdir=/etc/mysql \
  9689.              --sbindir='/usr/local/bin' \
  9690.              --libexecdir='/usr/local/bin' \
  9691.              --enable-thread-safe-client \
  9692.              --enable-large-files
  9693.  
  9694. Above are the options used to compile the MySQL distribution that can
  9695. be found at `http://www-frec.bull.com/'.
  9696.  
  9697. If you change the `-O3' to `-O2' in the above configure line, you must
  9698. also remove the `-qstrict' option (this is a limitation in the IBM C
  9699. compiler).
  9700.  
  9701. If you are using `gcc' or `egcs' to compile MySQL, you *MUST* use the
  9702. `-fno-exceptions' flag, as the exception handling in `gcc'/`egcs' is
  9703. not thread safe!  (This is tested with `egcs' 1.1.).  There are also
  9704. some known problems with IBM's assembler, which may cause it to
  9705. generate bad code when used with gcc.
  9706.  
  9707. We recommend the following `configure' line with `egcs' and `gcc 2.95'
  9708. on AIX:
  9709.  
  9710.      CC="gcc -pipe -mcpu=power -Wa,-many" \
  9711.      CXX="gcc -pipe -mcpu=power -Wa,-many" \
  9712.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti" \
  9713.      ./configure --prefix=/usr/local/mysql --with-low-memory
  9714.  
  9715. The `-Wa,-many' is necessary for the compile to be successful.  IBM is
  9716. aware of this problem but is in to hurry to fix it because of the
  9717. workaround available.  We don't know if the `-fno-exceptions' is
  9718. required with `gcc 2.95', but as MySQL doesn't use exceptions and the
  9719. above option generates faster code, we recommend that you should always
  9720. use this option with `egcs / gcc'.
  9721.  
  9722. If you get a problem with assembler code try changing the -mcpu=xxx to
  9723. match your cpu. Typically power2, power, or powerpc may need to be used,
  9724. alternatively you might need to use 604 or 604e. I'm not positive but I
  9725. would think using "power" would likely be safe most of the time, even on
  9726. a power2 machine.
  9727.  
  9728. If you don't know what your cpu is then do a "uname -m", this will give
  9729. you back a string that looks like "000514676700", with a format of
  9730. xxyyyyyymmss where xx and ss are always 0's, yyyyyy is a unique system
  9731. id and mm is the id of the CPU Planar. A chart of these values can be
  9732. found at
  9733. `http://www.rs6000.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/uname.htm'.
  9734. This will give you a machine type and a machine model you can use to
  9735. determine what type of cpu you have.
  9736.  
  9737. If you have problems with signals (MySQL dies unexpectedly under high
  9738. load) you may have found an OS bug with threads and signals.  In this
  9739. case you can tell MySQL not to use signals by configuring with:
  9740.  
  9741.      shell> CFLAGS=-DDONT_USE_THR_ALARM CXX=gcc \
  9742.             CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -DDONT_USE_THR_ALARM" \
  9743.             ./configure --prefix=/usr/local/mysql --with-debug --with-low-memory
  9744.  
  9745. This doesn't affect the performance of MySQL, but has the side effect
  9746. that you can't kill clients that are "sleeping" on a connection with
  9747. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  9748. die when it issues its next command.
  9749.  
  9750. On some versions of AIX, linking with `libbind.a' makes `getservbyname'
  9751. core dump.  This is an AIX bug and should be reported to IBM.
  9752.  
  9753. For AIX 4.2.1 and gcc you have to do the following changes.
  9754.  
  9755. After configuring, edit `config.h' and `include/my_config.h' and change
  9756. the line that says
  9757.  
  9758.      #define HAVE_SNPRINTF 1
  9759.  
  9760. to
  9761.  
  9762.      #undef HAVE_SNPRINTF
  9763.  
  9764. And finally, in `mysqld.cc' you need to add a prototype for initgoups.
  9765.  
  9766.      #ifdef _AIX41
  9767.      extern "C" int initgroups(const char *,int);
  9768.      #endif
  9769.  
  9770. SunOS 4 Notes
  9771. .............
  9772.  
  9773. On SunOS 4, MIT-pthreads is needed to compile MySQL, which in turn
  9774. means you will need GNU `make'.
  9775.  
  9776. Some SunOS 4 systems have problems with dynamic libraries and `libtool'.
  9777. You can use the following `configure' line to avoid this problem:
  9778.  
  9779.      shell> ./configure --disable-shared --with-mysqld-ldflags=-all-static
  9780.  
  9781. When compiling `readline', you may get warnings about duplicate defines.
  9782. These may be ignored.
  9783.  
  9784. When compiling `mysqld', there will be some `implicit declaration of
  9785. function' warnings. These may be ignored.
  9786.  
  9787. Alpha-DEC-UNIX Notes (Tru64)
  9788. ............................
  9789.  
  9790. If you are using egcs 1.1.2 on Digital Unix, you should upgrade to gcc
  9791. 2.95.2, as egcs on DEC has some serious bugs!
  9792.  
  9793. When compiling threaded programs under Digital Unix, the documentation
  9794. recommends using the `-pthread' option for `cc' and `cxx' and the
  9795. libraries `-lmach -lexc' (in addition to `-lpthread').  You should run
  9796. `configure' something like this:
  9797.  
  9798.      CC="cc -pthread" CXX="cxx -pthread -O" \
  9799.      ./configure --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  9800.  
  9801. When compiling `mysqld', you may see a couple of warnings like this:
  9802.  
  9803.      mysqld.cc: In function void handle_connections()':
  9804.      mysqld.cc:626: passing long unsigned int *' as argument 3 of
  9805.      accept(int,sockadddr *, int *)'
  9806.  
  9807. You can safely ignore these warnings.  They occur because `configure'
  9808. can detect only errors, not warnings.
  9809.  
  9810. If you start the server directly from the command line, you may have
  9811. problems with it dying when you log out.  (When you log out, your
  9812. outstanding processes receive a `SIGHUP' signal.)  If so, try starting
  9813. the server like this:
  9814.  
  9815.      shell> nohup mysqld [options] &
  9816.  
  9817. `nohup' causes the command following it to ignore any `SIGHUP' signal
  9818. sent from the terminal.  Alternatively, start the server by running
  9819. `safe_mysqld', which invokes `mysqld' using `nohup' for you.  *Note
  9820. `safe_mysqld': safe_mysqld.
  9821.  
  9822. If you get a problem when compiling mysys/get_opt.c, just remove the
  9823. line #define _NO_PROTO from the start of that file!
  9824.  
  9825. If you are using Compac's CC compiler, the following configure line
  9826. should work:
  9827.  
  9828.      CC="cc -pthread"
  9829.      CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
  9830.      CXX="cxx -pthread"
  9831.      CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
  9832.      export CC CFLAGS CXX CXXFLAGS
  9833.      ./configure \
  9834.      --prefix=/usr/local/mysql \
  9835.      --with-low-memory \
  9836.      --enable-large-files \
  9837.      --enable-shared=yes \
  9838.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  9839.      gnumake
  9840.  
  9841. If you get a problem with libtool, when compiling with shared libraries
  9842. as above, when linking `mysql', you should be able to get around this
  9843. by issuing:
  9844.  
  9845.      cd mysql
  9846.      /bin/sh ../libtool --mode=link cxx -pthread  -O3 -DDBUG_OFF \
  9847.      -O4 -ansi_alias -ansi_args -fast -inline speed \
  9848.      -speculate all \ -arch host  -DUNDEF_HAVE_GETHOSTBYNAME_R \
  9849.      -o mysql  mysql.o readline.o sql_string.o completion_hash.o \
  9850.      ../readline/libreadline.a -lcurses \
  9851.      ../libmysql/.libs/libmysqlclient.so  -lm
  9852.      cd ..
  9853.      gnumake
  9854.      gnumake install
  9855.      scripts/mysql_install_db
  9856.  
  9857. Alpha-DEC-OSF1 Notes
  9858. ....................
  9859.  
  9860. If you have problems compiling and have DEC `CC' and `gcc' installed,
  9861. try running `configure' like this:
  9862.  
  9863.      CC=cc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 \
  9864.      ./configure --prefix=/usr/local/mysql
  9865.  
  9866. If you get problems with the `c_asm.h' file, you can create and use a
  9867. 'dummy' `c_asm.h' file with:
  9868.  
  9869.      touch include/c_asm.h
  9870.      CC=gcc CFLAGS=-I./include \
  9871.      CXX=gcc CXXFLAGS=-O3 \
  9872.      ./configure --prefix=/usr/local/mysql
  9873.  
  9874. Note that the following problems with the `ld' program can be fixed by
  9875. downloading the latest DEC (Compaq) patch kit from:
  9876. `http://ftp.support.compaq.com/public/unix/'.
  9877.  
  9878. On OSF1 V4.0D and compiler "DEC C V5.6-071 on Digital Unix V4.0 (Rev.
  9879. 878)" the compiler had some strange behavior (undefined `asm' symbols).
  9880. `/bin/ld' also appears to be broken (problems with `_exit undefined'
  9881. errors occuring while linking `mysqld').  On this system, we have
  9882. managed to compile MySQL with the following `configure' line, after
  9883. replacing `/bin/ld' with the version from OSF 4.0C:
  9884.  
  9885.      CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  9886.  
  9887. With the Digital compiler "C++ V6.1-029", the following should work:
  9888.  
  9889.      CC=cc -pthread
  9890.      CFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all -arch host
  9891.      CXX=cxx -pthread
  9892.      CXXFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all -arch host -noexceptions -nortti
  9893.      export CC CFLAGS CXX CXXFLAGS
  9894.      ./configure --prefix=/usr/mysql/mysql --with-mysqld-ldflags=-all-static --disable-shared --with-named-thread-libs="-lmach -lexc -lc"
  9895.  
  9896. In some versions of OSF1, the `alloca()' function is broken. Fix this
  9897. by removing the line in `config.h' that defines `'HAVE_ALLOCA''.
  9898.  
  9899. The `alloca()' function also may have an incorrect prototype in
  9900. `/usr/include/alloca.h'.  This warning resulting from this can be
  9901. ignored.
  9902.  
  9903. `configure' will use the following thread libraries automatically:
  9904. `--with-named-thread-libs="-lpthread -lmach -lexc -lc"'.
  9905.  
  9906. When using `gcc', you can also try running `configure' like this:
  9907.  
  9908.      shell> CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-O3 ./configure ....
  9909.  
  9910. If you have problems with signals (MySQL dies unexpectedly under high
  9911. load), you may have found an OS bug with threads and signals. In this
  9912. case you can tell MySQL not to use signals by configuring with:
  9913.  
  9914.      shell> CFLAGS=-DDONT_USE_THR_ALARM \
  9915.             CXXFLAGS=-DDONT_USE_THR_ALARM \
  9916.             ./configure ...
  9917.  
  9918. This doesn't affect the performance of MySQL, but has the side effect
  9919. that you can't kill clients that are "sleeping" on a connection with
  9920. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  9921. die when it issues its next command.
  9922.  
  9923. With `gcc' 2.95.2, you will probably run into the following compile
  9924. error:
  9925.  
  9926.      sql_acl.cc:1456: Internal compiler error in `scan_region', at except.c:2566
  9927.      Please submit a full bug report.
  9928.  
  9929. To fix this you should change to the `sql' directory and do a "cut and
  9930. paste" of the last `gcc' line, but change `-O3' to `-O0' (or add `-O0'
  9931. immediately after `gcc' if you don't have any `-O' option on your
  9932. compile line.)  After this is done you can just change back to the
  9933. top-level directly and run `make' again.
  9934.  
  9935. SGI Irix Notes
  9936. ..............
  9937.  
  9938. If you are using Irix Version 6.5.3 or newer `mysqld' will only be able
  9939. to create threads if you run it as a user with `CAP_SCHED_MGT'
  9940. privileges (like `root') or give the `mysqld' server this privilege
  9941. with the following shell command:
  9942.  
  9943.      shell> chcap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld
  9944.  
  9945. You may have to undefine some things in `config.h' after running
  9946. `configure' and before compiling.
  9947.  
  9948. In some Irix implementations, the `alloca()' function is broken.  If the
  9949. `mysqld' server dies on some `SELECT' statements, remove the lines from
  9950. `config.h' that define `HAVE_ALLOC' and `HAVE_ALLOCA_H'.  If
  9951. `mysqladmin create' doesn't work, remove the line from `config.h' that
  9952. defines `HAVE_READDIR_R'.  You may have to remove the `HAVE_TERM_H'
  9953. line as well.
  9954.  
  9955. SGI recommends that you install all of the patches on this page as a
  9956. set:
  9957. http://support.sgi.com/surfzone/patches/patchset/6.2_indigo.rps.html
  9958.  
  9959. At the very minimum, you should install the latest kernel rollup, the
  9960. latest `rld' rollup, and the latest `libc' rollup.
  9961.  
  9962. You definitely need all the POSIX patches on this page, for pthreads
  9963. support:
  9964.  
  9965. `http://support.sgi.com/surfzone/patches/patchset/6.2_posix.rps.html'
  9966.  
  9967. If you get the something like the following error when compiling
  9968. `mysql.cc':
  9969.  
  9970.      "/usr/include/curses.h", line 82: error(1084): invalid combination of type
  9971.  
  9972. Type the following in the top-level directory of your MySQL source tree:
  9973.  
  9974.      shell> extra/replace bool curses_bool < /usr/include/curses.h > include/curses.h
  9975.      shell> make
  9976.  
  9977. There have also been reports of scheduling problems.  If only one
  9978. thread is running, things go slow.  Avoid this by starting another
  9979. client.  This may lead to a 2-to-10-fold increase in execution speed
  9980. thereafter for the other thread.  This is a poorly understood problem
  9981. with Irix threads; you may have to improvise to find solutions until
  9982. this can be fixed.
  9983.  
  9984. If you are compiling with `gcc', you can use the following `configure'
  9985. command:
  9986.  
  9987.      CC=gcc CXX=gcc CXXFLAGS=-O3 \
  9988.      ./configure --prefix=/usr/local/mysql --enable-thread-safe-client --with-named-thread-libs=-lpthread
  9989.  
  9990. On Irix 6.5.11 with native Irix C and C++ compilers ver. 7.3.1.2, the
  9991. following is reported to work
  9992.  
  9993.      CC=cc CXX=CC CFLAGS='-O3 -n32 -TARG:platform=IP22 -I/usr/local/include \
  9994.      -L/usr/local/lib' CXXFLAGS='-O3 -n32 -TARG:platform=IP22 \
  9995.      -I/usr/local/include -L/usr/local/lib' ./configure --prefix=/usr/local/mysql \
  9996.      --with-berkeley-db --with-innodb \
  9997.      --with-libwrap=/usr/local --with-named-curses-libs=/usr/local/lib/libncurses.a
  9998.  
  9999. SCO Notes
  10000. .........
  10001.  
  10002. The current port is tested only on a "sco3.2v5.0.4" and "sco3.2v5.0.5"
  10003. system.  There has also been a lot of progress on a port to "sco
  10004. 3.2v4.2".
  10005.  
  10006. For the moment the recommended compiler on OpenServer is gcc 2.95.2.
  10007. With this you should be able to compile MySQL with just:
  10008.  
  10009.      CC=gcc CXX=gcc ./configure ... (options)
  10010.  
  10011.   1. For OpenServer 5.0.X you need to use GDS in Skunkware 95 (95q4c).
  10012.      This is necessary because GNU `gcc' 2.7.2 in Skunkware 97 does not
  10013.      have GNU `as'.  You can also use `egcs' 1.1.2 or newer
  10014.      `http://www.egcs.com/'.  If you are using `egcs' 1.1.2 you have to
  10015.      execute the following command:
  10016.  
  10017.           shell> cp -p /usr/include/pthread/stdtypes.h /usr/local/lib/gcc-lib/i386-pc-sco3.2v5.0.5/egcs-2.91.66/include/pthread/
  10018.  
  10019.   2. You need the port of GCC 2.5.x for this product and the Development
  10020.      system.  They are required on this version of SCO Unix.  You cannot
  10021.      just use the GCC Dev system.
  10022.  
  10023.   3. You should get the FSU Pthreads package and install it first.
  10024.      This can be found at
  10025.      `http://www.cs.wustl.edu/~schmidt/ACE_wrappers/FSU-threads.tar.gz'.
  10026.      You can also get a precompiled package from
  10027.      `http://www.mysql.com/Downloads/SCO/FSU-threads-3.5c.tar.gz'.
  10028.  
  10029.   4. FSU Pthreads can be compiled with SCO Unix 4.2 with tcpip.  Or
  10030.      OpenServer 3.0 or Open Desktop 3.0 (OS 3.0 ODT 3.0), with the SCO
  10031.      Development System installed using a good port of GCC 2.5.x ODT or
  10032.      OS 3.0 you will need a good port of GCC 2.5.x There are a lot of
  10033.      problems without a good port.  The port for this product requires
  10034.      the SCO Unix Development system.  Without it, you are missing the
  10035.      libraries and the linker that is needed.
  10036.  
  10037.   5. To build FSU Pthreads on your system, do the following:
  10038.  
  10039.        a. Run `./configure' in the `threads/src' directory and select
  10040.           the SCO OpenServer option. This command copies
  10041.           `Makefile.SCO5' to `Makefile'.
  10042.  
  10043.        b. Run `make'.
  10044.  
  10045.        c. To install in the default `/usr/include' directory, login as
  10046.           root, then `cd' to the `thread/src' directory, and run `make
  10047.           install'.
  10048.  
  10049.   6. Remember to use GNU `make' when making MySQL.
  10050.  
  10051.   7. If you don't start `safe_mysqld' as root, you probably will get
  10052.      only the default 110 open files per process.  `mysqld' will write
  10053.      a note about this in the log file.
  10054.  
  10055.   8. With SCO 3.2V5.0.5, you should use FSU Pthreads version 3.5c or
  10056.      newer.  You should also use gcc 2.95.2 or newer!
  10057.  
  10058.      The following `configure' command should work:
  10059.  
  10060.           shell> ./configure --prefix=/usr/local/mysql --disable-shared
  10061.  
  10062.   9. With SCO 3.2V4.2, you should use FSU Pthreads version 3.5c or
  10063.      newer.  The following `configure' command should work:
  10064.  
  10065.           shell> CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
  10066.                  ./configure \
  10067.                      --prefix=/usr/local/mysql \
  10068.                      --with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \
  10069.                      --with-named-curses-libs="-lcurses"
  10070.  
  10071.      You may get some problems with some include files. In this case,
  10072.      you can find new SCO-specific include files at
  10073.      `http://www.mysql.com/Downloads/SCO/SCO-3.2v4.2-includes.tar.gz'.
  10074.      You should unpack this file in the `include' directory of your
  10075.      MySQL source tree.
  10076.  
  10077. SCO development notes:
  10078.  
  10079.    * MySQL should automatically detect FSU Pthreads and link `mysqld'
  10080.      with `-lgthreads -lsocket -lgthreads'.
  10081.  
  10082.    * The SCO development libraries are re-entrant in FSU Pthreads.  SCO
  10083.      claims that its libraries' functions are re-entrant, so they must
  10084.      be reentrant with FSU Pthreads.  FSU Pthreads on OpenServer tries
  10085.      to use the SCO scheme to make re-entrant libraries.
  10086.  
  10087.    * FSU Pthreads (at least the version at `http://www.mysql.com/')
  10088.      comes linked with GNU `malloc'.  If you encounter problems with
  10089.      memory usage, make sure that `gmalloc.o' is included in
  10090.      `libgthreads.a' and `libgthreads.so'.
  10091.  
  10092.    * In FSU Pthreads, the following system calls are pthreads-aware:
  10093.      `read()', `write()', `getmsg()', `connect()', `accept()',
  10094.      `select()', and `wait()'.
  10095.  
  10096. If you want to install DBI on SCO, you have to edit the `Makefile' in
  10097. DBI-xxx and each subdirectory.
  10098.  
  10099. Note that the following assumes gcc 2.95.2 or newer:
  10100.  
  10101.      OLD:                                  NEW:
  10102.      CC = cc                               CC = gcc
  10103.      CCCDLFLAGS = -KPIC -W1,-Bexport       CCCDLFLAGS = -fpic
  10104.      CCDLFLAGS = -wl,-Bexport              CCDLFLAGS =
  10105.      
  10106.      LD = ld                               LD = gcc -G -fpic
  10107.      LDDLFLAGS = -G -L/usr/local/lib       LDDLFLAGS = -L/usr/local/lib
  10108.      LDFLAGS = -belf -L/usr/local/lib      LDFLAGS = -L/usr/local/lib
  10109.      
  10110.      LD = ld                               LD = gcc -G -fpic
  10111.      OPTIMISE = -Od                        OPTIMISE = -O1
  10112.      
  10113.      OLD:
  10114.      CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  10115.      
  10116.      NEW:
  10117.      CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  10118.  
  10119. This is because the Perl dynaloader will not load the `DBI' modules if
  10120. they were compiled with `icc' or `cc'.
  10121.  
  10122. Perl works best when compiled with `cc'.
  10123.  
  10124. SCO Unixware Version 7.0 Notes
  10125. ..............................
  10126.  
  10127. You must use a version of MySQL at least as recent as Version 3.22.13
  10128. because that version fixes some portability problems under Unixware.
  10129.  
  10130. We have been able to compile MySQL with the following `configure'
  10131. command on Unixware Version 7.0.1:
  10132.  
  10133.      CC=cc CXX=CC ./configure --prefix=/usr/local/mysql
  10134.  
  10135. If you want to use `gcc', you must use `gcc' 2.95.2 or newer.
  10136.  
  10137. OS/2 Notes
  10138. ----------
  10139.  
  10140. MySQL uses quite a few open files. Because of this, you should add
  10141. something like the following to your `CONFIG.SYS' file:
  10142.  
  10143.      SET EMXOPT=-c -n -h1024
  10144.  
  10145. If you don't do this, you will probably run into the following error:
  10146.  
  10147.      File 'xxxx' not found (Errcode: 24)
  10148.  
  10149. When using MySQL with OS/2 Warp 3, FixPack 29 or above is required.
  10150. With OS/2 Warp 4, FixPack 4 or above is required. This is a requirement
  10151. of the Pthreads library.  MySQL must be installed in a partition that
  10152. supports long filenames such as HPFS, FAT32, etc.
  10153.  
  10154. The `INSTALL.CMD' script must be run from OS/2's own `CMD.EXE' and may
  10155. not work with replacement shells such as `4OS2.EXE'.
  10156.  
  10157. The `scripts/mysql-install-db' script has been renamed.  It is now
  10158. called `install.cmd' and is a REXX script, which will set up the default
  10159. MySQL security settings and create the WorkPlace Shell icons for MySQL.
  10160.  
  10161. Dynamic module support is compiled in but not fully tested. Dynamic
  10162. modules should be compiled using the Pthreads run-time library.
  10163.  
  10164.      gcc -Zdll -Zmt -Zcrtdll=pthrdrtl -I../include -I../regex -I.. \
  10165.          -o example udf_example.cc -L../lib -lmysqlclient udf_example.def
  10166.      mv example.dll example.udf
  10167.  
  10168. *Note:* Due to limitations in OS/2, UDF module name stems must not
  10169. exceed 8 characters. Modules are stored in the `/mysql2/udf' directory;
  10170. the `safe-mysqld.cmd' script will put this directory in the
  10171. `BEGINLIBPATH' environment variable. When using UDF modules, specified
  10172. extensions are ignored -- it is assumed to be `.udf'.  For example, in
  10173. Unix, the shared module might be named `example.so' and you would load
  10174. a function from it like this:
  10175.  
  10176.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example.so";
  10177.  
  10178. Is OS/2, the module would be named `example.udf', but you would not
  10179. specify the module extension:
  10180.  
  10181.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example";
  10182.  
  10183. BeOS Notes
  10184. ----------
  10185.  
  10186. We are really interested in getting MySQL to work on BeOS, but
  10187. unfortunately we don't have any person who knows BeOS or has time to do
  10188. a port.
  10189.  
  10190. We are interested in finding someone to do a port, and we will help them
  10191. with any technical questions they may have while doing the port.
  10192.  
  10193. We have previously talked with some BeOS developers that have said that
  10194. MySQL is 80% ported to BeOS, but we haven't heard from them in a while.
  10195.  
  10196. Novell Netware Notes
  10197. --------------------
  10198.  
  10199. We are really interested in getting MySQL to work on Netware, but
  10200. unfortunately we don't have any person who knows Netware or has time to
  10201. do a port.
  10202.  
  10203. We are interested in finding someone to do a port, and we will help them
  10204. with any technical questions they may have while doing the port.
  10205.  
  10206. Introduction to MySQL: A MySQL Tutorial
  10207. ***************************************
  10208.  
  10209. This chapter provides a tutorial introduction to MySQL by showing how
  10210. to use the `mysql' client program to create and use a simple database.
  10211. `mysql' (sometimes referred to as the "terminal monitor" or just
  10212. "monitor") is an interactive program that allows you to connect to a
  10213. MySQL server, run queries, and view the results.  `mysql' may also be
  10214. used in batch mode: you place your queries in a file beforehand, then
  10215. tell `mysql' to execute the contents of the file.  Both ways of using
  10216. `mysql' are covered here.
  10217.  
  10218. To see a list of options provided by `mysql', invoke it with the
  10219. `--help' option:
  10220.  
  10221.      shell> mysql --help
  10222.  
  10223. This chapter assumes that `mysql' is installed on your machine and that
  10224. a MySQL server is available to which you can connect.  If this is not
  10225. true, contact your MySQL administrator.  (If _you_ are the
  10226. administrator, you will need to consult other sections of this manual.)
  10227.  
  10228. This chapter describes the entire process of setting up and using a
  10229. database.  If you are interested only in accessing an already-existing
  10230. database, you may want to skip over the sections that describe how to
  10231. create the database and the tables it contains.
  10232.  
  10233. Because this chapter is tutorial in nature, many details are
  10234. necessarily left out.  Consult the relevant sections of the manual for
  10235. more information on the topics covered here.
  10236.  
  10237. Connecting to and Disconnecting from the Server
  10238. ===============================================
  10239.  
  10240. To connect to the server, you'll usually need to provide a MySQL user
  10241. name when you invoke `mysql' and, most likely, a password.  If the
  10242. server runs on a machine other than the one where you log in, you'll
  10243. also need to specify a hostname.  Contact your administrator to find
  10244. out what connection parameters you should use to connect (that is, what
  10245. host, user name, and password to use).  Once you know the proper
  10246. parameters, you should be able to connect like this:
  10247.  
  10248.      shell> mysql -h host -u user -p
  10249.      Enter password: ********
  10250.  
  10251. The `********' represents your password; enter it when `mysql' displays
  10252. the `Enter password:' prompt.
  10253.  
  10254. If that works, you should see some introductory information followed by
  10255. a `mysql>' prompt:
  10256.  
  10257.      shell> mysql -h host -u user -p
  10258.      Enter password: ********
  10259.      Welcome to the MySQL monitor.  Commands end with ; or \g.
  10260.      Your MySQL connection id is 459 to server version: 3.22.20a-log
  10261.      
  10262.      Type 'help' for help.
  10263.      
  10264.      mysql>
  10265.  
  10266. The prompt tells you that `mysql' is ready for you to enter commands.
  10267.  
  10268. Some MySQL installations allow users to connect as the anonymous
  10269. (unnamed) user to the server running on the local host.  If this is the
  10270. case on your machine, you should be able to connect to that server by
  10271. invoking `mysql' without any options:
  10272.  
  10273.      shell> mysql
  10274.  
  10275. After you have connected successfully, you can disconnect any time by
  10276. typing `QUIT' at the `mysql>' prompt:
  10277.  
  10278.      mysql> QUIT
  10279.      Bye
  10280.  
  10281. You can also disconnect by pressing Control-D.
  10282.  
  10283. Most examples in the following sections assume you are connected to the
  10284. server.  They indicate this by the `mysql>' prompt.
  10285.  
  10286. Entering Queries
  10287. ================
  10288.  
  10289. Make sure you are connected to the server, as discussed in the previous
  10290. section.  Doing so will not in itself select any database to work with,
  10291. but that's okay.  At this point, it's more important to find out a
  10292. little about how to issue queries than to jump right in creating
  10293. tables, loading data into them, and retrieving data from them.  This
  10294. section describes the basic principles of entering commands, using
  10295. several queries you can try out to familiarize yourself with how
  10296. `mysql' works.
  10297.  
  10298. Here's a simple command that asks the server to tell you its version
  10299. number and the current date.  Type it in as shown below following the
  10300. `mysql>' prompt and hit the RETURN key:
  10301.  
  10302.      mysql> SELECT VERSION(), CURRENT_DATE;
  10303.      +--------------+--------------+
  10304.      | version()    | CURRENT_DATE |
  10305.      +--------------+--------------+
  10306.      | 3.22.20a-log | 1999-03-19   |
  10307.      +--------------+--------------+
  10308.      1 row in set (0.01 sec)
  10309.      mysql>
  10310.  
  10311. This query illustrates several things about `mysql':
  10312.  
  10313.    * A command normally consists of a SQL statement followed by a
  10314.      semicolon.  (There are some exceptions where a semicolon is not
  10315.      needed.  `QUIT', mentioned earlier, is one of them.  We'll get to
  10316.      others later.)
  10317.  
  10318.    * When you issue a command, `mysql' sends it to the server for
  10319.      execution and displays the results, then prints another `mysql>'
  10320.      to indicate that it is ready for another command.
  10321.  
  10322.    * `mysql' displays query output as a table (rows and columns).  The
  10323.      first row contains labels for the columns.  The rows following are
  10324.      the query results.  Normally, column labels are the names of the
  10325.      columns you fetch from database tables.  If you're retrieving the
  10326.      value of an expression rather than a table column (as in the
  10327.      example just shown), `mysql' labels the column using the
  10328.      expression itself.
  10329.  
  10330.    * `mysql' shows how many rows were returned and how long the query
  10331.      took to execute, which gives you a rough idea of server
  10332.      performance.  These values are imprecise because they represent
  10333.      wall clock time (not CPU or machine time), and because they are
  10334.      affected by factors such as server load and network latency.  (For
  10335.      brevity, the "rows in set" line is not shown in the remaining
  10336.      examples in this chapter.)
  10337.  
  10338. Keywords may be entered in any lettercase.  The following queries are
  10339. equivalent:
  10340.  
  10341.      mysql> SELECT VERSION(), CURRENT_DATE;
  10342.      mysql> select version(), current_date;
  10343.      mysql> SeLeCt vErSiOn(), current_DATE;
  10344.  
  10345. Here's another query.  It demonstrates that you can use `mysql' as a
  10346. simple calculator:
  10347.  
  10348.      mysql> SELECT SIN(PI()/4), (4+1)*5;
  10349.      +-------------+---------+
  10350.      | SIN(PI()/4) | (4+1)*5 |
  10351.      +-------------+---------+
  10352.      |    0.707107 |      25 |
  10353.      +-------------+---------+
  10354.  
  10355. The commands shown thus far have been relatively short, single-line
  10356. statements.  You can even enter multiple statements on a single line.
  10357. Just end each one with a semicolon:
  10358.  
  10359.      mysql> SELECT VERSION(); SELECT NOW();
  10360.      +--------------+
  10361.      | version()    |
  10362.      +--------------+
  10363.      | 3.22.20a-log |
  10364.      +--------------+
  10365.      
  10366.      +---------------------+
  10367.      | NOW()               |
  10368.      +---------------------+
  10369.      | 1999-03-19 00:15:33 |
  10370.      +---------------------+
  10371.  
  10372. A command need not be given all on a single line, so lengthy commands
  10373. that require several lines are not a problem.  `mysql' determines where
  10374. your statement ends by looking for the terminating semicolon, not by
  10375. looking for the end of the input line.  (In other words, `mysql'
  10376. accepts free-format input:  it collects input lines but does not
  10377. execute them until it sees the semicolon.)
  10378.  
  10379. Here's a simple multiple-line statement:
  10380.  
  10381.      mysql> SELECT
  10382.          -> USER()
  10383.          -> ,
  10384.          -> CURRENT_DATE;
  10385.      +--------------------+--------------+
  10386.      | USER()             | CURRENT_DATE |
  10387.      +--------------------+--------------+
  10388.      | joesmith@localhost | 1999-03-18   |
  10389.      +--------------------+--------------+
  10390.  
  10391. In this example, notice how the prompt changes from `mysql>' to `->'
  10392. after you enter the first line of a multiple-line query.  This is how
  10393. `mysql' indicates that it hasn't seen a complete statement and is
  10394. waiting for the rest.  The prompt is your friend, because it provides
  10395. valuable feedback.  If you use that feedback, you will always be aware
  10396. of what `mysql' is waiting for.
  10397.  
  10398. If you decide you don't want to execute a command that you are in the
  10399. process of entering, cancel it by typing `\c':
  10400.  
  10401.      mysql> SELECT
  10402.          -> USER()
  10403.          -> \c
  10404.      mysql>
  10405.  
  10406. Here, too, notice the prompt.  It switches back to `mysql>' after you
  10407. type `\c', providing feedback to indicate that `mysql' is ready for a
  10408. new command.
  10409.  
  10410. The following table shows each of the prompts you may see and
  10411. summarizes what they mean about the state that `mysql' is in:
  10412.  
  10413. *Prompt**Meaning*
  10414. `mysql>'Ready for new command.
  10415. `       Waiting for next line of multiple-line command.
  10416. ->'     
  10417. `       Waiting for next line, collecting a string that begins with a
  10418. '>'     single quote (`'').
  10419. `       Waiting for next line, collecting a string that begins with a
  10420. ">'     double quote (`"').
  10421.  
  10422. Multiple-line statements commonly occur by accident when you intend to
  10423. issue a command on a single line, but forget the terminating semicolon.
  10424. In this case, `mysql' waits for more input:
  10425.  
  10426.      mysql> SELECT USER()
  10427.          ->
  10428.  
  10429. If this happens to you (you think you've entered a statement but the
  10430. only response is a `->' prompt), most likely `mysql' is waiting for the
  10431. semicolon.  If you don't notice what the prompt is telling you, you
  10432. might sit there for a while before realizing what you need to do.
  10433. Enter a semicolon to complete the statement, and `mysql' will execute
  10434. it:
  10435.  
  10436.      mysql> SELECT USER()
  10437.          -> ;
  10438.      +--------------------+
  10439.      | USER()             |
  10440.      +--------------------+
  10441.      | joesmith@localhost |
  10442.      +--------------------+
  10443.  
  10444. The `'>' and `">' prompts occur during string collection.  In MySQL,
  10445. you can write strings surrounded by either `'' or `"' characters (for
  10446. example, `'hello'' or `"goodbye"'), and `mysql' lets you enter strings
  10447. that span multiple lines.  When you see a `'>' or `">' prompt, it means
  10448. that you've entered a line containing a string that begins with a `''
  10449. or `"' quote character, but have not yet entered the matching quote
  10450. that terminates the string.  That's fine if you really are entering a
  10451. multiple-line string, but how likely is that?  Not very.  More often,
  10452. the `'>' and `">' prompts indicate that you've inadvertantly left out a
  10453. quote character.  For example:
  10454.  
  10455.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  10456.          ">
  10457.  
  10458. If you enter this `SELECT' statement, then hit RETURN and wait for the
  10459. result, nothing will happen.  Instead of wondering why this query takes
  10460. so long, notice the clue provided by the `">' prompt.  It tells you
  10461. that `mysql' expects to see the rest of an unterminated string.  (Do
  10462. you see the error in the statement?  The string `"Smith' is missing the
  10463. second quote.)
  10464.  
  10465. At this point, what do you do?  The simplest thing is to cancel the
  10466. command.  However, you cannot just type `\c' in this case, because
  10467. `mysql' interprets it as part of the string that it is collecting!
  10468. Instead, enter the closing quote character (so `mysql' knows you've
  10469. finished the string), then type `\c':
  10470.  
  10471.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  10472.          "> "\c
  10473.      mysql>
  10474.  
  10475. The prompt changes back to `mysql>', indicating that `mysql' is ready
  10476. for a new command.
  10477.  
  10478. It's important to know what the `'>' and `">' prompts signify, because
  10479. if you mistakenly enter an unterminated string, any further lines you
  10480. type will appear to be ignored by `mysql' -- including a line
  10481. containing `QUIT'!  This can be quite confusing, especially if you
  10482. don't know that you need to supply the terminating quote before you can
  10483. cancel the current command.
  10484.  
  10485. Creating and Using a Database
  10486. =============================
  10487.  
  10488. Now that you know how to enter commands, it's time to access a database.
  10489.  
  10490. Suppose you have several pets in your home (your menagerie) and you'd
  10491. like to keep track of various types of information about them.  You can
  10492. do so by creating tables to hold your data and loading them with the
  10493. desired information.  Then you can answer different sorts of questions
  10494. about your animals by retrieving data from the tables.  This section
  10495. shows you how to:
  10496.  
  10497.    * Create a database
  10498.  
  10499.    * Create a table
  10500.  
  10501.    * Load data into the table
  10502.  
  10503.    * Retrieve data from the table in various ways
  10504.  
  10505.    * Use multiple tables
  10506.  
  10507. The menagerie database will be simple (deliberately), but it is not
  10508. difficult to think of real-world situations in which a similar type of
  10509. database might be used.  For example, a database like this could be
  10510. used by a farmer to keep track of livestock, or by a veterinarian to
  10511. keep track of patient records.  A menagerie distribution containing
  10512. some of the queries and sample data used in the following sections can
  10513. be obtained from the MySQL Web site.  It's available in either
  10514. compressed `tar' format
  10515. (http://www.mysql.com/Downloads/Contrib/Examples/menagerie.tar.gz) or
  10516. Zip format
  10517. (http://www.mysql.com/Downloads/Contrib/Examples/menagerie.zip).
  10518.  
  10519. Use the `SHOW' statement to find out what databases currently exist on
  10520. the server:
  10521.  
  10522.      mysql> SHOW DATABASES;
  10523.      +----------+
  10524.      | Database |
  10525.      +----------+
  10526.      | mysql    |
  10527.      | test     |
  10528.      | tmp      |
  10529.      +----------+
  10530.  
  10531. The list of databases is probably different on your machine, but the
  10532. `mysql' and `test' databases are likely to be among them.  The `mysql'
  10533. database is required because it describes user access privileges.  The
  10534. `test' database is often provided as a workspace for users to try
  10535. things out.
  10536.  
  10537. If the `test' database exists, try to access it:
  10538.  
  10539.      mysql> USE test
  10540.      Database changed
  10541.  
  10542. Note that `USE', like `QUIT', does not require a semicolon.  (You can
  10543. terminate such statements with a semicolon if you like; it does no
  10544. harm.)  The `USE' statement is special in another way, too:  it must be
  10545. given on a single line.
  10546.  
  10547. You can use the `test' database (if you have access to it) for the
  10548. examples that follow, but anything you create in that database can be
  10549. removed by anyone else with access to it.  For this reason, you should
  10550. probably ask your MySQL administrator for permission to use a database
  10551. of your own.  Suppose you want to call yours `menagerie'.  The
  10552. administrator needs to execute a command like this:
  10553.  
  10554.      mysql> GRANT ALL ON menagerie.* TO your_mysql_name;
  10555.  
  10556. where `your_mysql_name' is the MySQL user name assigned to you.
  10557.  
  10558. Creating and Selecting a Database
  10559. ---------------------------------
  10560.  
  10561. If the administrator creates your database for you when setting up your
  10562. permissions, you can begin using it.  Otherwise, you need to create it
  10563. yourself:
  10564.  
  10565.      mysql> CREATE DATABASE menagerie;
  10566.  
  10567. Under Unix, database names are case sensitive (unlike SQL keywords), so
  10568. you must always refer to your database as `menagerie', not as
  10569. `Menagerie', `MENAGERIE', or some other variant.  This is also true for
  10570. table names.  (Under Windows, this restriction does not apply, although
  10571. you must refer to databases and tables using the same lettercase
  10572. throughout a given query.)
  10573.  
  10574. Creating a database does not select it for use; you must do that
  10575. explicitly.  To make `menagerie' the current database, use this command:
  10576.  
  10577.      mysql> USE menagerie
  10578.      Database changed
  10579.  
  10580. Your database needs to be created only once, but you must select it for
  10581. use each time you begin a `mysql' session.  You can do this by issuing a
  10582. `USE' statement as shown above.  Alternatively, you can select the
  10583. database on the command line when you invoke `mysql'.  Just specify its
  10584. name after any connection parameters that you might need to provide.
  10585. For example:
  10586.  
  10587.      shell> mysql -h host -u user -p menagerie
  10588.      Enter password: ********
  10589.  
  10590. Note that `menagerie' is not your password on the command just shown.
  10591. If you want to supply your password on the command line after the `-p'
  10592. option, you must do so with no intervening space (for example, as
  10593. `-pmypassword', not as `-p mypassword').  However, putting your
  10594. password on the command line is not recommended, because doing so
  10595. exposes it to snooping by other users logged in on your machine.
  10596.  
  10597. Creating a Table
  10598. ----------------
  10599.  
  10600. Creating the database is the easy part, but at this point it's empty, as
  10601. `SHOW TABLES' will tell you:
  10602.  
  10603.      mysql> SHOW TABLES;
  10604.      Empty set (0.00 sec)
  10605.  
  10606. The harder part is deciding what the structure of your database should
  10607. be: what tables you will need and what columns will be in each of them.
  10608.  
  10609. You'll want a table that contains a record for each of your pets.  This
  10610. can be called the `pet' table, and it should contain, as a bare minimum,
  10611. each animal's name.  Because the name by itself is not very
  10612. interesting, the table should contain other information.  For example,
  10613. if more than one person in your family keeps pets, you might want to
  10614. list each animal's owner.  You might also want to record some basic
  10615. descriptive information such as species and sex.
  10616.  
  10617. How about age?  That might be of interest, but it's not a good thing to
  10618. store in a database.  Age changes as time passes, which means you'd
  10619. have to update your records often.  Instead, it's better to store a
  10620. fixed value such as date of birth.  Then, whenever you need age, you
  10621. can calculate it as the difference between the current date and the
  10622. birth date.  MySQL provides functions for doing date arithmetic, so
  10623. this is not difficult.  Storing birth date rather than age has other
  10624. advantages, too:
  10625.  
  10626.    * You can use the database for tasks such as generating reminders
  10627.      for upcoming pet birthdays.  (If you think this type of query is
  10628.      somewhat silly, note that it is the same question you might ask in
  10629.      the context of a business database to identify clients to whom
  10630.      you'll soon need to send out birthday greetings, for that
  10631.      computer-assisted personal touch.)
  10632.  
  10633.    * You can calculate age in relation to dates other than the current
  10634.      date.  For example, if you store death date in the database, you
  10635.      can easily calculate how old a pet was when it died.
  10636.  
  10637. You can probably think of other types of information that would be
  10638. useful in the `pet' table, but the ones identified so far are
  10639. sufficient for now: name, owner, species, sex, birth, and death.
  10640.  
  10641. Use a `CREATE TABLE' statement to specify the layout of your table:
  10642.  
  10643.      mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
  10644.          -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
  10645.  
  10646. `VARCHAR' is a good choice for the `name', `owner', and `species'
  10647. columns because the column values will vary in length.  The lengths of
  10648. those columns need not all be the same, and need not be `20'.  You can
  10649. pick any length from `1' to `255', whatever seems most reasonable to
  10650. you.  (If you make a poor choice and it turns out later that you need a
  10651. longer field, MySQL provides an `ALTER TABLE' statement.)
  10652.  
  10653. Animal sex can be represented in a variety of ways, for example, `"m"'
  10654. and `"f"', or perhaps `"male"' and `"female"'.  It's simplest to use
  10655. the single characters `"m"' and `"f"'.
  10656.  
  10657. The use of the `DATE' data type for the `birth' and `death' columns is
  10658. a fairly obvious choice.
  10659.  
  10660. Now that you have created a table, `SHOW TABLES' should produce some
  10661. output:
  10662.  
  10663.      mysql> SHOW TABLES;
  10664.      +---------------------+
  10665.      | Tables in menagerie |
  10666.      +---------------------+
  10667.      | pet                 |
  10668.      +---------------------+
  10669.  
  10670. To verify that your table was created the way you expected, use a
  10671. `DESCRIBE' statement:
  10672.  
  10673.      mysql> DESCRIBE pet;
  10674.      +---------+-------------+------+-----+---------+-------+
  10675.      | Field   | Type        | Null | Key | Default | Extra |
  10676.      +---------+-------------+------+-----+---------+-------+
  10677.      | name    | varchar(20) | YES  |     | NULL    |       |
  10678.      | owner   | varchar(20) | YES  |     | NULL    |       |
  10679.      | species | varchar(20) | YES  |     | NULL    |       |
  10680.      | sex     | char(1)     | YES  |     | NULL    |       |
  10681.      | birth   | date        | YES  |     | NULL    |       |
  10682.      | death   | date        | YES  |     | NULL    |       |
  10683.      +---------+-------------+------+-----+---------+-------+
  10684.  
  10685. You can use `DESCRIBE' any time, for example, if you forget the names of
  10686. the columns in your table or what types they are.
  10687.  
  10688. Loading Data into a Table
  10689. -------------------------
  10690.  
  10691. After creating your table, you need to populate it.  The `LOAD DATA' and
  10692. `INSERT' statements are useful for this.
  10693.  
  10694. Suppose your pet records can be described as shown below.  (Observe
  10695. that MySQL expects dates in `YYYY-MM-DD' format; this may be different
  10696. than what you are used to.)
  10697.  
  10698. *name*       *owner*      *species*    *sex*        *birth*      *death*
  10699. Fluffy       Harold       cat          f            1993-02-04   
  10700. Claws        Gwen         cat          m            1994-03-17   
  10701. Buffy        Harold       dog          f            1989-05-13   
  10702. Fang         Benny        dog          m            1990-08-27   
  10703. Bowser       Diane        dog          m            1998-08-31   1995-07-29
  10704. Chirpy       Gwen         bird         f            1998-09-11   
  10705. Whistler     Gwen         bird                      1997-12-09   
  10706. Slim         Benny        snake        m            1996-04-29   
  10707.  
  10708. Because you are beginning with an empty table, an easy way to populate
  10709. it is to create a text file containing a row for each of your animals,
  10710. then load the contents of the file into the table with a single
  10711. statement.
  10712.  
  10713. You could create a text file `pet.txt' containing one record per line,
  10714. with values separated by tabs, and given in the order in which the
  10715. columns were listed in the `CREATE TABLE' statement.  For missing
  10716. values (such as unknown sexes or death dates for animals that are still
  10717. living), you can use `NULL' values.  To represent these in your text
  10718. file, use `\N'.  For example, the record for Whistler the bird would
  10719. look like this (where the whitespace between values is a single tab
  10720. character):
  10721.  
  10722. `Whistler'  `Gwen'      `bird'      `\N'        `1997-12-09'       `\N'
  10723.  
  10724. To load the text file `pet.txt' into the `pet' table, use this command:
  10725.  
  10726.      mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  10727.  
  10728. You can specify the column value separator and end of line marker
  10729. explicitly in the `LOAD DATA' statement if you wish, but the defaults
  10730. are tab and linefeed.  These are sufficient for the statement to read
  10731. the file `pet.txt' properly.
  10732.  
  10733. When you want to add new records one at a time, the `INSERT' statement
  10734. is useful.  In its simplest form, you supply values for each column, in
  10735. the order in which the columns were listed in the `CREATE TABLE'
  10736. statement.  Suppose Diane gets a new hamster named Puffball.  You could
  10737. add a new record using an `INSERT' statement like this:
  10738.  
  10739.      mysql> INSERT INTO pet
  10740.          -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
  10741.  
  10742. Note that string and date values are specified as quoted strings here.
  10743. Also, with `INSERT', you can insert `NULL' directly to represent a
  10744. missing value.  You do not use `\N' like you do with `LOAD DATA'.
  10745.  
  10746. From this example, you should be able to see that there would be a lot
  10747. more typing involved to load your records initially using several
  10748. `INSERT' statements rather than a single `LOAD DATA' statement.
  10749.  
  10750. Retrieving Information from a Table
  10751. -----------------------------------
  10752.  
  10753. The `SELECT' statement is used to pull information from a table.  The
  10754. general form of the statement is:
  10755.  
  10756.      SELECT what_to_select
  10757.      FROM which_table
  10758.      WHERE conditions_to_satisfy
  10759.  
  10760. `what_to_select' indicates what you want to see.  This can be a list of
  10761. columns, or `*' to indicate "all columns." `which_table' indicates the
  10762. table from which you want to retrieve data.  The `WHERE' clause is
  10763. optional.  If it's present, `conditions_to_satisfy' specifies
  10764. conditions that rows must satisfy to qualify for retrieval.
  10765.  
  10766. Selecting All Data
  10767. ..................
  10768.  
  10769. The simplest form of `SELECT' retrieves everything from a table:
  10770.  
  10771.      mysql> SELECT * FROM pet;
  10772.      +----------+--------+---------+------+------------+------------+
  10773.      | name     | owner  | species | sex  | birth      | death      |
  10774.      +----------+--------+---------+------+------------+------------+
  10775.      | Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |
  10776.      | Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |
  10777.      | Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |
  10778.      | Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |
  10779.      | Bowser   | Diane  | dog     | m    | 1998-08-31 | 1995-07-29 |
  10780.      | Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |
  10781.      | Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |
  10782.      | Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |
  10783.      | Puffball | Diane  | hamster | f    | 1999-03-30 | NULL       |
  10784.      +----------+--------+---------+------+------------+------------+
  10785.  
  10786. This form of `SELECT' is useful if you want to review your entire table,
  10787. for instance, after you've just loaded it with your initial dataset.
  10788. As it happens, the output just shown reveals an error in your data
  10789. file:  Bowser appears to have been born after he died!  Consulting your
  10790. original pedigree papers, you find that the correct birth year is 1989,
  10791. not 1998.
  10792.  
  10793. There are are least a couple of ways to fix this:
  10794.  
  10795.    * Edit the file `pet.txt' to correct the error, then empty the table
  10796.      and reload it using `DELETE' and `LOAD DATA':
  10797.  
  10798.           mysql> SET AUTOCOMMIT=1;  # Used for quick re-create of the table
  10799.           mysql> DELETE FROM pet;
  10800.           mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  10801.  
  10802.      However, if you do this, you must also re-enter the record for
  10803.      Puffball.
  10804.  
  10805.    * Fix only the erroneous record with an `UPDATE' statement:
  10806.  
  10807.           mysql> UPDATE pet SET birth = "1989-08-31" WHERE name = "Bowser";
  10808.  
  10809. As shown above, it is easy to retrieve an entire table.  But typically
  10810. you don't want to do that, particularly when the table becomes large.
  10811. Instead, you're usually more interested in answering a particular
  10812. question, in which case you specify some constraints on the information
  10813. you want.  Let's look at some selection queries in terms of questions
  10814. about your pets that they answer.
  10815.  
  10816. Selecting Particular Rows
  10817. .........................
  10818.  
  10819. You can select only particular rows from your table.  For example, if
  10820. you want to verify the change that you made to Bowser's birth date,
  10821. select Bowser's record like this:
  10822.  
  10823.      mysql> SELECT * FROM pet WHERE name = "Bowser";
  10824.      +--------+-------+---------+------+------------+------------+
  10825.      | name   | owner | species | sex  | birth      | death      |
  10826.      +--------+-------+---------+------+------------+------------+
  10827.      | Bowser | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  10828.      +--------+-------+---------+------+------------+------------+
  10829.  
  10830. The output confirms that the year is correctly recorded now as 1989,
  10831. not 1998.
  10832.  
  10833. String comparisons are normally case insensitive, so you can specify the
  10834. name as `"bowser"', `"BOWSER"', etc.  The query result will be the same.
  10835.  
  10836. You can specify conditions on any column, not just `name'.  For example,
  10837. if you want to know which animals were born after 1998, test the `birth'
  10838. column:
  10839.  
  10840.      mysql> SELECT * FROM pet WHERE birth >= "1998-1-1";
  10841.      +----------+-------+---------+------+------------+-------+
  10842.      | name     | owner | species | sex  | birth      | death |
  10843.      +----------+-------+---------+------+------------+-------+
  10844.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  10845.      | Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
  10846.      +----------+-------+---------+------+------------+-------+
  10847.  
  10848. You can combine conditions, for example, to locate female dogs:
  10849.  
  10850.      mysql> SELECT * FROM pet WHERE species = "dog" AND sex = "f";
  10851.      +-------+--------+---------+------+------------+-------+
  10852.      | name  | owner  | species | sex  | birth      | death |
  10853.      +-------+--------+---------+------+------------+-------+
  10854.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  10855.      +-------+--------+---------+------+------------+-------+
  10856.  
  10857. The preceding query uses the `AND' logical operator.  There is also an
  10858. `OR' operator:
  10859.  
  10860.      mysql> SELECT * FROM pet WHERE species = "snake" OR species = "bird";
  10861.      +----------+-------+---------+------+------------+-------+
  10862.      | name     | owner | species | sex  | birth      | death |
  10863.      +----------+-------+---------+------+------------+-------+
  10864.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  10865.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL  |
  10866.      | Slim     | Benny | snake   | m    | 1996-04-29 | NULL  |
  10867.      +----------+-------+---------+------+------------+-------+
  10868.  
  10869. `AND' and `OR' may be intermixed.  If you do that, it's a good idea to
  10870. use parentheses to indicate how conditions should be grouped:
  10871.  
  10872.      mysql> SELECT * FROM pet WHERE (species = "cat" AND sex = "m")
  10873.          -> OR (species = "dog" AND sex = "f");
  10874.      +-------+--------+---------+------+------------+-------+
  10875.      | name  | owner  | species | sex  | birth      | death |
  10876.      +-------+--------+---------+------+------------+-------+
  10877.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  10878.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  10879.      +-------+--------+---------+------+------------+-------+
  10880.  
  10881. Selecting Particular Columns
  10882. ............................
  10883.  
  10884. If you don't want to see entire rows from your table, just name the
  10885. columns in which you're interested, separated by commas.  For example,
  10886. if you want to know when your animals were born, select the `name' and
  10887. `birth' columns:
  10888.  
  10889.      mysql> SELECT name, birth FROM pet;
  10890.      +----------+------------+
  10891.      | name     | birth      |
  10892.      +----------+------------+
  10893.      | Fluffy   | 1993-02-04 |
  10894.      | Claws    | 1994-03-17 |
  10895.      | Buffy    | 1989-05-13 |
  10896.      | Fang     | 1990-08-27 |
  10897.      | Bowser   | 1989-08-31 |
  10898.      | Chirpy   | 1998-09-11 |
  10899.      | Whistler | 1997-12-09 |
  10900.      | Slim     | 1996-04-29 |
  10901.      | Puffball | 1999-03-30 |
  10902.      +----------+------------+
  10903.  
  10904. To find out who owns pets, use this query:
  10905.  
  10906.      mysql> SELECT owner FROM pet;
  10907.      +--------+
  10908.      | owner  |
  10909.      +--------+
  10910.      | Harold |
  10911.      | Gwen   |
  10912.      | Harold |
  10913.      | Benny  |
  10914.      | Diane  |
  10915.      | Gwen   |
  10916.      | Gwen   |
  10917.      | Benny  |
  10918.      | Diane  |
  10919.      +--------+
  10920.  
  10921. However, notice that the query simply retrieves the `owner' field from
  10922. each record, and some of them appear more than once.  To minimize the
  10923. output, retrieve each unique output record just once by adding the
  10924. keyword `DISTINCT':
  10925.  
  10926.      mysql> SELECT DISTINCT owner FROM pet;
  10927.      +--------+
  10928.      | owner  |
  10929.      +--------+
  10930.      | Benny  |
  10931.      | Diane  |
  10932.      | Gwen   |
  10933.      | Harold |
  10934.      +--------+
  10935.  
  10936. You can use a `WHERE' clause to combine row selection with column
  10937. selection.  For example, to get birth dates for dogs and cats only, use
  10938. this query:
  10939.  
  10940.      mysql> SELECT name, species, birth FROM pet
  10941.          -> WHERE species = "dog" OR species = "cat";
  10942.      +--------+---------+------------+
  10943.      | name   | species | birth      |
  10944.      +--------+---------+------------+
  10945.      | Fluffy | cat     | 1993-02-04 |
  10946.      | Claws  | cat     | 1994-03-17 |
  10947.      | Buffy  | dog     | 1989-05-13 |
  10948.      | Fang   | dog     | 1990-08-27 |
  10949.      | Bowser | dog     | 1989-08-31 |
  10950.      +--------+---------+------------+
  10951.  
  10952. Sorting Rows
  10953. ............
  10954.  
  10955. You may have noticed in the preceding examples that the result rows are
  10956. displayed in no particular order.  However, it's often easier to examine
  10957. query output when the rows are sorted in some meaningful way.  To sort a
  10958. result, use an `ORDER BY' clause.
  10959.  
  10960. Here are animal birthdays, sorted by date:
  10961.  
  10962.      mysql> SELECT name, birth FROM pet ORDER BY birth;
  10963.      +----------+------------+
  10964.      | name     | birth      |
  10965.      +----------+------------+
  10966.      | Buffy    | 1989-05-13 |
  10967.      | Bowser   | 1989-08-31 |
  10968.      | Fang     | 1990-08-27 |
  10969.      | Fluffy   | 1993-02-04 |
  10970.      | Claws    | 1994-03-17 |
  10971.      | Slim     | 1996-04-29 |
  10972.      | Whistler | 1997-12-09 |
  10973.      | Chirpy   | 1998-09-11 |
  10974.      | Puffball | 1999-03-30 |
  10975.      +----------+------------+
  10976.  
  10977. To sort in reverse order, add the `DESC' (descending) keyword to the
  10978. name of the column you are sorting by:
  10979.  
  10980.      mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
  10981.      +----------+------------+
  10982.      | name     | birth      |
  10983.      +----------+------------+
  10984.      | Puffball | 1999-03-30 |
  10985.      | Chirpy   | 1998-09-11 |
  10986.      | Whistler | 1997-12-09 |
  10987.      | Slim     | 1996-04-29 |
  10988.      | Claws    | 1994-03-17 |
  10989.      | Fluffy   | 1993-02-04 |
  10990.      | Fang     | 1990-08-27 |
  10991.      | Bowser   | 1989-08-31 |
  10992.      | Buffy    | 1989-05-13 |
  10993.      +----------+------------+
  10994.  
  10995. You can sort on multiple columns.  For example, to sort by type of
  10996. animal, then by birth date within animal type with youngest animals
  10997. first, use the following query:
  10998.  
  10999.      mysql> SELECT name, species, birth FROM pet ORDER BY species, birth DESC;
  11000.      +----------+---------+------------+
  11001.      | name     | species | birth      |
  11002.      +----------+---------+------------+
  11003.      | Chirpy   | bird    | 1998-09-11 |
  11004.      | Whistler | bird    | 1997-12-09 |
  11005.      | Claws    | cat     | 1994-03-17 |
  11006.      | Fluffy   | cat     | 1993-02-04 |
  11007.      | Fang     | dog     | 1990-08-27 |
  11008.      | Bowser   | dog     | 1989-08-31 |
  11009.      | Buffy    | dog     | 1989-05-13 |
  11010.      | Puffball | hamster | 1999-03-30 |
  11011.      | Slim     | snake   | 1996-04-29 |
  11012.      +----------+---------+------------+
  11013.  
  11014. Note that the `DESC' keyword applies only to the column name immediately
  11015. preceding it (`birth'); `species' values are still sorted in ascending
  11016. order.
  11017.  
  11018. Date Calculations
  11019. .................
  11020.  
  11021. MySQL provides several functions that you can use to perform
  11022. calculations on dates, for example, to calculate ages or extract parts
  11023. of dates.
  11024.  
  11025. To determine how many years old each of your pets is, compute the
  11026. difference in the year part of the current date and the birth date, then
  11027. subtract one if the current date occurs earlier in the calendar year
  11028. than the birth date.  The following query shows, for each pet, the
  11029. birth date, the current date, and the age in years.
  11030.  
  11031.      mysql> SELECT name, birth, CURRENT_DATE,
  11032.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  11033.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  11034.          -> AS age
  11035.          -> FROM pet;
  11036.      +----------+------------+--------------+------+
  11037.      | name     | birth      | CURRENT_DATE | age  |
  11038.      +----------+------------+--------------+------+
  11039.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  11040.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  11041.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  11042.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  11043.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  11044.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  11045.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  11046.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  11047.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  11048.      +----------+------------+--------------+------+
  11049.  
  11050. Here, `YEAR()' pulls out the year part of a date and `RIGHT()' pulls
  11051. off the rightmost five characters that represent the `MM-DD' (calendar
  11052. year) part of the date.  The part of the expression that compares the
  11053. `MM-DD' values evaluates to 1 or 0, which adjusts the year difference
  11054. down a year if `CURRENT_DATE' occurs earlier in the year than `birth'.
  11055. The full expression is somewhat ungainly, so an alias (`age') is used
  11056. to make the output column label more meaningful.
  11057.  
  11058. The query works, but the result could be scanned more easily if the rows
  11059. were presented in some order.  This can be done by adding an `ORDER BY
  11060. name' clause to sort the output by name:
  11061.  
  11062.      mysql> SELECT name, birth, CURRENT_DATE,
  11063.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  11064.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  11065.          -> AS age
  11066.          -> FROM pet ORDER BY name;
  11067.      +----------+------------+--------------+------+
  11068.      | name     | birth      | CURRENT_DATE | age  |
  11069.      +----------+------------+--------------+------+
  11070.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  11071.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  11072.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  11073.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  11074.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  11075.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  11076.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  11077.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  11078.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  11079.      +----------+------------+--------------+------+
  11080.  
  11081. To sort the output by `age' rather than `name', just use a different
  11082. `ORDER BY' clause:
  11083.  
  11084.      mysql> SELECT name, birth, CURRENT_DATE,
  11085.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  11086.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  11087.          -> AS age
  11088.          -> FROM pet ORDER BY age;
  11089.      +----------+------------+--------------+------+
  11090.      | name     | birth      | CURRENT_DATE | age  |
  11091.      +----------+------------+--------------+------+
  11092.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  11093.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  11094.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  11095.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  11096.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  11097.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  11098.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  11099.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  11100.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  11101.      +----------+------------+--------------+------+
  11102.  
  11103. A similar query can be used to determine age at death for animals that
  11104. have died.  You determine which animals these are by checking whether
  11105. or not the `death' value is `NULL'.  Then, for those with non-`NULL'
  11106. values, compute the difference between the `death' and `birth' values:
  11107.  
  11108.      mysql> SELECT name, birth, death,
  11109.          -> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5)<RIGHT(birth,5))
  11110.          -> AS age
  11111.          -> FROM pet WHERE death IS NOT NULL ORDER BY age;
  11112.      +--------+------------+------------+------+
  11113.      | name   | birth      | death      | age  |
  11114.      +--------+------------+------------+------+
  11115.      | Bowser | 1989-08-31 | 1995-07-29 |    5 |
  11116.      +--------+------------+------------+------+
  11117.  
  11118. The query uses `death IS NOT NULL' rather than `death != NULL' because
  11119. `NULL' is a special value.  This is explained later.  *Note Working
  11120. with `NULL': Working with NULL.
  11121.  
  11122. What if you want to know which animals have birthdays next month?  For
  11123. this type of calculation, year and day are irrelevant; you simply want
  11124. to extract the month part of the `birth' column.  MySQL provides several
  11125. date-part extraction functions, such as `YEAR()', `MONTH()', and
  11126. `DAYOFMONTH()'.  `MONTH()' is the appropriate function here.  To see
  11127. how it works, run a simple query that displays the value of both
  11128. `birth' and `MONTH(birth)':
  11129.  
  11130.      mysql> SELECT name, birth, MONTH(birth) FROM pet;
  11131.      +----------+------------+--------------+
  11132.      | name     | birth      | MONTH(birth) |
  11133.      +----------+------------+--------------+
  11134.      | Fluffy   | 1993-02-04 |            2 |
  11135.      | Claws    | 1994-03-17 |            3 |
  11136.      | Buffy    | 1989-05-13 |            5 |
  11137.      | Fang     | 1990-08-27 |            8 |
  11138.      | Bowser   | 1989-08-31 |            8 |
  11139.      | Chirpy   | 1998-09-11 |            9 |
  11140.      | Whistler | 1997-12-09 |           12 |
  11141.      | Slim     | 1996-04-29 |            4 |
  11142.      | Puffball | 1999-03-30 |            3 |
  11143.      +----------+------------+--------------+
  11144.  
  11145. Finding animals with birthdays in the upcoming month is easy, too.
  11146. Suppose the current month is April.  Then the month value is `4' and
  11147. you look for animals born in May (month 5) like this:
  11148.  
  11149.      mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
  11150.      +-------+------------+
  11151.      | name  | birth      |
  11152.      +-------+------------+
  11153.      | Buffy | 1989-05-13 |
  11154.      +-------+------------+
  11155.  
  11156. There is a small complication if the current month is December, of
  11157. course.  You don't just add one to the month number (`12') and look for
  11158. animals born in month 13, because there is no such month.  Instead, you
  11159. look for animals born in January (month 1).
  11160.  
  11161. You can even write the query so that it works no matter what the current
  11162. month is.  That way you don't have to use a particular month number in
  11163. the query.  `DATE_ADD()' allows you to add a time interval to a given
  11164. date.  If you add a month to the value of `NOW()', then extract the
  11165. month part with `MONTH()', the result produces the month in which to
  11166. look for birthdays:
  11167.  
  11168.      mysql> SELECT name, birth FROM pet
  11169.          -> WHERE MONTH(birth) = MONTH(DATE_ADD(NOW(), INTERVAL 1 MONTH));
  11170.  
  11171. A different way to accomplish the same task is to add `1' to get the
  11172. next month after the current one (after using the modulo function
  11173. (`MOD') to wrap around the month value to `0' if it is currently `12'):
  11174.  
  11175.      mysql> SELECT name, birth FROM pet
  11176.          -> WHERE MONTH(birth) = MOD(MONTH(NOW()), 12) + 1;
  11177.  
  11178. Note that `MONTH' returns a number between 1 and 12. And
  11179. `MOD(something,12)' returns a number between 0 and 11. So the addition
  11180. has to be after the `MOD()', otherwise we would go from November (11)
  11181. to January (1).
  11182.  
  11183. Working with `NULL' Values
  11184. ..........................
  11185.  
  11186. The `NULL' value can be surprising until you get used to it.
  11187. Conceptually, `NULL' means missing value or unknown value and it is
  11188. treated somewhat differently than other values.  To test for `NULL',
  11189. you cannot use the arithmetic comparison operators such as `=', `<', or
  11190. `!='.  To demonstrate this for yourself, try the following query:
  11191.  
  11192.      mysql> SELECT 1 = NULL, 1 != NULL, 1 < NULL, 1 > NULL;
  11193.      +----------+-----------+----------+----------+
  11194.      | 1 = NULL | 1 != NULL | 1 < NULL | 1 > NULL |
  11195.      +----------+-----------+----------+----------+
  11196.      |     NULL |      NULL |     NULL |     NULL |
  11197.      +----------+-----------+----------+----------+
  11198.  
  11199. Clearly you get no meaningful results from these comparisons.  Use the
  11200. `IS NULL' and `IS NOT NULL' operators instead:
  11201.  
  11202.      mysql> SELECT 1 IS NULL, 1 IS NOT NULL;
  11203.      +-----------+---------------+
  11204.      | 1 IS NULL | 1 IS NOT NULL |
  11205.      +-----------+---------------+
  11206.      |         0 |             1 |
  11207.      +-----------+---------------+
  11208.  
  11209. In MySQL, 0 or `NULL' means false and anything else means true.  The
  11210. default truth value from a boolean operation is 1.
  11211.  
  11212. This special treatment of `NULL' is why, in the previous section, it
  11213. was necessary to determine which animals are no longer alive using
  11214. `death IS NOT NULL' instead of `death != NULL'.
  11215.  
  11216. Pattern Matching
  11217. ................
  11218.  
  11219. MySQL provides standard SQL pattern matching as well as a form of
  11220. pattern matching based on extended regular expressions similar to those
  11221. used by Unix utilities such as `vi', `grep', and `sed'.
  11222.  
  11223. SQL pattern matching allows you to use `_' to match any single
  11224. character and `%' to match an arbitrary number of characters (including
  11225. zero characters).  In MySQL, SQL patterns are case insensitive by
  11226. default.  Some examples are shown below.  Note that you do not use `='
  11227. or `!=' when you use SQL patterns; use the `LIKE' or `NOT LIKE'
  11228. comparison operators instead.
  11229.  
  11230. To find names beginning with `b':
  11231.  
  11232.      mysql> SELECT * FROM pet WHERE name LIKE "b%";
  11233.      +--------+--------+---------+------+------------+------------+
  11234.      | name   | owner  | species | sex  | birth      | death      |
  11235.      +--------+--------+---------+------+------------+------------+
  11236.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  11237.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  11238.      +--------+--------+---------+------+------------+------------+
  11239.  
  11240. To find names ending with `fy':
  11241.  
  11242.      mysql> SELECT * FROM pet WHERE name LIKE "%fy";
  11243.      +--------+--------+---------+------+------------+-------+
  11244.      | name   | owner  | species | sex  | birth      | death |
  11245.      +--------+--------+---------+------+------------+-------+
  11246.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  11247.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  11248.      +--------+--------+---------+------+------------+-------+
  11249.  
  11250. To find names containing a `w':
  11251.  
  11252.      mysql> SELECT * FROM pet WHERE name LIKE "%w%";
  11253.      +----------+-------+---------+------+------------+------------+
  11254.      | name     | owner | species | sex  | birth      | death      |
  11255.      +----------+-------+---------+------+------------+------------+
  11256.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  11257.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  11258.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  11259.      +----------+-------+---------+------+------------+------------+
  11260.  
  11261. To find names containing exactly five characters, use the `_' pattern
  11262. character:
  11263.  
  11264.      mysql> SELECT * FROM pet WHERE name LIKE "_____";
  11265.      +-------+--------+---------+------+------------+-------+
  11266.      | name  | owner  | species | sex  | birth      | death |
  11267.      +-------+--------+---------+------+------------+-------+
  11268.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11269.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11270.      +-------+--------+---------+------+------------+-------+
  11271.  
  11272. The other type of pattern matching provided by MySQL uses extended
  11273. regular expressions.  When you test for a match for this type of
  11274. pattern, use the `REGEXP' and `NOT REGEXP' operators (or `RLIKE' and
  11275. `NOT RLIKE', which are synonyms).
  11276.  
  11277. Some characteristics of extended regular expressions are:
  11278.  
  11279.    * `.' matches any single character.
  11280.  
  11281.    * A character class `[...]' matches any character within the
  11282.      brackets.  For example, `[abc]' matches `a', `b', or `c'.  To name
  11283.      a range of characters, use a dash.  `[a-z]' matches any lowercase
  11284.      letter, whereas `[0-9]' matches any digit.
  11285.  
  11286.    * `*' matches zero or more instances of the thing preceding it.  For
  11287.      example, `x*' matches any number of `x' characters, `[0-9]*'
  11288.      matches any number of digits, and `.*' matches any number of
  11289.      anything.
  11290.  
  11291.    * Regular expressions are case sensitive, but you can use a
  11292.      character class to match both lettercases if you wish.  For
  11293.      example, `[aA]' matches lowercase or uppercase `a' and `[a-zA-Z]'
  11294.      matches any letter in either case.
  11295.  
  11296.    * The pattern matches if it occurs anywhere in the value being
  11297.      tested.  (SQL patterns match only if they match the entire value.)
  11298.  
  11299.    * To anchor a pattern so that it must match the beginning or end of
  11300.      the value being tested, use `^' at the beginning or `$' at the end
  11301.      of the pattern.
  11302.  
  11303. To demonstrate how extended regular expressions work, the `LIKE' queries
  11304. shown above are rewritten below to use `REGEXP'.
  11305.  
  11306. To find names beginning with `b', use `^' to match the beginning of the
  11307. name:
  11308.  
  11309.      mysql> SELECT * FROM pet WHERE name REGEXP "^b";
  11310.      +--------+--------+---------+------+------------+------------+
  11311.      | name   | owner  | species | sex  | birth      | death      |
  11312.      +--------+--------+---------+------+------------+------------+
  11313.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  11314.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  11315.      +--------+--------+---------+------+------------+------------+
  11316.  
  11317. Prior to MySQL Version 3.23.4, `REGEXP' is case sensitive, and the
  11318. previous query will return no rows. To match either lowercase or
  11319. uppercase `b', use this query instead:
  11320.  
  11321.      mysql> SELECT * FROM pet WHERE name REGEXP "^[bB]";
  11322.  
  11323. From MySQL 3.23.4 on, to force a `REGEXP' comparison to be case
  11324. sensitive, use the `BINARY' keyword to make one of the strings a binary
  11325. string. This query will match only lowercase `b' at the beginning of a
  11326. name:
  11327.  
  11328.      mysql> SELECT * FROM pet WHERE name REGEXP BINARY "^b";
  11329.  
  11330. To find names ending with `fy', use `$' to match the end of the name:
  11331.  
  11332.      mysql> SELECT * FROM pet WHERE name REGEXP "fy$";
  11333.      +--------+--------+---------+------+------------+-------+
  11334.      | name   | owner  | species | sex  | birth      | death |
  11335.      +--------+--------+---------+------+------------+-------+
  11336.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  11337.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  11338.      +--------+--------+---------+------+------------+-------+
  11339.  
  11340. To find names containing a lowercase or uppercase `w', use this query:
  11341.  
  11342.      mysql> SELECT * FROM pet WHERE name REGEXP "w";
  11343.      +----------+-------+---------+------+------------+------------+
  11344.      | name     | owner | species | sex  | birth      | death      |
  11345.      +----------+-------+---------+------+------------+------------+
  11346.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  11347.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  11348.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  11349.      +----------+-------+---------+------+------------+------------+
  11350.  
  11351. Because a regular expression pattern matches if it occurs anywhere in
  11352. the value, it is not necessary in the previous query to put a wild card
  11353. on either side of the pattern to get it to match the entire value like
  11354. it would be if you used a SQL pattern.
  11355.  
  11356. To find names containing exactly five characters, use `^' and `$' to
  11357. match the beginning and end of the name, and five instances of `.' in
  11358. between:
  11359.  
  11360.      mysql> SELECT * FROM pet WHERE name REGEXP "^.....$";
  11361.      +-------+--------+---------+------+------------+-------+
  11362.      | name  | owner  | species | sex  | birth      | death |
  11363.      +-------+--------+---------+------+------------+-------+
  11364.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11365.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11366.      +-------+--------+---------+------+------------+-------+
  11367.  
  11368. You could also write the previous query using the `{n}'
  11369. "repeat-`n'-times" operator:
  11370.  
  11371.      mysql> SELECT * FROM pet WHERE name REGEXP "^.{5}$";
  11372.      +-------+--------+---------+------+------------+-------+
  11373.      | name  | owner  | species | sex  | birth      | death |
  11374.      +-------+--------+---------+------+------------+-------+
  11375.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11376.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11377.      +-------+--------+---------+------+------------+-------+
  11378.  
  11379. Counting Rows
  11380. .............
  11381.  
  11382. Databases are often used to answer the question, "How often does a
  11383. certain type of data occur in a table?"  For example, you might want to
  11384. know how many pets you have, or how many pets each owner has, or you
  11385. might want to perform various kinds of censuses on your animals.
  11386.  
  11387. Counting the total number of animals you have is the same question as
  11388. "How many rows are in the `pet' table?" because there is one record per
  11389. pet.  The `COUNT()' function counts the number of non-`NULL' results, so
  11390. the query to count your animals looks like this:
  11391.  
  11392.      mysql> SELECT COUNT(*) FROM pet;
  11393.      +----------+
  11394.      | COUNT(*) |
  11395.      +----------+
  11396.      |        9 |
  11397.      +----------+
  11398.  
  11399. Earlier, you retrieved the names of the people who owned pets.  You can
  11400. use `COUNT()' if you want to find out how many pets each owner has:
  11401.  
  11402.      mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
  11403.      +--------+----------+
  11404.      | owner  | COUNT(*) |
  11405.      +--------+----------+
  11406.      | Benny  |        2 |
  11407.      | Diane  |        2 |
  11408.      | Gwen   |        3 |
  11409.      | Harold |        2 |
  11410.      +--------+----------+
  11411.  
  11412. Note the use of `GROUP BY' to group together all records for each
  11413. `owner'.  Without it, all you get is an error message:
  11414.  
  11415.      mysql> SELECT owner, COUNT(owner) FROM pet;
  11416.      ERROR 1140 at line 1: Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
  11417.      with no GROUP columns is illegal if there is no GROUP BY clause
  11418.  
  11419. `COUNT()' and `GROUP BY' are useful for characterizing your data in
  11420. various ways.  The following examples show different ways to perform
  11421. animal census operations.
  11422.  
  11423. Number of animals per species:
  11424.  
  11425.      mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
  11426.      +---------+----------+
  11427.      | species | COUNT(*) |
  11428.      +---------+----------+
  11429.      | bird    |        2 |
  11430.      | cat     |        2 |
  11431.      | dog     |        3 |
  11432.      | hamster |        1 |
  11433.      | snake   |        1 |
  11434.      +---------+----------+
  11435.  
  11436. Number of animals per sex:
  11437.  
  11438.      mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
  11439.      +------+----------+
  11440.      | sex  | COUNT(*) |
  11441.      +------+----------+
  11442.      | NULL |        1 |
  11443.      | f    |        4 |
  11444.      | m    |        4 |
  11445.      +------+----------+
  11446.  
  11447. (In this output, `NULL' indicates sex unknown.)
  11448.  
  11449. Number of animals per combination of species and sex:
  11450.  
  11451.      mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
  11452.      +---------+------+----------+
  11453.      | species | sex  | COUNT(*) |
  11454.      +---------+------+----------+
  11455.      | bird    | NULL |        1 |
  11456.      | bird    | f    |        1 |
  11457.      | cat     | f    |        1 |
  11458.      | cat     | m    |        1 |
  11459.      | dog     | f    |        1 |
  11460.      | dog     | m    |        2 |
  11461.      | hamster | f    |        1 |
  11462.      | snake   | m    |        1 |
  11463.      +---------+------+----------+
  11464.  
  11465. You need not retrieve an entire table when you use `COUNT()'.  For
  11466. example, the previous query, when performed just on dogs and cats,
  11467. looks like this:
  11468.  
  11469.      mysql> SELECT species, sex, COUNT(*) FROM pet
  11470.          -> WHERE species = "dog" OR species = "cat"
  11471.          -> GROUP BY species, sex;
  11472.      +---------+------+----------+
  11473.      | species | sex  | COUNT(*) |
  11474.      +---------+------+----------+
  11475.      | cat     | f    |        1 |
  11476.      | cat     | m    |        1 |
  11477.      | dog     | f    |        1 |
  11478.      | dog     | m    |        2 |
  11479.      +---------+------+----------+
  11480.  
  11481. Or, if you wanted the number of animals per sex only for known-sex
  11482. animals:
  11483.  
  11484.      mysql> SELECT species, sex, COUNT(*) FROM pet
  11485.          -> WHERE sex IS NOT NULL
  11486.          -> GROUP BY species, sex;
  11487.      +---------+------+----------+
  11488.      | species | sex  | COUNT(*) |
  11489.      +---------+------+----------+
  11490.      | bird    | f    |        1 |
  11491.      | cat     | f    |        1 |
  11492.      | cat     | m    |        1 |
  11493.      | dog     | f    |        1 |
  11494.      | dog     | m    |        2 |
  11495.      | hamster | f    |        1 |
  11496.      | snake   | m    |        1 |
  11497.      +---------+------+----------+
  11498.  
  11499. Using More Than one Table
  11500. .........................
  11501.  
  11502. The `pet' table keeps track of which pets you have.  If you want to
  11503. record other information about them, such as events in their lives like
  11504. visits to the vet or when litters are born, you need another table.
  11505. What should this table look like? It needs:
  11506.  
  11507.    * To contain the pet name so you know which animal each event
  11508.      pertains to.
  11509.  
  11510.    * A date so you know when the event occurred.
  11511.  
  11512.    * A field to describe the event.
  11513.  
  11514.    * An event type field, if you want to be able to categorize events.
  11515.  
  11516. Given these considerations, the `CREATE TABLE' statement for the
  11517. `event' table might look like this:
  11518.  
  11519.      mysql> CREATE TABLE event (name VARCHAR(20), date DATE,
  11520.          -> type VARCHAR(15), remark VARCHAR(255));
  11521.  
  11522. As with the `pet' table, it's easiest to load the initial records by
  11523. creating a tab-delimited text file containing the information:
  11524.  
  11525. Fluffy      1995-05-15  litter      4 kittens, 3 female, 1 male
  11526. Buffy       1993-06-23  litter      5 puppies, 2 female, 3 male
  11527. Buffy       1994-06-19  litter      3 puppies, 3 female
  11528. Chirpy      1999-03-21  vet         needed beak straightened
  11529. Slim        1997-08-03  vet         broken rib
  11530. Bowser      1991-10-12  kennel      
  11531. Fang        1991-10-12  kennel      
  11532. Fang        1998-08-28  birthday    Gave him a new chew toy
  11533. Claws       1998-03-17  birthday    Gave him a new flea collar
  11534. Whistler    1998-12-09  birthday    First birthday
  11535.  
  11536. Load the records like this:
  11537.  
  11538.      mysql> LOAD DATA LOCAL INFILE "event.txt" INTO TABLE event;
  11539.  
  11540. Based on what you've learned from the queries you've run on the `pet'
  11541. table, you should be able to perform retrievals on the records in the
  11542. `event' table; the principles are the same.  But when is the `event'
  11543. table by itself insufficient to answer questions you might ask?
  11544.  
  11545. Suppose you want to find out the ages of each pet when they had their
  11546. litters.  The `event' table indicates when this occurred, but to
  11547. calculate the age of the mother, you need her birth date.  Because that
  11548. is stored in the `pet' table, you need both tables for the query:
  11549.  
  11550.      mysql> SELECT pet.name, (TO_DAYS(date) - TO_DAYS(birth))/365 AS age, remark
  11551.          -> FROM pet, event
  11552.          -> WHERE pet.name = event.name AND type = "litter";
  11553.      +--------+------+-----------------------------+
  11554.      | name   | age  | remark                      |
  11555.      +--------+------+-----------------------------+
  11556.      | Fluffy | 2.27 | 4 kittens, 3 female, 1 male |
  11557.      | Buffy  | 4.12 | 5 puppies, 2 female, 3 male |
  11558.      | Buffy  | 5.10 | 3 puppies, 3 female         |
  11559.      +--------+------+-----------------------------+
  11560.  
  11561. There are several things to note about this query:
  11562.  
  11563.    * The `FROM' clause lists two tables because the query needs to pull
  11564.      information from both of them.
  11565.  
  11566.    * When combining (joining) information from multiple tables, you
  11567.      need to specify how records in one table can be matched to records
  11568.      in the other.  This is easy because they both have a `name'
  11569.      column.  The query uses `WHERE' clause to match up records in the
  11570.      two tables based on the `name' values.
  11571.  
  11572.    * Because the `name' column occurs in both tables, you must be
  11573.      specific about which table you mean when referring to the column.
  11574.      This is done by prepending the table name to the column name.
  11575.  
  11576. You need not have two different tables to perform a join.  Sometimes it
  11577. is useful to join a table to itself, if you want to compare records in
  11578. a table to other records in that same table.  For example, to find
  11579. breeding pairs among your pets, you can join the `pet' table with
  11580. itself to pair up males and females of like species:
  11581.  
  11582.      mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
  11583.          -> FROM pet AS p1, pet AS p2
  11584.          -> WHERE p1.species = p2.species AND p1.sex = "f" AND p2.sex = "m";
  11585.      +--------+------+--------+------+---------+
  11586.      | name   | sex  | name   | sex  | species |
  11587.      +--------+------+--------+------+---------+
  11588.      | Fluffy | f    | Claws  | m    | cat     |
  11589.      | Buffy  | f    | Fang   | m    | dog     |
  11590.      | Buffy  | f    | Bowser | m    | dog     |
  11591.      +--------+------+--------+------+---------+
  11592.  
  11593. In this query, we specify aliases for the table name in order to refer
  11594. to the columns and keep straight which instance of the table each
  11595. column reference is associated with.
  11596.  
  11597. Getting Information About Databases and Tables
  11598. ==============================================
  11599.  
  11600. What if you forget the name of a database or table, or what the
  11601. structure of a given table is (for example, what its columns are
  11602. called)?  MySQL addresses this problem through several statements that
  11603. provide information about the databases and tables it supports.
  11604.  
  11605. You have already seen `SHOW DATABASES', which lists the databases
  11606. managed by the server.  To find out which database is currently
  11607. selected, use the `DATABASE()' function:
  11608.  
  11609.      mysql> SELECT DATABASE();
  11610.      +------------+
  11611.      | DATABASE() |
  11612.      +------------+
  11613.      | menagerie  |
  11614.      +------------+
  11615.  
  11616. If you haven't selected any database yet, the result is blank.
  11617.  
  11618. To find out what tables the current database contains (for example, when
  11619. you're not sure about the name of a table), use this command:
  11620.  
  11621.      mysql> SHOW TABLES;
  11622.      +---------------------+
  11623.      | Tables in menagerie |
  11624.      +---------------------+
  11625.      | event               |
  11626.      | pet                 |
  11627.      +---------------------+
  11628.  
  11629. If you want to find out about the structure of a table, the `DESCRIBE'
  11630. command is useful; it displays information about each of a table's
  11631. columns:
  11632.  
  11633.      mysql> DESCRIBE pet;
  11634.      +---------+-------------+------+-----+---------+-------+
  11635.      | Field   | Type        | Null | Key | Default | Extra |
  11636.      +---------+-------------+------+-----+---------+-------+
  11637.      | name    | varchar(20) | YES  |     | NULL    |       |
  11638.      | owner   | varchar(20) | YES  |     | NULL    |       |
  11639.      | species | varchar(20) | YES  |     | NULL    |       |
  11640.      | sex     | char(1)     | YES  |     | NULL    |       |
  11641.      | birth   | date        | YES  |     | NULL    |       |
  11642.      | death   | date        | YES  |     | NULL    |       |
  11643.      +---------+-------------+------+-----+---------+-------+
  11644.  
  11645. `Field' indicates the column name, `Type' is the data type for the
  11646. column, `Null' indicates whether or not the column can contain `NULL'
  11647. values, `Key' indicates whether or not the column is indexed, and
  11648. `Default' specifies the column's default value.
  11649.  
  11650. If you have indexes on a table, `SHOW INDEX FROM tbl_name' produces
  11651. information about them.
  11652.  
  11653. Examples of Common Queries
  11654. ==========================
  11655.  
  11656. Here are examples of how to solve some common problems with MySQL.
  11657.  
  11658. Some of the examples use the table `shop' to hold the price of each
  11659. article (item number) for certain traders (dealers).  Supposing that
  11660. each trader has a single fixed price per article, then (`article',
  11661. `dealer') is a primary key for the records.
  11662.  
  11663. Start the command line tool `mysql' and select a database:
  11664.  
  11665.      mysql your-database-name
  11666.  
  11667. (In most MySQL installations, you can use the database-name 'test').
  11668.  
  11669. You can create the example table as:
  11670.  
  11671.      CREATE TABLE shop (
  11672.       article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  11673.       dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
  11674.       price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
  11675.       PRIMARY KEY(article, dealer));
  11676.      
  11677.      INSERT INTO shop VALUES
  11678.      (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
  11679.      (3,'D',1.25),(4,'D',19.95);
  11680.  
  11681. Okay, so the example data is:
  11682.  
  11683.      mysql> SELECT * FROM shop;
  11684.      
  11685.      +---------+--------+-------+
  11686.      | article | dealer | price |
  11687.      +---------+--------+-------+
  11688.      |    0001 | A      |  3.45 |
  11689.      |    0001 | B      |  3.99 |
  11690.      |    0002 | A      | 10.99 |
  11691.      |    0003 | B      |  1.45 |
  11692.      |    0003 | C      |  1.69 |
  11693.      |    0003 | D      |  1.25 |
  11694.      |    0004 | D      | 19.95 |
  11695.      +---------+--------+-------+
  11696.  
  11697. The Maximum Value for a Column
  11698. ------------------------------
  11699.  
  11700. "What's the highest item number?"
  11701.  
  11702.      SELECT MAX(article) AS article FROM shop
  11703.      
  11704.      +---------+
  11705.      | article |
  11706.      +---------+
  11707.      |       4 |
  11708.      +---------+
  11709.  
  11710. The Row Holding the Maximum of a Certain Column
  11711. -----------------------------------------------
  11712.  
  11713. "Find number, dealer, and price of the most expensive article."
  11714.  
  11715. In ANSI SQL this is easily done with a sub-query:
  11716.  
  11717.      SELECT article, dealer, price
  11718.      FROM   shop
  11719.      WHERE  price=(SELECT MAX(price) FROM shop)
  11720.  
  11721. In MySQL (which does not yet have sub-selects), just do it in two steps:
  11722.  
  11723.   1. Get the maximum price value from the table with a `SELECT'
  11724.      statement.
  11725.  
  11726.   2. Using this value compile the actual query:
  11727.           SELECT article, dealer, price
  11728.           FROM   shop
  11729.           WHERE  price=19.95
  11730.  
  11731. Another solution is to sort all rows descending by price and only get
  11732. the first row using the MySQL specific `LIMIT' clause:
  11733.  
  11734.      SELECT article, dealer, price
  11735.      FROM   shop
  11736.      ORDER BY price DESC
  11737.      LIMIT 1
  11738.  
  11739. *NOTE*:  If there are several most expensive articles (for example,
  11740. each 19.95) the `LIMIT' solution shows only one of them!
  11741.  
  11742. Maximum of Column per Group
  11743. ---------------------------
  11744.  
  11745. "What's the highest price per article?"
  11746.  
  11747.      SELECT article, MAX(price) AS price
  11748.      FROM   shop
  11749.      GROUP BY article
  11750.      
  11751.      +---------+-------+
  11752.      | article | price |
  11753.      +---------+-------+
  11754.      |    0001 |  3.99 |
  11755.      |    0002 | 10.99 |
  11756.      |    0003 |  1.69 |
  11757.      |    0004 | 19.95 |
  11758.      +---------+-------+
  11759.  
  11760. The Rows Holding the Group-wise Maximum of a Certain Field
  11761. ----------------------------------------------------------
  11762.  
  11763. "For each article, find the dealer(s) with the most expensive price."
  11764.  
  11765. In ANSI SQL, I'd do it with a sub-query like this:
  11766.  
  11767.      SELECT article, dealer, price
  11768.      FROM   shop s1
  11769.      WHERE  price=(SELECT MAX(s2.price)
  11770.                    FROM shop s2
  11771.                    WHERE s1.article = s2.article);
  11772.  
  11773. In MySQL it's best do it in several steps:
  11774.  
  11775.   1. Get the list of (article,maxprice).
  11776.  
  11777.   2. For each article get the corresponding rows that have the stored
  11778.      maximum price.
  11779.  
  11780. This can easily be done with a temporary table:
  11781.  
  11782.      CREATE TEMPORARY TABLE tmp (
  11783.              article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  11784.              price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL);
  11785.      
  11786.      LOCK TABLES shop read;
  11787.      
  11788.      INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article;
  11789.      
  11790.      SELECT shop.article, dealer, shop.price FROM shop, tmp
  11791.      WHERE shop.article=tmp.article AND shop.price=tmp.price;
  11792.      
  11793.      UNLOCK TABLES;
  11794.      
  11795.      DROP TABLE tmp;
  11796.  
  11797. If you don't use a `TEMPORARY' table, you must also lock the 'tmp'
  11798. table.
  11799.  
  11800. "Can it be done with a single query?"
  11801.  
  11802. Yes, but only by using a quite inefficient trick that I call the
  11803. "MAX-CONCAT trick":
  11804.  
  11805.      SELECT article,
  11806.             SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer,
  11807.        0.00+LEFT(      MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price
  11808.      FROM   shop
  11809.      GROUP BY article;
  11810.      
  11811.      +---------+--------+-------+
  11812.      | article | dealer | price |
  11813.      +---------+--------+-------+
  11814.      |    0001 | B      |  3.99 |
  11815.      |    0002 | A      | 10.99 |
  11816.      |    0003 | C      |  1.69 |
  11817.      |    0004 | D      | 19.95 |
  11818.      +---------+--------+-------+
  11819.  
  11820. The last example can, of course, be made a bit more efficient by doing
  11821. the splitting of the concatenated column in the client.
  11822.  
  11823. Using user variables
  11824. --------------------
  11825.  
  11826. You can use MySQL user variables to remember results without having to
  11827. store them in temporary variables in the client.  *Note Variables::.
  11828.  
  11829. For example, to find the articles with the highest and lowest price you
  11830. can do:
  11831.  
  11832.      select @min_price:=min(price),@max_price:=max(price) from shop;
  11833.      select * from shop where price=@min_price or price=@max_price;
  11834.      
  11835.      +---------+--------+-------+
  11836.      | article | dealer | price |
  11837.      +---------+--------+-------+
  11838.      |    0003 | D      |  1.25 |
  11839.      |    0004 | D      | 19.95 |
  11840.      +---------+--------+-------+
  11841.  
  11842. Using Foreign Keys
  11843. ------------------
  11844.  
  11845. You don't need foreign keys to join 2 tables.
  11846.  
  11847. The only thing MySQL doesn't do is `CHECK' to make sure that the keys
  11848. you use really exist in the table(s) you're referencing and it doesn't
  11849. automatically delete rows from table with a foreign key definition. If
  11850. you use your keys like normal, it'll work just fine:
  11851.  
  11852.      CREATE TABLE persons (
  11853.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  11854.          name CHAR(60) NOT NULL,
  11855.          PRIMARY KEY (id)
  11856.      );
  11857.      
  11858.      CREATE TABLE shirts (
  11859.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  11860.          style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
  11861.          color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
  11862.          owner SMALLINT UNSIGNED NOT NULL REFERENCES persons,
  11863.          PRIMARY KEY (id)
  11864.      );
  11865.      
  11866.      
  11867.      INSERT INTO persons VALUES (NULL, 'Antonio Paz');
  11868.      
  11869.      INSERT INTO shirts VALUES
  11870.      (NULL, 'polo', 'blue', LAST_INSERT_ID()),
  11871.      (NULL, 'dress', 'white', LAST_INSERT_ID()),
  11872.      (NULL, 't-shirt', 'blue', LAST_INSERT_ID());
  11873.      
  11874.      
  11875.      INSERT INTO persons VALUES (NULL, 'Lilliana Angelovska');
  11876.      
  11877.      INSERT INTO shirts VALUES
  11878.      (NULL, 'dress', 'orange', LAST_INSERT_ID()),
  11879.      (NULL, 'polo', 'red', LAST_INSERT_ID()),
  11880.      (NULL, 'dress', 'blue', LAST_INSERT_ID()),
  11881.      (NULL, 't-shirt', 'white', LAST_INSERT_ID());
  11882.      
  11883.      
  11884.      SELECT * FROM persons;
  11885.      +----+---------------------+
  11886.      | id | name                |
  11887.      +----+---------------------+
  11888.      |  1 | Antonio Paz         |
  11889.      |  2 | Lilliana Angelovska |
  11890.      +----+---------------------+
  11891.      
  11892.      SELECT * FROM shirts;
  11893.      +----+---------+--------+-------+
  11894.      | id | style   | color  | owner |
  11895.      +----+---------+--------+-------+
  11896.      |  1 | polo    | blue   |     1 |
  11897.      |  2 | dress   | white  |     1 |
  11898.      |  3 | t-shirt | blue   |     1 |
  11899.      |  4 | dress   | orange |     2 |
  11900.      |  5 | polo    | red    |     2 |
  11901.      |  6 | dress   | blue   |     2 |
  11902.      |  7 | t-shirt | white  |     2 |
  11903.      +----+---------+--------+-------+
  11904.      
  11905.      
  11906.      SELECT s.* FROM persons p, shirts s
  11907.       WHERE p.name LIKE 'Lilliana%'
  11908.         AND s.owner = p.id
  11909.         AND s.color <> 'white';
  11910.      
  11911.      +----+-------+--------+-------+
  11912.      | id | style | color  | owner |
  11913.      +----+-------+--------+-------+
  11914.      |  4 | dress | orange |     2 |
  11915.      |  5 | polo  | red    |     2 |
  11916.      |  6 | dress | blue   |     2 |
  11917.      +----+-------+--------+-------+
  11918.  
  11919. Searching on Two Keys
  11920. ---------------------
  11921.  
  11922. MySQL doesn't yet optimize when you search on two different keys
  11923. combined with `OR' (Searching on one key with different `OR' parts is
  11924. optimized quite good):
  11925.  
  11926.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1'
  11927.      OR  field2_index = '1'
  11928.  
  11929. The reason is that we haven't yet had time to come up with an efficient
  11930. way to handle this in the general case. (The `AND' handling is, in
  11931. comparison, now completely general and works very well).
  11932.  
  11933. For the moment you can solve this very efficiently by using a
  11934. `TEMPORARY' table. This type of optimization is also very good if you
  11935. are using very complicated queries where the SQL server does the
  11936. optimizations in the wrong order.
  11937.  
  11938.      CREATE TEMPORARY TABLE tmp
  11939.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1';
  11940.      INSERT INTO tmp
  11941.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  11942.      SELECT * from tmp;
  11943.      DROP TABLE tmp;
  11944.  
  11945. The above way to solve this query is in effect an `UNION' of two
  11946. queries.
  11947.  
  11948. Calculating visits per day
  11949. --------------------------
  11950.  
  11951. The following shows an idea of how you can use the bit group functions
  11952. to calculate the number of days per month a user has visited a web page.
  11953.  
  11954.      CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL, day INT(2) UNSIGNED ZEROFILL);
  11955.      INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2),(2000,2,23),(2000,2,23);
  11956.      
  11957.      SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1 GROUP BY year,month;
  11958.      
  11959.      Which returns:
  11960.      
  11961.      +------+-------+------+
  11962.      | year | month | days |
  11963.      +------+-------+------+
  11964.      | 2000 |    01 |    3 |
  11965.      | 2000 |    02 |    2 |
  11966.      +------+-------+------+
  11967.  
  11968. The above calculates how many different days was used for a given
  11969. year/month combination, with automatic removal of duplicate entries.
  11970.  
  11971. Using `mysql' in Batch Mode
  11972. ===========================
  11973.  
  11974. In the previous sections, you used `mysql' interactively to enter
  11975. queries and view the results.  You can also run `mysql' in batch mode.
  11976. To do this, put the commands you want to run in a file, then tell
  11977. `mysql' to read its input from the file:
  11978.  
  11979.      shell> mysql < batch-file
  11980.  
  11981. If you need to specify connection parameters on the command line, the
  11982. command might look like this:
  11983.  
  11984.      shell> mysql -h host -u user -p < batch-file
  11985.      Enter password: ********
  11986.  
  11987. When you use `mysql' this way, you are creating a script file, then
  11988. executing the script.
  11989.  
  11990. Why use a script?  Here are a few reasons:
  11991.  
  11992.    * If you run a query repeatedly (say, every day or every week),
  11993.      making it a script allows you to avoid retyping it each time you
  11994.      execute it.
  11995.  
  11996.    * You can generate new queries from existing ones that are similar
  11997.      by copying and editing script files.
  11998.  
  11999.    * Batch mode can also be useful while you're developing a query,
  12000.      particularly for multiple-line commands or multiple-statement
  12001.      sequences of commands.  If you make a mistake, you don't have to
  12002.      retype everything.  Just edit your script to correct the error,
  12003.      then tell `mysql' to execute it again.
  12004.  
  12005.    * If you have a query that produces a lot of output, you can run the
  12006.      output through a pager rather than watching it scroll off the top
  12007.      of your screen:
  12008.  
  12009.           shell> mysql < batch-file | more
  12010.  
  12011.    * You can catch the output in a file for further processing:
  12012.  
  12013.           shell> mysql < batch-file > mysql.out
  12014.  
  12015.    * You can distribute your script to other people so they can run the
  12016.      commands, too.
  12017.  
  12018.    * Some situations do not allow for interactive use, for example,
  12019.      when you run a query from a `cron' job.  In this case, you must
  12020.      use batch mode.
  12021.  
  12022. The default output format is different (more concise) when you run
  12023. `mysql' in batch mode than when you use it interactively.  For example,
  12024. the output of `SELECT DISTINCT species FROM pet' looks like this when
  12025. run interactively:
  12026.  
  12027.      +---------+
  12028.      | species |
  12029.      +---------+
  12030.      | bird    |
  12031.      | cat     |
  12032.      | dog     |
  12033.      | hamster |
  12034.      | snake   |
  12035.      +---------+
  12036.  
  12037. But like this when run in batch mode:
  12038.  
  12039.      species
  12040.      bird
  12041.      cat
  12042.      dog
  12043.      hamster
  12044.      snake
  12045.  
  12046. If you want to get the interactive output format in batch mode, use
  12047. `mysql -t'.  To echo to the output the commands that are executed, use
  12048. `mysql -vvv'.
  12049.  
  12050. Queries from Twin Project
  12051. =========================
  12052.  
  12053. At Analytikerna and Lentus, we have been doing the systems and field
  12054. work for a big research project. This project is a collaboration
  12055. between the Institute of Environmental Medicine at Karolinska
  12056. Institutet Stockholm and the Section on Clinical Research in Aging and
  12057. Psychology at the University of Southern California.
  12058.  
  12059. The project involves a screening part where all twins in Sweden older
  12060. than 65 years are interviewed by telephone. Twins who meet certain
  12061. criteria are passed on to the next stage. In this latter stage, twins
  12062. who want to participate are visited by a doctor/nurse team. Some of the
  12063. examinations include physical and neuropsychological examination,
  12064. laboratory testing, neuroimaging, psychological status assessment, and
  12065. family history collection. In addition, data are collected on medical
  12066. and environmental risk factors.
  12067.  
  12068. More information about Twin studies can be found at:
  12069.  
  12070.      <http://www.imm.ki.se/TWIN/TWINUKW.HTM>
  12071.  
  12072. The latter part of the project is administered with a Web interface
  12073. written using Perl and MySQL.
  12074.  
  12075. Each night all data from the interviews are moved into a MySQL database.
  12076.  
  12077. Find all Non-distributed Twins
  12078. ------------------------------
  12079.  
  12080. The following query is used to determine who goes into the second part
  12081. of the project:
  12082.  
  12083.      select
  12084.              concat(p1.id, p1.tvab) + 0 as tvid,
  12085.              concat(p1.christian_name, " ", p1.surname) as Name,
  12086.              p1.postal_code as Code,
  12087.              p1.city as City,
  12088.              pg.abrev as Area,
  12089.              if(td.participation = "Aborted", "A", " ") as A,
  12090.              p1.dead as dead1,
  12091.              l.event as event1,
  12092.              td.suspect as tsuspect1,
  12093.              id.suspect as isuspect1,
  12094.              td.severe as tsevere1,
  12095.              id.severe as isevere1,
  12096.              p2.dead as dead2,
  12097.              l2.event as event2,
  12098.              h2.nurse as nurse2,
  12099.              h2.doctor as doctor2,
  12100.              td2.suspect as tsuspect2,
  12101.              id2.suspect as isuspect2,
  12102.              td2.severe as tsevere2,
  12103.              id2.severe as isevere2,
  12104.              l.finish_date
  12105.      from
  12106.              twin_project as tp
  12107.              /* For Twin 1 */
  12108.              left join twin_data as td on tp.id = td.id and tp.tvab = td.tvab
  12109.              left join informant_data as id on tp.id = id.id and tp.tvab = id.tvab
  12110.              left join harmony as h on tp.id = h.id and tp.tvab = h.tvab
  12111.              left join lentus as l on tp.id = l.id and tp.tvab = l.tvab
  12112.              /* For Twin 2 */
  12113.              left join twin_data as td2 on p2.id = td2.id and p2.tvab = td2.tvab
  12114.              left join informant_data as id2 on p2.id = id2.id and p2.tvab = id2.tvab
  12115.              left join harmony as h2 on p2.id = h2.id and p2.tvab = h2.tvab
  12116.              left join lentus as l2 on p2.id = l2.id and p2.tvab = l2.tvab,
  12117.              person_data as p1,
  12118.              person_data as p2,
  12119.              postal_groups as pg
  12120.      where
  12121.              /* p1 gets main twin and p2 gets his/her twin. */
  12122.              /* ptvab is a field inverted from tvab */
  12123.              p1.id = tp.id and p1.tvab = tp.tvab and
  12124.              p2.id = p1.id and p2.ptvab = p1.tvab and
  12125.              /* Just the sceening survey */
  12126.              tp.survey_no = 5 and
  12127.              /* Skip if partner died before 65 but allow emigration (dead=9) */
  12128.              (p2.dead = 0 or p2.dead = 9 or
  12129.               (p2.dead = 1 and
  12130.                (p2.death_date = 0 or
  12131.                 (((to_days(p2.death_date) - to_days(p2.birthday)) / 365)
  12132.                  >= 65))))
  12133.              and
  12134.              (
  12135.              /* Twin is suspect */
  12136.              (td.future_contact = 'Yes' and td.suspect = 2) or
  12137.              /* Twin is suspect - Informant is Blessed */
  12138.              (td.future_contact = 'Yes' and td.suspect = 1 and id.suspect = 1) or
  12139.              /* No twin - Informant is Blessed */
  12140.              (ISNULL(td.suspect) and id.suspect = 1 and id.future_contact = 'Yes') or
  12141.              /* Twin broken off - Informant is Blessed */
  12142.              (td.participation = 'Aborted'
  12143.               and id.suspect = 1 and id.future_contact = 'Yes') or
  12144.              /* Twin broken off - No inform - Have partner */
  12145.              (td.participation = 'Aborted' and ISNULL(id.suspect) and p2.dead = 0))
  12146.              and
  12147.              l.event = 'Finished'
  12148.              /* Get at area code */
  12149.              and substring(p1.postal_code, 1, 2) = pg.code
  12150.              /* Not already distributed */
  12151.              and (h.nurse is NULL or h.nurse=00 or h.doctor=00)
  12152.              /* Has not refused or been aborted */
  12153.              and not (h.status = 'Refused' or h.status = 'Aborted'
  12154.              or h.status = 'Died' or h.status = 'Other')
  12155.      order by
  12156.              tvid;
  12157.  
  12158. Some explanations:
  12159. `concat(p1.id, p1.tvab) + 0 as tvid'
  12160.      We want to sort on the concatenated `id' and `tvab' in numerical
  12161.      order. Adding `0' to the result causes MySQL to treat the result
  12162.      as a number.
  12163.  
  12164. column `id'
  12165.      This identifies a pair of twins. It is a key in all tables.
  12166.  
  12167. column `tvab'
  12168.      This identifies a twin in a pair. It has a value of `1' or `2'.
  12169.  
  12170. column `ptvab'
  12171.      This is an inverse of `tvab'. When `tvab' is `1' this is `2', and
  12172.      vice versa. It exists to save typing and to make it easier for
  12173.      MySQL to optimize the query.
  12174.  
  12175. This query demonstrates, among other things, how to do lookups on a
  12176. table from the same table with a join (`p1' and `p2'). In the example,
  12177. this is used to check whether a twin's partner died before the age of
  12178. 65. If so, the row is not returned.
  12179.  
  12180. All of the above exist in all tables with twin-related information. We
  12181. have a key on both `id,tvab' (all tables), and `id,ptvab'
  12182. (`person_data') to make queries faster.
  12183.  
  12184. On our production machine (A 200MHz UltraSPARC), this query returns
  12185. about 150-200 rows and takes less than one second.
  12186.  
  12187. The current number of records in the tables used above:
  12188. *Table*                *Rows*
  12189. `person_data'          71074
  12190. `lentus'               5291
  12191. `twin_project'         5286
  12192. `twin_data'            2012
  12193. `informant_data'       663
  12194. `harmony'              381
  12195. `postal_groups'        100
  12196.  
  12197. Show a Table on Twin Pair Status
  12198. --------------------------------
  12199.  
  12200. Each interview ends with a status code called `event'. The query shown
  12201. below is used to display a table over all twin pairs combined by event.
  12202. This indicates in how many pairs both twins are finished, in how many
  12203. pairs one twin is finished and the other refused, and so on.
  12204.  
  12205.      select
  12206.              t1.event,
  12207.              t2.event,
  12208.              count(*)
  12209.      from
  12210.              lentus as t1,
  12211.              lentus as t2,
  12212.              twin_project as tp
  12213.      where
  12214.              /* We are looking at one pair at a time */
  12215.              t1.id = tp.id
  12216.              and t1.tvab=tp.tvab
  12217.              and t1.id = t2.id
  12218.              /* Just the sceening survey */
  12219.              and tp.survey_no = 5
  12220.              /* This makes each pair only appear once */
  12221.              and t1.tvab='1' and t2.tvab='2'
  12222.      group by
  12223.              t1.event, t2.event;
  12224.  
  12225. Using MySQL with Apache
  12226. =======================
  12227.  
  12228. The Contrib section includes programs that let you authenticate your
  12229. users from a MySQL database and also let you log your log files into a
  12230. MySQL table. *Note Contrib::.
  12231.  
  12232. You can change the Apache logging format to be easily readable by MySQL
  12233. by putting the following into the Apache configuration file:
  12234.  
  12235.      LogFormat \
  12236.              "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",  \
  12237.              \"%U\",\"%{Referer}i\",\"%{User-Agent}i\""
  12238.  
  12239. In MySQL you can do something like this:
  12240.  
  12241.      LOAD DATA INFILE '/local/access_log' INTO TABLE table_name
  12242.      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
  12243.  
  12244. MySQL Database Administration
  12245. *****************************
  12246.  
  12247. Configuring MySQL
  12248. =================
  12249.  
  12250. mysqld Command-line Options
  12251. ---------------------------
  12252.  
  12253. `mysqld' accepts the following command-line options:
  12254.  
  12255. `--ansi'
  12256.      Use ANSI SQL syntax instead of MySQL syntax.  *Note ANSI mode::.
  12257.  
  12258. `-b, --basedir=path'
  12259.      Path to installation directory. All paths are usually resolved
  12260.      relative to this.
  12261.  
  12262. `--big-tables'
  12263.      Allow big result sets by saving all temporary sets on file.  It
  12264.      solves most 'table full' errors, but also slows down the queries
  12265.      where in-memory tables would suffice.  Since Version 3.23.2, MySQL
  12266.      is able to solve it automatically by using memory for small
  12267.      temporary tables and switching to disk tables where necessary.
  12268.  
  12269. `--bind-address=IP'
  12270.      IP address to bind to.
  12271.  
  12272. `--character-sets-dir=path'
  12273.      Directory where character sets are.  *Note Character sets::.
  12274.  
  12275. `--chroot=path'
  12276.      Chroot `mysqld' daemon during startup.  Recommended security
  12277.      measure. It will somewhat limit `LOAD DATA INFILE' and `SELECT ...
  12278.      INTO OUTFILE' though.
  12279.  
  12280. `--core-file'
  12281.      Write a core file if `mysqld' dies.  For some systems you must also
  12282.      specify `--core-file-size' to `safe_mysqld'. *Note `safe_mysqld':
  12283.      safe_mysqld.
  12284.  
  12285. `-h, --datadir=path'
  12286.      Path to the database root.
  12287.  
  12288. `--default-character-set=charset'
  12289.      Set the default character set.  *Note Character sets::.
  12290.  
  12291. `--default-table-type=type'
  12292.      Set the default table type for tables.  *Note Table types::.
  12293.  
  12294. `--debug[...]='
  12295.      If MySQL is configured with `--with-debug', you can use this
  12296.      option to get a trace file of what `mysqld' is doing.  *Note
  12297.      Making trace files::.
  12298.  
  12299. `--delay-key-write-for-all-tables'
  12300.      Don't flush key buffers between writes for any `MyISAM' table.
  12301.      *Note Server parameters::.
  12302.  
  12303. `--enable-locking'
  12304.      Enable system locking.  Note that if you use this option on a
  12305.      system which a not fully working lockd() (as on Linux) you will
  12306.      easily get mysqld to deadlock.
  12307.  
  12308. `-T, --exit-info'
  12309.      This is a bit mask of different flags one can use for debugging the
  12310.      mysqld server;  One should not use this option if one doesn't know
  12311.      exactly what it does!
  12312.  
  12313. `--flush'
  12314.      Flush all changes to disk after each SQL command.  Normally MySQL
  12315.      only does a write of all changes to disk after each SQL command
  12316.      and lets the operating system handle the syncing to disk.  *Note
  12317.      Crashing::.
  12318.  
  12319. `-?, --help'
  12320.      Display short help and exit.
  12321.  
  12322. `--init-file=file'
  12323.      Read SQL commands from this file at startup.
  12324.  
  12325. `-L, --language=...'
  12326.      Client error messages in given language.  May be given as a full
  12327.      path.  *Note Languages::.
  12328.  
  12329. `-l, --log[=file]'
  12330.      Log connections and queries to file. *Note Query log::.
  12331.  
  12332. `--log-isam[=file]'
  12333.      Log all ISAM/MyISAM changes to file (only used when debugging
  12334.      ISAM/MyISAM).
  12335.  
  12336. `--log-slow-queries[=file]'
  12337.      Log all queries that have taken more than `long_query_time'
  12338.      seconds to execute to file.  *Note Slow query log::.
  12339.  
  12340. `--log-update[=file]'
  12341.      Log updates to `file.#' where `#' is a unique number if not given.
  12342.      *Note Update log::.
  12343.  
  12344. `--log-long-format'
  12345.      Log some extra information to update log.  If you are using
  12346.      `--log-slow-queries' then queries that are not using indexes are
  12347.      logged to the slow query log.
  12348.  
  12349. `--low-priority-updates'
  12350.      Table-modifying operations (`INSERT'/`DELETE'/`UPDATE') will have
  12351.      lower priority than selects.  It can also be done via `{INSERT |
  12352.      REPLACE | UPDATE | DELETE} LOW_PRIORITY ...' to lower the priority
  12353.      of only one query, or by `SET OPTION SQL_LOW_PRIORITY_UPDATES=1'
  12354.      to change the priority in one thread.  *Note Table locking::.
  12355.  
  12356. `--memlock'
  12357.      Lock the `mysqld' process in memory.  This works only if your
  12358.      system supports the `mlockall()' system call (like Solaris).  This
  12359.      may help if you have a problem where the operating system is
  12360.      causing `mysqld' to swap on disk.
  12361.  
  12362. `--myisam-recover [=option[,option...]]] where option is any combination'
  12363.      of `DEFAULT', `BACKUP', `FORCE' or `QUICK'.  You can also set this
  12364.      explicitely to `""' if you want to disable this option. If this
  12365.      option is used, `mysqld' will on open check if the table is marked
  12366.      as crashed or if if the table wasn't closed properly.  (The last
  12367.      option only works if you are running with `--skip-locking').  If
  12368.      this is the case `mysqld' will run check on the table. If the
  12369.      table was corrupted, `mysqld' will attempt to repair it.
  12370.  
  12371.      The following options affects how the repair works.
  12372.  
  12373.      DEFAULT              The same as not giving any option to
  12374.                                    `--myisam-recover'.
  12375.      BACKUP               If the data table was changed during recover,
  12376.                           save a                     backup of the
  12377.                           `table_name.MYD' data file as
  12378.                             `table_name-datetime.BAK'.
  12379.      FORCE                Run recover even if we will loose more than
  12380.                           one row                     from the .MYD file.
  12381.      QUICK                Don't check the rows in the table if there
  12382.                           isn't any                     delete blocks.
  12383.  
  12384.      Before a table is automatically repaired, MySQL will add a note
  12385.      about this in the error log.  If you want to be able to recover
  12386.      from most things without user intervention, you should use the
  12387.      options `BACKUP,FORCE'.  This will force a repair of a table even
  12388.      if some rows would be deleted, but it will keep the old data file
  12389.      as a backup so that you can later examine what happened.
  12390.  
  12391. `--pid-file=path'
  12392.      Path to pid file used by `safe_mysqld'.
  12393.  
  12394. `-P, --port=...'
  12395.      Port number to listen for TCP/IP connections.
  12396.  
  12397. `-o, --old-protocol'
  12398.      Use the 3.20 protocol for compatibility with some very old clients.
  12399.      *Note Upgrading-from-3.20::.
  12400.  
  12401. `--one-thread'
  12402.      Only use one thread (for debugging under Linux).  *Note Debugging
  12403.      server::.
  12404.  
  12405. `-O, --set-variable var=option'
  12406.      Give a variable a value. `--help' lists variables.  You can find a
  12407.      full description for all variables in the `SHOW VARIABLES' section
  12408.      in this manual.  *Note SHOW VARIABLES::.  The tuning server
  12409.      parameters section includes information of how to optimize these.
  12410.      *Note Server parameters::.
  12411.  
  12412. `--safe-mode'
  12413.      Skip some optimize stages.  Implies `--skip-delay-key-write'.
  12414.  
  12415. `--safe-show-database'
  12416.      Don't show databases for which the user doesn't have any
  12417.      privileges.
  12418.  
  12419. `--safe-user-create'
  12420.      If this is enabled, a user can't create new users with the GRANT
  12421.      command, if the user doesn't have `INSERT' privilege to the
  12422.      `mysql.user' table or any column in this table.
  12423.  
  12424. `--skip-concurrent-insert'
  12425.      Turn off the ability to select and insert at the same time on
  12426.      `MyISAM' tables. (This is only to be used if you think you have
  12427.      found a bug in this feature).
  12428.  
  12429. `--skip-delay-key-write'
  12430.      Ignore the `delay_key_write' option for all tables.  *Note Server
  12431.      parameters::.
  12432.  
  12433. `--skip-grant-tables'
  12434.      This option causes the server not to use the privilege system at
  12435.      all.  This gives everyone _full access_ to all databases!  (You
  12436.      can tell a running server to start using the grant tables again by
  12437.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  12438.  
  12439. `--skip-host-cache'
  12440.      Never use host name cache for faster name-ip resolution, but query
  12441.      DNS server on every connect instead.  *Note DNS::.
  12442.  
  12443. `--skip-locking'
  12444.      Don't use system locking.  To use `isamchk' or `myisamchk' you must
  12445.      shut down the server.  *Note Stability::.  Note that in MySQL
  12446.      Version 3.23 you can use `REPAIR' and `CHECK' to repair/check
  12447.      `MyISAM' tables.
  12448.  
  12449. `--skip-name-resolve'
  12450.      Hostnames are not resolved.  All `Host' column values in the grant
  12451.      tables must be IP numbers or `localhost'.  *Note DNS::.
  12452.  
  12453. `--skip-networking'
  12454.      Don't listen for TCP/IP connections at all.  All interaction with
  12455.      `mysqld' must be made via Unix sockets.  This option is highly
  12456.      recommended for systems where only local requests are allowed.
  12457.      *Note DNS::.
  12458.  
  12459. `--skip-new'
  12460.      Don't use new, possible wrong routines.  Implies
  12461.      `--skip-delay-key-write'.  This will also set default table type
  12462.      to `ISAM'.  *Note ISAM::.
  12463.  
  12464. `--skip-symlink'
  12465.      Don't delete or rename files that a symlinked file in the data
  12466.      directory points to.
  12467.  
  12468. `--skip-safemalloc'
  12469.      If MySQL is configured with `--with-debug=full', all programs will
  12470.      check the memory for overruns for every memory allocation and
  12471.      memory freeing.  As this checking is very slow, you can avoid
  12472.      this, when you don't need memory checking, by using this option.
  12473.  
  12474. `--skip-show-database'
  12475.      Don't allow 'SHOW DATABASE' commands, unless the user has *process*
  12476.      privilege.
  12477.  
  12478. `--skip-stack-trace'
  12479.      Don't write stack traces.  This option is useful when you are
  12480.      running `mysqld' under a debugger. *Note Debugging server::.
  12481.  
  12482. `--skip-thread-priority'
  12483.      Disable using thread priorities for faster response time.
  12484.  
  12485. `--socket=path'
  12486.      Socket file to use for local connections instead of default
  12487.      `/tmp/mysql.sock'.
  12488.  
  12489. `--sql-mode=option[,option[,option...]]'
  12490.      Option can be any combination of: `REAL_AS_FLOAT',
  12491.      `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE', `SERIALIZE',
  12492.      `ONLY_FULL_GROUP_BY'.  It can also be empty (`""') if you want to
  12493.      reset this.
  12494.  
  12495.      By specifying all of the above options is same as using -ansi.
  12496.      With this option one can turn on only needed SQL modes. *Note ANSI
  12497.      mode::.
  12498.  
  12499. `transaction-isolation= { READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE }'
  12500.      Sets the default transaction isolation level.  *Note SET
  12501.      TRANSACTION::.
  12502.  
  12503. `-t, --tmpdir=path'
  12504.      Path for temporary files. It may be useful if your default `/tmp'
  12505.      directory resides on a partition too small to hold temporary
  12506.      tables.
  12507.  
  12508. `-u, --user=user_name'
  12509.      Run `mysqld' daemon as user `user_name'.  This option is
  12510.      _mandatory_ when starting `mysqld' as root.
  12511.  
  12512. `-V, --version'
  12513.      Output version information and exit.
  12514.  
  12515. `-W, --warnings'
  12516.      Print out warnings like `Aborted connection...' to the `.err' file.
  12517.      *Note Communication errors::.
  12518.  
  12519. my.cnf Option Files
  12520. -------------------
  12521.  
  12522. MySQL can, since Version 3.22, read default startup options for the
  12523. server and for clients from option files.
  12524.  
  12525. MySQL reads default options from the following files on Unix:
  12526.  
  12527. *Filename*             *Purpose*
  12528. `/etc/my.cnf'          Global options
  12529. `DATADIR/my.cnf'       Server-specific options
  12530. `defaults-extra-file'  The file specified with -defaults-extra-file=#
  12531. `~/.my.cnf'            User-specific options
  12532.  
  12533. `DATADIR' is the MySQL data directory (typically
  12534. `/usr/local/mysql/data' for a binary installation or `/usr/local/var'
  12535. for a source installation).  Note that this is the directory that was
  12536. specified at configuration time, not the one specified with `--datadir'
  12537. when `mysqld' starts up!  (`--datadir' has no effect on where the
  12538. server looks for option files, because it looks for them before it
  12539. processes any command-line arguments.)
  12540.  
  12541. MySQL reads default options from the following files on Windows:
  12542.  
  12543. *Filename*             *Purpose*
  12544. `windows-system-directory\my.ini'Global options
  12545. `C:\my.cnf'            Global options
  12546. `C:\mysql\data\my.cnf' Server-specific options
  12547.  
  12548. Note that on Windows, you should specify all paths with `/' instead of
  12549. `\'. If you use `\', you need to specify this twice, as `\' is the
  12550. escape character in MySQL.
  12551.  
  12552. MySQL tries to read option files in the order listed above.  If
  12553. multiple option files exist, an option specified in a file read later
  12554. takes precedence over the same option specified in a file read earlier.
  12555. Options specified on the command line take precedence over options
  12556. specified in any option file.  Some options can be specified using
  12557. environment variables.  Options specified on the command line or in
  12558. option files take precedence over environment variable values. *Note
  12559. Environment variables::.
  12560.  
  12561. The following programs support option files:  `mysql', `mysqladmin',
  12562. `mysqld', `mysqldump', `mysqlimport', `mysql.server', `myisamchk', and
  12563. `myisampack'.
  12564.  
  12565. You can use option files to specify any long option that a program
  12566. supports!  Run the program with `--help' to get a list of available
  12567. options.
  12568.  
  12569. An option file can contain lines of the following forms:
  12570.  
  12571. `#comment'
  12572.      Comment lines start with `#' or `;'. Empty lines are ignored.
  12573.  
  12574. `[group]'
  12575.      `group' is the name of the program or group for which you want to
  12576.      set options.  After a group line, any `option' or `set-variable'
  12577.      lines apply to the named group until the end of the option file or
  12578.      another group line is given.
  12579.  
  12580. `option'
  12581.      This is equivalent to `--option' on the command line.
  12582.  
  12583. `option=value'
  12584.      This is equivalent to `--option=value' on the command line.
  12585.  
  12586. `set-variable = variable=value'
  12587.      This is equivalent to `--set-variable variable=value' on the
  12588.      command line.  This syntax must be used to set a `mysqld' variable.
  12589.  
  12590. The `client' group allows you to specify options that apply to all
  12591. MySQL clients (not `mysqld'). This is the perfect group to use to
  12592. specify the password you use to connect to the server.  (But make sure
  12593. the option file is readable and writable only by yourself.)
  12594.  
  12595. Note that for options and values, all leading and trailing blanks are
  12596. automatically deleted.  You may use the escape sequences `\b', `\t',
  12597. `\n', `\r', `\\', and `\s' in your value string (`\s' == blank).
  12598.  
  12599. Here is a typical global option file:
  12600.  
  12601.      [client]
  12602.      port=3306
  12603.      socket=/tmp/mysql.sock
  12604.      
  12605.      [mysqld]
  12606.      port=3306
  12607.      socket=/tmp/mysql.sock
  12608.      set-variable = key_buffer_size=16M
  12609.      set-variable = max_allowed_packet=1M
  12610.      
  12611.      [mysqldump]
  12612.      quick
  12613.  
  12614. Here is typical user option file:
  12615.  
  12616.      [client]
  12617.      # The following password will be sent to all standard MySQL clients
  12618.      password=my_password
  12619.      
  12620.      [mysql]
  12621.      no-auto-rehash
  12622.      set-variable = connect_timeout=2
  12623.      
  12624.      [mysqlhotcopy]
  12625.      interactive-timeout
  12626.  
  12627. If you have a source distribution, you will find sample configuration
  12628. files named `my-xxxx.cnf' in the `support-files' directory.  If you
  12629. have a binary distribution, look in the `DIR/support-files' directory,
  12630. where `DIR' is the pathname to the MySQL installation directory
  12631. (typically `/usr/local/mysql').  Currently there are sample
  12632. configuration files for small, medium, large, and very large systems.
  12633. You can copy `my-xxxx.cnf' to your home directory (rename the copy to
  12634. `.my.cnf') to experiment with this.
  12635.  
  12636. All MySQL clients that support option files support the following
  12637. options:
  12638.  
  12639. -no-defaults                  Don't read any option files.
  12640. -print-defaults               Print the program name and all options
  12641.                               that it will get.
  12642. -defaults-file=full-path-to-default-fileOnly use the given configuration file.
  12643. -defaults-extra-file=full-path-to-default-fileRead this configuration file after the
  12644.                               global configuration file but before the
  12645.                               user configuration file.
  12646.  
  12647. Note that the above options must be first on the command line to work!
  12648. `--print-defaults' may however be used directly after the
  12649. `--defaults-xxx-file' commands.
  12650.  
  12651. Note for developers:  Option file handling is implemented simply by
  12652. processing all matching options (that is, options in the appropriate
  12653. group) before any command-line arguments. This works nicely for
  12654. programs that use the last instance of an option that is specified
  12655. multiple times. If you have an old program that handles
  12656. multiply-specified options this way but doesn't read option files, you
  12657. need add only two lines to give it that capability.  Check the source
  12658. code of any of the standard MySQL clients to see how to do this.
  12659.  
  12660. In shell scripts you can use the `my_print_defaults' command to parse
  12661. the config files:
  12662.  
  12663.  
  12664.      shell> my_print_defaults client mysql
  12665.      --port=3306
  12666.      --socket=/tmp/mysql.sock
  12667.      --no-auto-rehash
  12668.  
  12669. The above output contains all options for the groups 'client' and
  12670. 'mysql'.
  12671.  
  12672. Installing Many Servers on the Same Machine
  12673. -------------------------------------------
  12674.  
  12675. In some cases you may want to have many different `mysqld' daemons
  12676. (servers) running on the same machine.  You may for example want to run
  12677. a new version of MySQL for testing together with an old version that is
  12678. in production.  Another case is when you want to give different users
  12679. access to different `mysqld' servers that they manage themselves.
  12680.  
  12681. One way to get a new server running is by starting it with a different
  12682. socket and port as follows:
  12683.  
  12684.      shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock
  12685.      shell> MYSQL_TCP_PORT=3307
  12686.      shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT
  12687.      shell> scripts/mysql_install_db
  12688.      shell> bin/safe_mysqld &
  12689.  
  12690. The environment variables appendix includes a list of other environment
  12691. variables you can use to affect `mysqld'. *Note Environment variables::.
  12692.  
  12693. The above is the quick and dirty way that one commonly uses for testing.
  12694. The nice thing with this is that all connections you do in the above
  12695. shell will automatically be directed to the new running server!
  12696.  
  12697. If you need to do this more permanently, you should create an option
  12698. file for each server. *Note Option files::.  In your startup script that
  12699. is executed at boot time (mysql.server?) you should specify for both
  12700. servers:
  12701.  
  12702. `safe_mysqld --default-file=path-to-option-file'
  12703.  
  12704. At least the following options should be different per server:
  12705.  
  12706. `port=#'
  12707.  
  12708. `socket=path'
  12709.  
  12710. `pid-file=path'
  12711. The following options should be different, if they are used:
  12712.  
  12713. `log=path'
  12714.  
  12715. `log-bin=path'
  12716.  
  12717. `log-update=path'
  12718.  
  12719. `log-isam=path'
  12720.  
  12721. `bdb-logdir=path'
  12722. If you want more performance, you can also specify the following
  12723. differently:
  12724.  
  12725. `tmpdir=path'
  12726.  
  12727. `bdb-tmpdir=path'
  12728. *Note Command-line options::.
  12729.  
  12730. If you are installing binary MySQL versions (.tar files) and start them
  12731. with `./bin/safe_mysqld' then in most cases the only option you need to
  12732. add/change is the `socket' and `port' argument to `safe_mysqld'.
  12733.  
  12734. Running Multiple MySQL Servers on the Same Machine
  12735. --------------------------------------------------
  12736.  
  12737. There are circumstances when you might want to run multiple servers on
  12738. the same machine.  For example, you might want to test a new MySQL
  12739. release while leaving your existing production setup undisturbed.  Or
  12740. you might be an Internet service provider that wants to provide
  12741. independent MySQL installations for different customers.
  12742.  
  12743. If you want to run multiple servers, the easiest way is to compile the
  12744. servers with different TCP/IP ports and socket files so they are not
  12745. both listening to the same TCP/IP port or socket file. *Note
  12746. `mysqld_multi': mysqld_multi.
  12747.  
  12748. Assume an existing server is configured for the default port number and
  12749. socket file.  Then configure the new server with a `configure' command
  12750. something like this:
  12751.  
  12752.      shell> ./configure  --with-tcp-port=port_number \
  12753.                   --with-unix-socket-path=file_name \
  12754.                   --prefix=/usr/local/mysql-3.22.9
  12755.  
  12756. Here `port_number' and `file_name' should be different than the default
  12757. port number and socket file pathname, and the `--prefix' value should
  12758. specify an installation directory different than the one under which
  12759. the existing MySQL installation is located.
  12760.  
  12761. You can check the socket used by any currently executing MySQL server
  12762. with this command:
  12763.  
  12764.      shell> mysqladmin -h hostname --port=port_number variables
  12765.  
  12766. Note that if you specify "`localhost'" as a hostname, `mysqladmin' will
  12767. default to using Unix sockets instead of TCP/IP.
  12768.  
  12769. If you have a MySQL server running on the port you used, you will get a
  12770. list of some of the most important configurable variables in MySQL,
  12771. including the socket name.
  12772.  
  12773. You don't have to recompile a new MySQL server just to start with a
  12774. different port and socket.  You can change the port and socket to be
  12775. used by specifying them at run time as options to `safe_mysqld':
  12776.  
  12777.      shell> /path/to/safe_mysqld --socket=file_name --port=port_number
  12778.  
  12779. `mysqld_multi' can also take `safe_mysqld' (or `mysqld') as an argument
  12780. and pass the options from a configuration file to `safe_mysqld' and
  12781. further to `mysqld'.
  12782.  
  12783. If you run the new server on the same database directory as another
  12784. server with logging enabled, you should also specify the name of the log
  12785. files to `safe_mysqld' with `--log', `--log-update', or
  12786. `--log-slow-queries'.  Otherwise, both servers may be trying to write
  12787. to the same log file.
  12788.  
  12789. *WARNING*: Normally you should never have two servers that update data
  12790. in the same database!  If your OS doesn't support fault-free system
  12791. locking, this may lead to unpleasant surprises!
  12792.  
  12793. If you want to use another database directory for the second server, you
  12794. can use the `--datadir=path' option to `safe_mysqld'.
  12795.  
  12796. *NOTE* also that starting several MySQL servers (`mysqlds') in
  12797. different machines and letting them access one data directory over
  12798. `NFS' is generally a *BAD IDEA*! The problem is that the `NFS' will
  12799. become the bottleneck with the speed. It is not meant for such use. And
  12800. last but not least, you would still have to come up with a solution how
  12801. to make sure that two or more `mysqlds' are not interfering with each
  12802. other. At the moment there is no platform that would 100% reliable do
  12803. the file locking (`lockd' daemon usually) in every situation. Yet there
  12804. would be one more possible risk with `NFS'; it would make the work even
  12805. more complicated for `lockd' daemon to handle. So make it easy for your
  12806. self and forget about the idea. The working solution is to have one
  12807. computer with an operating system that efficiently handles threads and
  12808. have several CPUs in it.
  12809.  
  12810. When you want to connect to a MySQL server that is running with a
  12811. different port than the port that is compiled into your client, you can
  12812. use one of the following methods:
  12813.  
  12814.    * Start the client with `--host 'hostname' --port=port_number' to
  12815.      connect with TCP/IP, or `[--host localhost] --socket=file_name' to
  12816.      connect via a Unix socket.
  12817.  
  12818.    * In your C or Perl programs, you can give the port or socket
  12819.      arguments when connecting to the MySQL server.
  12820.  
  12821.    * If your are using the Perl `DBD::mysql' module you can read the
  12822.      options from the MySQL option files.  *Note Option files::.
  12823.  
  12824.           $dsn = "DBI:mysql:test;mysql_read_default_group=client;mysql_read_default_file=/usr/local/mysql/data/my.cnf"
  12825.           $dbh = DBI->connect($dsn, $user, $password);
  12826.  
  12827.    * Set the `MYSQL_UNIX_PORT' and `MYSQL_TCP_PORT' environment
  12828.      variables to point to the Unix socket and TCP/IP port before you
  12829.      start your clients.  If you normally use a specific socket or
  12830.      port, you should place commands to set these environment variables
  12831.      in your `.login' file.  *Note Environment variables::.
  12832.  
  12833.    * Specify the default socket and TCP/IP port in the `.my.cnf' file
  12834.      in your home directory. *Note Option files::.
  12835.  
  12836. General Security Issues and the MySQL Access Privilege System
  12837. =============================================================
  12838.  
  12839. MySQL has an advanced but non-standard security/privilege system.  This
  12840. section describes how it works.
  12841.  
  12842. General Security Guidelines
  12843. ---------------------------
  12844.  
  12845. Anyone using MySQL on a computer connected to the Internet should read
  12846. this section to avoid the most common security mistakes.
  12847.  
  12848. In discussing security, we emphasize the necessity of fully protecting
  12849. the entire server host (not simply the MySQL server) against all types
  12850. of applicable attacks: eavesdropping, altering, playback, and denial of
  12851. service. We do not cover all aspects of availability and fault tolerance
  12852. here.
  12853.  
  12854. MySQL uses security based on Access Control Lists (ACLs) for all
  12855. connections, queries, and other operations that a user may attempt to
  12856. perform. There is also some support for SSL-encrypted connections
  12857. between MySQL clients and servers. Many of the concepts discussed here
  12858. are not specific to MySQL at all; the same general ideas apply to
  12859. almost all applications.
  12860.  
  12861. When running MySQL, follow these guidelines whenever possible:
  12862.  
  12863.    * DON'T EVER GIVE ANYONE (EXCEPT THE MySQL ROOT USER) ACCESS TO THE
  12864.      `user' TABLE IN THE `mysql' DATABASE!  The encrypted password is
  12865.      the real password in MySQL. If you know the password listed in the
  12866.      `user' table for a given user, you can easily log in as that user
  12867.      if you have access to the host listed for that account.
  12868.  
  12869.    * Learn the MySQL access privilege system. The `GRANT' and `REVOKE'
  12870.      commands are used for controlling access to MySQL. Do not grant
  12871.      any more privileges than necessary. Never grant privileges to all
  12872.      hosts.
  12873.  
  12874.      Checklist:
  12875.         - Try `mysql -u root'. If you are able to connect successfully
  12876.           to the server without being asked for a password, you have
  12877.           problems. Anyone can connect to your MySQL server as the MySQL
  12878.           `root' user with full privileges!  Review the MySQL
  12879.           installation instructions, paying particular attention to the
  12880.           item about setting a `root' password.
  12881.  
  12882.         - Use the command `SHOW GRANTS' and check to see who has access
  12883.           to what. Remove those privileges that are not necessary using
  12884.           the `REVOKE' command.
  12885.  
  12886.    * Do not keep any plain-text passwords in your database. When your
  12887.      computer becomes compromised, the intruder can take the full list
  12888.      of passwords and use them. Instead use `MD5()' or another one-way
  12889.      hashing function.
  12890.  
  12891.    * Do not choose passwords from dictionaries. There are special
  12892.      programs to break them. Even passwords like "xfish98" are very
  12893.      bad.  Much better is "duag98" which contains the same word "fish"
  12894.      but typed one key to the left on a standard QWERTY keyboard.
  12895.      Another method is to use "Mhall" which is taken from the first
  12896.      characters of each word in the sentence "Mary had a little lamb."
  12897.      This is easy to remember and type, but difficult to guess for
  12898.      someone who does not know it.
  12899.  
  12900.    * Invest in a firewall. This protects you from at least 50% of all
  12901.      types of exploits in any software. Put MySQL behind the firewall
  12902.      or in a demilitarized zone (DMZ).
  12903.  
  12904.      Checklist:
  12905.         - Try to scan your ports from the Internet using a tool such as
  12906.           `nmap'. MySQL uses port 3306 by default. This port should be
  12907.           inaccessible from untrusted hosts. Another simple way to
  12908.           check whether or not your MySQL port is open is to try the
  12909.           following command from some remote machine, where
  12910.           `server_host' is the hostname of your MySQL server:
  12911.  
  12912.                shell> telnet server_host 3306
  12913.  
  12914.           If you get a connection and some garbage characters, the port
  12915.           is open, and should be closed on your firewall or router,
  12916.           unless you really have a good reason to keep it open. If
  12917.           `telnet' just hangs or the connection is refused, everything
  12918.           is OK; the port is blocked.
  12919.  
  12920.    * Do not trust any data entered by your users. They can try to trick
  12921.      your code by entering special or escaped character sequences in
  12922.      Web forms, URLs, or whatever application you have built. Be sure
  12923.      that your application remains secure if a user enters something
  12924.      like "`; DROP DATABASE mysql;'". This is an extreme example, but
  12925.      large security leaks and data loss may occur as a result of
  12926.      hackers using similar techniques, if you do not prepare for them.
  12927.  
  12928.      Also remember to check numeric data. A common mistake is to
  12929.      protect only strings. Sometimes people think that if a database
  12930.      contains only publicly available data that it need not be
  12931.      protected. This is incorrect. At least denial-of-service type
  12932.      attacks can be performed on such databases. The simplest way to
  12933.      protect from this type of attack is to use apostrophes around the
  12934.      numeric constants: `SELECT * FROM table WHERE ID='234'' rather
  12935.      than `SELECT * FROM table WHERE ID=234'.  MySQL automatically
  12936.      converts this string to a number and strips all non-numeric
  12937.      symbols from it.
  12938.  
  12939.      Checklist:
  12940.         - All Web applications:
  12941.              * Try to enter `'' and `"' in all your Web forms. If you
  12942.                get any kind of MySQL error, investigate the problem
  12943.                right away.
  12944.  
  12945.              * Try to modify any dynamic URLs by adding `%22' (`"'),
  12946.                `%23' (`#'), and `%27' (`'') in the URL.
  12947.  
  12948.              * Try to modify datatypes in dynamic URLs from numeric
  12949.                ones to character ones containing characters from
  12950.                previous examples. Your application should be safe
  12951.                against this and similar attacks.
  12952.  
  12953.              * Try to enter characters, spaces, and special symbols
  12954.                instead of numbers in numeric fields. Your application
  12955.                should remove them before passing them to MySQL or your
  12956.                application should generate an error. Passing unchecked
  12957.                values to MySQL is very dangerous!
  12958.  
  12959.              * Check data sizes before passing them to MySQL.
  12960.  
  12961.              * Consider having your application connect to the database
  12962.                using a different user name than the one you use for
  12963.                administrative purposes. Do not give your applications
  12964.                any more access privileges than they need.
  12965.  
  12966.         - Users of PHP:
  12967.              * Check out the `addslashes()' function.  As of PHP 4.0.3,
  12968.                a `mysql_escape_string()' function is available that is
  12969.                based on the function of the same name in the MySQL C
  12970.                API.
  12971.  
  12972.         - Users of MySQL C API:
  12973.              * Check out the `mysql_escape_string()' API call.
  12974.  
  12975.         - Users of MySQL++:
  12976.              * Check out the `escape' and `quote' modifiers for query
  12977.                streams.
  12978.  
  12979.         - Users of Perl DBI:
  12980.              * Check out the `quote()' method or use placeholders.
  12981.  
  12982.         - Users of Java JDBC:
  12983.              * Use a `PreparedStatement' object and placeholders.
  12984.  
  12985.    * Do not transmit plain (unencrypted) data over the Internet. These
  12986.      data are accessible to everyone who has the time and ability to
  12987.      intercept it and use it for their own purposes. Instead, use an
  12988.      encrypted protocol such as SSL or SSH. MySQL supports internal SSL
  12989.      connections as of Version 3.23.9.  SSH port-forwarding can be used
  12990.      to create an encrypted (and compressed) tunnel for the
  12991.      communication.
  12992.  
  12993.    * Learn to use the `tcpdump' and `strings' utilities. For most cases,
  12994.      you can check whether or not MySQL data streams are unencrypted by
  12995.      issuing a command like the following:
  12996.  
  12997.           shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
  12998.  
  12999.      (This works under Linux and should work with small modifications
  13000.      under other systems).  Warning: If you do not see data this
  13001.      doesn't always actually mean that it is encrypted. If you need
  13002.      high security, you should consult with a security expert.
  13003.  
  13004. How to Make MySQL Secure Against Crackers
  13005. -----------------------------------------
  13006.  
  13007. When you connect to a MySQL server, you normally should use a password.
  13008. The password is not transmitted in clear text over the connection,
  13009. however the encryption algorithm is not very strong, and with some
  13010. effort a clever attacker can crack the password if he is able to sniff
  13011. the traffic between the client and the server. If the connection
  13012. between the client and the server goes through an untrusted network,
  13013. you should use an SSH tunnel to encrypt the communication.
  13014.  
  13015. All other information is transferred as text that can be read by anyone
  13016. who is able to watch the connection.  If you are concerned about this,
  13017. you can use the compressed protocol (in MySQL Version 3.22 and above)
  13018. to make things much harder.  To make things even more secure you should
  13019. use `ssh'.  You can find an open source `ssh' client at
  13020. `http://www.openssh.org', and a commercial `ssh' client at
  13021. `http://www.ssh.com'.  With this, you can get an encrypted TCP/IP
  13022. connection between a MySQL server and a MySQL client.
  13023.  
  13024. To make a MySQL system secure, you should strongly consider the
  13025. following suggestions:
  13026.  
  13027.    * Use passwords for all MySQL users. Remember that anyone can log in
  13028.      as any other person as simply as `mysql -u other_user db_name' if
  13029.      `other_user' has no password.  It is common behavior with
  13030.      client/server applications that the client may specify any user
  13031.      name.  You can change the password of all users by editing the
  13032.      `mysql_install_db' script before you run it, or only the password
  13033.      for the MySQL `root' user like this:
  13034.  
  13035.           shell> mysql -u root mysql
  13036.           mysql> UPDATE user SET Password=PASSWORD('new_password')
  13037.                      WHERE user='root';
  13038.           mysql> FLUSH PRIVILEGES;
  13039.  
  13040.    * Don't run the MySQL daemon as the Unix `root' user.  This is very
  13041.      dangerous, because any user with `FILE' privileges will be able to
  13042.      create files as `root' (for example, `~root/.bashrc'). To prevent
  13043.      this, `mysqld' will refuse to run as `root' unless it is specified
  13044.      directly using a `--user=root' option.
  13045.  
  13046.      `mysqld' can be run as an ordinary unprivileged user instead.  You
  13047.      can also create a new Unix user `mysql' to make everything even
  13048.      more secure.  If you run `mysqld' as another Unix user, you don't
  13049.      need to change the `root' user name in the `user' table, because
  13050.      MySQL user names have nothing to do with Unix user names.  To
  13051.      start `mysqld' as another Unix user, add a `user' line that
  13052.      specifies the user name to the `[mysqld]' group of the
  13053.      `/etc/my.cnf' option file or the `my.cnf' option file in the
  13054.      server's data directory. For example:
  13055.  
  13056.           [mysqld]
  13057.           user=mysql
  13058.  
  13059.      This will cause the server to start as the designated user whether
  13060.      you start it manually or by using `safe_mysqld' or `mysql.server'.
  13061.      For more details, see *Note Changing MySQL user: Changing MySQL
  13062.      user.
  13063.  
  13064.    * Don't support symlinks to tables (This can be disabled with the
  13065.      `--skip-symlink' option. This is especially important if you run
  13066.      `mysqld' as root as anyone that has write access to the mysqld data
  13067.      directories could then delete any file in the system!  *Note
  13068.      Symbolic links to tables::.
  13069.  
  13070.    * Check that the Unix user that `mysqld' runs as is the only user
  13071.      with read/write privileges in the database directories.
  13072.  
  13073.    * Don't give the *process* privilege to all users.  The output of
  13074.      `mysqladmin processlist' shows the text of the currently executing
  13075.      queries, so any user who is allowed to execute that command might
  13076.      be able to see if another user issues an `UPDATE user SET
  13077.      password=PASSWORD('not_secure')' query.
  13078.  
  13079.      `mysqld' reserves an extra connection for users who have the
  13080.      *process* privilege, so that a MySQL `root' user can log in and
  13081.      check things even if all normal connections are in use.
  13082.  
  13083.    * Don't give the *file* privilege to all users.  Any user that has
  13084.      this privilege can write a file anywhere in the file system with
  13085.      the privileges of the `mysqld' daemon!  To make this a bit safer,
  13086.      all files generated with `SELECT ... INTO OUTFILE' are readable to
  13087.      everyone, and you cannot overwrite existing files.
  13088.  
  13089.      The *file* privilege may also be used to read any file accessible
  13090.      to the Unix user that the server runs as.  This could be abused,
  13091.      for example, by using `LOAD DATA' to load `/etc/passwd' into a
  13092.      table, which can then be read with `SELECT'.
  13093.  
  13094.    * If you don't trust your DNS, you should use IP numbers instead of
  13095.      hostnames in the grant tables. In any case, you should be very
  13096.      careful about creating grant table entries using hostname values
  13097.      that contain wild cards!
  13098.  
  13099.    * If you want to restrict the number of connections for a single
  13100.      user, you can do this by setting the `max_user_connections'
  13101.      variable in `mysqld'.
  13102.  
  13103. Startup Options for `mysqld' Concerning Security
  13104. ------------------------------------------------
  13105.  
  13106. The following `mysqld' options affect security:
  13107.  
  13108. `--safe-show-database'
  13109.      With this option, `SHOW DATABASES' returns only those databases
  13110.      for which the user has some kind of privilege.
  13111.  
  13112. `--safe-user-create'
  13113.      If this is enabled, an user can't create new users with the `GRANT'
  13114.      command, if the user doesn't have `INSERT' privilege to the
  13115.      `mysql.user' table.  If you want to give a user access to just
  13116.      create new users with those privileges that the user has right to
  13117.      grant, you should give the user the following privilege:
  13118.  
  13119.           GRANT INSERT(user) on mysql.user to 'user'h'ostname';
  13120.  
  13121.      This will ensure that the user can't change any privilege columns
  13122.      directly, but has to use the `GRANT' command to give privileges to
  13123.      other users.
  13124.  
  13125. `--skip-grant-tables'
  13126.      This option causes the server not to use the privilege system at
  13127.      all. This gives everyone _full access_ to all databases!  (You can
  13128.      tell a running server to start using the grant tables again by
  13129.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  13130.  
  13131. `--skip-name-resolve'
  13132.      Hostnames are not resolved.  All `Host' column values in the grant
  13133.      tables must be IP numbers or `localhost'.
  13134.  
  13135. `--skip-networking'
  13136.      Don't allow TCP/IP connections over the network.  All connections
  13137.      to `mysqld' must be made via Unix sockets. This option is
  13138.      unsuitable for systems that use MIT-pthreads, because the
  13139.      MIT-pthreads package doesn't support Unix sockets.
  13140.  
  13141. `--skip-show-database'
  13142.      With this option, the `SHOW DATABASES' statement doesn't return
  13143.      anything.
  13144.  
  13145. What the Privilege System Does
  13146. ------------------------------
  13147.  
  13148. The primary function of the MySQL privilege system is to authenticate a
  13149. user connecting from a given host, and to associate that user with
  13150. privileges on a database such as *select*, *insert*, *update* and
  13151. *delete*.
  13152.  
  13153. Additional functionality includes the ability to have an anonymous user
  13154. and to grant privileges for MySQL-specific functions such as `LOAD DATA
  13155. INFILE' and administrative operations.
  13156.  
  13157. How the Privilege System Works
  13158. ------------------------------
  13159.  
  13160. The MySQL privilege system ensures that all users may do exactly the
  13161. things that they are supposed to be allowed to do.  When you connect to
  13162. a MySQL server, your identity is determined by *the host from which you
  13163. connect* and *the user name you specify*.  The system grants privileges
  13164. according to your identity and *what you want to do*.
  13165.  
  13166. MySQL considers both your hostname and user name in identifying you
  13167. because there is little reason to assume that a given user name belongs
  13168. to the same person everywhere on the Internet.  For example, the user
  13169. `bill' who connects from `whitehouse.gov' need not be the same person
  13170. as the user `bill' who connects from `microsoft.com'.  MySQL handles
  13171. this by allowing you to distinguish users on different hosts that
  13172. happen to have the same name:  you can grant `bill' one set of
  13173. privileges for connections from `whitehouse.gov', and a different set
  13174. of privileges for connections from `microsoft.com'.
  13175.  
  13176. MySQL access control involves two stages:
  13177.  
  13178.    * Stage 1: The server checks whether or not you are even allowed to
  13179.      connect.
  13180.  
  13181.    * Stage 2: Assuming you can connect, the server checks each request
  13182.      you issue to see whether or not you have sufficient privileges to
  13183.      perform it.  For example, if you try to select rows from a table
  13184.      in a database or drop a table from the database, the server makes
  13185.      sure you have the *select* privilege for the table or the *drop*
  13186.      privilege for the database.
  13187.  
  13188. The server uses the `user', `db', and `host' tables in the `mysql'
  13189. database at both stages of access control.  The fields in these grant
  13190. tables are shown below:
  13191.  
  13192. *Table name*   `user'             `db'               `host'
  13193. *Scope         `Host'             `Host'             `Host'
  13194. fields*                                              
  13195.                `User'             `Db'               `Db'
  13196.                `Password'         `User'             
  13197. *Privilege     `Select_priv'      `Select_priv'      `Select_priv'
  13198. fields*                                              
  13199.                `Insert_priv'      `Insert_priv'      `Insert_priv'
  13200.                `Update_priv'      `Update_priv'      `Update_priv'
  13201.                `Delete_priv'      `Delete_priv'      `Delete_priv'
  13202.                `Index_priv'       `Index_priv'       `Index_priv'
  13203.                `Alter_priv'       `Alter_priv'       `Alter_priv'
  13204.                `Create_priv'      `Create_priv'      `Create_priv'
  13205.                `Drop_priv'        `Drop_priv'        `Drop_priv'
  13206.                `Grant_priv'       `Grant_priv'       `Grant_priv'
  13207.                `References_priv'                     
  13208.                `Reload_priv'                         
  13209.                `Shutdown_priv'                       
  13210.                `Process_priv'                        
  13211.                `File_priv'                           
  13212.  
  13213. For the second stage of access control (request verification), the
  13214. server may, if the request involves tables, additionally consult the
  13215. `tables_priv' and `columns_priv' tables.  The fields in these tables
  13216. are shown below:
  13217.  
  13218. *Table name*   `tables_priv'      `columns_priv'
  13219. *Scope         `Host'             `Host'
  13220. fields*                           
  13221.                `Db'               `Db'
  13222.                `User'             `User'
  13223.                `Table_name'       `Table_name'
  13224.                                   `Column_name'
  13225. *Privilege     `Table_priv'       `Column_priv'
  13226. fields*                           
  13227.                `Column_priv'      
  13228. *Other         `Timestamp'        `Timestamp'
  13229. fields*                           
  13230.                `Grantor'          
  13231.  
  13232. Each grant table contains scope fields and privilege fields.
  13233.  
  13234. Scope fields determine the scope of each entry in the tables, that is,
  13235. the context in which the entry applies.  For example, a `user' table
  13236. entry with `Host' and `User' values of `'thomas.loc.gov'' and `'bob''
  13237. would be used for authenticating connections made to the server by
  13238. `bob' from the host `thomas.loc.gov'.  Similarly, a `db' table entry
  13239. with `Host', `User', and `Db' fields of `'thomas.loc.gov'', `'bob'' and
  13240. `'reports'' would be used when `bob' connects from the host
  13241. `thomas.loc.gov' to access the `reports' database.  The `tables_priv'
  13242. and `columns_priv' tables contain scope fields indicating tables or
  13243. table/column combinations to which each entry applies.
  13244.  
  13245. For access-checking purposes, comparisons of `Host' values are case
  13246. insensitive.  `User', `Password', `Db', and `Table_name' values are
  13247. case sensitive.  `Column_name' values are case insensitive in MySQL
  13248. Version 3.22.12 or later.
  13249.  
  13250. Privilege fields indicate the privileges granted by a table entry, that
  13251. is, what operations can be performed.  The server combines the
  13252. information in the various grant tables to form a complete description
  13253. of a user's privileges.  The rules used to do this are described in
  13254. *Note Request access::.
  13255.  
  13256. Scope fields are strings, declared as shown below; the default value for
  13257. each is the empty string:
  13258.  
  13259. *Field      *Type*      
  13260. name*                   
  13261. `Host'      `CHAR(60)'  
  13262. `User'      `CHAR(16)'  
  13263. `Password'  `CHAR(16)'  
  13264. `Db'        `CHAR(64)'  (`CHAR(60)' for the `tables_priv' and
  13265.                         `columns_priv' tables)
  13266. `Table_name'`CHAR(60)'  
  13267. `Column_name'`CHAR(60)'  
  13268.  
  13269. In the `user', `db' and `host' tables, all privilege fields are
  13270. declared as `ENUM('N','Y')' -- each can have a value of `'N'' or `'Y'',
  13271. and the default value is `'N''.
  13272.  
  13273. In the `tables_priv' and `columns_priv' tables, the privilege fields
  13274. are declared as `SET' fields:
  13275.  
  13276. *Table name*   *Field name*   *Possible set elements*
  13277. `tables_priv'  `Table_priv'   `'Select', 'Insert', 'Update', 'Delete',
  13278.                               'Create', 'Drop', 'Grant', 'References',
  13279.                               'Index', 'Alter''
  13280. `tables_priv'  `Column_priv'  `'Select', 'Insert', 'Update',
  13281.                               'References''
  13282. `columns_priv' `Column_priv'  `'Select', 'Insert', 'Update',
  13283.                               'References''
  13284.  
  13285. Briefly, the server uses the grant tables like this:
  13286.  
  13287.    * The `user' table scope fields determine whether to allow or reject
  13288.      incoming connections.  For allowed connections, any privileges
  13289.      granted in the `user' table indicate the user's global (superuser)
  13290.      privileges.  These privileges apply to *all* databases on the
  13291.      server.
  13292.  
  13293.    * The `db' and `host' tables are used together:
  13294.  
  13295.         - The `db' table scope fields determine which users can access
  13296.           which databases from which hosts.  The privilege fields
  13297.           determine which operations are allowed.
  13298.  
  13299.         - The `host' table is used as an extension of the `db' table
  13300.           when you want a given `db' table entry to apply to several
  13301.           hosts.  For example, if you want a user to be able to use a
  13302.           database from several hosts in your network, leave the `Host'
  13303.           value empty in the user's `db' table entry, then populate the
  13304.           `host' table with an entry for each of those hosts.  This
  13305.           mechanism is described more detail in *Note Request access::.
  13306.  
  13307.    * The `tables_priv' and `columns_priv' tables are similar to the
  13308.      `db' table, but are more fine-grained: they apply at the table and
  13309.      column levels rather than at the database level.
  13310.  
  13311. Note that administrative privileges (*reload*, *shutdown*, etc.) are
  13312. specified only in the `user' table.  This is because administrative
  13313. operations are operations on the server itself and are not
  13314. database-specific, so there is no reason to list such privileges in the
  13315. other grant tables.  In fact, only the `user' table need be consulted
  13316. to determine whether or not you can perform an administrative operation.
  13317.  
  13318. The *file* privilege is specified only in the `user' table, too.  It is
  13319. not an administrative privilege as such, but your ability to read or
  13320. write files on the server host is independent of the database you are
  13321. accessing.
  13322.  
  13323. The `mysqld' server reads the contents of the grant tables once, when it
  13324. starts up.  Changes to the grant tables take effect as indicated in
  13325. *Note Privilege changes::.
  13326.  
  13327. When you modify the contents of the grant tables, it is a good idea to
  13328. make sure that your changes set up privileges the way you want.  For
  13329. help in diagnosing problems, see *Note Access denied::.  For advice on
  13330. security issues, *note Security::.
  13331.  
  13332. A useful diagnostic tool is the `mysqlaccess' script, which Yves
  13333. Carlier has provided for the MySQL distribution.  Invoke `mysqlaccess'
  13334. with the `--help' option to find out how it works.  Note that
  13335. `mysqlaccess' checks access using only the `user', `db' and `host'
  13336. tables.  It does not check table- or column-level privileges.
  13337.  
  13338. Privileges Provided by MySQL
  13339. ----------------------------
  13340.  
  13341. Information about user privileges is stored in the `user', `db',
  13342. `host', `tables_priv', and `columns_priv' tables in the `mysql'
  13343. database (that is, in the database named `mysql').  The MySQL server
  13344. reads the contents of these tables when it starts up and under the
  13345. circumstances indicated in *Note Privilege changes::.
  13346.  
  13347. The names used in this manual to refer to the privileges provided by
  13348. MySQL are shown below, along with the table column name associated with
  13349. each privilege in the grant tables and the context in which the
  13350. privilege applies:
  13351.  
  13352. *Privilege* *Column*           *Context*
  13353. *select*    `Select_priv'      tables
  13354. *insert*    `Insert_priv'      tables
  13355. *update*    `Update_priv'      tables
  13356. *delete*    `Delete_priv'      tables
  13357. *index*     `Index_priv'       tables
  13358. *alter*     `Alter_priv'       tables
  13359. *create*    `Create_priv'      databases, tables, or indexes
  13360. *drop*      `Drop_priv'        databases or tables
  13361. *grant*     `Grant_priv'       databases or tables
  13362. *references*`References_priv'  databases or tables
  13363. *reload*    `Reload_priv'      server administration
  13364. *shutdown*  `Shutdown_priv'    server administration
  13365. *process*   `Process_priv'     server administration
  13366. *file*      `File_priv'        file access on server
  13367.  
  13368. The *select*, *insert*, *update*, and *delete* privileges allow you to
  13369. perform operations on rows in existing tables in a database.
  13370.  
  13371. `SELECT' statements require the *select* privilege only if they
  13372. actually retrieve rows from a table.  You can execute certain `SELECT'
  13373. statements even without permission to access any of the databases on the
  13374. server.  For example, you could use the `mysql' client as a simple
  13375. calculator:
  13376.  
  13377.      mysql> SELECT 1+1;
  13378.      mysql> SELECT PI()*2;
  13379.  
  13380. The *index* privilege allows you to create or drop (remove) indexes.
  13381.  
  13382. The *alter* privilege allows you to use `ALTER TABLE'.
  13383.  
  13384. The *create* and *drop* privileges allow you to create new databases
  13385. and tables, or to drop (remove) existing databases and tables.
  13386.  
  13387. Note that if you grant the *drop* privilege for the `mysql' database to
  13388. a user, that user can drop the database in which the MySQL access
  13389. privileges are stored!
  13390.  
  13391. The *grant* privilege allows you to give to other users those
  13392. privileges you yourself possess.
  13393.  
  13394. The *file* privilege gives you permission to read and write files on
  13395. the server using the `LOAD DATA INFILE' and `SELECT ... INTO OUTFILE'
  13396. statements.  Any user to whom this privilege is granted can read or
  13397. write any file that the MySQL server can read or write.
  13398.  
  13399. The remaining privileges are used for administrative operations, which
  13400. are performed using the `mysqladmin' program.  The table below shows
  13401. which `mysqladmin' commands each administrative privilege allows you to
  13402. execute:
  13403.  
  13404. *Privilege* *Commands permitted to privilege holders*
  13405. *reload*    `reload', `refresh', `flush-privileges', `flush-hosts',
  13406.             `flush-logs', and `flush-tables'
  13407. *shutdown*  `shutdown'
  13408. *process*   `processlist', `kill'
  13409.  
  13410. The `reload' command tells the server to re-read the grant tables.  The
  13411. `refresh' command flushes all tables and opens and closes the log
  13412. files.  `flush-privileges' is a synonym for `reload'.  The other
  13413. `flush-*' commands perform functions similar to `refresh' but are more
  13414. limited in scope, and may be preferable in some instances.  For example,
  13415. if you want to flush just the log files, `flush-logs' is a better choice
  13416. than `refresh'.
  13417.  
  13418. The `shutdown' command shuts down the server.
  13419.  
  13420. The `processlist' command displays information about the threads
  13421. executing within the server.  The `kill' command kills server threads.
  13422. You can always display or kill your own threads, but you need the
  13423. *process* privilege to display or kill threads initiated by other
  13424. users. *Note KILL::.
  13425.  
  13426. It is a good idea in general to grant privileges only to those users
  13427. who need them, but you should exercise particular caution in granting
  13428. certain privileges:
  13429.  
  13430.    * The *grant* privilege allows users to give away their privileges to
  13431.      other users.  Two users with different privileges and with the
  13432.      *grant* privilege are able to combine privileges.
  13433.  
  13434.    * The *alter* privilege may be used to subvert the privilege system
  13435.      by renaming tables.
  13436.  
  13437.    * The *file* privilege can be abused to read any world-readable file
  13438.      on the server into a database table, the contents of which can
  13439.      then be accessed using `SELECT'. This includes the contents of all
  13440.      databases hosted by the server!
  13441.  
  13442.    * The *shutdown* privilege can be abused to deny service to other
  13443.      users entirely, by terminating the server.
  13444.  
  13445.    * The *process* privilege can be used to view the plain text of
  13446.      currently executing queries, including queries that set or change
  13447.      passwords.
  13448.  
  13449.    * Privileges on the `mysql' database can be used to change passwords
  13450.      and other access privilege information.  (Passwords are stored
  13451.      encrypted, so a malicious user cannot simply read them to know the
  13452.      plain text password).  If they can access the `mysql.user' password
  13453.      column, they can use it to log into the MySQL server for the given
  13454.      user.  (With sufficient privileges, the same user can replace a
  13455.      password with a different one.)
  13456.  
  13457. There are some things that you cannot do with the MySQL privilege
  13458. system:
  13459.  
  13460.    * You cannot explicitly specify that a given user should be denied
  13461.      access.  That is, you cannot explicitly match a user and then
  13462.      refuse the connection.
  13463.  
  13464.    * You cannot specify that a user has privileges to create or drop
  13465.      tables in a database but not to create or drop the database itself.
  13466.  
  13467. Connecting to the MySQL Server
  13468. ------------------------------
  13469.  
  13470. MySQL client programs generally require that you specify connection
  13471. parameters when you want to access a MySQL server: the host you want to
  13472. connect to, your user name, and your password.  For example, the
  13473. `mysql' client can be started like this (optional arguments are enclosed
  13474. between `[' and `]'):
  13475.  
  13476.      shell> mysql [-h host_name] [-u user_name] [-pyour_pass]
  13477.  
  13478. Alternate forms of the `-h', `-u', and `-p' options are
  13479. `--host=host_name', `--user=user_name', and `--password=your_pass'.
  13480. Note that there is _no space_ between `-p' or `--password=' and the
  13481. password following it.
  13482.  
  13483. *NOTE:* Specifying a password on the command line is not secure!  Any
  13484. user on your system may then find out your password by typing a command
  13485. like: `ps auxww'.  *Note Option files::.
  13486.  
  13487. `mysql' uses default values for connection parameters that are missing
  13488. from the command line:
  13489.  
  13490.    * The default hostname is `localhost'.
  13491.  
  13492.    * The default user name is your Unix login name.
  13493.  
  13494.    * No password is supplied if `-p' is missing.
  13495.  
  13496. Thus, for a Unix user `joe', the following commands are equivalent:
  13497.  
  13498.      shell> mysql -h localhost -u joe
  13499.      shell> mysql -h localhost
  13500.      shell> mysql -u joe
  13501.      shell> mysql
  13502.  
  13503. Other MySQL clients behave similarly.
  13504.  
  13505. On Unix systems, you can specify different default values to be used
  13506. when you make a connection, so that you need not enter them on the
  13507. command line each time you invoke a client program.  This can be done
  13508. in a couple of ways:
  13509.  
  13510.    * You can specify connection parameters in the `[client]' section of
  13511.      the `.my.cnf' configuration file in your home directory.  The
  13512.      relevant section of the file might look like this:
  13513.  
  13514.           [client]
  13515.           host=host_name
  13516.           user=user_name
  13517.           password=your_pass
  13518.  
  13519.      *Note Option files::.
  13520.  
  13521.    * You can specify connection parameters using environment variables.
  13522.      The host can be specified for `mysql' using `MYSQL_HOST'.  The
  13523.      MySQL user name can be specified using `USER' (this is for Windows
  13524.      only).  The password can be specified using `MYSQL_PWD' (but this
  13525.      is insecure; see the next section).  *Note Environment variables::.
  13526.  
  13527. Access Control, Stage 1: Connection Verification
  13528. ------------------------------------------------
  13529.  
  13530. When you attempt to connect to a MySQL server, the server accepts or
  13531. rejects the connection based on your identity and whether or not you can
  13532. verify your identity by supplying the correct password.  If not, the
  13533. server denies access to you completely.  Otherwise, the server accepts
  13534. the connection, then enters Stage 2 and waits for requests.
  13535.  
  13536. Your identity is based on two pieces of information:
  13537.  
  13538.    * The host from which you connect
  13539.  
  13540.    * Your MySQL user name
  13541.  
  13542. Identity checking is performed using the three `user' table scope fields
  13543. (`Host', `User', and `Password').  The server accepts the connection
  13544. only if a `user' table entry matches your hostname and user name, and
  13545. you supply the correct password.
  13546.  
  13547. Values in the `user' table scope fields may be specified as follows:
  13548.  
  13549.    * A `Host' value may be a hostname or an IP number, or `'localhost''
  13550.      to indicate the local host.
  13551.  
  13552.    * You can use the wild-card characters `%' and `_' in the `Host'
  13553.      field.
  13554.  
  13555.    * A `Host' value of `'%'' matches any hostname.
  13556.  
  13557.    * A blank `Host' value means that the privilege should be anded with
  13558.      the entry in the `host' table that matches the given host name.
  13559.      You can find more information about this in the next chapter.
  13560.  
  13561.    * As of MySQL Version 3.23, for `Host' values specified as IP
  13562.      numbers, you can specify a netmask indicating how many address
  13563.      bits to use for the network number. For example:
  13564.  
  13565.           GRANT ALL PRIVILEGES on db.* to david@'192.58.197.0/255.255.255.0';
  13566.  
  13567.      This will allow everyone to connect from an IP where the following
  13568.      is true:
  13569.  
  13570.           user_ip & netmask = host_ip.
  13571.  
  13572.      In the above example all IP:s in the interval 192.58.197.0 -
  13573.      192.58.197.255 can connect to the MySQL server.
  13574.  
  13575.    * Wild-card characters are not allowed in the `User' field, but you
  13576.      can specify a blank value, which matches any name.  If the `user'
  13577.      table entry that matches an incoming connection has a blank user
  13578.      name, the user is considered to be the anonymous user (the user
  13579.      with no name), rather than the name that the client actually
  13580.      specified.  This means that a blank user name is used for all
  13581.      further access checking for the duration of the connection (that
  13582.      is, during Stage 2).
  13583.  
  13584.    * The `Password' field can be blank.  This does not mean that any
  13585.      password matches, it means the user must connect without
  13586.      specifying a password.
  13587.  
  13588. Non-blank `Password' values represent encrypted passwords.  MySQL does
  13589. not store passwords in plaintext form for anyone to see.  Rather, the
  13590. password supplied by a user who is attempting to connect is encrypted
  13591. (using the `PASSWORD()' function). The encrypted password is then used
  13592. when the client/server is checking if the password is correct (This is
  13593. done without the encrypted password ever traveling over the
  13594. connection.)  Note that from MySQL's point of view the encrypted
  13595. password is the REAL password, so you should not give anyone access to
  13596. it!  In particular, don't give normal users read access to the tables
  13597. in the `mysql' database!
  13598.  
  13599. The examples below show how various combinations of `Host' and `User'
  13600. values in `user' table entries apply to incoming connections:
  13601.  
  13602. `Host' *value*     `User'      *Connections matched by entry*
  13603.                    *value*     
  13604. `'thomas.loc.gov'' `'fred''    `fred', connecting from `thomas.loc.gov'
  13605. `'thomas.loc.gov'' `'''        Any user, connecting from `thomas.loc.gov'
  13606. `'%''              `'fred''    `fred', connecting from any host
  13607. `'%''              `'''        Any user, connecting from any host
  13608. `'%.loc.gov''      `'fred''    `fred', connecting from any host in the
  13609.                                `loc.gov' domain
  13610. `'x.y.%''          `'fred''    `fred', connecting from `x.y.net',
  13611.                                `x.y.com',`x.y.edu', etc. (this is
  13612.                                probably not useful)
  13613. `'144.155.166.177''`'fred''    `fred', connecting from the host with IP
  13614.                                address `144.155.166.177'
  13615. `'144.155.166.%''  `'fred''    `fred', connecting from any host in the
  13616.                                `144.155.166' class C subnet
  13617. `'144.155.166.0/255.255.255.0''`'fred''    Same as previous example
  13618.  
  13619. Because you can use IP wild-card values in the `Host' field (for
  13620. example, `'144.155.166.%'' to match every host on a subnet), there is
  13621. the possibility that someone might try to exploit this capability by
  13622. naming a host `144.155.166.somewhere.com'.  To foil such attempts, MySQL
  13623. disallows matching on hostnames that start with digits and a dot. Thus,
  13624. if you have a host named something like `1.2.foo.com', its name will
  13625. never match the `Host' column of the grant tables.  Only an IP number
  13626. can match an IP wild-card value.
  13627.  
  13628. An incoming connection may be matched by more than one entry in the
  13629. `user' table.  For example, a connection from `thomas.loc.gov' by
  13630. `fred' would be matched by several of the entries just shown above.  How
  13631. does the server choose which entry to use if more than one matches?  The
  13632. server resolves this question by sorting the `user' table after reading
  13633. it at startup time, then looking through the entries in sorted order
  13634. when a user attempts to connect.  The first matching entry is the one
  13635. that is used.
  13636.  
  13637. `user' table sorting works as follows.  Suppose the `user' table looks
  13638. like this:
  13639.  
  13640.      +-----------+----------+-
  13641.      | Host      | User     | ...
  13642.      +-----------+----------+-
  13643.      | %         | root     | ...
  13644.      | %         | jeffrey  | ...
  13645.      | localhost | root     | ...
  13646.      | localhost |          | ...
  13647.      +-----------+----------+-
  13648.  
  13649. When the server reads in the table, it orders the entries with the
  13650. most-specific `Host' values first (`'%'' in the `Host' column means
  13651. "any host" and is least specific).  Entries with the same `Host' value
  13652. are ordered with the most-specific `User' values first (a blank `User'
  13653. value means "any user" and is least specific).  The resulting sorted
  13654. `user' table looks like this:
  13655.  
  13656.      +-----------+----------+-
  13657.      | Host      | User     | ...
  13658.      +-----------+----------+-
  13659.      | localhost | root     | ...
  13660.      | localhost |          | ...
  13661.      | %         | jeffrey  | ...
  13662.      | %         | root     | ...
  13663.      +-----------+----------+-
  13664.  
  13665. When a connection is attempted, the server looks through the sorted
  13666. entries and uses the first match found.  For a connection from
  13667. `localhost' by `jeffrey', the entries with `'localhost'' in the `Host'
  13668. column match first.  Of those, the entry with the blank user name
  13669. matches both the connecting hostname and user name.  (The
  13670. `'%'/'jeffrey'' entry would have matched, too, but it is not the first
  13671. match in the table.)
  13672.  
  13673. Here is another example.  Suppose the `user' table looks like this:
  13674.  
  13675.      +----------------+----------+-
  13676.      | Host           | User     | ...
  13677.      +----------------+----------+-
  13678.      | %              | jeffrey  | ...
  13679.      | thomas.loc.gov |          | ...
  13680.      +----------------+----------+-
  13681.  
  13682. The sorted table looks like this:
  13683.  
  13684.      +----------------+----------+-
  13685.      | Host           | User     | ...
  13686.      +----------------+----------+-
  13687.      | thomas.loc.gov |          | ...
  13688.      | %              | jeffrey  | ...
  13689.      +----------------+----------+-
  13690.  
  13691. A connection from `thomas.loc.gov' by `jeffrey' is matched by the first
  13692. entry, whereas a connection from `whitehouse.gov' by `jeffrey' is
  13693. matched by the second.
  13694.  
  13695. A common misconception is to think that for a given user name, all
  13696. entries that explicitly name that user will be used first when the
  13697. server attempts to find a match for the connection.  This is simply not
  13698. true.  The previous example illustrates this, where a connection from
  13699. `thomas.loc.gov' by `jeffrey' is first matched not by the entry
  13700. containing `'jeffrey'' as the `User' field value, but by the entry with
  13701. no user name!
  13702.  
  13703. If you have problems connecting to the server, print out the `user'
  13704. table and sort it by hand to see where the first match is being made.
  13705.  
  13706. Access Control, Stage 2: Request Verification
  13707. ---------------------------------------------
  13708.  
  13709. Once you establish a connection, the server enters Stage 2.  For each
  13710. request that comes in on the connection, the server checks whether you
  13711. have sufficient privileges to perform it, based on the type of
  13712. operation you wish to perform.  This is where the privilege fields in
  13713. the grant tables come into play.  These privileges can come from any of
  13714. the `user', `db', `host', `tables_priv', or `columns_priv' tables.  The
  13715. grant tables are manipulated with `GRANT' and `REVOKE' commands.  *Note
  13716. `GRANT': GRANT.  (You may find it helpful to refer to *Note
  13717. Privileges::, which lists the fields present in each of the grant
  13718. tables.)
  13719.  
  13720. The `user' table grants privileges that are assigned to you on a global
  13721. basis and that apply no matter what the current database is.  For
  13722. example, if the `user' table grants you the *delete* privilege, you can
  13723. delete rows from any database on the server host!  In other words,
  13724. `user' table privileges are superuser privileges.  It is wise to grant
  13725. privileges in the `user' table only to superusers such as server or
  13726. database administrators.  For other users, you should leave the
  13727. privileges in the `user' table set to `'N'' and grant privileges on a
  13728. database-specific basis only, using the `db' and `host' tables.
  13729.  
  13730. The `db' and `host' tables grant database-specific privileges.  Values
  13731. in the scope fields may be specified as follows:
  13732.  
  13733.    * The wild-card characters `%' and `_' can be used in the `Host' and
  13734.      `Db' fields of either table.
  13735.  
  13736.    * A `'%'' `Host' value in the `db' table means "any host." A blank
  13737.      `Host' value in the `db' table means "consult the `host' table for
  13738.      further information."
  13739.  
  13740.    * A `'%'' or blank `Host' value in the `host' table means "any host."
  13741.  
  13742.    * A `'%'' or blank `Db' value in either table means "any database."
  13743.  
  13744.    * A blank `User' value in either table matches the anonymous user.
  13745.  
  13746. The `db' and `host' tables are read in and sorted when the server
  13747. starts up (at the same time that it reads the `user' table).  The `db'
  13748. table is sorted on the `Host', `Db', and `User' scope fields, and the
  13749. `host' table is sorted on the `Host' and `Db' scope fields.  As with
  13750. the `user' table, sorting puts the most-specific values first and
  13751. least-specific values last, and when the server looks for matching
  13752. entries, it uses the first match that it finds.
  13753.  
  13754. The `tables_priv' and `columns_priv' tables grant table- and
  13755. column-specific privileges.  Values in the scope fields may be
  13756. specified as follows:
  13757.  
  13758.    * The wild-card characters `%' and `_' can be used in the `Host'
  13759.      field of either table.
  13760.  
  13761.    * A `'%'' or blank `Host' value in either table means "any host."
  13762.  
  13763.    * The `Db', `Table_name' and `Column_name' fields cannot contain
  13764.      wild cards or be blank in either table.
  13765.  
  13766. The `tables_priv' and `columns_priv' tables are sorted on the `Host',
  13767. `Db', and `User' fields.  This is similar to `db' table sorting,
  13768. although the sorting is simpler because only the `Host' field may
  13769. contain wild cards.
  13770.  
  13771. The request verification process is described below.  (If you are
  13772. familiar with the access-checking source code, you will notice that the
  13773. description here differs slightly from the algorithm used in the code.
  13774. The description is equivalent to what the code actually does; it
  13775. differs only to make the explanation simpler.)
  13776.  
  13777. For administrative requests (*shutdown*, *reload*, etc.), the server
  13778. checks only the `user' table entry, because that is the only table that
  13779. specifies administrative privileges.  Access is granted if the entry
  13780. allows the requested operation and denied otherwise.  For example, if
  13781. you want to execute `mysqladmin shutdown' but your `user' table entry
  13782. doesn't grant the *shutdown* privilege to you, access is denied without
  13783. even checking the `db' or `host' tables.  (They contain no
  13784. `Shutdown_priv' column, so there is no need to do so.)
  13785.  
  13786. For database-related requests (*insert*, *update*, etc.), the server
  13787. first checks the user's global (superuser) privileges by looking in the
  13788. `user' table entry.  If the entry allows the requested operation,
  13789. access is granted.  If the global privileges in the `user' table are
  13790. insufficient, the server determines the user's database-specific
  13791. privileges by checking the `db' and `host' tables:
  13792.  
  13793.   1. The server looks in the `db' table for a match on the `Host',
  13794.      `Db', and `User' fields.  The `Host' and `User' fields are matched
  13795.      to the connecting user's hostname and MySQL user name.  The `Db'
  13796.      field is matched to the database the user wants to access.  If
  13797.      there is no entry for the `Host' and `User', access is denied.
  13798.  
  13799.   2. If there is a matching `db' table entry and its `Host' field is
  13800.      not blank, that entry defines the user's database-specific
  13801.      privileges.
  13802.  
  13803.   3. If the matching `db' table entry's `Host' field is blank, it
  13804.      signifies that the `host' table enumerates which hosts should be
  13805.      allowed access to the database.  In this case, a further lookup is
  13806.      done in the `host' table to find a match on the `Host' and `Db'
  13807.      fields.  If no `host' table entry matches, access is denied.  If
  13808.      there is a match, the user's database-specific privileges are
  13809.      computed as the intersection (_not_ the union!) of the privileges
  13810.      in the `db' and `host' table entries, that is, the privileges that
  13811.      are `'Y'' in both entries.  (This way you can grant general
  13812.      privileges in the `db' table entry and then selectively restrict
  13813.      them on a host-by-host basis using the `host' table entries.)
  13814.  
  13815. After determining the database-specific privileges granted by the `db'
  13816. and `host' table entries, the server adds them to the global privileges
  13817. granted by the `user' table.  If the result allows the requested
  13818. operation, access is granted.  Otherwise, the server checks the user's
  13819. table and column privileges in the `tables_priv' and `columns_priv'
  13820. tables and adds those to the user's privileges.  Access is allowed or
  13821. denied based on the result.
  13822.  
  13823. Expressed in boolean terms, the preceding description of how a user's
  13824. privileges are calculated may be summarized like this:
  13825.  
  13826.      global privileges
  13827.      OR (database privileges AND host privileges)
  13828.      OR table privileges
  13829.      OR column privileges
  13830.  
  13831. It may not be apparent why, if the global `user' entry privileges are
  13832. initially found to be insufficient for the requested operation, the
  13833. server adds those privileges to the database-, table-, and
  13834. column-specific privileges later. The reason is that a request might
  13835. require more than one type of privilege.  For example, if you execute
  13836. an `INSERT ...  SELECT' statement, you need both *insert* and *select*
  13837. privileges.  Your privileges might be such that the `user' table entry
  13838. grants one privilege and the `db' table entry grants the other.  In
  13839. this case, you have the necessary privileges to perform the request,
  13840. but the server cannot tell that from either table by itself; the
  13841. privileges granted by the entries in both tables must be combined.
  13842.  
  13843. The `host' table can be used to maintain a list of secure servers.
  13844.  
  13845. At TcX, the `host' table contains a list of all machines on the local
  13846. network. These are granted all privileges.
  13847.  
  13848. You can also use the `host' table to indicate hosts that are _not_
  13849. secure.  Suppose you have a machine `public.your.domain' that is located
  13850. in a public area that you do not consider secure.  You can allow access
  13851. to all hosts on your network except that machine by using `host' table
  13852. entries like this:
  13853.  
  13854.      +--------------------+----+-
  13855.      | Host               | Db | ...
  13856.      +--------------------+----+-
  13857.      | public.your.domain | %  | ... (all privileges set to 'N')
  13858.      | %.your.domain      | %  | ... (all privileges set to 'Y')
  13859.      +--------------------+----+-
  13860.  
  13861. Naturally, you should always test your entries in the grant tables (for
  13862. example, using `mysqlaccess') to make sure your access privileges are
  13863. actually set up the way you think they are.
  13864.  
  13865. Causes of `Access denied' Errors
  13866. --------------------------------
  13867.  
  13868. If you encounter `Access denied' errors when you try to connect to the
  13869. MySQL server, the list below indicates some courses of action you can
  13870. take to correct the problem:
  13871.  
  13872.    * After installing MySQL, did you run the `mysql_install_db' script
  13873.      to set up the initial grant table contents?  If not, do so.  *Note
  13874.      Default privileges::.  Test the initial privileges by executing
  13875.      this command:
  13876.  
  13877.           shell> mysql -u root test
  13878.  
  13879.      The server should let you connect without error.  You should also
  13880.      make sure you have a file `user.MYD' in the MySQL database
  13881.      directory.  Ordinarily, this is `PATH/var/mysql/user.MYD', where
  13882.      `PATH' is the pathname to the MySQL installation root.
  13883.  
  13884.    * After a fresh installation, you should connect to the server and
  13885.      set up your users and their access permissions:
  13886.  
  13887.           shell> mysql -u root mysql
  13888.  
  13889.      The server should let you connect because the MySQL `root' user
  13890.      has no password initially.  That is also a security risk, so
  13891.      setting the `root' password is something you should do while
  13892.      you're setting up your other MySQL users.
  13893.  
  13894.      If you try to connect as `root' and get this error:
  13895.  
  13896.           Access denied for user: '@unknown' to database mysql
  13897.  
  13898.      this means that you don't have an entry in the `user' table with a
  13899.      `User' column value of `'root'' and that `mysqld' cannot resolve
  13900.      the hostname for your client.  In this case, you must restart the
  13901.      server with the `--skip-grant-tables' option and edit your
  13902.      `/etc/hosts' or `\windows\hosts' file to add an entry for your
  13903.      host.
  13904.  
  13905.    * If you get an error like the following:
  13906.  
  13907.           shell> mysqladmin -u root -pxxxx ver
  13908.           Access denied for user: 'root@localhost' (Using password: YES)
  13909.  
  13910.      It means that you are using a wrong password. *Note Passwords::.
  13911.  
  13912.      If you have forgot the root password, you can restart `mysqld' with
  13913.      `--skip-grant-tables' to change the password. You can find more
  13914.      about this option later on in this manual section.
  13915.  
  13916.      If you get the above error even if you haven't specified a
  13917.      password, this means that you a wrong password in some `my.ini'
  13918.      file. *Note Option files::.  You can avoid using option files with
  13919.      the `--no-defaults' option, as follows:
  13920.  
  13921.           shell> mysqladmin --no-defaults -u root ver
  13922.  
  13923.    * If you updated an existing MySQL installation from a version
  13924.      earlier than Version 3.22.11 to Version 3.22.11 or later, did you
  13925.      run the `mysql_fix_privilege_tables' script?  If not, do so.  The
  13926.      structure of the grant tables changed with MySQL Version 3.22.11
  13927.      when the `GRANT' statement became functional.
  13928.  
  13929.    * If your privileges seem to have changed in the middle of a
  13930.      session, it may be that a superuser has changed them.  Reloading
  13931.      the grant tables affects new client connections, but it also
  13932.      affects existing connections as indicated in *Note Privilege
  13933.      changes::.
  13934.  
  13935.    * If you can't get your password to work, remember that you must use
  13936.      the `PASSWORD()' function if you set the password with the
  13937.      `INSERT', `UPDATE', or `SET PASSWORD' statements.  The
  13938.      `PASSWORD()' function is unnecessary if you specify the password
  13939.      using the `GRANT ... INDENTIFIED BY' statement or the `mysqladmin
  13940.      password' command.  *Note Passwords::.
  13941.  
  13942.    * `localhost' is a synonym for your local hostname, and is also the
  13943.      default host to which clients try to connect if you specify no host
  13944.      explicitly.  However, connections to `localhost' do not work if
  13945.      you are running on a system that uses MIT-pthreads (`localhost'
  13946.      connections are made using Unix sockets, which are not supported
  13947.      by MIT-pthreads).  To avoid this problem on such systems, you
  13948.      should use the `--host' option to name the server host explicitly.
  13949.      This will make a TCP/IP connection to the `mysqld' server.  In
  13950.      this case, you must have your real hostname in `user' table
  13951.      entries on the server host.  (This is true even if you are running
  13952.      a client program on the same host as the server.)
  13953.  
  13954.    * If you get an `Access denied' error when trying to connect to the
  13955.      database with `mysql -u user_name db_name', you may have a problem
  13956.      with the `user' table. Check this by executing `mysql -u root
  13957.      mysql' and issuing this SQL statement:
  13958.  
  13959.           mysql> SELECT * FROM user;
  13960.  
  13961.      The result should include an entry with the `Host' and `User'
  13962.      columns matching your computer's hostname and your MySQL user name.
  13963.  
  13964.    * The `Access denied' error message will tell you who you are trying
  13965.      to log in as, the host from which you are trying to connect, and
  13966.      whether or not you were using a password. Normally, you should
  13967.      have one entry in the `user' table that exactly matches the
  13968.      hostname and user name that were given in the error message. For
  13969.      example if you get an error message that contains `Using password:
  13970.      NO', this means that you tried to login without an password.
  13971.  
  13972.    * If you get the following error when you try to connect from a
  13973.      different host than the one on which the MySQL server is running,
  13974.      then there is no row in the `user' table that matches that host:
  13975.  
  13976.           Host ... is not allowed to connect to this MySQL server
  13977.  
  13978.      You can fix this by using the command-line tool `mysql' (on the
  13979.      server host!) to add a row to the `user', `db', or `host' table
  13980.      for the user/hostname combination from which you are trying to
  13981.      connect and then execute `mysqladmin flush-privileges'.  If you are
  13982.      not running MySQL Version 3.22 and you don't know the IP number or
  13983.      hostname of the machine from which you are connecting, you should
  13984.      put an entry with `'%'' as the `Host' column value in the `user'
  13985.      table and restart `mysqld' with the `--log' option on the server
  13986.      machine.  After trying to connect from the client machine, the
  13987.      information in the MySQL log will indicate how you really did
  13988.      connect.  (Then replace the `'%'' in the `user' table entry with
  13989.      the actual hostname that shows up in the log.  Otherwise, you'll
  13990.      have a system that is insecure.)
  13991.  
  13992.      Another reason for this error on Linux is that you are using a
  13993.      binary MySQL version that is compiled with a different glibc
  13994.      version than the one you are using.  In this case you should
  13995.      either upgrade your OS/glibc or download the source MySQL version
  13996.      and compile this yourself.  A source RPM is normally trivial to
  13997.      compile and install, so this isn't a big problem.
  13998.  
  13999.    * If you get an error message where the hostname is not shown or
  14000.      where the hostname is an IP, even if you try to connect with a
  14001.      hostname:
  14002.  
  14003.           shell> mysqladmin -u root -pxxxx -h some-hostname ver
  14004.           Access denied for user: 'root('Using password: YES)
  14005.  
  14006.      This means that MySQL got some error when trying to resolve the IP
  14007.      to a hostname.  In this case you can execute `mysqladmin
  14008.      flush-hosts' to reset the internal DNS cache. *Note DNS::.
  14009.  
  14010.      Some permanent solutions are:
  14011.  
  14012.         - Try to find out what is wrong with your DNS server and fix
  14013.           this.
  14014.  
  14015.         - Specify IPs instead of hostnames in the MySQL privilege
  14016.           tables.
  14017.  
  14018.         - Start `mysqld' with `--skip-name-resolve'.
  14019.  
  14020.         - Start `mysqld' with `--skip-host-cache'.
  14021.  
  14022.         - Connect to `localhost' if you are running the server and the
  14023.           client on the same machine.
  14024.  
  14025.         - Put the client machine names in `/etc/hosts'.
  14026.  
  14027.    * If `mysql -u root test' works but `mysql -h your_hostname -u root
  14028.      test' results in `Access denied', then you may not have the
  14029.      correct name for your host in the `user' table.  A common problem
  14030.      here is that the `Host' value in the user table entry specifies an
  14031.      unqualified hostname, but your system's name resolution routines
  14032.      return a fully qualified domain name (or vice-versa).  For
  14033.      example, if you have an entry with host `'tcx'' in the `user'
  14034.      table, but your DNS tells MySQL that your hostname is
  14035.      `'tcx.subnet.se'', the entry will not work. Try adding an entry to
  14036.      the `user' table that contains the IP number of your host as the
  14037.      `Host' column value.  (Alternatively, you could add an entry to the
  14038.      `user' table with a `Host' value that contains a wild card--for
  14039.      example, `'tcx.%''.  However, use of hostnames ending with `%' is
  14040.      _insecure_ and is _not_ recommended!)
  14041.  
  14042.    * If `mysql -u user_name test' works but `mysql -u user_name
  14043.      other_db_name' doesn't work, you don't have an entry for
  14044.      `other_db_name' listed in the `db' table.
  14045.  
  14046.    * If `mysql -u user_name db_name' works when executed on the server
  14047.      machine, but `mysql -u host_name -u user_name db_name' doesn't
  14048.      work when executed on another client machine, you don't have the
  14049.      client machine listed in the `user' table or the `db' table.
  14050.  
  14051.    * If you can't figure out why you get `Access denied', remove from
  14052.      the `user' table all entries that have `Host' values containing
  14053.      wild cards (entries that contain `%' or `_').  A very common error
  14054.      is to insert a new entry with `Host'=`'%'' and `User'=`'some
  14055.      user'', thinking that this will allow you to specify `localhost'
  14056.      to connect from the same machine.  The reason that this doesn't
  14057.      work is that the default privileges include an entry with
  14058.      `Host'=`'localhost'' and `User'=`'''.  Because that entry has a
  14059.      `Host' value `'localhost'' that is more specific than `'%'', it is
  14060.      used in preference to the new entry when connecting from
  14061.      `localhost'!  The correct procedure is to insert a second entry
  14062.      with `Host'=`'localhost'' and `User'=`'some_user'', or to remove
  14063.      the entry with `Host'=`'localhost'' and `User'=`'''.
  14064.  
  14065.    * If you get the following error, you may have a problem with the
  14066.      `db' or `host' table:
  14067.  
  14068.           Access to database denied
  14069.  
  14070.      If the entry selected from the `db' table has an empty value in the
  14071.      `Host' column, make sure there are one or more corresponding
  14072.      entries in the `host' table specifying which hosts the `db' table
  14073.      entry applies to.
  14074.  
  14075.      If you get the error when using the SQL commands `SELECT ...  INTO
  14076.      OUTFILE' or `LOAD DATA INFILE', your entry in the `user' table
  14077.      probably doesn't have the *file* privilege enabled.
  14078.  
  14079.    * Remember that client programs will use connection parameters
  14080.      specified in configuration files or environment variables.  *Note
  14081.      Environment variables::.  If a client seems to be sending the
  14082.      wrong default connection parameters when you don't specify them on
  14083.      the command line, check your environment and the `.my.cnf' file in
  14084.      your home directory.  You might also check the system-wide MySQL
  14085.      configuration files, though it is far less likely that client
  14086.      connection parameters will be specified there. *Note Option
  14087.      files::.  If you get `Access denied' when you run a client without
  14088.      any options, make sure you haven't specified an old password in
  14089.      any of your option files!  *Note Option files::.
  14090.  
  14091.    * If you make changes to the grant tables directly (using an
  14092.      `INSERT' or `UPDATE' statement) and your changes seem to be
  14093.      ignored, remember that you must issue a `FLUSH PRIVILEGES'
  14094.      statement or execute a `mysqladmin flush-privileges' command to
  14095.      cause the server to re-read the privilege tables.  Otherwise your
  14096.      changes have no effect until the next time the server is
  14097.      restarted.  Remember that after you set the `root' password with
  14098.      an `UPDATE' command, you won't need to specify it until after you
  14099.      flush the privileges, because the server won't know you've changed
  14100.      the password yet!
  14101.  
  14102.    * If you have access problems with a Perl, PHP, Python, or ODBC
  14103.      program, try to connect to the server with `mysql -u user_name
  14104.      db_name' or `mysql -u user_name -pyour_pass db_name'.  If you are
  14105.      able to connect using the `mysql' client, there is a problem with
  14106.      your program and not with the access privileges.  (Note that there
  14107.      is no space between `-p' and the password; you can also use the
  14108.      `--password=your_pass' syntax to specify the password. If you use
  14109.      the `-p' option alone, MySQL will prompt you for the password.)
  14110.  
  14111.    * For testing, start the `mysqld' daemon with the
  14112.      `--skip-grant-tables' option.  Then you can change the MySQL grant
  14113.      tables and use the `mysqlaccess' script to check whether or not
  14114.      your modifications have the desired effect.  When you are
  14115.      satisfied with your changes, execute `mysqladmin flush-privileges'
  14116.      to tell the `mysqld' server to start using the new grant tables.
  14117.      *Note:* Reloading the grant tables overrides the
  14118.      `--skip-grant-tables' option.  This allows you to tell the server
  14119.      to begin using the grant tables again without bringing it down and
  14120.      restarting it.
  14121.  
  14122.    * If everything else fails, start the `mysqld' daemon with a
  14123.      debugging option (for example, `--debug=d,general,query'). This
  14124.      will print host and user information about attempted connections,
  14125.      as well as information about each command issued. *Note Making
  14126.      trace files::.
  14127.  
  14128.    * If you have any other problems with the MySQL grant tables and
  14129.      feel you must post the problem to the mailing list, always provide
  14130.      a dump of the MySQL grant tables. You can dump the tables with the
  14131.      `mysqldump mysql' command. As always, post your problem using the
  14132.      `mysqlbug' script.  *Note Bug reports::.  In some cases you may
  14133.      need to restart `mysqld' with `--skip-grant-tables' to run
  14134.      `mysqldump'.
  14135.  
  14136. MySQL User Account Management
  14137. =============================
  14138.  
  14139. `GRANT' and `REVOKE' Syntax
  14140. ---------------------------
  14141.  
  14142.      GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
  14143.          ON {tbl_name | * | *.* | db_name.*}
  14144.          TO user_name [IDENTIFIED BY 'password']
  14145.              [, user_name [IDENTIFIED BY 'password'] ...]
  14146.          [WITH GRANT OPTION]
  14147.      
  14148.      REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
  14149.          ON {tbl_name | * | *.* | db_name.*}
  14150.          FROM user_name [, user_name ...]
  14151.  
  14152. `GRANT' is implemented in MySQL Version 3.22.11 or later. For earlier
  14153. MySQL versions, the `GRANT' statement does nothing.
  14154.  
  14155. The `GRANT' and `REVOKE' commands allow system administrators to create
  14156. users and grant and revoke rights to MySQL users at four privilege
  14157. levels:
  14158.  
  14159. *Global level*
  14160.      Global privileges apply to all databases on a given server. These
  14161.      privileges are stored in the `mysql.user' table.
  14162.  
  14163. *Database level*
  14164.      Database privileges apply to all tables in a given database. These
  14165.      privileges are stored in the `mysql.db' and `mysql.host' tables.
  14166.  
  14167. *Table level*
  14168.      Table privileges apply to all columns in a given table. These
  14169.      privileges are stored in the `mysql.tables_priv' table.
  14170.  
  14171. *Column level*
  14172.      Column privileges apply to single columns in a given table. These
  14173.      privileges are stored in the `mysql.columns_priv' table.
  14174.  
  14175. If you give a grant for a users that doesn't exists, that user is
  14176. created.  For examples of how `GRANT' works, see *Note Adding users::.
  14177.  
  14178. For the `GRANT' and `REVOKE' statements, `priv_type' may be specified
  14179. as any of the following:
  14180.  
  14181.      ALL PRIVILEGES      FILE                RELOAD
  14182.      ALTER               INDEX               SELECT
  14183.      CREATE              INSERT              SHUTDOWN
  14184.      DELETE              PROCESS             UPDATE
  14185.      DROP                REFERENCES          USAGE
  14186.  
  14187. `ALL' is a synonym for `ALL PRIVILEGES'.  `REFERENCES' is not yet
  14188. implemented.  `USAGE' is currently a synonym for "no privileges."  It
  14189. can be used when you want to create a user that has no privileges.
  14190.  
  14191. To revoke the *grant* privilege from a user, use a `priv_type' value of
  14192. `GRANT OPTION':
  14193.  
  14194.      REVOKE GRANT OPTION ON ... FROM ...;
  14195.  
  14196. The only `priv_type' values you can specify for a table are `SELECT',
  14197. `INSERT', `UPDATE', `DELETE', `CREATE', `DROP', `GRANT', `INDEX', and
  14198. `ALTER'.
  14199.  
  14200. The only `priv_type' values you can specify for a column (that is, when
  14201. you use a `column_list' clause) are `SELECT', `INSERT', and `UPDATE'.
  14202.  
  14203. You can set global privileges by using `ON *.*' syntax.  You can set
  14204. database privileges by using `ON db_name.*' syntax. If you specify `ON
  14205. *' and you have a current database, you will set the privileges for
  14206. that database.  (*WARNING:* If you specify `ON *' and you _don't_ have
  14207. a current database, you will affect the global privileges!)
  14208.  
  14209. In order to accommodate granting rights to users from arbitrary hosts,
  14210. MySQL supports specifying the `user_name' value in the form
  14211. `user@host'.  If you want to specify a `user' string containing special
  14212. characters (such as `-'), or a `host' string containing special
  14213. characters or wild-card characters (such as `%'), you can quote the
  14214. user or host name (for example, `'test-user'@'test-hostname'').
  14215.  
  14216. You can specify wild cards in the hostname.  For example,
  14217. `user@"%.loc.gov"' applies to `user' for any host in the `loc.gov'
  14218. domain, and `user@"144.155.166.%"' applies to `user' for any host in
  14219. the `144.155.166' class C subnet.
  14220.  
  14221. The simple form `user' is a synonym for `user@"%"'.  *NOTE:* If you
  14222. allow anonymous users to connect to the MySQL server (which is the
  14223. default), you should also add all local users as `user@localhost'
  14224. because otherwise the anonymous user entry for the local host in the
  14225. `mysql.user' table will be used when the user tries to log into the
  14226. MySQL server from the local machine!  Anonymous users are defined by
  14227. inserting entries with `User=''' into the `mysql.user' table. You can
  14228. verify if this applies to you by executing this query:
  14229.  
  14230.      mysql> SELECT Host,User FROM mysql.user WHERE User='';
  14231.  
  14232. For the moment, `GRANT' only supports host, table, database, and column
  14233. names up to 60 characters long. A user name can be up to 16 characters.
  14234.  
  14235. The privileges for a table or column are formed from the logical OR of
  14236. the privileges at each of the four privilege levels.  For example, if
  14237. the `mysql.user' table specifies that a user has a global *select*
  14238. privilege, this can't be denied by an entry at the database, table, or
  14239. column level.
  14240.  
  14241. The privileges for a column can be calculated as follows:
  14242.  
  14243.      global privileges
  14244.      OR (database privileges AND host privileges)
  14245.      OR table privileges
  14246.      OR column privileges
  14247.  
  14248. In most cases, you grant rights to a user at only one of the privilege
  14249. levels, so life isn't normally as complicated as above. The details of
  14250. the privilege-checking procedure are presented in *Note Privilege
  14251. system::.
  14252.  
  14253. If you grant privileges for a user/hostname combination that does not
  14254. exist in the `mysql.user' table, an entry is added and remains there
  14255. until deleted with a `DELETE' command.  In other words, `GRANT' may
  14256. create `user' table entries, but `REVOKE' will not remove them; you
  14257. must do that explicitly using `DELETE'.
  14258.  
  14259. In MySQL Version 3.22.12 or later, if a new user is created or if you
  14260. have global grant privileges, the user's password will be set to the
  14261. password specified by the `IDENTIFIED BY' clause, if one is given.  If
  14262. the user already had a password, it is replaced by the new one.
  14263.  
  14264. *WARNING:* If you create a new user but do not specify an `IDENTIFIED
  14265. BY' clause, the user has no password.  This is insecure.
  14266.  
  14267. Passwords can also be set with the `SET PASSWORD' command.  *Note `SET
  14268. OPTION': SET OPTION.
  14269.  
  14270. If you grant privileges for a database, an entry in the `mysql.db'
  14271. table is created if needed. When all privileges for the database have
  14272. been removed with `REVOKE', this entry is deleted.
  14273.  
  14274. If a user doesn't have any privileges on a table, the table is not
  14275. displayed when the user requests a list of tables (for example, with a
  14276. `SHOW TABLES' statement).
  14277.  
  14278. The `WITH GRANT OPTION' clause gives the user the ability to give to
  14279. other users any privileges the user has at the specified privilege
  14280. level.  You should be careful to whom you give the *grant* privilege,
  14281. as two users with different privileges may be able to join privileges!
  14282.  
  14283. You cannot grant another user a privilege you don't have yourself; the
  14284. *grant* privilege allows you to give away only those privileges you
  14285. possess.
  14286.  
  14287. Be aware that when you grant a user the *grant* privilege at a
  14288. particular privilege level, any privileges the user already possesses
  14289. (or is given in the future!) at that level are also grantable by that
  14290. user.  Suppose you grant a user the *insert* privilege on a database.
  14291. If you then grant the *select* privilege on the database and specify
  14292. `WITH GRANT OPTION', the user can give away not only the *select*
  14293. privilege, but also *insert*.  If you then grant the *update* privilege
  14294. to the user on the database, the user can give away the *insert*,
  14295. *select* and *update*.
  14296.  
  14297. You should not grant *alter* privileges to a normal user.  If you do
  14298. that, the user can try to subvert the privilege system by renaming
  14299. tables!
  14300.  
  14301. Note that if you are using table or column privileges for even one
  14302. user, the server examines table and column privileges for all users and
  14303. this will slow down MySQL a bit.
  14304.  
  14305. When `mysqld' starts, all privileges are read into memory.  Database,
  14306. table, and column privileges take effect at once, and user-level
  14307. privileges take effect the next time the user connects.  Modifications
  14308. to the grant tables that you perform using `GRANT' or `REVOKE' are
  14309. noticed by the server immediately.  If you modify the grant tables
  14310. manually (using `INSERT', `UPDATE', etc.), you should execute a `FLUSH
  14311. PRIVILEGES' statement or run `mysqladmin flush-privileges' to tell the
  14312. server to reload the grant tables.  *Note Privilege changes::.
  14313.  
  14314. The biggest differences between the ANSI SQL and MySQL versions of
  14315. `GRANT' are:
  14316.  
  14317.    * In MySQL privileges are given for an username + hostname
  14318.      combination and not only for an username.
  14319.  
  14320.    * ANSI SQL doesn't have global or database-level privileges, and
  14321.      ANSI SQL doesn't support all privilege types that MySQL supports.
  14322.      MySQL doesn't support the ANSI SQL `TRIGGER', `EXECUTE' or `UNDER'
  14323.      privileges.
  14324.  
  14325.    * ANSI SQL privileges are structured in a hierarchal manner. If you
  14326.      remove an user, all privileges the user has granted are revoked. In
  14327.      MySQL the granted privileges are not automatically revoked, but
  14328.      you have to revoke these yourself if needed.
  14329.  
  14330.    * If you in MySQL have the `INSERT' grant on only part of the
  14331.      columns in a table, you can execute `INSERT' statements on the
  14332.      table; The columns for which you don't have the `INSERT' privilege
  14333.      will set to their default values. ANSI SQL requires you to have the
  14334.      `INSERT' privilege on all columns.
  14335.  
  14336.    * When you drop a table in ANSI SQL, all privileges for the table
  14337.      are revoked.  If you revoke a privilege in ANSI SQL, all
  14338.      privileges that were granted based on this privilege are also
  14339.      revoked. In MySQL, privileges can be dropped only with explicit
  14340.      `REVOKE' commands or by manipulating the MySQL grant tables.
  14341.  
  14342. MySQL User Names and Passwords
  14343. ------------------------------
  14344.  
  14345. There are several distinctions between the way user names and passwords
  14346. are used by MySQL and the way they are used by Unix or Windows:
  14347.  
  14348.    * User names, as used by MySQL for authentication purposes, have
  14349.      nothing to do with Unix user names (login names) or Windows user
  14350.      names.  Most MySQL clients by default try to log in using the
  14351.      current Unix user name as the MySQL user name, but that is for
  14352.      convenience only.  Client programs allow a different name to be
  14353.      specified with the `-u' or `--user' options. This means that you
  14354.      can't make a database secure in any way unless all MySQL user
  14355.      names have passwords.  Anyone may attempt to connect to the server
  14356.      using any name, and they will succeed if they specify any name
  14357.      that doesn't have a password.
  14358.  
  14359.    * MySQL user names can be up to 16 characters long; Unix user names
  14360.      typically are limited to 8 characters.
  14361.  
  14362.    * MySQL passwords have nothing to do with Unix passwords.  There is
  14363.      no necessary connection between the password you use to log in to
  14364.      a Unix machine and the password you use to access a database on
  14365.      that machine.
  14366.  
  14367.    * MySQL encrypts passwords using a different algorithm than the one
  14368.      used during the Unix login process.  See the descriptions of the
  14369.      `PASSWORD()' and `ENCRYPT()' functions in *Note Miscellaneous
  14370.      functions::.  Note that even if the password is stored
  14371.      'scrambled', and knowing your 'scrambled' password is enough to be
  14372.      able to connect to the MySQL server!
  14373.  
  14374. MySQL users and their privileges are normally created with the `GRANT'
  14375. command. *Note GRANT::.
  14376.  
  14377. When you login to a MySQL server with a command line client you should
  14378. specify the password with `--password=your-password'.  *Note
  14379. Connecting::.
  14380.  
  14381.      mysql --user=monty --password=guess database_name
  14382.  
  14383. If you want the client to prompt for a password, you should use
  14384. `--password' without any argument
  14385.  
  14386.      mysql --user=monty --password database_name
  14387.  
  14388. or the short form:
  14389.  
  14390.      mysql -u monty -p database_name
  14391.  
  14392. Note that in the last example the password is *NOT* 'database_name'.
  14393.  
  14394. If you want to use the `-p' option to supply a password you should do so
  14395. like this:
  14396.  
  14397.      mysql -u monty -pguess database_name
  14398.  
  14399. On some systems, the library call that MySQL uses to prompt for a
  14400. password will automatically cut the password to 8 characters. Internally
  14401. MySQL doesn't have any limit for the length of the password.
  14402.  
  14403. When Privilege Changes Take Effect
  14404. ----------------------------------
  14405.  
  14406. When `mysqld' starts, all grant table contents are read into memory and
  14407. become effective at that point.
  14408.  
  14409. Modifications to the grant tables that you perform using `GRANT',
  14410. `REVOKE', or `SET PASSWORD' are noticed by the server immediately.
  14411.  
  14412. If you modify the grant tables manually (using `INSERT', `UPDATE',
  14413. etc.), you should execute a `FLUSH PRIVILEGES' statement or run
  14414. `mysqladmin flush-privileges' or `mysqladmin reload' to tell the server
  14415. to reload the grant tables.  Otherwise your changes will have _no
  14416. effect_ until you restart the server. If you change the grant tables
  14417. manually but forget to reload the privileges, you will be wondering why
  14418. your changes don't seem to make any difference!
  14419.  
  14420. When the server notices that the grant tables have been changed,
  14421. existing client connections are affected as follows:
  14422.  
  14423.    * Table and column privilege changes take effect with the client's
  14424.      next request.
  14425.  
  14426.    * Database privilege changes take effect at the next `USE db_name'
  14427.      command.
  14428.  
  14429. Global privilege changes and password changes take effect the next time
  14430. the client connects.
  14431.  
  14432. Setting Up the Initial MySQL Privileges
  14433. ---------------------------------------
  14434.  
  14435. After installing MySQL, you set up the initial access privileges by
  14436. running `scripts/mysql_install_db'.  *Note Quick install::.  The
  14437. `mysql_install_db' script starts up the `mysqld' server, then
  14438. initializes the grant tables to contain the following set of privileges:
  14439.  
  14440.    * The MySQL `root' user is created as a superuser who can do
  14441.      anything.  Connections must be made from the local host.
  14442.  
  14443.      *NOTE:* The initial `root' password is empty, so anyone can
  14444.      connect as `root' _without a password_ and be granted all
  14445.      privileges.
  14446.  
  14447.    * An anonymous user is created that can do anything with databases
  14448.      that have a name of `'test'' or starting with `'test_''.
  14449.      Connections must be made from the local host.  This means any
  14450.      local user can connect without a password and be treated as the
  14451.      anonymous user.
  14452.  
  14453.    * Other privileges are denied.  For example, normal users can't use
  14454.      `mysqladmin shutdown' or `mysqladmin processlist'.
  14455.  
  14456. *NOTE:* The default privileges are different for Windows.  *Note
  14457. Windows running::.
  14458.  
  14459. Because your installation is initially wide open, one of the first
  14460. things you should do is specify a password for the MySQL `root' user.
  14461. You can do this as follows (note that you specify the password using
  14462. the `PASSWORD()' function):
  14463.  
  14464.      shell> mysql -u root mysql
  14465.      mysql> UPDATE user SET Password=PASSWORD('new_password')
  14466.                 WHERE user='root';
  14467.      mysql> FLUSH PRIVILEGES;
  14468.  
  14469. You can, in MySQL Version 3.22 and above, use the `SET PASSWORD'
  14470. statement:
  14471.  
  14472.      shell> mysql -u root mysql
  14473.      mysql> SET PASSWORD FOR root=PASSWORD('new_password');
  14474.  
  14475. Another way to set the password is by using the `mysqladmin' command:
  14476.  
  14477.      shell> mysqladmin -u root password new_password
  14478.  
  14479. Only users with write/update access to the `mysql' database can change
  14480. the password for others users.  All normal users (not anonymous ones)
  14481. can only change their own password with either of the above commands or
  14482. with `SET PASSWORD=PASSWORD('new password')'.
  14483.  
  14484. Note that if you update the password in the `user' table directly using
  14485. the first method, you must tell the server to re-read the grant tables
  14486. (with `FLUSH PRIVILEGES'), because the change will go unnoticed
  14487. otherwise.
  14488.  
  14489. Once the `root' password has been set, thereafter you must supply that
  14490. password when you connect to the server as `root'.
  14491.  
  14492. You may wish to leave the `root' password blank so that you don't need
  14493. to specify it while you perform additional setup or testing. However,
  14494. be sure to set it before using your installation for any real
  14495. production work.
  14496.  
  14497. See the `scripts/mysql_install_db' script to see how it sets up the
  14498. default privileges.  You can use this as a basis to see how to add
  14499. other users.
  14500.  
  14501. If you want the initial privileges to be different than those just
  14502. described above, you can modify `mysql_install_db' before you run it.
  14503.  
  14504. To re-create the grant tables completely, remove all the `.frm',
  14505. `.MYI', and `.MYD' files in the directory containing the `mysql'
  14506. database.  (This is the directory named `mysql' under the database
  14507. directory, which is listed when you run `mysqld --help'.) Then run the
  14508. `mysql_install_db' script, possibly after editing it first to have the
  14509. privileges you want.
  14510.  
  14511. *NOTE:* For MySQL versions older than Version 3.22.10, you should NOT
  14512. delete the `.frm' files.  If you accidentally do this, you should copy
  14513. them back from your MySQL distribution before running
  14514. `mysql_install_db'.
  14515.  
  14516. Adding New Users to MySQL
  14517. -------------------------
  14518.  
  14519. You can add users two different ways: by using `GRANT' statements or by
  14520. manipulating the MySQL grant tables directly.  The preferred method is
  14521. to use `GRANT' statements, because they are more concise and less
  14522. error-prone. *Note GRANT::.
  14523.  
  14524. There is also a lot of contributed programs like `phpmyadmin' that can
  14525. be used to create and administrate users. *Note Contrib::.
  14526.  
  14527. The examples below show how to use the `mysql' client to set up new
  14528. users.  These examples assume that privileges are set up according to
  14529. the defaults described in the previous section.  This means that to
  14530. make changes, you must be on the same machine where `mysqld' is
  14531. running, you must connect as the MySQL `root' user, and the `root' user
  14532. must have the *insert* privilege for the `mysql' database and the
  14533. *reload* administrative privilege.  Also, if you have changed the
  14534. `root' user password, you must specify it for the `mysql' commands
  14535. below.
  14536.  
  14537. You can add new users by issuing `GRANT' statements:
  14538.  
  14539.      shell> mysql --user=root mysql
  14540.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
  14541.                 IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  14542.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@"%"
  14543.                 IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  14544.      mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
  14545.      mysql> GRANT USAGE ON *.* TO dummy@localhost;
  14546.  
  14547. These `GRANT' statements set up three new users:
  14548.  
  14549. `monty'
  14550.      A full superuser who can connect to the server from anywhere, but
  14551.      who must use a password `'some_pass'' to do so.  Note that we must
  14552.      issue `GRANT' statements for both `monty@localhost' and
  14553.      `monty@"%"'.  If we don't add the entry with `localhost', the
  14554.      anonymous user entry for `localhost' that is created by
  14555.      `mysql_install_db' will take precedence when we connect from the
  14556.      local host, because it has a more specific `Host' field value and
  14557.      thus comes earlier in the `user' table sort order.
  14558.  
  14559. `admin'
  14560.      A user who can connect from `localhost' without a password and who
  14561.      is granted the *reload* and *process* administrative privileges.
  14562.      This allows the user to execute the `mysqladmin reload',
  14563.      `mysqladmin refresh', and `mysqladmin flush-*' commands, as well as
  14564.      `mysqladmin processlist' .  No database-related privileges are
  14565.      granted.  (They can be granted later by issuing additional `GRANT'
  14566.      statements.)
  14567.  
  14568. `dummy'
  14569.      A user who can connect without a password, but only from the local
  14570.      host.  The global privileges are all set to `'N'' -- the `USAGE'
  14571.      privilege type allows you to create a user with no privileges.  It
  14572.      is assumed that you will grant database-specific privileges later.
  14573.  
  14574. You can also add the same user access information directly by issuing
  14575. `INSERT' statements and then telling the server to reload the grant
  14576. tables:
  14577.  
  14578.      shell> mysql --user=root mysql
  14579.      mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),
  14580.                      'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  14581.      mysql> INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),
  14582.                      'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  14583.      mysql> INSERT INTO user SET Host='localhost',User='admin',
  14584.                       Reload_priv='Y', Process_priv='Y';
  14585.      mysql> INSERT INTO user (Host,User,Password)
  14586.                              VALUES('localhost','dummy','');
  14587.      mysql> FLUSH PRIVILEGES;
  14588.  
  14589. Depending on your MySQL version, you may have to use a different number
  14590. of `'Y'' values above (versions prior to Version 3.22.11 had fewer
  14591. privilege columns).  For the `admin' user, the more readable extended
  14592. `INSERT' syntax that is available starting with Version 3.22.11 is used.
  14593.  
  14594. Note that to set up a superuser, you need only create a `user' table
  14595. entry with the privilege fields set to `'Y''.  No `db' or `host' table
  14596. entries are necessary.
  14597.  
  14598. The privilege columns in the `user' table were not set explicitly in the
  14599. last `INSERT' statement (for the `dummy' user), so those columns are
  14600. assigned the default value of `'N''.  This is the same thing that
  14601. `GRANT USAGE' does.
  14602.  
  14603. The following example adds a user `custom' who can connect from hosts
  14604. `localhost', `server.domain', and `whitehouse.gov'.  He wants to access
  14605. the `bankaccount' database only from `localhost', the `expenses'
  14606. database only from `whitehouse.gov', and the `customer' database from
  14607. all three hosts.  He wants to use the password `stupid' from all three
  14608. hosts.
  14609.  
  14610. To set up this user's privileges using `GRANT' statements, run these
  14611. commands:
  14612.  
  14613.      shell> mysql --user=root mysql
  14614.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  14615.                 ON bankaccount.*
  14616.                 TO custom@localhost
  14617.                 IDENTIFIED BY 'stupid';
  14618.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  14619.                 ON expenses.*
  14620.                 TO custom@whitehouse.gov
  14621.                 IDENTIFIED BY 'stupid';
  14622.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  14623.                 ON customer.*
  14624.                 TO custom@'%'
  14625.                 IDENTIFIED BY 'stupid';
  14626.  
  14627. The reason that we do to grant statements for the user 'custom' is that
  14628. we want the give the user access to MySQL both from the local machine
  14629. with Unix sockets and from the remote machine 'whitehouse.gov' over
  14630. TCP/IP.
  14631.  
  14632. To set up the user's privileges by modifying the grant tables directly,
  14633. run these commands (note the `FLUSH PRIVILEGES' at the end):
  14634.  
  14635.      shell> mysql --user=root mysql
  14636.      mysql> INSERT INTO user (Host,User,Password)
  14637.             VALUES('localhost','custom',PASSWORD('stupid'));
  14638.      mysql> INSERT INTO user (Host,User,Password)
  14639.             VALUES('server.domain','custom',PASSWORD('stupid'));
  14640.      mysql> INSERT INTO user (Host,User,Password)
  14641.             VALUES('whitehouse.gov','custom',PASSWORD('stupid'));
  14642.      mysql> INSERT INTO db
  14643.             (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  14644.              Create_priv,Drop_priv)
  14645.             VALUES
  14646.             ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y');
  14647.      mysql> INSERT INTO db
  14648.             (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  14649.              Create_priv,Drop_priv)
  14650.             VALUES
  14651.             ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y');
  14652.      mysql> INSERT INTO db
  14653.             (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  14654.              Create_priv,Drop_priv)
  14655.             VALUES('%','customer','custom','Y','Y','Y','Y','Y','Y');
  14656.      mysql> FLUSH PRIVILEGES;
  14657.  
  14658. The first three `INSERT' statements add `user' table entries that allow
  14659. user `custom' to connect from the various hosts with the given
  14660. password, but grant no permissions to him (all privileges are set to the
  14661. default value of `'N'').  The next three `INSERT' statements add `db'
  14662. table entries that grant privileges to `custom' for the `bankaccount',
  14663. `expenses', and `customer' databases, but only when accessed from the
  14664. proper hosts.  As usual, when the grant tables are modified directly,
  14665. the server must be told to reload them (with `FLUSH PRIVILEGES') so
  14666. that the privilege changes take effect.
  14667.  
  14668. If you want to give a specific user access from any machine in a given
  14669. domain, you can issue a `GRANT' statement like the following:
  14670.  
  14671.      mysql> GRANT ...
  14672.                 ON *.*
  14673.                 TO myusername@"%.mydomainname.com"
  14674.                 IDENTIFIED BY 'mypassword';
  14675.  
  14676. To do the same thing by modifying the grant tables directly, do this:
  14677.  
  14678.      mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername',
  14679.                 PASSWORD('mypassword'),...);
  14680.      mysql> FLUSH PRIVILEGES;
  14681.  
  14682. You can also use `xmysqladmin', `mysql_webadmin', and even `xmysql' to
  14683. insert, change, and update values in the grant tables.  You can find
  14684. these utilities in the Contrib directory of the MySQL Website
  14685. (http://www.mysql.com/Downloads/Contrib/).
  14686.  
  14687. Setting Up Passwords
  14688. --------------------
  14689.  
  14690. In most cases you should use `GRANT' to set up your users/passwords, so
  14691. the following only applies for advanced users. *Note `GRANT': GRANT.
  14692.  
  14693. The examples in the preceding sections illustrate an important
  14694. principle: when you store a non-empty password using `INSERT' or
  14695. `UPDATE' statements, you must use the `PASSWORD()' function to encrypt
  14696. it.  This is because the `user' table stores passwords in encrypted
  14697. form, not as plaintext.  If you forget that fact, you are likely to
  14698. attempt to set passwords like this:
  14699.  
  14700.      shell> mysql -u root mysql
  14701.      mysql> INSERT INTO user (Host,User,Password)
  14702.             VALUES('%','jeffrey','biscuit');
  14703.      mysql> FLUSH PRIVILEGES;
  14704.  
  14705. The result is that the plaintext value `'biscuit'' is stored as the
  14706. password in the `user' table.  When the user `jeffrey' attempts to
  14707. connect to the server using this password, the `mysql' client encrypts
  14708. it with `PASSWORD()', generates an authentification vector based on
  14709. *encrypted* password and a random number, obtained from server, and
  14710. sends the result to the server.  The server uses the `password' value
  14711. in the `user' table (that is *not encrypted* value `'biscuit'') to
  14712. perform the same calculations, and compares results.  The comparison
  14713. fails and the server rejects the connection:
  14714.  
  14715.      shell> mysql -u jeffrey -pbiscuit test
  14716.      Access denied
  14717.  
  14718. Passwords must be encrypted when they are inserted in the `user' table,
  14719. so the `INSERT' statement should have been specified like this instead:
  14720.  
  14721.      mysql> INSERT INTO user (Host,User,Password)
  14722.             VALUES('%','jeffrey',PASSWORD('biscuit'));
  14723.  
  14724. You must also use the `PASSWORD()' function when you use `SET PASSWORD'
  14725. statements:
  14726.  
  14727.      mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
  14728.  
  14729. If you set passwords using the `GRANT ... IDENTIFIED BY' statement or
  14730. the `mysqladmin password' command, the `PASSWORD()' function is
  14731. unnecessary.  They both take care of encrypting the password for you,
  14732. so you would specify a password of `'biscuit'' like this:
  14733.  
  14734.      mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
  14735.  
  14736. or
  14737.  
  14738.      shell> mysqladmin -u jeffrey password biscuit
  14739.  
  14740. *NOTE:* `PASSWORD()' does not perform password encryption in the same
  14741. way that Unix passwords are encrypted.  You should not assume that if
  14742. your Unix password and your MySQL password are the same, that
  14743. `PASSWORD()' will result in the same encrypted value as is stored in the
  14744. Unix password file. *Note User names::.
  14745.  
  14746. Keeping Your Password Secure
  14747. ----------------------------
  14748.  
  14749. It is inadvisable to specify your password in a way that exposes it to
  14750. discovery by other users.  The methods you can use to specify your
  14751. password when you run client programs are listed below, along with an
  14752. assessment of the risks of each method:
  14753.  
  14754.    * Never give a normal user access to the `mysql.user' table. Knowing
  14755.      the encrypted password for a user makes it possible to login as
  14756.      this user.  The passwords are only scrambled so that one shouldn't
  14757.      be able to see the real password you used (if you happen to use a
  14758.      similar password with your other applications).
  14759.  
  14760.    * Use a `-pyour_pass' or `--password=your_pass' option on the command
  14761.      line.  This is convenient but insecure, because your password
  14762.      becomes visible to system status programs (such as `ps') that may
  14763.      be invoked by other users to display command lines.  (MySQL
  14764.      clients typically overwrite the command-line argument with zeroes
  14765.      during their initialization sequence, but there is still a brief
  14766.      interval during which the value is visible.)
  14767.  
  14768.    * Use a `-p' or `--password' option (with no `your_pass' value
  14769.      specified).  In this case, the client program solicits the
  14770.      password from the terminal:
  14771.  
  14772.           shell> mysql -u user_name -p
  14773.           Enter password: ********
  14774.  
  14775.      The `*' characters represent your password.
  14776.  
  14777.      It is more secure to enter your password this way than to specify
  14778.      it on the command line because it is not visible to other users.
  14779.      However, this method of entering a password is suitable only for
  14780.      programs that you run interactively.  If you want to invoke a
  14781.      client from a script that runs non-interactively, there is no
  14782.      opportunity to enter the password from the terminal. On some
  14783.      systems, you may even find that the first line of your script is
  14784.      read and interpreted (incorrectly) as your password!
  14785.  
  14786.    * Store your password in a configuration file.  For example, you can
  14787.      list your password in the `[client]' section of the `.my.cnf' file
  14788.      in your home directory:
  14789.  
  14790.           [client]
  14791.           password=your_pass
  14792.  
  14793.      If you store your password in `.my.cnf', the file should not be
  14794.      group or world readable or writable.  Make sure the file's access
  14795.      mode is `400' or `600'.
  14796.  
  14797.      *Note Option files::.
  14798.  
  14799.    * You can store your password in the `MYSQL_PWD' environment
  14800.      variable, but this method must be considered extremely insecure
  14801.      and should not be used.  Some versions of `ps' include an option
  14802.      to display the environment of running processes; your password
  14803.      will be in plain sight for all to see if you set `MYSQL_PWD'.
  14804.      Even on systems without such a version of `ps', it is unwise to
  14805.      assume there is no other method to observe process environments.
  14806.      *Note Environment variables::.
  14807.  
  14808. All in all, the safest methods are to have the client program prompt
  14809. for the password or to specify the password in a properly protected
  14810. `.my.cnf' file.
  14811.  
  14812. Disaster Prevention and Recovery
  14813. ================================
  14814.  
  14815. Database Backups
  14816. ----------------
  14817.  
  14818. Because MySQL tables are stored as files, it is easy to do a backup. To
  14819. get a consistent backup, do a `LOCK TABLES' on the relevant tables
  14820. followed by `FLUSH TABLES' for the tables.  *Note `LOCK TABLES': LOCK
  14821. TABLES.  *Note `FLUSH': FLUSH.  You only need a read lock; this allows
  14822. other threads to continue to query the tables while you are making a
  14823. copy of the files in the database directory.  The `FLUSH TABLE' is
  14824. needed to ensure that the all active index pages is written to disk
  14825. before you start the backup.
  14826.  
  14827. If you want to make a SQL level backup of a table, you can use `SELECT
  14828. INTO OUTFILE' or `BACKUP TABLE'. *Note SELECT::.  *Note BACKUP TABLE::.
  14829.  
  14830. Another way to back up a database is to use the `mysqldump' program or
  14831. the `mysqlhotcopy script'. *Note `mysqldump': mysqldump.  *Note
  14832. `mysqlhotcopy': mysqlhotcopy.
  14833.  
  14834.   1. Do a full backup of your databases:
  14835.  
  14836.           shell> mysqldump --tab=/path/to/some/dir --opt --full
  14837.           
  14838.           or
  14839.           
  14840.           shell> mysqlhotcopy database /path/to/some/dir
  14841.  
  14842.      You can also simply copy all table files (`*.frm', `*.MYD', and
  14843.      `*.MYI' files) as long as the server isn't updating anything.  The
  14844.      script `mysqlhotcopy' does use this method.
  14845.  
  14846.   2. Stop `mysqld' if it's running, then start it with the
  14847.      `--log-update[=file_name]' option.  *Note Update log::. The update
  14848.      log file(s) provide you with the information you need to replicate
  14849.      changes to the database that are made subsequent to the point at
  14850.      which you executed `mysqldump'.
  14851.  
  14852. If you have to restore something, try to recover your tables using
  14853. `REPAIR TABLE' or `myisamchk -r' first.  That should work in 99.9% of
  14854. all cases.  If `myisamchk' fails, try the following procedure: (This
  14855. will only work if you have started MySQL with `--log-update'. *Note
  14856. Update log::.):
  14857.  
  14858.   1. Restore the original `mysqldump' backup.
  14859.  
  14860.   2. Execute the following command to re-run the updates in the binary
  14861.      log:
  14862.  
  14863.           shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  14864.  
  14865.      If you are using the update log you can use:
  14866.  
  14867.           shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql
  14868.  
  14869. `ls' is used to get all the update log files in the right order.
  14870.  
  14871. You can also do selective backups with `SELECT * INTO OUTFILE
  14872. 'file_name' FROM tbl_name' and restore with `LOAD DATA INFILE
  14873. 'file_name' REPLACE ...' To avoid duplicate records, you need a
  14874. `PRIMARY KEY' or a `UNIQUE' key in the table. The `REPLACE' keyword
  14875. causes old records to be replaced with new ones when a new record
  14876. duplicates an old record on a unique key value.
  14877.  
  14878. If you get performance problems in making backups on your system, you
  14879. can solve this by setting up replication and do the backups on the slave
  14880. instead of on the master. *Note Replication Intro::.
  14881.  
  14882. If you are using a Veritas file system, you can do:
  14883.  
  14884.   1. Execute in a client (perl ?) `FLUSH TABLES WITH READ LOCK'
  14885.  
  14886.   2. Fork a shell or execute in another client `mount vxfs snapshot'.
  14887.  
  14888.   3. Execute in the first client `UNLOCK TABLES'
  14889.  
  14890.   4. Copy files from snapshot
  14891.  
  14892.   5. Unmount snapshot
  14893.  
  14894. `BACKUP TABLE' Syntax
  14895. ---------------------
  14896.  
  14897.      BACKUP TABLE tbl_name[,tbl_name...] TO '/path/to/backup/directory'
  14898.  
  14899. Make a copy of all the table files to the backup directory that are the
  14900. minimum needed to restore it. Currenlty only works for `MyISAM' tables.
  14901. For `MyISAM' table, copies `.frm' (definition)  and `.MYD' (data)
  14902. files. The index file can be rebuilt from those two.
  14903.  
  14904. Before using this command, please see *Note Backup::.
  14905.  
  14906. During the backup, read lock will be held for each table, one at time,
  14907. as they are being backed up. If you want to backup several tables as a
  14908. snapshot, you must first issue `LOCK TABLES' obtaining a read lock for
  14909. each table in the group.
  14910.  
  14911. The command returns a table with the following columns:
  14912.  
  14913. *Column*                  *Value*
  14914. Table                     Table name
  14915. Op                        Always "backup"
  14916. Msg_type                  One of `status', `error', `info' or `warning'.
  14917. Msg_text                  The message.
  14918.  
  14919. Note that `BACKUP TABLE' is only available in MySQL version 3.23.25 and
  14920. later.
  14921.  
  14922. `RESTORE TABLE' Syntax
  14923. ----------------------
  14924.  
  14925.      RESTORE TABLE tbl_name[,tbl_name...] FROM '/path/to/backup/directory'
  14926.  
  14927. Restores the table(s) from the backup that was made with `BACKUP
  14928. TABLE'. Existing tables will not be overwritten - if you try to restore
  14929. over an existing table, you will get an error. Restore will take
  14930. longer than BACKUP due to the need to rebuilt the index. The more keys
  14931. you have, the longer it is going to take. Just as `BACKUP TABLE',
  14932. currently only works of `MyISAM' tables.
  14933.  
  14934. The command returns a table with the following columns:
  14935.  
  14936. *Column*                  *Value*
  14937. Table                     Table name
  14938. Op                        Always "restore"
  14939. Msg_type                  One of `status', `error', `info' or `warning'.
  14940. Msg_text                  The message.
  14941.  
  14942. `CHECK TABLE' Syntax
  14943. --------------------
  14944.  
  14945.      CHECK TABLE tbl_name[,tbl_name...] [option [option...]]
  14946.      
  14947.      option = QUICK | FAST | MEDIUM | EXTENDED | CHANGED
  14948.  
  14949. `CHECK TABLE' only works on `MyISAM' tables. On `MyISAM' tables it's
  14950. the same thing as running `myisamchk -m table_name' on the table.
  14951.  
  14952. If you don't specify any option `MEDIUM' is used.
  14953.  
  14954. Checks the table(s) for errors. For `MyISAM' tables the key statistics
  14955. is updated. The command returns a table with the following columns:
  14956.  
  14957. *Column*                  *Value*
  14958. Table                     Table name.
  14959. Op                        Always "check".
  14960. Msg_type                  One of `status', `error', `info', or `warning'.
  14961. Msg_text                  The message.
  14962.  
  14963. Note that you can get many rows of information for each checked table.
  14964. The last row will be of `Msg_type status' and should normally be `OK'.
  14965. If you don't get `OK', or `Not checked' you should normally run a
  14966. repair of the table. *Note Table maintenance::. `Not checked' means
  14967. that the table the given `TYPE' told MySQL that there wasn't any need
  14968. to check the table.
  14969.  
  14970. The different check types stand for the following:
  14971.  
  14972. *Type*         *Meaning*
  14973. `QUICK'        Don't scan the rows to check for wrong links.
  14974. `FAST'         Only check tables which haven't been closed properly.
  14975. `CHANGED'      Only check tables which have been changed since last
  14976.                check or haven't been closed properly.
  14977. `MEDIUM'       Scan rows to verify that deleted links are ok. This also
  14978.                calculates a key checksum for the rows and verifies this
  14979.                with a calcualted checksum for the keys.
  14980. `EXTENDED'     Do a full key lookup for all keys for each row.  This
  14981.                ensures that the table is 100 % consistent, but will take
  14982.                a long time!
  14983.  
  14984. For dynamic sized `MyISAM' tables a started check will always do a
  14985. `MEDIUM' check. For static size rows we skip the row scan for `QUICK'
  14986. and `FAST' as the rows are very seldom corrupted.
  14987.  
  14988. You can combine check options as in:
  14989.  
  14990.      CHECK TABLE test_table FAST QUICK;
  14991.  
  14992. Which only would do a quick check on the table if it wasn't closed
  14993. properly.
  14994.  
  14995. *NOTE:* that in some case `CHECK TABLE' will change the table!  This
  14996. happens if the table is marked as 'corrupted' or 'not closed properly'
  14997. but `CHECK TABLE' didn't find any problems in the table.  In this case
  14998. `CHECK TABLE' will mark the table as ok.
  14999.  
  15000. If a table is corrupted, then it's most likely that the problem is in
  15001. the indexes and not in the data part.  All of the above check types
  15002. checks the indexes throughly and should thus find most errors.
  15003.  
  15004. If you just want to check a table that you assume is ok, you should use
  15005. no check options or the `QUICK' option. The later should be used when
  15006. you are in a hurry and can take the very small risk that `QUICK' didn't
  15007. find an error in the data file (In most cases MySQL should find, under
  15008. normal usage, any error in the data file. If this happens then the
  15009. table will be marked as 'corrupted', in which case the table can't be
  15010. used until it's repaired).
  15011.  
  15012. `FAST' and `CHANGED' are mostly intended to be used from a script (for
  15013. example to be executed from cron) if you want to check your table from
  15014. time to time. In most cases you `FAST' is to be prefered over
  15015. `CHANGED'.  (The only case when it isn't is when you suspect a bug you
  15016. have found a bug in the `MyISAM' code.).
  15017.  
  15018. `EXTENDED' is only to be used after you have run a normal check but
  15019. still get strange errors from a table when MySQL tries to update a row
  15020. or find a row by key (this is VERY unlikely to happen if a normal check
  15021. has succeeded!).
  15022.  
  15023. Some things reported by check table, can't be corrected automatically:
  15024.  
  15025.    * `Found row where the auto_increment column has the value 0'.
  15026.  
  15027.      This means that you have in the table a row where the
  15028.      `auto_increment' index column contains the value 0.  (It's
  15029.      possible to create a row where the auto_increment column is 0 by
  15030.      explicitely setting the column to 0 with an `UPDATE' statement)
  15031.  
  15032.      This isn't an error in itself, but could cause trouble if you
  15033.      decide to dump the table and restore it or do an `ALTER TABLE' on
  15034.      the table. In this case the auto_increment column will change
  15035.      value, according to the rules of auto_increment columns, which
  15036.      could cause problems like a duplicate key error.
  15037.  
  15038.      To get rid of the warning, just execute an `UPDATE' statement to
  15039.      set the column to some other value than 0.
  15040.  
  15041. `REPAIR TABLE' Syntax
  15042. ---------------------
  15043.  
  15044.      REPAIR TABLE tbl_name[,tbl_name...] [QUICK] [EXTENDED]
  15045.  
  15046. `REPAIR TABLE' only works on `MyISAM' tables and is the same as running
  15047. `myisamchk -r table_name' on the table.
  15048.  
  15049. Normally you should never have to run this command, but if disaster
  15050. strikes you are very likely to get back all your data from a MyISAM
  15051. table with `REPAIR TABLE'. If your tables get corrupted a lot you should
  15052. try to find the reason for this! *Note Crashing::. *Note MyISAM table
  15053. problems::.
  15054.  
  15055. `REPAIR TABLE' repairs a possible corrupted table. The command returns a
  15056. table with the following columns:
  15057.  
  15058. *Column*                  *Value*
  15059. Table                     Table name
  15060. Op                        Always "repair"
  15061. Msg_type                  One of `status', `error', `info' or `warning'.
  15062. Msg_text                  The message.
  15063.  
  15064. Note that you can get many rows of information for each repaired table.
  15065. The last one row will be of `Msg_type status' and should normally be
  15066. `OK'.  If you don't get `OK', you should try repairing the table with
  15067. `myisamchk -o', as `REPAIR TABLE' does not yet implement all the
  15068. options of `myisamchk'. In the near future, we will make it more
  15069. flexible.
  15070.  
  15071. If `QUICK' is given then MySQL will try to do a `REPAIR' of only the
  15072. index tree.
  15073.  
  15074. If you use `EXTENDED' then MySQL will create the index row by row
  15075. instead of creating one index at a time with sorting;  This may be
  15076. better than sorting on fixed-length keys if you have long `char()' keys
  15077. that compress very good.
  15078.  
  15079. Using `myisamchk' for Table Maintenance and Crash Recovery
  15080. ----------------------------------------------------------
  15081.  
  15082. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  15083. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  15084. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  15085.  
  15086. To check/repair MyISAM tables (`.MYI' and `.MYD') you should use the
  15087. `myisamchk' utility. To check/repair ISAM tables (`.ISM' and `.ISD')
  15088. you should use the `isamchk' utility. *Note Table types::.
  15089.  
  15090. In the following text we will talk about `myisamchk', but everything
  15091. also applies to the old `isamchk'.
  15092.  
  15093. You can use the `myisamchk' utility to get information about your
  15094. database tables, check and repair them, or optimize them.  The following
  15095. sections describe how to invoke `myisamchk' (including a description of
  15096. its options), how to set up a table maintenance schedule, and how to
  15097. use `myisamchk' to perform its various functions.
  15098.  
  15099. You can, in most cases, also use the command `OPTIMIZE TABLES' to
  15100. optimize and repair tables, but this is not as fast or reliable (in case
  15101. of real fatal errors) as `myisamchk'.  On the other hand, `OPTIMIZE
  15102. TABLE' is easier to use and you don't have to worry about flushing
  15103. tables.  *Note `OPTIMIZE TABLE': OPTIMIZE TABLE.
  15104.  
  15105. Even that the repair in `myisamchk' is quite secure, it's always a good
  15106. idea to make a backup BEFORE doing a repair (or anything that could
  15107. make a lot of changes to a table)
  15108.  
  15109. `myisamchk' Invocation Syntax
  15110. .............................
  15111.  
  15112. `myisamchk' is invoked like this:
  15113.  
  15114.      shell> myisamchk [options] tbl_name
  15115.  
  15116. The `options' specify what you want `myisamchk' to do.  They are
  15117. described below.  (You can also get a list of options by invoking
  15118. `myisamchk --help'.)  With no options, `myisamchk' simply checks your
  15119. table.  To get more information or to tell `myisamchk' to take
  15120. corrective action, specify options as described below and in the
  15121. following sections.
  15122.  
  15123. `tbl_name' is the database table you want to check/repair.  If you run
  15124. `myisamchk' somewhere other than in the database directory, you must
  15125. specify the path to the file, because `myisamchk' has no idea where your
  15126. database is located.  Actually, `myisamchk' doesn't care whether or not
  15127. the files you are working on are located in a database directory; you
  15128. can copy the files that correspond to a database table into another
  15129. location and perform recovery operations on them there.
  15130.  
  15131. You can name several tables on the `myisamchk' command line if you
  15132. wish.  You can also specify a name as an index file name (with the
  15133. `.MYI' suffix), which allows you to specify all tables in a directory
  15134. by using the pattern `*.MYI'.  For example, if you are in a database
  15135. directory, you can check all the tables in the directory like this:
  15136.  
  15137.      shell> myisamchk *.MYI
  15138.  
  15139. If you are not in the database directory, you can check all the tables
  15140. there by specifying the path to the directory:
  15141.  
  15142.      shell> myisamchk /path/to/database_dir/*.MYI
  15143.  
  15144. You can even check all tables in all databases by specifying a wild card
  15145. with the path to the MySQL data directory:
  15146.  
  15147.      shell> myisamchk /path/to/datadir/*/*.MYI
  15148.  
  15149. The recommended way to quickly check all tables is:
  15150.  
  15151.      myisamchk --silent --fast /path/to/datadir/*/*.MYI
  15152.      isamchk --silent /path/to/datadir/*/*.ISM
  15153.  
  15154. If you want to check all tables and repair all tables that are
  15155. corrupted, you can use the following line:
  15156.  
  15157.      myisamchk --silent --force --fast --update-state -O key_buffer=64M -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M /path/to/datadir/*/*.MYI
  15158.      isamchk --silent --force -O key_buffer=64M -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M /path/to/datadir/*/*.ISM
  15159.  
  15160. The above assumes that you have more than 64 M free.
  15161.  
  15162. Note that if you get an error like:
  15163.  
  15164.      myisamchk: warning: 1 clients is using or hasn't closed the table properly
  15165.  
  15166. This means that you are trying to check a table that has been updated by
  15167. the another program (like the `mysqld' server) that hasn't yet closed
  15168. the file or that has died without closing the file properly.
  15169.  
  15170. If you `mysqld' is running, you must force a sync/close of all tables
  15171. with `FLUSH TABLES' and ensure that no one is using the tables while
  15172. you are running `myisamchk'.  In MySQL Version 3.23 the easiest way to
  15173. avoid this problem is to use `CHECK TABLE' instead of `myisamchk' to
  15174. check tables.
  15175.  
  15176. General Options for `myisamchk'
  15177. ...............................
  15178.  
  15179. `myisamchk' supports the following options.
  15180.  
  15181. `-# or --debug=debug_options'
  15182.      Output debug log. The `debug_options' string often is
  15183.      `'d:t:o,filename''.
  15184.  
  15185. `-? or --help'
  15186.      Display a help message and exit.
  15187.  
  15188. `-O var=option, --set-variable var=option'
  15189.      Set the value of a variable.  The possible variables and their
  15190.      default values for myisamchk can be examined with `myisamchk
  15191.      --help':
  15192.      key_buffer_size      523264
  15193.      read_buffer_size     262136
  15194.      write_buffer_size    262136
  15195.      sort_buffer_size     2097144
  15196.      sort_key_blocks      16
  15197.      decode_bits          9
  15198.  
  15199.      `sort_buffer_size' is used when the keys are repaired by sorting
  15200.      keys, which is the normal case when you use `--recover'.
  15201.  
  15202.      `key_buffer_size' is used when you are checking the table with
  15203.      `--extended-check' or when the keys are repaired by inserting key
  15204.      row by row in to the table (like when doing normal inserts).
  15205.      Repairing through the key buffer is used in the following cases:
  15206.  
  15207.         * If you use `--safe-recover'.
  15208.  
  15209.         * If you are using a `FULLTEXT' index.
  15210.  
  15211.         * If the temporary files needed to sort the keys would be more
  15212.           than twice as big as when creating the key file directly.
  15213.           This is often the case when you have big `CHAR', `VARCHAR' or
  15214.           `TEXT' keys as the sort needs to store the whole keys during
  15215.           sorting. If you have lots of temporary space and you can
  15216.           force `myisamchk' to repair by sorting you can use the
  15217.           `--sort-recover' option.
  15218.  
  15219.      Reparing through the key buffer takes much less disk space than
  15220.      using sorting, but is also much slower.
  15221.  
  15222.      If you want a faster repair, set the above variables to about 1/4
  15223.      of your available memory.  You can set both variables to big
  15224.      values, as only one of the above buffers will be used at a time.
  15225.  
  15226. `-s or --silent'
  15227.      Silent mode.  Write output only when errors occur. You can use `-s'
  15228.      twice (`-ss') to make `myisamchk' very silent.
  15229.  
  15230. `-v or --verbose'
  15231.      Verbose mode.  Print more information. This can be used with `-d'
  15232.      and `-e'. Use `-v' multiple times (`-vv', `-vvv') for more
  15233.      verbosity!
  15234.  
  15235. `-V or --version'
  15236.      Print the `myisamchk' version and exit.
  15237.  
  15238. `-w or, --wait'
  15239.      Instead of giving an error if the table is locked, wait until the
  15240.      table is unlocked before continuing.  Note that if you are running
  15241.      `mysqld' on the table with `--skip-locking', the table can only be
  15242.      locked by another `myisamchk' command.
  15243.  
  15244. Check Options for `myisamchk'
  15245. .............................
  15246.  
  15247. `-c or --check'
  15248.      Check table for errors. This is the default operation if you are
  15249.      not giving `myisamchk' any options that override this.
  15250.  
  15251. `-e or --extend-check'
  15252.      Check the table VERY thoroughly (which is quite slow if you have
  15253.      many indexes).  This option should only be used in extreme cases.
  15254.      Normally, `myisamchk' or `myisamchk --medium-check' should, in most
  15255.      cases, be able to find out if there are any errors in the table.
  15256.  
  15257.      If you are using `--extended-check' and have much memory, you
  15258.      should increase the value of `key_buffer_size' a lot!
  15259.  
  15260. `-F or --fast'
  15261.      Check only tables that haven't been closed properly.
  15262.  
  15263. `-C or --check-only-changed'
  15264.      Check only tables that have changed since the last check.
  15265.  
  15266. `-f or --force'
  15267.      Restart `myisamchk' with `-r' (repair) on the table, if
  15268.      `myisamchk' finds any errors in the table.
  15269.  
  15270. `-i or --information'
  15271.      Print informational statistics about the table that is checked.
  15272.  
  15273. `-m or --medium-check'
  15274.      Faster than extended-check, but only finds 99.99% of all errors.
  15275.      Should, however, be good enough for most cases.
  15276.  
  15277. `-U or --update-state'
  15278.      Store in the `.MYI' file when the table was checked and if the
  15279.      table crashed.  This should be used to get full benefit of the
  15280.      `--check-only-changed' option, but you shouldn't use this option
  15281.      if the `mysqld' server is using the table and you are running
  15282.      `mysqld' with `--skip-locking'.
  15283.  
  15284. `-T or --read-only'
  15285.      Don't mark table as checked. This is useful if you use `myisamchk'
  15286.      to check a table that is in use by some other application that
  15287.      doesn't use locking (like `mysqld --skip-locking').
  15288.  
  15289. Repair Options for myisamchk
  15290. ............................
  15291.  
  15292. The following options are used if you start `myisamchk' with `-r' or
  15293. `-o':
  15294.  
  15295. `-D # or --data-file-length=#'
  15296.      Max length of data file (when re-creating data file when it's
  15297.      'full').
  15298.  
  15299. `-e or --extend-check'
  15300.      Try to recover every possible row from the data file.  Normally
  15301.      this will also find a lot of garbage rows. Don't use this option
  15302.      if you are not totally desperate.
  15303.  
  15304. `-f or --force'
  15305.      Overwrite old temporary files (`table_name.TMD') instead of
  15306.      aborting.
  15307.  
  15308. `-k # or keys-used=#'
  15309.      If you are using ISAM, tells the ISAM table handler to update only
  15310.      the first `#' indexes.  If you are using `MyISAM', tells which keys
  15311.      to use, where each binary bit stands for one key (first key is bit
  15312.      0).  This can be used to get faster inserts!  Deactivated indexes
  15313.      can be reactivated by using `myisamchk -r'.  keys.
  15314.  
  15315. `-l or --no-symlinks'
  15316.      Do not follow symbolic links. Normally `myisamchk' repairs the
  15317.      table a symlink points at.  This option doesn't exist in MySQL 4.0,
  15318.      as MySQL 4.0 will not remove symlinks during repair.
  15319.  
  15320. `-r or --recover'
  15321.      Can fix almost anything except unique keys that aren't unique
  15322.      (which is an extremely unlikely error with ISAM/MyISAM tables).
  15323.      If you want to recover a table, this is the option to try first.
  15324.      Only if myisamchk reports that the table can't be recovered by
  15325.      `-r', you should then try `-o'.  (Note that in the unlikely case
  15326.      that `-r' fails, the data file is still intact.)  If you have lots
  15327.      of memory, you should increase the size of `sort_buffer_size'!
  15328.  
  15329. `-o or --safe-recover'
  15330.      Uses an old recovery method (reads through all rows in order and
  15331.      updates all index trees based on the found rows); this is a
  15332.      magnitude slower than `-r', but can handle a couple of very
  15333.      unlikely cases that `-r' cannot handle.  This recovery method also
  15334.      uses much less disk space than `-r'. Normally one should always
  15335.      first repair with `-r', and only if this fails use `-o'.
  15336.  
  15337.      If you have lots of memory, you should increase the size of
  15338.      `key_buffer_size'!
  15339.  
  15340. `-n or --sort-recover'
  15341.      Force `myisamchk' to use sorting to resolve the keys even if the
  15342.      temporary files should be very big.  This will not have any effect
  15343.      if you have fulltext keys in the table.
  15344.  
  15345. `--character-sets-dir=...'
  15346.      Directory where character sets are stored.
  15347.  
  15348. `--set-character-set=name'
  15349.      Change the character set used by the index
  15350.  
  15351. `.t or --tmpdir=path'
  15352.      Path for storing temporary files. If this is not set, `myisamchk'
  15353.      will use the environment variable `TMPDIR' for this.
  15354.  
  15355. `-q or --quick'
  15356.      Faster repair by not modifying the data file. One can give a second
  15357.      `-q' to force `myisamchk' to modify the original datafile in case
  15358.      of duplicate keys
  15359.  
  15360. `-u or --unpack'
  15361.      Unpack file packed with myisampack.
  15362.  
  15363. Other Options for `myisamchk'
  15364. .............................
  15365.  
  15366. Other actions that `myisamchk' can do, besides repair and check tables:
  15367.  
  15368. `-a or --analyze'
  15369.      Analyze the distribution of keys. This improves join performance by
  15370.      enabling the join optimizer to better choose in which order it
  15371.      should join the tables and which keys it should use: `myisamchk
  15372.      --describe --verbose table_name'' or using `SHOW KEYS' in MySQL.
  15373.  
  15374. `-d or --description'
  15375.      Prints some information about table.
  15376.  
  15377. `-A or --set-auto-increment[=value]'
  15378.      Force auto_increment to start at this or higher value. If no value
  15379.      is given, then sets the next auto_increment value to the highest
  15380.      used value for the auto key + 1.
  15381.  
  15382. `-S or --sort-index'
  15383.      Sort the index tree blocks in high-low order.  This will optimize
  15384.      seeks and will make table scanning by key faster.
  15385.  
  15386. `-R or --sort-records=#'
  15387.      Sorts records according to an index.  This makes your data much
  15388.      more localized and may speed up ranged `SELECT' and `ORDER BY'
  15389.      operations on this index. (It may be VERY slow to do a sort the
  15390.      first time!)  To find out a table's index numbers, use `SHOW
  15391.      INDEX', which shows a table's indexes in the same order that
  15392.      `myisamchk' sees them.  Indexes are numbered beginning with 1.
  15393.  
  15394. `myisamchk' Memory Usage
  15395. ........................
  15396.  
  15397. Memory allocation is important when you run `myisamchk'.  `myisamchk'
  15398. uses no more memory than you specify with the `-O' options.  If you are
  15399. going to use `myisamchk' on very large files, you should first decide
  15400. how much memory you want it to use.  The default is to use only about
  15401. 3M to fix things.  By using larger values, you can get `myisamchk' to
  15402. operate faster.  For example, if you have more than 32M RAM, you could
  15403. use options such as these (in addition to any other options you might
  15404. specify):
  15405.  
  15406.      shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...
  15407.  
  15408. Using `-O sort=16M' should probably be enough for most cases.
  15409.  
  15410. Be aware that `myisamchk' uses temporary files in `TMPDIR'. If `TMPDIR'
  15411. points to a memory file system, you may easily get out of memory
  15412. errors. If this happens, set `TMPDIR' to point at some directory with
  15413. more space and restart `myisamchk'.
  15414.  
  15415. When repairing, `myisamchk' will also need a lot of disk space:
  15416.  
  15417.    * Double the size of the record file (the original one and a copy).
  15418.      This space is not needed if one does a repair with `--quick', as
  15419.      in this case only the index file will be re-created.  This space
  15420.      is needed on the same disk as the original record file!
  15421.  
  15422.    * Space for the new index file that replaces the old one. The old
  15423.      index file is truncated at start, so one usually ignore this space.
  15424.      This space is needed on the same disk as the original index file!
  15425.  
  15426.    * When using `--recover' or `--sort-recover' (but not when using
  15427.      `--safe-recover', you will need space for a sort buffer for:
  15428.      `(largest_key + row_pointer_length)*number_of_rows * 2'.  You can
  15429.      check the length of the keys and the row_pointer_length with
  15430.      `myisamchk -dv table'.  This space is allocated on the temporary
  15431.      disk (specified by `TMPDIR' or `--tmpdir=#').
  15432.  
  15433. If you have a problem with disk space during repair, you can try to use
  15434. `--safe-recover' instead of `--recover'.
  15435.  
  15436. Using `myisamchk' for Crash Recovery
  15437. ....................................
  15438.  
  15439. If you run `mysqld' with `--skip-locking' (which is the default on some
  15440. systems, like Linux), you can't reliably use `myisamchk' to check a
  15441. table when `mysqld' is using the same table.  If you can be sure that
  15442. no one is accessing the tables through `mysqld' while you run
  15443. `myisamchk', you only have to do `mysqladmin flush-tables' before you
  15444. start checking the tables.  If you can't guarantee the above, then you
  15445. must take down `mysqld' while you check the tables.  If you run
  15446. `myisamchk' while `mysqld' is updating the tables, you may get a
  15447. warning that a table is corrupt even if it isn't.
  15448.  
  15449. If you are not using `--skip-locking', you can use `myisamchk' to check
  15450. tables at any time.  While you do this, all clients that try to update
  15451. the table will wait until `myisamchk' is ready before continuing.
  15452.  
  15453. If you use `myisamchk' to repair or optimize tables, you *MUST* always
  15454. ensure that the `mysqld' server is not using the table (this also
  15455. applies if you are using `--skip-locking').  If you don't take down
  15456. `mysqld' you should at least do a `mysqladmin flush-tables' before you
  15457. run `myisamchk'.
  15458.  
  15459. This chapter describes how to check for and deal with data corruption
  15460. in MySQL databases.  If your tables get corrupted a lot you should try
  15461. to find the reason for this! *Note Crashing::.
  15462.  
  15463. The `MyISAM' table section contains reason for why a table could be
  15464. corrupted. *Note MyISAM table problems::.
  15465.  
  15466. When performing crash recovery, it is important to understand that each
  15467. table `tbl_name' in a database corresponds to three files in the
  15468. database directory:
  15469.  
  15470. *File*         *Purpose*
  15471. `tbl_name.frm' Table definition (form) file
  15472. `tbl_name.MYD' Data file
  15473. `tbl_name.MYI' Index file
  15474.  
  15475. Each of these three file types is subject to corruption in various
  15476. ways, but problems occur most often in data files and index files.
  15477.  
  15478. `myisamchk' works by creating a copy of the `.MYD' (data) file row by
  15479. row. It ends the repair stage by removing the old `.MYD' file and
  15480. renaming the new file to the original file name.  If you use `--quick',
  15481. `myisamchk' does not create a temporary `.MYD' file, but instead
  15482. assumes that the `.MYD' file is correct and only generates a new index
  15483. file without touching the `.MYD' file. This is safe, because
  15484. `myisamchk' automatically detects if the `.MYD' file is corrupt and
  15485. aborts the repair in this case.  You can also give two `--quick'
  15486. options to `myisamchk'.  In this case, `myisamchk' does not abort on
  15487. some errors (like duplicate key) but instead tries to resolve them by
  15488. modifying the `.MYD' file. Normally the use of two `--quick' options is
  15489. useful only if you have too little free disk space to perform a normal
  15490. repair.  In this case you should at least make a backup before running
  15491. `myisamchk'.
  15492.  
  15493. How to Check Tables for Errors
  15494. ..............................
  15495.  
  15496. To check a MyISAM table, use the following commands:
  15497.  
  15498. `myisamchk tbl_name'
  15499.      This finds 99.99% of all errors. What it can't find is corruption
  15500.      that involves *ONLY* the data file (which is very unusual). If you
  15501.      want to check a table, you should normally run `myisamchk' without
  15502.      options or with either the `-s' or `--silent' option.
  15503.  
  15504. `myisamchk -m tbl_name'
  15505.      This finds 99.999% of all errors. It checks first all index
  15506.      entries for errors and then it reads through all rows. It
  15507.      calculates a checksum for all keys in the rows and verifies that
  15508.      they checksum matches the checksum for the keys in the index tree.
  15509.  
  15510. `myisamchk -e tbl_name'
  15511.      This does a complete and thorough check of all data (`-e' means
  15512.      "extended check"). It does a check-read of every key for each row
  15513.      to verify that they indeed point to the correct row.  This may
  15514.      take a LONG time on a big table with many keys.  `myisamchk' will
  15515.      normally stop after the first error it finds. If you want to
  15516.      obtain more information, you can add the `--verbose' (`-v')
  15517.      option.  This causes `myisamchk' to keep going, up through a
  15518.      maximum of 20 errors.  In normal usage, a simple `myisamchk' (with
  15519.      no arguments other than the table name) is sufficient.
  15520.  
  15521. `myisamchk -e -i tbl_name'
  15522.      Like the previous command, but the `-i' option tells `myisamchk' to
  15523.      print some informational statistics, too.
  15524.  
  15525. How to Repair Tables
  15526. ....................
  15527.  
  15528. In the following section we only talk about using `myisamchk' on
  15529. `MyISAM' tables (extensions `.MYI' and `.MYD').  If you are using
  15530. `ISAM' tables (extensions `.ISM' and `.ISD'), you should use `isamchk'
  15531. instead.
  15532.  
  15533. Starting with MySQL Version 3.23.14, you can repair MyISAM tables with
  15534. the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  15535.  
  15536. The symptoms of a corrupted table include queries that abort
  15537. unexpectedly and observable errors such as these:
  15538.  
  15539.    * `tbl_name.frm' is locked against change
  15540.  
  15541.    * Can't find file `tbl_name.MYI' (Errcode: ###)
  15542.  
  15543.    * Unexpected end of file
  15544.  
  15545.    * Record file is crashed
  15546.  
  15547.    * Got error ### from table handler
  15548.  
  15549.      To get more information about the error you can run `perror ###'.
  15550.      Here is the most common errors that indicates a problem with the
  15551.      table:
  15552.  
  15553.           shell> perror 126 127 132 134 135 136 141 144 145
  15554.           126 = Index file is crashed / Wrong file format
  15555.           127 = Record-file is crashed
  15556.           132 = Old database file
  15557.           134 = Record was already deleted (or record file crashed)
  15558.           135 = No more room in record file
  15559.           136 = No more room in index file
  15560.           141 = Duplicate unique key or constraint on write or update
  15561.           144 = Table is crashed and last repair failed
  15562.           145 = Table was marked as crashed and should be repaired
  15563.  
  15564.      Note that error 135, no more room in record file, is not an error
  15565.      that can be fixed by a simple repair. In this case you have to do:
  15566.  
  15567.           ALTER TABLE table MAX_ROWS=xxx AVG_ROW_LENGTH=yyy;
  15568.  
  15569.  
  15570. In the other cases, you must repair your tables. `myisamchk' can
  15571. usually detect and fix most things that go wrong.
  15572.  
  15573. The repair process involves up to four stages, described below. Before
  15574. you begin, you should `cd' to the database directory and check the
  15575. permissions of the table files. Make sure they are readable by the Unix
  15576. user that `mysqld' runs as (and to you, because you need to access the
  15577. files you are checking).  If it turns out you need to modify files,
  15578. they must also be writable by you.
  15579.  
  15580. If you are using MySQL Version 3.23.16 and above, you can (and should)
  15581. use the `CHECK' and `REPAIR' commands to check and repair `MyISAM'
  15582. tables.  *Note CHECK TABLE::.  *Note REPAIR TABLE::.
  15583.  
  15584. The manual section about table maintenance includes the options to
  15585. `isamchk'/`myisamchk'.  *Note Table maintenance::.
  15586.  
  15587. The following section is for the cases where the above command fails or
  15588. if you want to use the extended features that `isamchk'/`myisamchk'
  15589. provides.
  15590.  
  15591. If you are going to repair a table from the command line, you must first
  15592. take down the `mysqld' server. Note that when you do `mysqladmin
  15593. shutdown' on a remote server, the `mysqld' server will still be alive
  15594. for a while after `mysqladmin' returns, until all queries are stopped
  15595. and all keys have been flushed to disk.
  15596.  
  15597. *Stage 1: Checking your tables*
  15598.  
  15599. Run `myisamchk *.MYI' or `myisamchk -e *.MYI' if you have more time.
  15600. Use the `-s' (silent) option to suppress unnecessary information.
  15601.  
  15602. If the `mysqld' server is done you should use the -update option to tell
  15603. `myisamchk' to mark the table as 'checked'.
  15604.  
  15605. You have to repair only those tables for which `myisamchk' announces an
  15606. error.  For such tables, proceed to Stage 2.
  15607.  
  15608. If you get weird errors when checking (such as `out of memory' errors),
  15609. or if `myisamchk' crashes, go to Stage 3.
  15610.  
  15611. *Stage 2: Easy safe repair*
  15612.  
  15613. NOTE: If you want repairing to go much faster, you should add: `-O
  15614. sort_buffer=# -O key_buffer=#' (where # is about 1/4 of the available
  15615. memory) to all `isamchk/myisamchk' commands.
  15616.  
  15617. First, try `myisamchk -r -q tbl_name' (`-r -q' means "quick recovery
  15618. mode"). This will attempt to repair the index file without touching the
  15619. data file.  If the data file contains everything that it should and the
  15620. delete links point at the correct locations within the data file, this
  15621. should work, and the table is fixed. Start repairing the next table.
  15622. Otherwise, use the following procedure:
  15623.  
  15624.   1. Make a backup of the data file before continuing.
  15625.  
  15626.   2. Use `myisamchk -r tbl_name' (`-r' means "recovery mode"). This will
  15627.      remove incorrect records and deleted records from the data file and
  15628.      reconstruct the index file.
  15629.  
  15630.   3. If the preceding step fails, use `myisamchk --safe-recover
  15631.      tbl_name'.  Safe recovery mode uses an old recovery method that
  15632.      handles a few cases that regular recovery mode doesn't (but is
  15633.      slower).
  15634.  
  15635. If you get weird errors when repairing (such as `out of memory'
  15636. errors), or if `myisamchk' crashes, go to Stage 3.
  15637.  
  15638. *Stage 3: Difficult repair*
  15639.  
  15640. You should only reach this stage if the first 16K block in the index
  15641. file is destroyed or contains incorrect information, or if the index
  15642. file is missing.  In this case, it's necessary to create a new index
  15643. file. Do so as follows:
  15644.  
  15645.   1. Move the data file to some safe place.
  15646.  
  15647.   2. Use the table description file to create new (empty) data and
  15648.      index files:
  15649.  
  15650.           shell> mysql db_name
  15651.           mysql> SET AUTOCOMMIT=1;
  15652.           mysql> TRUNCATE TABLE table_name;
  15653.           mysql> quit
  15654.  
  15655.      If your SQL version doesn't have `TRUNCATE TABLE', use `DELETE FROM
  15656.      table_name' instead.
  15657.  
  15658.   3. Copy the old data file back onto the newly created data file.
  15659.      (Don't just move the old file back onto the new file; you want to
  15660.      retain a copy in case something goes wrong.)
  15661.  
  15662. Go back to Stage 2.  `myisamchk -r -q' should work now.  (This shouldn't
  15663. be an endless loop.)
  15664.  
  15665. *Stage 4: Very difficult repair*
  15666.  
  15667. You should reach this stage only if the description file has also
  15668. crashed. That should never happen, because the description file isn't
  15669. changed after the table is created:
  15670.  
  15671.   1. Restore the description file from a backup and go back to Stage 3.
  15672.      You can also restore the index file and go back to Stage 2.  In
  15673.      the latter case, you should start with `myisamchk -r'.
  15674.  
  15675.   2. If you don't have a backup but know exactly how the table was
  15676.      created, create a copy of the table in another database.  Remove
  15677.      the new data file, then move the description and index files from
  15678.      the other database to your crashed database.  This gives you new
  15679.      description and index files, but leaves the data file alone.  Go
  15680.      back to Stage 2 and attempt to reconstruct the index file.
  15681.  
  15682. Table Optimization
  15683. ..................
  15684.  
  15685. To coalesce fragmented records and eliminate wasted space resulting from
  15686. deleting or updating records, run `myisamchk' in recovery mode:
  15687.  
  15688.      shell> myisamchk -r tbl_name
  15689.  
  15690. You can optimize a table in the same way using the SQL `OPTIMIZE TABLE'
  15691. statement.  `OPTIMIZE TABLE' does a repair of the table, a key analyzes
  15692. and also sorts the index tree to give faster key lookups.  There is
  15693. also no possibility of unwanted interaction between a utility and the
  15694. server, because the server does all the work when you use `OPTIMIZE
  15695. TABLE'. *Note OPTIMIZE TABLE::.
  15696.  
  15697. `myisamchk' also has a number of other options you can use to improve
  15698. the performance of a table:
  15699.  
  15700. `-S, --sort-index'
  15701.  
  15702. `-R index_num, --sort-records=index_num'
  15703.  
  15704. `-a, --analyze'
  15705. For a full description of the option. *Note myisamchk syntax::.
  15706.  
  15707. Setting Up a Table Maintenance Regimen
  15708. --------------------------------------
  15709.  
  15710. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  15711. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  15712. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  15713.  
  15714. It is a good idea to perform table checks on a regular basis rather than
  15715. waiting for problems to occur.  For maintenance purposes, you can use
  15716. `myisamchk -s' to check tables.  The `-s' option (short for `--silent')
  15717. causes `myisamchk' to run in silent mode, printing messages only when
  15718. errors occur.
  15719.  
  15720. It's also a good idea to check tables when the server starts up.  For
  15721. example, whenever the machine has done a reboot in the middle of an
  15722. update, you usually need to check all the tables that could have been
  15723. affected. (This is an "expected crashed table".) You could add a test to
  15724. `safe_mysqld' that runs `myisamchk' to check all tables that have been
  15725. modified during the last 24 hours if there is an old `.pid' (process
  15726. ID) file left after a reboot.  (The `.pid' file is created by `mysqld'
  15727. when it starts up and removed when it terminates normally.  The
  15728. presence of a `.pid' file at system startup time indicates that
  15729. `mysqld' terminated abnormally.)
  15730.  
  15731. An even better test would be to check any table whose last-modified time
  15732. is more recent than that of the `.pid' file.
  15733.  
  15734. You should also check your tables regularly during normal system
  15735. operation.  At MySQL AB, we run a `cron' job to check all our important
  15736. tables once a week, using a line like this in a `crontab' file:
  15737.  
  15738.      35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI
  15739.  
  15740. This prints out information about crashed tables so we can examine and
  15741. repair them when needed.
  15742.  
  15743. As we haven't had any unexpectedly crashed tables (tables that become
  15744. corrupted for reasons other than hardware trouble) for a couple of
  15745. years now (this is really true), once a week is more than enough for us.
  15746.  
  15747. We recommend that to start with, you execute `myisamchk -s' each night
  15748. on all tables that have been updated during the last 24 hours, until
  15749. you come to trust MySQL as much as we do.
  15750.  
  15751. Normally you don't need to maintain MySQL tables that much.  If you are
  15752. changing tables with dynamic size rows (tables with `VARCHAR', `BLOB'
  15753. or `TEXT' columns) or have tables with many deleted rows you may want
  15754. to from time to time (once a month?) defragment/reclaim space from the
  15755. tables.
  15756.  
  15757. You can do this by using `OPTIMIZE TABLE' on the tables in question or
  15758. if you can take the `mysqld' server down for a while do:
  15759.  
  15760.      isamchk -r --silent --sort-index -O sort_buffer_size=16M */*.ISM
  15761.      myisamchk -r --silent --sort-index  -O sort_buffer_size=16M */*.MYI
  15762.  
  15763. Getting Information About a Table
  15764. ---------------------------------
  15765.  
  15766. To get a description of a table or statistics about it, use the
  15767. commands shown below. We explain some of the information in more detail
  15768. later:
  15769.  
  15770. `myisamchk -d tbl_name'
  15771.      Runs `myisamchk' in "describe mode" to produce a description of
  15772.      your table. If you start the MySQL server using the
  15773.      `--skip-locking' option, `myisamchk' may report an error for a
  15774.      table that is updated while it runs.  However, because `myisamchk'
  15775.      doesn't change the table in describe mode, there isn't any risk of
  15776.      destroying data.
  15777.  
  15778. `myisamchk -d -v tbl_name'
  15779.      To produce more information about what `myisamchk' is doing, add
  15780.      `-v' to tell it to run in verbose mode.
  15781.  
  15782. `myisamchk -eis tbl_name'
  15783.      Shows only the most important information from a table. It is slow
  15784.      because it must read the whole table.
  15785.  
  15786. `myisamchk -eiv tbl_name'
  15787.      This is like `-eis', but tells you what is being done.
  15788.  
  15789. Example of `myisamchk -d' output:
  15790.      MyISAM file:     company.MYI
  15791.      Record format:   Fixed length
  15792.      Data records:    1403698  Deleted blocks:         0
  15793.      Recordlength:    226
  15794.      
  15795.      table description:
  15796.      Key Start Len Index   Type
  15797.      1   2     8   unique  double
  15798.      2   15    10  multip. text packed stripped
  15799.      3   219   8   multip. double
  15800.      4   63    10  multip. text packed stripped
  15801.      5   167   2   multip. unsigned short
  15802.      6   177   4   multip. unsigned long
  15803.      7   155   4   multip. text
  15804.      8   138   4   multip. unsigned long
  15805.      9   177   4   multip. unsigned long
  15806.          193   1           text
  15807.  
  15808. Example of `myisamchk -d -v' output:
  15809.      MyISAM file:         company
  15810.      Record format:       Fixed length
  15811.      File-version:        1
  15812.      Creation time:       1999-10-30 12:12:51
  15813.      Recover time:        1999-10-31 19:13:01
  15814.      Status:              checked
  15815.      Data records:           1403698  Deleted blocks:              0
  15816.      Datafile parts:         1403698  Deleted data:                0
  15817.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     3
  15818.      Max datafile length: 3791650815  Max keyfile length: 4294967294
  15819.      Recordlength:               226
  15820.      
  15821.      table description:
  15822.      Key Start Len Index   Type                  Rec/key     Root Blocksize
  15823.      1   2     8   unique  double                      1 15845376      1024
  15824.      2   15    10  multip. text packed stripped        2 25062400      1024
  15825.      3   219   8   multip. double                     73 40907776      1024
  15826.      4   63    10  multip. text packed stripped        5 48097280      1024
  15827.      5   167   2   multip. unsigned short           4840 55200768      1024
  15828.      6   177   4   multip. unsigned long            1346 65145856      1024
  15829.      7   155   4   multip. text                     4995 75090944      1024
  15830.      8   138   4   multip. unsigned long              87 85036032      1024
  15831.      9   177   4   multip. unsigned long             178 96481280      1024
  15832.          193   1           text
  15833.  
  15834. Example of `myisamchk -eis' output:
  15835.      Checking MyISAM file: company
  15836.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  15837.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  15838.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  15839.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  15840.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  15841.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  15842.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  15843.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  15844.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  15845.      Total:    Keyblocks used:  98%  Packed:   17%
  15846.      
  15847.      Records:          1403698    M.recordlength:     226   Packed:             0%
  15848.      Recordspace used:     100%   Empty space:          0%  Blocks/Record:   1.00
  15849.      Record blocks:    1403698    Delete blocks:        0
  15850.      Recorddata:     317235748    Deleted data:         0
  15851.      Lost space:             0    Linkdata:             0
  15852.      
  15853.      User time 1626.51, System time 232.36
  15854.      Maximum resident set size 0, Integral resident set size 0
  15855.      Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
  15856.      Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  15857.      Voluntary context switches 639, Involuntary context switches 28966
  15858.  
  15859. Example of `myisamchk -eiv' output:
  15860.      Checking MyISAM file: company
  15861.      Data records: 1403698   Deleted blocks:       0
  15862.      - check file-size
  15863.      - check delete-chain
  15864.      block_size 1024:
  15865.      index  1:
  15866.      index  2:
  15867.      index  3:
  15868.      index  4:
  15869.      index  5:
  15870.      index  6:
  15871.      index  7:
  15872.      index  8:
  15873.      index  9:
  15874.      No recordlinks
  15875.      - check index reference
  15876.      - check data record references index: 1
  15877.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  15878.      - check data record references index: 2
  15879.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  15880.      - check data record references index: 3
  15881.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  15882.      - check data record references index: 4
  15883.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  15884.      - check data record references index: 5
  15885.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  15886.      - check data record references index: 6
  15887.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  15888.      - check data record references index: 7
  15889.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  15890.      - check data record references index: 8
  15891.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  15892.      - check data record references index: 9
  15893.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  15894.      Total:    Keyblocks used:   9%  Packed:   17%
  15895.      
  15896.      - check records and index references
  15897.      [LOTS OF ROW NUMBERS DELETED]
  15898.      
  15899.      Records:          1403698    M.recordlength:     226   Packed:             0%
  15900.      Recordspace used:     100%   Empty space:          0%  Blocks/Record:   1.00
  15901.      Record blocks:    1403698    Delete blocks:        0
  15902.      Recorddata:     317235748    Deleted data:         0
  15903.      Lost space:             0    Linkdata:             0
  15904.      
  15905.      User time 1639.63, System time 251.61
  15906.      Maximum resident set size 0, Integral resident set size 0
  15907.      Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
  15908.      Blocks in 4 out 0, Messages in 0 out 0, Signals 0
  15909.      Voluntary context switches 10604, Involuntary context switches 122798
  15910.  
  15911. Here are the sizes of the data and index files for the table used in the
  15912. preceding examples:
  15913.  
  15914.      -rw-rw-r--   1 monty    tcx     317235748 Jan 12 17:30 company.MYD
  15915.      -rw-rw-r--   1 davida   tcx      96482304 Jan 12 18:35 company.MYM
  15916.  
  15917. Explanations for the types of information `myisamchk' produces are
  15918. given below.  The "keyfile" is the index file.  "Record" and "row" are
  15919. synonymous:
  15920.  
  15921. `ISAM file'
  15922.      Name of the ISAM (index) file.
  15923.  
  15924. `Isam-version'
  15925.      Version of ISAM format. Currently always 2.
  15926.  
  15927. `Creation time'
  15928.      When the data file was created.
  15929.  
  15930. `Recover time'
  15931.      When the index/data file was last reconstructed.
  15932.  
  15933. `Data records'
  15934.      How many records are in the table.
  15935.  
  15936. `Deleted blocks'
  15937.      How many deleted blocks still have reserved space.  You can
  15938.      optimize your table to minimize this space.  *Note Optimization::.
  15939.  
  15940. `Datafile: Parts'
  15941.      For dynamic record format, this indicates how many data blocks
  15942.      there are. For an optimized table without fragmented records, this
  15943.      is the same as `Data records'.
  15944.  
  15945. `Deleted data'
  15946.      How many bytes of non-reclaimed deleted data there are.  You can
  15947.      optimize your table to minimize this space.  *Note Optimization::.
  15948.  
  15949. `Datafile pointer'
  15950.      The size of the data file pointer, in bytes. It is usually 2, 3,
  15951.      4, or 5 bytes. Most tables manage with 2 bytes, but this cannot be
  15952.      controlled from MySQL yet. For fixed tables, this is a record
  15953.      address. For dynamic tables, this is a byte address.
  15954.  
  15955. `Keyfile pointer'
  15956.      The size of the index file pointer, in bytes. It is usually 1, 2,
  15957.      or 3 bytes. Most tables manage with 2 bytes, but this is calculated
  15958.      automatically by MySQL. It is always a block address.
  15959.  
  15960. `Max datafile length'
  15961.      How long the table's data file (`.MYD' file) can become, in bytes.
  15962.  
  15963. `Max keyfile length'
  15964.      How long the table's key file (`.MYI' file) can become, in bytes.
  15965.  
  15966. `Recordlength'
  15967.      How much space each record takes, in bytes.
  15968.  
  15969. `Record format'
  15970.      The format used to store table rows.  The examples shown above use
  15971.      `Fixed length'.  Other possible values are `Compressed' and
  15972.      `Packed'.
  15973.  
  15974. `table description'
  15975.      A list of all keys in the table. For each key, some low-level
  15976.      information is presented:
  15977.  
  15978.     `Key'
  15979.           This key's number.
  15980.  
  15981.     `Start'
  15982.           Where in the record this index part starts.
  15983.  
  15984.     `Len'
  15985.           How long this index part is. For packed numbers, this should
  15986.           always be the full length of the column. For strings, it may
  15987.           be shorter than the full length of the indexed column,
  15988.           because you can index a prefix of a string column.
  15989.  
  15990.     `Index'
  15991.           `unique' or `multip.' (multiple). Indicates whether or not
  15992.           one value can exist multiple times in this index.
  15993.  
  15994.     `Type'
  15995.           What data-type this index part has. This is an ISAM data-type
  15996.           with the options `packed', `stripped' or `empty'.
  15997.  
  15998.     `Root'
  15999.           Address of the root index block.
  16000.  
  16001.     `Blocksize'
  16002.           The size of each index block. By default this is 1024, but
  16003.           the value may be changed at compile time.
  16004.  
  16005.     `Rec/key'
  16006.           This is a statistical value used by the optimizer. It tells
  16007.           how many records there are per value for this key. A unique
  16008.           key always has a value of 1. This may be updated after a
  16009.           table is loaded (or greatly changed) with `myisamchk -a'. If
  16010.           this is not updated at all, a default value of 30 is given.
  16011.  
  16012. `'
  16013.      In the first example above, the 9th key is a multi-part key with
  16014.      two parts.
  16015.  
  16016. `Keyblocks used'
  16017.      What percentage of the keyblocks are used. Because the table used
  16018.      in the examples had just been reorganized with `myisamchk', the
  16019.      values are very high (very near the theoretical maximum).
  16020.  
  16021. `Packed'
  16022.      MySQL tries to pack keys with a common suffix. This can only be
  16023.      used for `CHAR'/`VARCHAR'/`DECIMAL' keys. For long strings like
  16024.      names, this can significantly reduce the space used. In the third
  16025.      example above, the 4th key is 10 characters long and a 60%
  16026.      reduction in space is achieved.
  16027.  
  16028. `Max levels'
  16029.      How deep the B-tree for this key is. Large tables with long keys
  16030.      get high values.
  16031.  
  16032. `Records'
  16033.      How many rows are in the table.
  16034.  
  16035. `M.recordlength'
  16036.      The average record length. For tables with fixed-length records,
  16037.      this is the exact record length.
  16038.  
  16039. `Packed'
  16040.      MySQL strips spaces from the end of strings. The `Packed' value
  16041.      indicates the percentage of savings achieved by doing this.
  16042.  
  16043. `Recordspace used'
  16044.      What percentage of the data file is used.
  16045.  
  16046. `Empty space'
  16047.      What percentage of the data file is unused.
  16048.  
  16049. `Blocks/Record'
  16050.      Average number of blocks per record (that is, how many links a
  16051.      fragmented record is composed of). This is always 1 for
  16052.      fixed-format tables. This value should stay as close to 1.0 as
  16053.      possible. If it gets too big, you can reorganize the table with
  16054.      `myisamchk'.  *Note Optimization::.
  16055.  
  16056. `Recordblocks'
  16057.      How many blocks (links) are used. For fixed format, this is the
  16058.      same as the number of records.
  16059.  
  16060. `Deleteblocks'
  16061.      How many blocks (links) are deleted.
  16062.  
  16063. `Recorddata'
  16064.      How many bytes in the data file are used.
  16065.  
  16066. `Deleted data'
  16067.      How many bytes in the data file are deleted (unused).
  16068.  
  16069. `Lost space'
  16070.      If a record is updated to a shorter length, some space is lost.
  16071.      This is the sum of all such losses, in bytes.
  16072.  
  16073. `Linkdata'
  16074.      When the dynamic table format is used, record fragments are linked
  16075.      with pointers (4 to 7 bytes each). `Linkdata' is the sum of the
  16076.      amount of storage used by all such pointers.
  16077.  
  16078. If a table has been compressed with `myisampack', `myisamchk -d' prints
  16079. additional information about each table column.  See *Note
  16080. `myisampack': myisampack, for an example of this information and a
  16081. description of what it means.
  16082.  
  16083. Database Administration Language Reference
  16084. ==========================================
  16085.  
  16086. `OPTIMIZE TABLE' Syntax
  16087. -----------------------
  16088.  
  16089.      OPTIMIZE TABLE tbl_name[,tbl_name]...
  16090.  
  16091. `OPTIMIZE TABLE' should be used if you have deleted a large part of a
  16092. table or if you have made many changes to a table with variable-length
  16093. rows (tables that have `VARCHAR', `BLOB', or `TEXT' columns).  Deleted
  16094. records are maintained in a linked list and subsequent `INSERT'
  16095. operations reuse old record positions. You can use `OPTIMIZE TABLE' to
  16096. reclaim the unused space and to defragment the data file.
  16097.  
  16098. For the moment `OPTIMIZE TABLE' only works on *MyISAM* and `BDB'
  16099. tables. For `BDB' tables, `OPTIMIZE TABLE' is currently mapped to
  16100. `ANALYZE TABLE'. *Note ANALYZE TABLE::.
  16101.  
  16102. You can get optimize table to work on other table types by starting
  16103. `mysqld' with `--skip-new' or `--safe-mode', but in this case `OPTIMIZE
  16104. TABLE' is just mapped to `ALTER TABLE'.
  16105.  
  16106. `OPTIMIZE TABLE' works the following way:
  16107.    * If the table has deleted or split rows, repair the table.
  16108.  
  16109.    * If the index pages are not sorted, sort them.
  16110.  
  16111.    * If the statistics are not up to date (and the repair couldn't be
  16112.      done by sorting the index), update them.
  16113.  
  16114. `OPTIMIZE TABLE' for `MyISAM' tables is equvialent of running
  16115. `myisamchk --quick --check-changed-tables --sort-index --analyze' on
  16116. the table.
  16117.  
  16118. Note that the table is locked during the time `OPTIMIZE TABLE' is
  16119. running!
  16120.  
  16121. `ANALYZE TABLE' Syntax
  16122. ----------------------
  16123.  
  16124.      ANALYZE TABLE tbl_name[,tbl_name...]
  16125.  
  16126. Analyze and store the key distribution for the table.  During the
  16127. analyze the table is locked with a read lock.  This works on `MyISAM'
  16128. and `BDB' tables.
  16129.  
  16130. This is equivalent to running `myisamchk -a' on the table.
  16131.  
  16132. MySQL uses the stored key distribution to decide in which order tables
  16133. should be joined when one does a join on something else than a constant.
  16134.  
  16135. The command returns a table with the following columns:
  16136.  
  16137. *Column*                  *Value*
  16138. Table                     Table name
  16139. Op                        Always "analyze"
  16140. Msg_type                  One of `status', `error', `info' or `warning'.
  16141. Msg_text                  The message.
  16142.  
  16143. You can check the stored key distribution with the `SHOW INDEX' command.
  16144. *Note SHOW DATABASE INFO::.
  16145.  
  16146. If the table hasn't changed since the last `ANALYZE TABLE' command, the
  16147. table will not be analyzed again.
  16148.  
  16149. `FLUSH' Syntax
  16150. --------------
  16151.  
  16152.      FLUSH flush_option [,flush_option]
  16153.  
  16154. You should use the `FLUSH' command if you want to clear some of the
  16155. internal caches MySQL uses.  To execute `FLUSH', you must have the
  16156. *RELOAD* privilege.
  16157.  
  16158. `flush_option' can be any of the following:
  16159.  
  16160. `HOSTS'     Empties the host cache tables.  You should flush the host
  16161.             tables if some of your hosts change IP number or if you get
  16162.             the error message `Host ... is blocked'.  When more than
  16163.             `max_connect_errors' errors occur in a row for a given host
  16164.             while connection to the MySQL server, MySQL assumes
  16165.             something is wrong and blocks the host from further
  16166.             connection requests.  Flushing the host tables allows the
  16167.             host to attempt to connect again. *Note Blocked host::.) You
  16168.             can start `mysqld' with `-O max_connection_errors=999999999'
  16169.             to avoid this error message.
  16170. `LOGS'      Closes and reopens all log files.  If you have specified the
  16171.             update log file or a binary log file without an extension,
  16172.             the extension number of the log file will be incremented by
  16173.             one relative to the previous file.  If you have used an
  16174.             extension in the file name, MySQL will close and reopen the
  16175.             update log file.  *Note Update log::. This is the same thing
  16176.             as sending the `SIGHUP' signal to the `mysqld' server.
  16177. `PRIVILEGES'Reloads the privileges from the grant tables in the `mysql'
  16178.             database.
  16179. `TABLES'    Closes all open tables and force all tables in use to be
  16180.             closed.
  16181. `[TABLE |   Flushes only the given tables.
  16182. TABLES]     
  16183. table_name  
  16184. [,table_name...]'
  16185. `TABLES     Closes all open tables and locks all tables for all
  16186. WITH READ   databases with a read until one executes `UNLOCK TABLES'.
  16187. LOCK'       This is very convenient way to get backups if you have a
  16188.             file system, like Veritas,that can take snapshots in time.
  16189. `STATUS'    Resets most status variables to zero. This is something one
  16190.             should only use when debugging a query.
  16191.  
  16192. You can also access each of the commands shown above with the
  16193. `mysqladmin' utility, using the `flush-hosts', `flush-logs', `reload',
  16194. or `flush-tables' commands.
  16195.  
  16196. Take also a look at the `RESET' command used with replication. *Note
  16197. Replication SQL::.
  16198.  
  16199. `KILL' Syntax
  16200. -------------
  16201.  
  16202.      KILL thread_id
  16203.  
  16204. Each connection to `mysqld' runs in a separate thread.  You can see
  16205. which threads are running with the `SHOW PROCESSLIST' command and kill
  16206. a thread with the `KILL thread_id' command.
  16207.  
  16208. If you have the *process* privilege, you can see and kill all threads.
  16209. Otherwise, you can see and kill only your own threads.
  16210.  
  16211. You can also use the `mysqladmin processlist' and `mysqladmin kill'
  16212. commands to examine and kill threads.
  16213.  
  16214. When you do a `KILL', a thread specific `kill flag' is set for the
  16215. thread.
  16216.  
  16217. In most cases it may take some time for the thread to die as the kill
  16218. flag is only checked at specific intervals.
  16219.  
  16220.    * In `SELECT', `ORDER BY' and `GROUP BY' loops, the flag is checked
  16221.      after reading a block of rows. If the kill flag is set the
  16222.      statement is aborted
  16223.  
  16224.    * When doing an `ALTER TABLE' the kill flag is checked before each
  16225.      block of rows are read from the original table. If the kill flag
  16226.      was set the command is aborted and the temporary table is deleted.
  16227.  
  16228.    * When doing an `UPDATE TABLE' and `DELETE TABLE', the kill flag is
  16229.      checked after each block read and after each updated or delete
  16230.      row. If the kill flag is set the statement is aborted.  Note that
  16231.      if you are not using transactions, the changes will not be rolled
  16232.      back!
  16233.  
  16234.    * `GET_LOCK()' will abort with `NULL'.
  16235.  
  16236.    * An `INSERT DELAYED' thread will quickly flush all rows it has in
  16237.      memory and die.
  16238.  
  16239.    * If the thread is in the table lock handler (state: `Locked'), the
  16240.      table lock will be quickly aborted.
  16241.  
  16242.    * If the thread is waiting for free disk space in a `write' call, the
  16243.      write is aborted with an disk full error message.
  16244.  
  16245. `SHOW' Syntax
  16246. -------------
  16247.  
  16248.         SHOW DATABASES [LIKE wild]
  16249.      or SHOW [OPEN] TABLES [FROM db_name] [LIKE wild]
  16250.      or SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE wild]
  16251.      or SHOW INDEX FROM tbl_name [FROM db_name]
  16252.      or SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  16253.      or SHOW STATUS [LIKE wild]
  16254.      or SHOW VARIABLES [LIKE wild]
  16255.      or SHOW LOGS
  16256.      or SHOW [FULL] PROCESSLIST
  16257.      or SHOW GRANTS FOR user
  16258.      or SHOW CREATE TABLE table_name
  16259.      or SHOW MASTER STATUS
  16260.      or SHOW MASTER LOGS
  16261.      or SHOW SLAVE STATUS
  16262.  
  16263. `SHOW' provides information about databases, tables, columns, or status
  16264. information about the server. If the `LIKE wild' part is used, the
  16265. `wild' string can be a string that uses the SQL `%' and `_' wild-card
  16266. characters.
  16267.  
  16268. Retrieving information about Database, Tables, Columns, and Indexes
  16269. ...................................................................
  16270.  
  16271. You can use `db_name.tbl_name' as an alternative to the `tbl_name FROM
  16272. db_name' syntax.  These two statements are equivalent:
  16273.  
  16274.      mysql> SHOW INDEX FROM mytable FROM mydb;
  16275.      mysql> SHOW INDEX FROM mydb.mytable;
  16276.  
  16277. `SHOW DATABASES' lists the databases on the MySQL server host.  You can
  16278. also get this list using the `mysqlshow' command.
  16279.  
  16280. `SHOW TABLES' lists the tables in a given database.  You can also get
  16281. this list using the `mysqlshow db_name' command.
  16282.  
  16283. *NOTE:* If a user doesn't have any privileges for a table, the table
  16284. will not show up in the output from `SHOW TABLES' or `mysqlshow
  16285. db_name'.
  16286.  
  16287. `SHOW OPEN TABLES' lists the tables that are currently open in the
  16288. table cache. *Note Table cache::.  The `Comment' field tells how many
  16289. times the table is `cached' and `in_use'.
  16290.  
  16291. `SHOW COLUMNS' lists the columns in a given table.  If you specify the
  16292. `FULL' option, you will also get the privileges you have for each
  16293. column.  If the column types are different than you expect them to be
  16294. based on a `CREATE TABLE' statement, note that MySQL sometimes changes
  16295. column types.  *Note Silent column changes::.
  16296.  
  16297. The `DESCRIBE' statement provides information similar to `SHOW COLUMNS'.
  16298. *Note `DESCRIBE': DESCRIBE.
  16299.  
  16300. `SHOW FIELDS' is a synonym for `SHOW COLUMNS', and `SHOW KEYS' is a
  16301. synonym for `SHOW INDEX'.  You can also list a table's columns or
  16302. indexes with `mysqlshow db_name tbl_name' or `mysqlshow -k db_name
  16303. tbl_name'.
  16304.  
  16305. `SHOW INDEX' returns the index information in a format that closely
  16306. resembles the `SQLStatistics' call in ODBC. The following columns are
  16307. returned:
  16308.  
  16309. *Column*                  *Meaning*
  16310. `Table'                   Name of the table.
  16311. `Non_unique'              0 if the index can't contain duplicates.
  16312. `Key_name'                Name of the index.
  16313. `Seq_in_index'            Column sequence number in index,
  16314.                                                  starting with 1.
  16315. `Column_name'             Column name.
  16316. `Collation'               How the column is sorted in the index.
  16317.                                                         In MySQL, this
  16318.                           can have values
  16319.                                 `A' (Ascending) or `NULL' (Not
  16320.                                                       sorted).
  16321. `Cardinality'             Number of unique values in the index.
  16322.                                                        This is updated
  16323.                           by running
  16324.                            `isamchk -a'.
  16325. `Sub_part'                Number of indexed characters if the
  16326.                                                     column is only
  16327.                           partly indexed.
  16328.                                  `NULL' if the entire key is indexed.
  16329. `Comment'                 Various remarks.  For now, it tells
  16330.                                                     whether index is
  16331.                           FULLTEXT or not.
  16332.  
  16333. Note that as the `Cardinality' is counted based on statistics stored as
  16334. integers, it's not necessarily accurate for small tables.
  16335.  
  16336. `SHOW TABLE STATUS'
  16337. ...................
  16338.  
  16339.      SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  16340.  
  16341. `SHOW TABLE STATUS' (new in Version 3.23) works likes `SHOW STATUS',
  16342. but provides a lot of information about each table. You can also get
  16343. this list using the `mysqlshow --status db_name' command.  The
  16344. following columns are returned:
  16345.  
  16346. *Column*               *Meaning*
  16347. `Name'                 Name of the table.
  16348. `Type'                 Type of table. *Note Table types::.
  16349. `Row_format'           The row storage format (Fixed, Dynamic, or
  16350.                        Compressed).
  16351. `Rows'                 Number of rows.
  16352. `Avg_row_length'       Average row length.
  16353. `Data_length'          Length of the data file.
  16354. `Max_data_length'      Max length of the data file.
  16355. `Index_length'         Length of the index file.
  16356. `Data_free'            Number of allocated but not used bytes.
  16357. `Auto_increment'       Next autoincrement value.
  16358. `Create_time'          When the table was created.
  16359. `Update_time'          When the data file was last updated.
  16360. `Check_time'           When the table was last checked.
  16361. `Create_options'       Extra options used with `CREATE TABLE'.
  16362. `Comment'              The comment used when creating the table (or some
  16363.                        information why MySQL couldn't access the table
  16364.                        information).
  16365.  
  16366. `InnoDB' tables will report the free space in the tablespace in the
  16367. table comment.
  16368.  
  16369. `SHOW STATUS'
  16370. .............
  16371.  
  16372. `SHOW STATUS' provides server status information (like `mysqladmin
  16373. extended-status'). The output resembles that shown below, though the
  16374. format and numbers probably differ:
  16375.  
  16376.      +--------------------------+------------+
  16377.      | Variable_name            | Value      |
  16378.      +--------------------------+------------+
  16379.      | Aborted_clients          | 0          |
  16380.      | Aborted_connects         | 0          |
  16381.      | Bytes_received           | 155372598  |
  16382.      | Bytes_sent               | 1176560426 |
  16383.      | Connections              | 30023      |
  16384.      | Created_tmp_disk_tables  | 0          |
  16385.      | Created_tmp_tables       | 8340       |
  16386.      | Created_tmp_files        | 60         |
  16387.      | Delayed_insert_threads   | 0          |
  16388.      | Delayed_writes           | 0          |
  16389.      | Delayed_errors           | 0          |
  16390.      | Flush_commands           | 1          |
  16391.      | Handler_delete           | 462604     |
  16392.      | Handler_read_first       | 105881     |
  16393.      | Handler_read_key         | 27820558   |
  16394.      | Handler_read_next        | 390681754  |
  16395.      | Handler_read_prev        | 6022500    |
  16396.      | Handler_read_rnd         | 30546748   |
  16397.      | Handler_read_rnd_next    | 246216530  |
  16398.      | Handler_update           | 16945404   |
  16399.      | Handler_write            | 60356676   |
  16400.      | Key_blocks_used          | 14955      |
  16401.      | Key_read_requests        | 96854827   |
  16402.      | Key_reads                | 162040     |
  16403.      | Key_write_requests       | 7589728    |
  16404.      | Key_writes               | 3813196    |
  16405.      | Max_used_connections     | 0          |
  16406.      | Not_flushed_key_blocks   | 0          |
  16407.      | Not_flushed_delayed_rows | 0          |
  16408.      | Open_tables              | 1          |
  16409.      | Open_files               | 2          |
  16410.      | Open_streams             | 0          |
  16411.      | Opened_tables            | 44600      |
  16412.      | Questions                | 2026873    |
  16413.      | Select_full_join         | 0          |
  16414.      | Select_full_range_join   | 0          |
  16415.      | Select_range             | 99646      |
  16416.      | Select_range_check       | 0          |
  16417.      | Select_scan              | 30802      |
  16418.      | Slave_running            | OFF        |
  16419.      | Slave_open_temp_tables   | 0          |
  16420.      | Slow_launch_threads      | 0          |
  16421.      | Slow_queries             | 0          |
  16422.      | Sort_merge_passes        | 30         |
  16423.      | Sort_range               | 500        |
  16424.      | Sort_rows                | 30296250   |
  16425.      | Sort_scan                | 4650       |
  16426.      | Table_locks_immediate    | 1920382    |
  16427.      | Table_locks_waited       | 0          |
  16428.      | Threads_cached           | 0          |
  16429.      | Threads_created          | 30022      |
  16430.      | Threads_connected        | 1          |
  16431.      | Threads_running          | 1          |
  16432.      | Uptime                   | 80380      |
  16433.      +--------------------------+------------+
  16434.  
  16435. The status variables listed above have the following meaning:
  16436.  
  16437. *Variable*                *Meaning*
  16438. `Aborted_clients'         Number of connections aborted because the
  16439.                           client died without closing the connection
  16440.                           properly. *Note Communication errors::.
  16441. `Aborted_connects'        Number of tries to connect to the MySQL server
  16442.                           that failed. *Note Communication errors::.
  16443. `Bytes_received'          Number of bytes received from all clients.
  16444. `Bytes_sent'              Number of bytes sent to all clients.
  16445. `Connections'             Number of connection attempts to the MySQL
  16446.                           server.
  16447. `Created_tmp_disk_tables' Number of implicit temporary tables on disk
  16448.                           created while executing statements.
  16449. `Created_tmp_tables'      Number of implicit temporary tables in memory
  16450.                           created while executing statements.
  16451. `Created_tmp_files'       How many temporary files `mysqld' have created.
  16452. `Delayed_insert_threads'  Number of delayed insert handler threads in
  16453.                           use.
  16454. `Delayed_writes'          Number of rows written with `INSERT DELAYED'.
  16455. `Delayed_errors'          Number of rows written with `INSERT DELAYED'
  16456.                           for which some error occurred (probably
  16457.                           `duplicate key').
  16458. `Flush_commands'          Number of executed `FLUSH' commands.
  16459. `Handler_delete'          Number of times a row was deleted from a table.
  16460. `Handler_read_first'      Number of times the first entry was read from
  16461.                           an index.  If this is high, it suggests that
  16462.                           the server is doing a lot of full index scans,
  16463.                           for example, `SELECT col1 FROM foo', assuming
  16464.                           that col1 is indexed.
  16465. `Handler_read_key'        Number of requests to read a row based on a
  16466.                           key. If this is high, it is a good indication
  16467.                           that your queries and tables are properly
  16468.                           indexed.
  16469. `Handler_read_next'       Number of requests to read next row in key
  16470.                           order. This will be incremented if you are
  16471.                           querying an index column with a range
  16472.                           constraint. This also will be incremented if
  16473.                           you are doing an index scan.
  16474. `Handler_read_rnd'        Number of requests to read a row based on a
  16475.                           fixed position.  This will be high if you are
  16476.                           doing a lot of queries that require sorting of
  16477.                           the result.
  16478. `Handler_read_rnd_next'   Number of requests to read the next row in the
  16479.                           datafile.  This will be high if you are doing
  16480.                           a lot of table scans. Generally this suggests
  16481.                           that your tables are not properly indexed or
  16482.                           that your queries are not written to take
  16483.                           advantage of the indexes you have.
  16484. `Handler_update'          Number of requests to update a row in a table.
  16485. `Handler_write'           Number of requests to insert a row in a table.
  16486. `Key_blocks_used'         The number of used blocks in the key cache.
  16487. `Key_read_requests'       The number of requests to read a key block
  16488.                           from the cache.
  16489. `Key_reads'               The number of physical reads of a key block
  16490.                           from disk.
  16491. `Key_write_requests'      The number of requests to write a key block to
  16492.                           the cache.
  16493. `Key_writes'              The number of physical writes of a key block
  16494.                           to disk.
  16495. `Max_used_connections'    The maximum number of connections in use
  16496.                           simultaneously.
  16497. `Not_flushed_key_blocks'  Keys blocks in the key cache that has changed
  16498.                           but hasn't yet been flushed to disk.
  16499. `Not_flushed_delayed_rows'Number of rows waiting to be written in
  16500.                           `INSERT DELAY' queues.
  16501. `Open_tables'             Number of tables that are open.
  16502. `Open_files'              Number of files that are open.
  16503. `Open_streams'            Number of streams that are open (used mainly
  16504.                           for logging).
  16505. `Opened_tables'           Number of tables that have been opened.
  16506. `Select_full_join'        Number of joins without keys (Should be 0).
  16507. `Select_full_range_join'  Number of joins where we used a range search
  16508.                           on reference table.
  16509. `Select_range'            Number of joins where we used ranges on the
  16510.                           first table. (It's normally not critical even
  16511.                           if this is big.)
  16512. `Select_scan'             Number of joins where we scanned the first
  16513.                           table.
  16514. `Select_range_check'      Number of joins without keys where we check
  16515.                           for key usage after each row (Should be 0).
  16516. `Questions'               Number of queries sent to the server.
  16517. `Slave_open_temp_tables'  Number of temporary tables currently open by
  16518.                           the slave thread
  16519. `Slow_launch_threads'     Number of threads that have taken more than
  16520.                           `slow_launch_time' to connect.
  16521. `Slow_queries'            Number of queries that have taken more than
  16522.                           `long_query_time'. *Note Slow query log::.
  16523. `Sort_merge_passes'       Number of merges the sort has to do. If this
  16524.                           value is large you should consider increasing
  16525.                           `sort_buffer'.
  16526. `Sort_range'              Number of sorts that where done with ranges.
  16527. `Sort_rows'               Number of sorted rows.
  16528. `Sort_scan'               Number of sorts that where done by scanning
  16529.                           the table.
  16530. `Table_locks_immediate'   Number of times a table lock was acquired
  16531.                           immediately. Available after 3.23.33.
  16532. `Table_locks_waited'      Number of times a table lock could not be
  16533.                           acquired immediately and a wait was needed. If
  16534.                           this is high, and you have performance
  16535.                           problems, you should first optimize your
  16536.                           queries, and then either split your table(s)
  16537.                           or use replication. Available after 3.23.33.
  16538. `Threads_cached'          Number of threads in the thread cache.
  16539. `Threads_connected'       Number of currently open connections.
  16540. `Threads_created'         Number of threads created to handle
  16541.                           connections.
  16542. `Threads_running'         Number of threads that are not sleeping.
  16543. `Uptime'                  How many seconds the server has been up.
  16544.  
  16545. Some comments about the above:
  16546.  
  16547.    * If `Opened_tables' is big, then your `table_cache' variable is
  16548.      probably too small.
  16549.  
  16550.    * If `key_reads' is big, then your `key_cache' is probably too
  16551.      small.  The cache hit rate can be calculated with
  16552.      `key_reads'/`key_read_requests'.
  16553.  
  16554.    * If `Handler_read_rnd' is big, then you probably have a lot of
  16555.      queries that require MySQL to scan whole tables or you have joins
  16556.      that don't use keys properly.
  16557.  
  16558.    * If `Threads_created' is big, you may want to increase the
  16559.      `thread_cache_size' variable.
  16560.  
  16561. `SHOW VARIABLES'
  16562. ................
  16563.  
  16564.      SHOW VARIABLES [LIKE wild]
  16565.  
  16566. `SHOW VARIABLES' shows the values of some MySQL system variables.  You
  16567. can also get this information using the `mysqladmin variables' command.
  16568. If the default values are unsuitable, you can set most of these
  16569. variables using command-line options when `mysqld' starts up.  *Note
  16570. Command-line options::.
  16571.  
  16572. The output resembles that shown below, though the format and numbers may
  16573. differ somewhat:
  16574.  
  16575.      +-------------------------+---------------------------+
  16576.      | Variable_name           | Value                     |
  16577.      +-------------------------+---------------------------+
  16578.      | ansi_mode               | OFF                       |
  16579.      | back_log                | 50                        |
  16580.      | basedir                 | /my/monty/                |
  16581.      | bdb_cache_size          | 16777216                  |
  16582.      | bdb_log_buffer_size     | 32768                     |
  16583.      | bdb_home                | /my/monty/data/           |
  16584.      | bdb_max_lock            | 10000                     |
  16585.      | bdb_logdir              |                           |
  16586.      | bdb_shared_data         | OFF                       |
  16587.      | bdb_tmpdir              | /tmp/                     |
  16588.      | binlog_cache_size       | 32768                     |
  16589.      | concurrent_insert       | ON                        |
  16590.      | connect_timeout         | 5                         |
  16591.      | datadir                 | /my/monty/data/           |
  16592.      | delay_key_write         | ON                        |
  16593.      | delayed_insert_limit    | 100                       |
  16594.      | delayed_insert_timeout  | 300                       |
  16595.      | delayed_queue_size      | 1000                      |
  16596.      | flush                   | OFF                       |
  16597.      | flush_time              | 0                         |
  16598.      | have_bdb                | YES                       |
  16599.      | have_innodb             | YES                       |
  16600.      | have_raid               | YES                       |
  16601.      | have_ssl                | NO                        |
  16602.      | init_file               |                           |
  16603.      | interactive_timeout     | 28800                     |
  16604.      | join_buffer_size        | 131072                    |
  16605.      | key_buffer_size         | 16776192                  |
  16606.      | language                | /my/monty/share/english/  |
  16607.      | large_files_support     | ON                        |
  16608.      | log                     | OFF                       |
  16609.      | log_update              | OFF                       |
  16610.      | log_bin                 | OFF                       |
  16611.      | log_slave_updates       | OFF                       |
  16612.      | long_query_time         | 10                        |
  16613.      | low_priority_updates    | OFF                       |
  16614.      | lower_case_table_names  | 0                         |
  16615.      | max_allowed_packet      | 1048576                   |
  16616.      | max_binlog_cache_size   | 4294967295                |
  16617.      | max_connections         | 100                       |
  16618.      | max_connect_errors      | 10                        |
  16619.      | max_delayed_threads     | 20                        |
  16620.      | max_heap_table_size     | 16777216                  |
  16621.      | max_join_size           | 4294967295                |
  16622.      | max_sort_length         | 1024                      |
  16623.      | max_tmp_tables          | 32                        |
  16624.      | max_write_lock_count    | 4294967295                |
  16625.      | myisam_recover_options  | DEFAULT                   |
  16626.      | myisam_sort_buffer_size | 8388608                   |
  16627.      | net_buffer_length       | 16384                     |
  16628.      | net_read_timeout        | 30                        |
  16629.      | net_retry_count         | 10                        |
  16630.      | net_write_timeout       | 60                        |
  16631.      | open_files_limit        | 0                         |
  16632.      | pid_file                | /my/monty/data/donna.pid  |
  16633.      | port                    | 3306                      |
  16634.      | protocol_version        | 10                        |
  16635.      | record_buffer           | 131072                    |
  16636.      | query_buffer_size       | 0                         |
  16637.      | safe_show_database      | OFF                       |
  16638.      | server_id               | 0                         |
  16639.      | skip_locking            | ON                        |
  16640.      | skip_networking         | OFF                       |
  16641.      | skip_show_database      | OFF                       |
  16642.      | slow_launch_time        | 2                         |
  16643.      | socket                  | /tmp/mysql.sock           |
  16644.      | sort_buffer             | 2097116                   |
  16645.      | table_cache             | 64                        |
  16646.      | table_type              | MYISAM                    |
  16647.      | thread_cache_size       | 4                         |
  16648.      | thread_stack            | 65536                     |
  16649.      | tmp_table_size          | 1048576                   |
  16650.      | tmpdir                  | /tmp/                     |
  16651.      | version                 | 3.23.29a-gamma-debug      |
  16652.      | wait_timeout            | 28800                     |
  16653.      +-------------------------+---------------------------+
  16654.  
  16655. Each option is described below. Values for buffer sizes, lengths, and
  16656. stack sizes are given in bytes.  You can specify values with a suffix
  16657. of `K' or `M' to indicate kilobytes or megabytes. For example, `16M'
  16658. indicates 16 megabytes.  The case of suffix letters does not matter;
  16659. `16M' and `16m' are equivalent:
  16660.  
  16661. ``ansi_mode'.'
  16662.      Is `ON' if `mysqld' was started with `--ansi'.  *Note ANSI mode::.
  16663.  
  16664. ``back_log''
  16665.      The number of outstanding connection requests MySQL can have. This
  16666.      comes into play when the main MySQL thread gets *VERY* many
  16667.      connection requests in a very short time. It then takes some time
  16668.      (although very little) for the main thread to check the connection
  16669.      and start a new thread. The `back_log' value indicates how many
  16670.      requests can be stacked during this short time before MySQL
  16671.      momentarily stops answering new requests. You need to increase
  16672.      this only if you expect a large number of connections in a short
  16673.      period of time.
  16674.  
  16675.      In other words, this value is the size of the listen queue for
  16676.      incoming TCP/IP connections.  Your operating system has its own
  16677.      limit on the size of this queue.  The manual page for the Unix
  16678.      `listen(2)' system call should have more details.  Check your OS
  16679.      documentation for the maximum value for this variable.  Attempting
  16680.      to set `back_log' higher than your operating system limit will be
  16681.      ineffective.
  16682.  
  16683. ``basedir''
  16684.      The value of the `--basedir' option.
  16685.  
  16686. ``bdb_cache_size''
  16687.      The buffer that is allocated to cache index and rows for `BDB'
  16688.      tables.  If you don't use `BDB' tables, you should start `mysqld'
  16689.      with `--skip-bdb' to not waste memory for this cache.
  16690.  
  16691. ``bdb_log_buffer_size''
  16692.      The buffer that is allocated to cache index and rows for `BDB'
  16693.      tables.  If you don't use `BDB' tables, you should set this to 0 or
  16694.      start `mysqld' with `--skip-bdb' to not waste memory for this
  16695.      cache.
  16696.  
  16697. ``bdb_home''
  16698.      The value of the `--bdb-home' option.
  16699.  
  16700. ``bdb_max_lock''
  16701.      The maximum number of locks (1000 by default) you can have active
  16702.      on a BDB table. You should increase this if you get errors of type
  16703.      `bdb: Lock table is out of available locks' or `Got error 12 from
  16704.      ...' when you have do long transactions or when `mysqld' has to
  16705.      examine a lot of rows to calculate the query.
  16706.  
  16707. ``bdb_logdir''
  16708.      The value of the `--bdb-logdir' option.
  16709.  
  16710. ``bdb_shared_data''
  16711.      Is `ON' if you are using `--bdb-shared-data'.
  16712.  
  16713. ``bdb_tmpdir''
  16714.      The value of the `--bdb-tmpdir' option.
  16715.  
  16716. ``binlog_cache_size'.  The size of the cache to hold the SQL'
  16717.      statements for the binary log during a transaction.  If you often
  16718.      use big, multi-statement transactions you can increase this to get
  16719.      more performance. *Note COMMIT::.
  16720.  
  16721. ``character_set''
  16722.      The default character set.
  16723.  
  16724. ``character_sets''
  16725.      The supported character sets.
  16726.  
  16727. ``concurrent_inserts''
  16728.      If `ON' (the default), MySQL will allow you to use `INSERT' on
  16729.      `MyISAM' tables at the same time as you run `SELECT' queries on
  16730.      them.  You can turn this option off by starting `mysqld' with
  16731.      `--safe' or `--skip-new'.
  16732.  
  16733. ``connect_timeout''
  16734.      The number of seconds the `mysqld' server is waiting for a connect
  16735.      packet before responding with `Bad handshake'.
  16736.  
  16737. ``datadir''
  16738.      The value of the `--datadir' option.
  16739.  
  16740. ``delay_key_write''
  16741.      If enabled (is on by default), MySQL will honor the
  16742.      `delay_key_write' option `CREATE TABLE'.  This means that the key
  16743.      buffer for tables with this option will not get flushed on every
  16744.      index update, but only when a table is closed.  This will speed up
  16745.      writes on keys a lot, but you should add automatic checking of all
  16746.      tables with `myisamchk --fast --force' if you use this.  Note that
  16747.      if you start `mysqld' with the `--delay-key-write-for-all-tables'
  16748.      option this means that all tables will be treated as if they were
  16749.      created with the `delay_key_write' option.  You can clear this flag
  16750.      by starting `mysqld' with `--skip-new' or `--safe-mode'.
  16751.  
  16752. ``delayed_insert_limit''
  16753.      After inserting `delayed_insert_limit' rows, the `INSERT DELAYED'
  16754.      handler will check if there are any `SELECT' statements pending.
  16755.      If so, it allows these to execute before continuing.
  16756.  
  16757. ``delayed_insert_timeout''
  16758.      How long a `INSERT DELAYED' thread should wait for `INSERT'
  16759.      statements before terminating.
  16760.  
  16761. ``delayed_queue_size''
  16762.      What size queue (in rows) should be allocated for handling `INSERT
  16763.      DELAYED'.  If the queue becomes full, any client that does `INSERT
  16764.      DELAYED' will wait until there is room in the queue again.
  16765.  
  16766. ``flush''
  16767.      This is `ON' if you have started MySQL with the `--flush' option.
  16768.  
  16769. ``flush_time''
  16770.      If this is set to a non-zero value, then every `flush_time'
  16771.      seconds all tables will be closed (to free up resources and sync
  16772.      things to disk). We only recommend this option on Win95, Win98, or
  16773.      on systems where you have very little resources.
  16774.  
  16775. ``have_bdb''
  16776.      `YES' if `mysqld' supports Berkeley DB tables. `DISABLED' if
  16777.      `--skip-bdb' is used.
  16778.  
  16779. ``have_innodb''
  16780.      `YES' if `mysqld' supports InnoDB tables. `DISABLED' if
  16781.      `--skip-innodb' is used.
  16782.  
  16783. ``have_raid''
  16784.      `YES' if `mysqld' supports the `RAID' option.
  16785.  
  16786. ``have_ssl''
  16787.      `YES' if `mysqld' supports SSL (encryption) on the client/server
  16788.      protocol.
  16789.  
  16790. ``init_file''
  16791.      The name of the file specified with the `--init-file' option when
  16792.      you start the server.  This is a file of SQL statements you want
  16793.      the server to execute when it starts.
  16794.  
  16795. ``interactive_timeout''
  16796.      The number of seconds the server waits for activity on an
  16797.      interactive connection before closing it.  An interactive client
  16798.      is defined as a client that uses the `CLIENT_INTERACTIVE' option to
  16799.      `mysql_real_connect()'.  See also `wait_timeout'.
  16800.  
  16801. ``join_buffer_size''
  16802.      The size of the buffer that is used for full joins (joins that do
  16803.      not use indexes).  The buffer is allocated one time for each full
  16804.      join between two tables. Increase this value to get a faster full
  16805.      join when adding indexes is not possible. (Normally the best way
  16806.      to get fast joins is to add indexes.)
  16807.  
  16808. ``key_buffer_size''
  16809.      Index blocks are buffered and are shared by all threads.
  16810.      `key_buffer_size' is the size of the buffer used for index blocks.
  16811.  
  16812.      Increase this to get better index handling (for all reads and
  16813.      multiple writes) to as much as you can afford; 64M on a 256M
  16814.      machine that mainly runs MySQL is quite common.  If you, however,
  16815.      make this too big (more than 50% of your total memory?) your
  16816.      system may start to page and become REALLY slow. Remember that
  16817.      because MySQL does not cache data read, that you will have to
  16818.      leave some room for the OS filesystem cache.
  16819.  
  16820.      You can check the performance of the key buffer by doing `show
  16821.      status' and examine the variables `Key_read_requests',
  16822.      `Key_reads', `Key_write_requests', and `Key_writes'.  The
  16823.      `Key_reads/Key_read_request' ratio should normally be < 0.01.  The
  16824.      `Key_write/Key_write_requests' is usually near 1 if you are using
  16825.      mostly updates/deletes but may be much smaller if you tend to do
  16826.      updates that affect many at the same time or if you are using
  16827.      `delay_key_write'. *Note SHOW::.
  16828.  
  16829.      To get even more speed when writing many rows at the same time, use
  16830.      `LOCK TABLES'.  *Note `LOCK TABLES': LOCK TABLES.
  16831.  
  16832. ``language''
  16833.      The language used for error messages.
  16834.  
  16835. ``large_file_support''
  16836.      If `mysqld' was compiled with options for big file support.
  16837.  
  16838. ``locked_in_memory''
  16839.      If `mysqld' was locked in memory with `--memlock'
  16840.  
  16841. ``log''
  16842.      If logging of all queries is enabled.
  16843.  
  16844. ``log_update''
  16845.      If the update log is enabled.
  16846.  
  16847. ``log_bin''
  16848.      If the binary log is enabled.
  16849.  
  16850. ``log_slave_updates''
  16851.      If the updates from the slave should be logged.
  16852.  
  16853. ``long_query_time''
  16854.      If a query takes longer than this (in seconds), the `Slow_queries'
  16855.      counter will be incremented. If you are using
  16856.      `--log-slow-queries', the query will be logged to the slow query
  16857.      logfile. *Note Slow query log::.
  16858.  
  16859. ``lower_case_table_names''
  16860.      If set to 1 table names are stored in lowercase on disk and table
  16861.      names will be case-insensitive.  *Note Name case sensitivity::.
  16862.  
  16863. ``max_allowed_packet''
  16864.      The maximum size of one packet. The message buffer is initialized
  16865.      to `net_buffer_length' bytes, but can grow up to
  16866.      `max_allowed_packet' bytes when needed.  This value by default is
  16867.      small, to catch big (possibly wrong) packets.  You must increase
  16868.      this value if you are using big `BLOB' columns. It should be as
  16869.      big as the biggest `BLOB' you want to use.  The current protocol
  16870.      limits `max_allowed_packet' to 16M.
  16871.  
  16872. ``max_binlog_cache_size''
  16873.      If a multi-statement transaction requires more than this amount of
  16874.      memory, one will get the error "Multi-statement transaction
  16875.      required more than 'max_binlog_cache_size' bytes of storage".
  16876.  
  16877. ``max_binlog_size''
  16878.      Available after 3.23.33. If a write to the binary (replication)
  16879.      log exceeds the given value, rotate the logs. You cannot set it to
  16880.      less than 1024 bytes, or more than 1 GB. Default is 1 GB.
  16881.  
  16882. ``max_connections''
  16883.      The number of simultaneous clients allowed. Increasing this value
  16884.      increases the number of file descriptors that `mysqld' requires.
  16885.      See below for comments on file descriptor limits. *Note Too many
  16886.      connections::.
  16887.  
  16888. ``max_connect_errors''
  16889.      If there is more than this number of interrupted connections from
  16890.      a host this host will be blocked from further connections.  You
  16891.      can unblock a host with the command `FLUSH HOSTS'.
  16892.  
  16893. ``max_delayed_threads''
  16894.      Don't start more than this number of threads to handle `INSERT
  16895.      DELAYED' statements.  If you try to insert data into a new table
  16896.      after all `INSERT DELAYED' threads are in use, the row will be
  16897.      inserted as if the `DELAYED' attribute wasn't specified.
  16898.  
  16899. ``max_heap_table_size''
  16900.      Don't allow creation of heap tables bigger than this.
  16901.  
  16902. ``max_join_size''
  16903.      Joins that are probably going to read more than `max_join_size'
  16904.      records return an error. Set this value if your users tend to
  16905.      perform joins that lack a `WHERE' clause, that take a long time,
  16906.      and that return millions of rows.
  16907.  
  16908. ``max_sort_length''
  16909.      The number of bytes to use when sorting `BLOB' or `TEXT' values
  16910.      (only the first `max_sort_length' bytes of each value are used;
  16911.      the rest are ignored).
  16912.  
  16913. ``max_user_connections''
  16914.      The maximum number of active connections for a single user (0 = no
  16915.      limit).
  16916.  
  16917. ``max_tmp_tables''
  16918.      (This option doesn't yet do anything.)  Maximum number of
  16919.      temporary tables a client can keep open at the same time.
  16920.  
  16921. ``max_write_lock_count''
  16922.      After this many write locks, allow some read locks to run in
  16923.      between.
  16924.  
  16925. ``myisam_recover_options''
  16926.      The value of the `--myisam-recover' option.
  16927.  
  16928. ``myisam_sort_buffer_size''
  16929.      The buffer that is allocated when sorting the index when doing a
  16930.      `REPAIR' or when creating indexes with `CREATE INDEX' or `ALTER
  16931.      TABLE'.
  16932.  
  16933. ``myisam_max_extra_sort_file_size'.'
  16934.      If the creating of the temporary file for fast index creation
  16935.      would be this much bigger than using the key cache, then prefer
  16936.      the key cache method.  This is mainly used to force long character
  16937.      keys in large tables to use the slower key cache method to create
  16938.      the index.  *NOTE* that this parameter is given in megabytes!
  16939.  
  16940. ``myisam_max_sort_file_size''
  16941.      The maximum size of the temporary file MySQL is allowed to use
  16942.      while recreating the index (during `REPAIR', `ALTER TABLE' or
  16943.      `LOAD DATA INFILE'.  If the file size would be bigger than this,
  16944.      the index will be created through the key cache (which is slower).
  16945.      *NOTE* that this parameter is given in megabytes!
  16946.  
  16947. ``net_buffer_length''
  16948.      The communication buffer is reset to this size between queries.
  16949.      This should not normally be changed, but if you have very little
  16950.      memory, you can set it to the expected size of a query.  (That is,
  16951.      the expected length of SQL statements sent by clients.  If
  16952.      statements exceed this length, the buffer is automatically
  16953.      enlarged, up to `max_allowed_packet' bytes.)
  16954.  
  16955. ``net_read_timeout''
  16956.      Number of seconds to wait for more data from a connection before
  16957.      aborting the read.  Note that when we don't expect data from a
  16958.      connection, the timeout is defined by `write_timeout'. See also
  16959.      `slave_read_timeout'.
  16960.  
  16961. ``net_retry_count''
  16962.      If a read on a communication port is interrupted, retry this many
  16963.      times before giving up.  This value should be quite high on
  16964.      `FreeBSD' as internal interrupts are sent to all threads.
  16965.  
  16966. ``net_write_timeout''
  16967.      Number of seconds to wait for a block to be written to a
  16968.      connection before aborting the write.
  16969.  
  16970. ``open_files_limit''
  16971.      If this is not 0, then `mysqld' will use this value to reserve file
  16972.      descriptors to use with `setrlimit()'.  If this value is 0 then
  16973.      `mysqld' will reserve `max_connections*5' or `max_connections +
  16974.      table_cache*2' (whichever is larger) number of files.  You should
  16975.      try increasing this if `mysqld' gives you the error 'Too many open
  16976.      files'.
  16977.  
  16978. ``pid_file''
  16979.      The value of the `--pid-file' option.
  16980.  
  16981. ``port''
  16982.      The value of the `--port' option.
  16983.  
  16984. ``protocol_version''
  16985.      The protocol version used by the MySQL server.
  16986.  
  16987. ``record_buffer''
  16988.      Each thread that does a sequential scan allocates a buffer of this
  16989.      size for each table it scans. If you do many sequential scans, you
  16990.      may want to increase this value.
  16991.  
  16992. ``record_rnd_buffer''
  16993.      When reading rows in sorted order after a sort, the rows are read
  16994.      through this buffer to avoid a disk seeks.  If not set, then it's
  16995.      set to the value of `record_buffer'.
  16996.  
  16997. ``query_buffer_size''
  16998.      The initial allocation of the query buffer. If most of your
  16999.      queries are long (like when inserting blobs), you should increase
  17000.      this!
  17001.  
  17002. ``safe_show_databases''
  17003.      Don't show databases for which the user doesn't have any database
  17004.      or table privileges. This can improve security if you're concerned
  17005.      about people being able to see what databases other users have.
  17006.      See also `skip_show_databases'.
  17007.  
  17008. ``server_id''
  17009.      The value of the `--server-id' option.
  17010.  
  17011. ``skip_locking''
  17012.      Is OFF if `mysqld' uses external locking.
  17013.  
  17014. ``skip_networking''
  17015.      Is ON if we only allow local (socket) connections.
  17016.  
  17017. ``skip_show_databases''
  17018.      This prevents people from doing `SHOW DATABASES' if they don't have
  17019.      the `PROCESS_PRIV' privilege. This can improve security if you're
  17020.      concerned about people being able to see what databases other users
  17021.      have. See also `safe_show_databases'.
  17022.  
  17023. ``slave_read_timeout''
  17024.      Number of seconds to wait for more data from a master/slave
  17025.      connection before aborting the read.
  17026.  
  17027. ``slow_launch_time''
  17028.      If creating the thread takes longer than this value (in seconds),
  17029.      the `Slow_launch_threads' counter will be incremented.
  17030.  
  17031. ``socket''
  17032.      The Unix socket used by the server.
  17033.  
  17034. ``sort_buffer''
  17035.      Each thread that needs to do a sort allocates a buffer of this
  17036.      size. Increase this value for faster `ORDER BY' or `GROUP BY'
  17037.      operations.  *Note Temporary files::.
  17038.  
  17039. ``table_cache''
  17040.      The number of open tables for all threads. Increasing this value
  17041.      increases the number of file descriptors that `mysqld' requires.
  17042.      MySQL needs two file descriptors for each unique open table.  See
  17043.      below for comments on file descriptor limits. You can check if you
  17044.      need to increase the table cache by checking the `Opened_tables'
  17045.      variable. *Note SHOW::.  If this variable is big and you don't do
  17046.      `FLUSH TABLES' a lot (which just forces all tables to be closed and
  17047.      reopenend), then you should increase the value of this variable.
  17048.  
  17049.      Make sure that your operating system can handle the number of open
  17050.      file descriptors implied by the `table_cache' setting.  If
  17051.      `table_cache' is set too high, MySQL may run out of file
  17052.      descriptors and refuse connections, fail to perform queries, and
  17053.      be very unreliable.
  17054.  
  17055.      For information about how the table cache works, see *Note Table
  17056.      cache::.
  17057.  
  17058. ``table_type''
  17059.      The default table type
  17060.  
  17061. ``thread_cache_size''
  17062.      How many threads we should keep in a cache for reuse.  When a
  17063.      client disconnects, the client's threads are put in the cache if
  17064.      there aren't more than `thread_cache_size' threads from before.
  17065.      All new threads are first taken from the cache, and only when the
  17066.      cache is empty is a new thread created.  This variable can be
  17067.      increased to improve performance if you have a lot of new
  17068.      connections. (Normally this doesn't give a notable performance
  17069.      improvement if you have a good thread implementation.)  By examing
  17070.      the difference between the `Connections' and `Threads_created' you
  17071.      can see how efficient the current thread cache is for you.
  17072.  
  17073. ``thread_concurrency''
  17074.      On Solaris, `mysqld' will call `thr_setconcurrency()' with this
  17075.      value.  `thr_setconcurrency()' permits the application to give the
  17076.      threads system a hint for the desired number of threads that should
  17077.      be run at the same time.
  17078.  
  17079. ``thread_stack''
  17080.      The stack size for each thread.  Many of the limits detected by the
  17081.      `crash-me' test are dependent on this value. The default is large
  17082.      enough for normal operation.  *Note MySQL Benchmarks::.
  17083.  
  17084. ``timezone''
  17085.      The timezone for the server.
  17086.  
  17087. ``tmp_table_size''
  17088.      If an in-memory temporary table exceeds this size, MySQL will
  17089.      automatically convert it to an on-disk `MyISAM' table.  Increase
  17090.      the value of `tmp_table_size' if you do many advanced `GROUP BY'
  17091.      queries and you have lots of memory.
  17092.  
  17093. ``tmpdir''
  17094.      The directory used for temporary files and temporary tables.
  17095.  
  17096. ``version''
  17097.      The version number for the server.
  17098.  
  17099. ``wait_timeout''
  17100.      The number of seconds the server waits for activity on a
  17101.      connection before closing it. See also `interactive_timeout'.
  17102.  
  17103. The manual section that describes tuning MySQL contains some
  17104. information of how to tune the above variables. *Note Server
  17105. parameters::.
  17106.  
  17107. `SHOW LOGS'
  17108. ...........
  17109.  
  17110. `SHOW LOGS' shows you status information about existing log files.  It
  17111. currently only displays information about Berkeley DB log files.
  17112.  
  17113.    * `File' shows the full path to the log file
  17114.  
  17115.    * `Type' shows the type of the log file (`BDB' for Berkeley DB log
  17116.      files)
  17117.  
  17118.    * `Status' shows the status of the log file (`FREE' if the file can
  17119.      be removed, or `IN USE' if the file is needed by the transaction
  17120.      subsystem)
  17121.  
  17122. `SHOW PROCESSLIST'
  17123. ..................
  17124.  
  17125. `SHOW PROCESSLIST' shows you which threads are running.  You can also
  17126. get this information using the `mysqladmin processlist' command.  If
  17127. you have the *process* privilege, you can see all threads.  Otherwise,
  17128. you can see only your own threads.  *Note `KILL': KILL.  If you don't
  17129. use the `FULL' option, then only the first 100 characters of each query
  17130. will be shown.
  17131.  
  17132. This command is very useful if you get the 'too many connections' error
  17133. message and want to find out what's going on. MySQL reserves one extra
  17134. connection for a client with the `Process_priv' privilege to ensure
  17135. that you should always be able to login and check the system (assuming
  17136. you are not giving this privilege to all your users).
  17137.  
  17138. `SHOW GRANTS'
  17139. .............
  17140.  
  17141. `SHOW GRANTS FOR user' lists the grant commands that must be issued to
  17142. duplicate the grants for a user.
  17143.  
  17144.      mysql> SHOW GRANTS FOR root@localhost;
  17145.      +---------------------------------------------------------------------+
  17146.      | Grants for root@localhost                                           |
  17147.      +---------------------------------------------------------------------+
  17148.      | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
  17149.      +---------------------------------------------------------------------+
  17150.  
  17151. `SHOW CREATE TABLE'
  17152. ...................
  17153.  
  17154. Shows a `CREATE TABLE' statement that will create the given table:
  17155.  
  17156.      mysql> show create table t\G
  17157.      *************************** 1. row ***************************
  17158.             Table: t
  17159.      Create Table: CREATE TABLE t (
  17160.        id int(11) default NULL auto_increment,
  17161.        s char(60) default NULL,
  17162.        PRIMARY KEY (id)
  17163.      ) TYPE=MyISAM
  17164.  
  17165. `SHOW CREATE TABLE' will quote table and column names according to
  17166. `SQL_QUOTE_SHOW_CREATE' option.  *Note `SET OPTION
  17167. SQL_QUOTE_SHOW_CREATE': SET OPTION.
  17168.  
  17169. MySQL Localization and International Usage
  17170. ==========================================
  17171.  
  17172. The Character Set Used for Data and Sorting
  17173. -------------------------------------------
  17174.  
  17175. By default, MySQL uses the ISO-8859-1 (Latin1) character set with
  17176. sorting according to Swedish/Finnish. This is the character set suitable
  17177. in the USA and western Europe.
  17178.  
  17179. All standard MySQL binaries are compiled with
  17180. `--with-extra-charsets=complex'.  This will add code to all standard
  17181. programs to be able to handle `latin1' and all multi-byte character
  17182. sets within the binary. Other character sets will be loaded from a
  17183. character-set definition file when needed.
  17184.  
  17185. The character set determines what characters are allowed in names and
  17186. how things are sorted by the `ORDER BY' and `GROUP BY' clauses of the
  17187. `SELECT' statement.
  17188.  
  17189. You can change the character set with the `--default-character-set'
  17190. option when you start the server.  The character sets available depend
  17191. on the `--with-charset=charset' and `--with-extra-charset=
  17192. list-of-charset | complex | all' options to `configure', and the
  17193. character set configuration files listed in `SHAREDIR/charsets/Index'.
  17194. *Note configure options::.
  17195.  
  17196. If you change the character set when running MySQL (which may also
  17197. change the sort order), you must run myisamchk -r -q on all tables.
  17198. Otherwise your indexes may not be ordered correctly.
  17199.  
  17200. When a client connects to a MySQL server, the server sends the default
  17201. character set in use to the client.  The client will switch to use this
  17202. character set for this connection.
  17203.  
  17204. One should use `mysql_real_escape_string()' when escaping strings for a
  17205. SQL query.  `mysql_real_escape_string()' is identical to the old
  17206. `mysql_escape_string()' function, except that it takes the MYSQL
  17207. connection handle as the first parameter.
  17208.  
  17209. If the client is compiled with different paths than where the server is
  17210. installed and the user who configured MySQL didn't included all
  17211. character sets in the MySQL binary, one must specify for the client
  17212. where it can find the additional character sets it will need if the
  17213. server runs with a different character set than the client.
  17214.  
  17215. One can specify this by putting in a MySQL option file:
  17216.  
  17217.      [client]
  17218.      character-sets-dir=/usr/local/mysql/share/mysql/charsets
  17219.  
  17220. where the path points to where the dynamic MySQL character sets are
  17221. stored.
  17222.  
  17223. One can force the client to use specific character set by specifying:
  17224.  
  17225.      [client]
  17226.      default-character-set=character-set-name
  17227.  
  17228. but normally this is never needed.
  17229.  
  17230. Non-English Error Messages
  17231. --------------------------
  17232.  
  17233. `mysqld' can issue error messages in the following languages: Czech,
  17234. Danish, Dutch, English (the default), Estonian, French, German, Greek,
  17235. Hungarian, Italian, Japanese, Korean, Norwegian, Norwegian-ny, Polish,
  17236. Portuguese, Romanian, Russian, Slovak, Spanish, and Swedish.
  17237.  
  17238. To start `mysqld' with a particular language, use either the
  17239. `--language=lang' or `-L lang' options. For example:
  17240.  
  17241.      shell> mysqld --language=swedish
  17242.  
  17243. or:
  17244.  
  17245.      shell> mysqld --language=/usr/local/share/swedish
  17246.  
  17247. Note that all language names are specified in lowercase.
  17248.  
  17249. The language files are located (by default) in
  17250. `MYSQL_BASE_DIR/share/LANGUAGE/'.
  17251.  
  17252. To update the error message file, you should edit the `errmsg.txt' file
  17253. and execute the following command to generate the `errmsg.sys' file:
  17254.  
  17255.      shell> comp_err errmsg.txt errmsg.sys
  17256.  
  17257. If you upgrade to a newer version of MySQL, remember to repeat your
  17258. changes with the new `errmsg.txt' file.
  17259.  
  17260. Adding a New Character Set
  17261. --------------------------
  17262.  
  17263. To add another character set to MySQL, use the following procedure.
  17264.  
  17265. Decide if the set is simple or complex.  If the character set does not
  17266. need to use special string collating routines for sorting and does not
  17267. need multi-byte character support, it is simple.  If it needs either of
  17268. those features, it is complex.
  17269.  
  17270. For example, `latin1' and `danish' are simple charactersets while
  17271. `big5' or `czech' are complex character sets.
  17272.  
  17273. In the following section, we have assumed that you name your character
  17274. set `MYSET'.
  17275.  
  17276. For a simple character set do the following:
  17277.  
  17278.   1. Add MYSET to the end of the `sql/share/charsets/Index' file Assign
  17279.      an unique number to it.
  17280.  
  17281.   2. Create the file `sql/share/charsets/MYSET.conf'.  (You can use
  17282.      `sql/share/charsets/latin1.conf' as a base for this).
  17283.  
  17284.      The syntax for the file very simple:
  17285.  
  17286.         * Comments start with a '#' character and proceed to the end of
  17287.           the line.
  17288.  
  17289.         * Words are separated by arbitrary amounts of whitespace.
  17290.  
  17291.         * When defining the character set, every word must be a number
  17292.           in hexadecimal format
  17293.  
  17294.         * The `ctype' array takes up the first 257 words. The
  17295.           `to_lower', `to_upper' and `sort_order' arrays take up 256
  17296.           words each after that.
  17297.  
  17298.      *Note Character arrays::.
  17299.  
  17300.   3. Add the character set name to the `CHARSETS_AVAILABLE' and
  17301.      `COMPILED_CHARSETS' lists in `configure.in'.
  17302.  
  17303.   4. Reconfigure, recompile, and test.
  17304.  
  17305.  
  17306. For a complex character set do the following:
  17307.  
  17308.   1. Create the file `strings/ctype-MYSET.c' in the MySQL source
  17309.      distribution.
  17310.  
  17311.   2. Add MYSET to the end of the `sql/share/charsets/Index' file.
  17312.      Assign an unique number to it.
  17313.  
  17314.   3. Look at one of the existing `ctype-*.c' files to see what needs to
  17315.      be defined, for example `strings/ctype-big5.c'. Note that the
  17316.      arrays in your file must have names like `ctype_MYSET',
  17317.      `to_lower_MYSET', and so on.  This corresponds to the arrays in
  17318.      the simple character set. *Note Character arrays::.  For a complex
  17319.      character set
  17320.  
  17321.   4. Near the top of the file, place a special comment like this:
  17322.  
  17323.           /*
  17324.            * This comment is parsed by configure to create ctype.c,
  17325.            * so don't change it unless you know what you are doing.
  17326.            *
  17327.            * .configure. number_MYSET=MYNUMBER
  17328.            * .configure. strxfrm_multiply_MYSET=N
  17329.            * .configure. mbmaxlen_MYSET=N
  17330.            */
  17331.  
  17332.      The `configure' program uses this comment to include the character
  17333.      set into the MySQL library automatically.
  17334.  
  17335.      The strxfrm_multiply and mbmaxlen lines will be explained in the
  17336.      following sections.  Only include them if you the string collating
  17337.      functions or the multi-byte character set functions, respectively.
  17338.  
  17339.   5. You should then create some of the following functions:
  17340.  
  17341.         * `my_strncoll_MYSET()'
  17342.  
  17343.         * `my_strcoll_MYSET()'
  17344.  
  17345.         * `my_strxfrm_MYSET()'
  17346.  
  17347.         * `my_like_range_MYSET()'
  17348.  
  17349.      *Note String collating::.
  17350.  
  17351.   6. Add the character set name to the `CHARSETS_AVAILABLE' and
  17352.      `COMPILED_CHARSETS' lists in `configure.in'.
  17353.  
  17354.   7. Reconfigure, recompile, and test.
  17355.  
  17356. The file `sql/share/charsets/README' includes some more instructions.
  17357.  
  17358. If you want to have the character set included in the MySQL
  17359. distribution, mail a patch to <internals@lists.mysql.com>.
  17360.  
  17361. The character definition arrays
  17362. -------------------------------
  17363.  
  17364. `to_lower[]' and `to_upper[]' are simple arrays that hold the lowercase
  17365. and uppercase characters corresponding to each member of the character
  17366. set.  For example:
  17367.  
  17368.      to_lower['A'] should contain 'a'
  17369.      to_upper['a'] should contain 'A'
  17370.  
  17371. `sort_order[]' is a map indicating how characters should be ordered for
  17372. comparison and sorting purposes.  For many character sets, this is the
  17373. same as `to_upper[]' (which means sorting will be case insensitive).
  17374. MySQL will sort characters based on the value of
  17375. `sort_order[character]'.  For more complicated sorting rules, see the
  17376. discussion of string collating below. *Note String collating::.
  17377.  
  17378. `ctype[]' is an array of bit values, with one element for one character.
  17379. (Note that `to_lower[]', `to_upper[]', and `sort_order[]' are indexed
  17380. by character value, but `ctype[]' is indexed by character value + 1.
  17381. This is an old legacy to be able to handle EOF.)
  17382.  
  17383. You can find the following bitmask definitions in `m_ctype.h':
  17384.  
  17385.      #define _U      01      /* Uppercase */
  17386.      #define _L      02      /* Lowercase */
  17387.      #define _N      04      /* Numeral (digit) */
  17388.      #define _S      010     /* Spacing character */
  17389.      #define _P      020     /* Punctuation */
  17390.      #define _C      040     /* Control character */
  17391.      #define _B      0100    /* Blank */
  17392.      #define _X      0200    /* heXadecimal digit */
  17393.  
  17394. The `ctype[]' entry for each character should be the union of the
  17395. applicable bitmask values that describe the character.  For example,
  17396. `'A'' is an uppercase character (`_U') as well as a hexadecimal digit
  17397. (`_X'), so `ctype['A'+1]' should contain the value:
  17398.  
  17399.      _U + _X = 01 + 0200 = 0201
  17400.  
  17401. String Collating Support
  17402. ------------------------
  17403.  
  17404. If the sorting rules for your language are too complex to be handled
  17405. with the simple `sort_order[]' table, you need to use the string
  17406. collating functions.
  17407.  
  17408. Right now the best documentation on this is the character sets that are
  17409. already implemented.  Look at the big5, czech, gbk, sjis, and tis160
  17410. character sets for examples.
  17411.  
  17412. You must specify the `strxfrm_multiply_MYSET=N' value in the special
  17413. comment at the top of the file.  `N' should be set to the maximum ratio
  17414. the strings may grow during `my_strxfrm_MYSET' (it must be a positive
  17415. integer).
  17416.  
  17417. Multi-byte Character Support
  17418. ----------------------------
  17419.  
  17420. If your want to add support for a new character set that includes
  17421. multi-byte characters, you need to use the multi-byte character
  17422. functions.
  17423.  
  17424. Right now the best documentation on this is the character sets that are
  17425. already implemented.  Look at the euc_kr, gb2312, gbk, sjis and ujis
  17426. character sets for examples. These are implemented in the
  17427. `ctype-'charset'.c' files in the `strings' directory.
  17428.  
  17429. You must specify the `mbmaxlen_MYSET=N' value in the special comment at
  17430. the top of the source file.  `N' should be set to the size in bytes of
  17431. the largest character in the set.
  17432.  
  17433. MySQL Server-Side Scripts and Utilities
  17434. =======================================
  17435.  
  17436. Overview of the Server-Side Scripts and Utilities
  17437. -------------------------------------------------
  17438.  
  17439. All MySQL clients that communicate with the server using the
  17440. `mysqlclient' library use the following environment variables:
  17441.  
  17442. *Name*             *Description*
  17443. `MYSQL_UNIX_PORT'  The default socket; used for connections to
  17444.                    `localhost'
  17445. `MYSQL_TCP_PORT'   The default TCP/IP port
  17446. `MYSQL_PWD'        The default password
  17447. `MYSQL_DEBUG'      Debug-trace options when debugging
  17448. `TMPDIR'           The directory where temporary tables/files are created
  17449.  
  17450. Use of `MYSQL_PWD' is insecure.  *Note Connecting::.
  17451.  
  17452. The `mysql' client uses the file named in the `MYSQL_HISTFILE'
  17453. environment variable to save the command-line history. The default
  17454. value for the history file is `$HOME/.mysql_history', where `$HOME' is
  17455. the value of the `HOME' environment variable. *Note Environment
  17456. variables::.
  17457.  
  17458. All MySQL programs take many different options. However, every MySQL
  17459. program provides a `--help' option that you can use to get a full
  17460. description of the program's different options. For example, try `mysql
  17461. --help'.
  17462.  
  17463. You can override default options for all standard client programs with
  17464. an option file. *Note Option files::.
  17465.  
  17466. The list below briefly describes the MySQL programs:
  17467.  
  17468. `myisamchk'
  17469.      Utility to describe, check, optimize, and repair MySQL tables.
  17470.      Because `myisamchk' has many functions, it is described in its own
  17471.      chapter. *Note MySQL Database Administration::.
  17472.  
  17473. `make_binary_distribution'
  17474.      Makes a binary release of a compiled MySQL. This could be sent by
  17475.      FTP to `/pub/mysql/Incoming' on `support.mysql.com' for the
  17476.      convenience of other MySQL users.
  17477.  
  17478. `msql2mysql'
  17479.      A shell script that converts `mSQL' programs to MySQL. It doesn't
  17480.      handle all cases, but it gives a good start when converting.
  17481.  
  17482. `mysqlaccess'
  17483.      A script that checks the access privileges for a host, user, and
  17484.      database combination.
  17485.  
  17486. `mysqladmin'
  17487.      Utility for performing administrative operations, such as creating
  17488.      or dropping databases, reloading the grant tables, flushing tables
  17489.      to disk, and reopening log files.  `mysqladmin' can also be used
  17490.      to retrieve version, process, and status information from the
  17491.      server.  *Note `mysqladmin': mysqladmin.
  17492.  
  17493. `mysqlbug'
  17494.      The MySQL bug report script.  This script should always be used
  17495.      when filing a bug report to the MySQL list.
  17496.  
  17497. `mysqld'
  17498.      The SQL daemon. This should always be running.
  17499.  
  17500. `mysqldump'
  17501.      Dumps a MySQL database into a file as SQL statements or as
  17502.      tab-separated text files. Enhanced freeware originally by Igor
  17503.      Romanenko.  *Note `mysqldump': mysqldump.
  17504.  
  17505. `mysqlimport'
  17506.      Imports text files into their respective tables using `LOAD DATA
  17507.      INFILE'. *Note `mysqlimport': mysqlimport.
  17508.  
  17509. `mysqlshow'
  17510.      Displays information about databases, tables, columns, and indexes.
  17511.  
  17512. `mysql_install_db'
  17513.      Creates the MySQL grant tables with default privileges. This is
  17514.      usually executed only once, when first installing MySQL on a
  17515.      system.
  17516.  
  17517. `replace'
  17518.      A utility program that is used by `msql2mysql', but that has more
  17519.      general applicability as well.  `replace' changes strings in place
  17520.      in files or on the standard input. Uses a finite state machine to
  17521.      match longer strings first. Can be used to swap strings. For
  17522.      example, this command swaps `a' and `b' in the given files:
  17523.  
  17524.           shell> replace a b b a -- file1 file2 ...
  17525.  
  17526. safe_mysqld, the wrapper around mysqld
  17527. --------------------------------------
  17528.  
  17529. `safe_mysqld' is the recommended way to start a `mysqld' daemon on
  17530. Unix.  `safe_mysqld' adds some safety features such as restarting the
  17531. server when an error occurs and logging run-time information to a log
  17532. file.
  17533.  
  17534. If you don't use `--mysqld=#' or `--mysqld-version=#' `safe_mysqld'
  17535. will use an executable named `mysqld-max' if it exists. If not,
  17536. `safe_mysqld' will start `mysqld'.  This makes it very easy to test to
  17537. use `mysqld-max' instead of `mysqld';  Just copy `mysqld-max' to where
  17538. you have `mysqld' and it will be used.
  17539.  
  17540. Normally one should never edit the `safe_mysqld' script, but instead
  17541. put the options to `safe_mysqld' in the `[safe_mysqld]' section in the
  17542. `my.cnf' file. `safe_mysqld' will read all options from the `[mysqld]',
  17543. `[server]' and `[safe_mysqld]' sections from the option files.  *Note
  17544. Option files::.
  17545.  
  17546. Note that all options on the command line to `safe_mysqld' are passed
  17547. to `mysqld'.  If you wants to use any options in `safe_mysqld' that
  17548. `mysqld' doesn't support, you must specify these in the option file.
  17549.  
  17550. Most of the options to `safe_mysqld' are the same as the options to
  17551. `mysqld'. *Note Command-line options::.
  17552.  
  17553. `safe_mysqld' supports the following options:
  17554.  
  17555. `--basedir=path'
  17556.  
  17557. `--core-file-size=#'
  17558.      Size of the core file `mysqld' should be able to create. Passed to
  17559.      `ulimit -c'.
  17560.  
  17561. `--datadir=path'
  17562.  
  17563. `--defaults-extra-file=path'
  17564.  
  17565. `--defaults-file=path'
  17566.  
  17567. `--err-log=path'
  17568.  
  17569. `--ledir=path'
  17570.      Path to `mysqld'
  17571.  
  17572. `--log=path'
  17573.  
  17574. `--mysqld=mysqld-version'
  17575.      Name of the `mysqld' version in the `ledir' directory you want to
  17576.      start.
  17577.  
  17578. `--mysqld-version=version'
  17579.      Similar to `--mysqld=' but here you only give the suffix for
  17580.      `mysqld'.  For example if you use `--mysqld-version=max',
  17581.      `safe_mysqld' will start the `ledir/mysqld-max' version.  If the
  17582.      argument to `--mysqld-version' is empty, `ledir/mysqld' will be
  17583.      used.
  17584.  
  17585. `--no-defaults'
  17586.  
  17587. `--open-files-limit=#'
  17588.      Number of files `mysqld' should be able to open. Passed to `ulimit
  17589.      -n'. Note that you need to start `safe_mysqld' as root for this to
  17590.      work properly!
  17591.  
  17592. `--pid-file=path'
  17593.  
  17594. `--port=#'
  17595.  
  17596. `--socket=path'
  17597.  
  17598. `--timezone=#'
  17599.      Set the timezone (the `TZ') variable to the value of this
  17600.      parameter.
  17601.  
  17602. `--user=#'
  17603. The `safe_mysqld' script is written so that it normally is able to start
  17604. a server that was installed from either a source or a binary version of
  17605. MySQL, even if these install the server in slightly different
  17606. locations.  `safe_mysqld' expects one of these conditions to be true:
  17607.  
  17608.    * The server and databases can be found relative to the directory
  17609.      from which `safe_mysqld' is invoked.  `safe_mysqld' looks under
  17610.      its working directory for `bin' and `data' directories (for binary
  17611.      distributions) or for `libexec' and `var' directories (for source
  17612.      distributions).  This condition should be met if you execute
  17613.      `safe_mysqld' from your MySQL installation directory (for example,
  17614.      `/usr/local/mysql' for a binary distribution).
  17615.  
  17616.    * If the server and databases cannot be found relative to the
  17617.      working directory, `safe_mysqld' attempts to locate them by
  17618.      absolute pathnames.  Typical locations are `/usr/local/libexec'
  17619.      and `/usr/local/var'.  The actual locations are determined when
  17620.      the distribution was built from which `safe_mysqld' comes.  They
  17621.      should be correct if MySQL was installed in a standard location.
  17622.  
  17623. Because `safe_mysqld' will try to find the server and databases relative
  17624. to its own working directory, you can install a binary distribution of
  17625. MySQL anywhere, as long as you start `safe_mysqld' from the MySQL
  17626. installation directory:
  17627.  
  17628.      shell> cd mysql_installation_directory
  17629.      shell> bin/safe_mysqld &
  17630.  
  17631. If `safe_mysqld' fails, even when invoked from the MySQL installation
  17632. directory, you can modify it to use the path to `mysqld' and the
  17633. pathname options that are correct for your system.  Note that if you
  17634. upgrade MySQL in the future, your modified version of `safe_mysqld'
  17635. will be overwritten, so you should make a copy of your edited version
  17636. that you can reinstall.
  17637.  
  17638. mysqld_multi, program for managing multiple MySQL servers
  17639. ---------------------------------------------------------
  17640.  
  17641. `mysqld_multi' is meant for managing several `mysqld' processes running
  17642. in different UNIX sockets and TCP/IP ports.
  17643.  
  17644. The program will search for group(s) named [mysqld#] from my.cnf (or the
  17645. given -config-file=...), where # can be any positive number starting
  17646. from 1. These groups should be the same as the usual `[mysqld]' group
  17647. (e.g. options to mysqld, see MySQL manual for detailed information
  17648. about this group), but with those port, socket etc. options that are
  17649. wanted for each separate `mysqld' processes. The number in the group
  17650. name has another function; it can be used for starting, stopping, or
  17651. reporting some specific `mysqld' servers with this program. See the
  17652. usage and options below for more information.
  17653.  
  17654.      Usage: mysqld_multi [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
  17655.      or     mysqld_multi [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
  17656.  
  17657. The GNR above means the group number. You can start, stop or report any
  17658. GNR, or several of them at the same time. (See -example) The GNRs list
  17659. can be comma separated, or a dash combined, of which the latter means
  17660. that all the GNRs between GNR1-GNR2 will be affected. Without GNR
  17661. argument all the found groups will be either started, stopped, or
  17662. reported. Note that you must not have any white spaces in the GNR list.
  17663. Anything after a white space is ignored.
  17664.  
  17665. `mysqld_multi' supports the following options:
  17666.  
  17667. `--config-file=...'
  17668.      Alternative config file. NOTE: This will not affect this program's
  17669.      own options (group `[mysqld_multi]'), but only groups [mysqld#].
  17670.      Without this option everything will be searched from the ordinary
  17671.      my.cnf file.
  17672.  
  17673. `--example'
  17674.      Give an example of a config file.
  17675.  
  17676. `--help'
  17677.      Print this help and exit.
  17678.  
  17679. `--log=...'
  17680.      Log file. Full path to and the name for the log file. NOTE: If the
  17681.      file exists, everything will be appended.
  17682.  
  17683. `--mysqladmin=...'
  17684.      `mysqladmin' binary to be used for a server shutdown.
  17685.  
  17686. `--mysqld=...'
  17687.      `mysqld' binary to be used. Note that you can give `safe_mysqld'
  17688.      to this option also. The options are passed to `mysqld'. Just make
  17689.      sure you have `mysqld' in your environment variable `PATH' or fix
  17690.      `safe_mysqld'.
  17691.  
  17692. `--no-log'
  17693.      Print to stdout instead of the log file. By default the log file is
  17694.      turned on.
  17695.  
  17696. `--password=...'
  17697.      Password for user for `mysqladmin'.
  17698.  
  17699. `--tcp-ip'
  17700.      Connect to the MySQL server(s) via the TCP/IP port instead of the
  17701.      UNIX socket. This affects stopping and reporting.  If a socket file
  17702.      is missing, the server may still be running, but can be accessed
  17703.      only via the TCP/IP port.  By default connecting is done via the
  17704.      UNIX socket.
  17705.  
  17706. `--user=...'
  17707.      MySQL user for `mysqladmin'.
  17708.  
  17709. `--version'
  17710.      Print the version number and exit.
  17711.  
  17712. Some notes about `mysqld_multi':
  17713.  
  17714.    * Make sure that the MySQL user, who is stopping the `mysqld'
  17715.      services (e.g using the `mysqladmin') have the same password and
  17716.      username for all the data directories accessed (to the 'mysql'
  17717.      database) And make sure that the user has the 'Shutdown_priv'
  17718.      privilege! If you have many data- directories and many different
  17719.      'mysql' databases with different passwords for the MySQL 'root'
  17720.      user, you may want to create a common 'multi_admin' user for each
  17721.      using the same password (see below). Example how to do it:
  17722.           shell> mysql -u root -S /tmp/mysql.sock -proot_password -e
  17723.           "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'multipass'"
  17724.           *Note Privileges::.
  17725.      You will have to do the above for each `mysqld' running in each
  17726.      data directory, that you have (just change the socket, -S=...)
  17727.  
  17728.    * `pid-file' is very important, if you are using `safe_mysqld' to
  17729.      start `mysqld' (e.g. -mysqld=safe_mysqld) Every `mysqld' should
  17730.      have its own `pid-file'. The advantage using `safe_mysqld' instead
  17731.      of `mysqld' directly here is, that `safe_mysqld' 'guards' every
  17732.      `mysqld' process and will restart it, if a `mysqld' process fails
  17733.      due to signal kill -9, or similar. (Like segmentation fault, which
  17734.      MySQL should never do, of course ;) Please note that `safe_mysqld'
  17735.      script may require that you start it from a certain place. This
  17736.      means that you may have to CD to a certain directory, before you
  17737.      start the `mysqld_multi'. If you have problems starting, please
  17738.      see the `safe_mysqld' script. Check especially the lines:
  17739.           --------------------------------------------------------------------------
  17740.           MY_PWD=`pwd` Check if we are starting this relative (for the binary
  17741.           release) if test -d /data/mysql -a -f ./share/mysql/english/errmsg.sys
  17742.           -a -x ./bin/mysqld
  17743.           --------------------------------------------------------------------------
  17744.           *Note `safe_mysqld': safe_mysqld.
  17745.      The above test should be successful, or you may encounter problems.
  17746.  
  17747.    * Beware of the dangers starting multiple `mysqlds' in the same data
  17748.      directory.  Use separate data directories, unless you *KNOW* what
  17749.      you are doing!
  17750.  
  17751.    * The socket file and the TCP/IP port must be different for every
  17752.      `mysqld'.
  17753.  
  17754.    * The first and fifth `mysqld' group were intentionally left out from
  17755.      the example.  You may have 'gaps' in the config file. This gives
  17756.      you more flexibility.  The order in which the `mysqlds' are
  17757.      started or stopped depends on the order in which they appear in
  17758.      the config file.
  17759.  
  17760.    * When you want to refer to a certain group using GNR with this
  17761.      program, just use the number in the end of the group name (
  17762.      [mysqld# <== ).
  17763.  
  17764.    * You may want to use option '-user' for `mysqld', but in order to
  17765.      do this you need to be root when you start the `mysqld_multi'
  17766.      script. Having the option in the config file doesn't matter; you
  17767.      will just get a warning, if you are not the superuser and the
  17768.      `mysqlds' are started under *YOUR* UNIX account. *IMPORTANT*: Make
  17769.      sure that the `pid-file' and the data directory are
  17770.      read+write(+execute for the latter one) accessible for *THAT* UNIX
  17771.      user, who the specific `mysqld' process is started as. *DON'T* use
  17772.      the UNIX root account for this, unless you *KNOW* what you are
  17773.      doing!
  17774.  
  17775.    * *MOST IMPORTANT*: Make sure that you understand the meanings of
  17776.      the options that are passed to the `mysqlds' and why *WOULD YOU
  17777.      WANT* to have separate `mysqld' processes. Starting multiple
  17778.      `mysqlds' in one data directory *WILL NOT* give you extra
  17779.      performance in a threaded system!
  17780.  
  17781. *Note Multiple servers::.
  17782.  
  17783. This is an example of the config file on behalf of `mysqld_multi'.
  17784.  
  17785.      # This file should probably be in your home dir (~/.my.cnf) or /etc/my.cnf
  17786.      # Version 2.1 by Jani Tolonen
  17787.      
  17788.      [mysqld_multi]
  17789.      mysqld     = /usr/local/bin/safe_mysqld
  17790.      mysqladmin = /usr/local/bin/mysqladmin
  17791.      user       = multi_admin
  17792.      password   = multipass
  17793.      
  17794.      [mysqld2]
  17795.      socket     = /tmp/mysql.sock2
  17796.      port       = 3307
  17797.      pid-file   = /usr/local/mysql/var2/hostname.pid2
  17798.      datadir    = /usr/local/mysql/var2
  17799.      language   = /usr/local/share/mysql/english
  17800.      user       = john
  17801.      
  17802.      [mysqld3]
  17803.      socket     = /tmp/mysql.sock3
  17804.      port       = 3308
  17805.      pid-file   = /usr/local/mysql/var3/hostname.pid3
  17806.      datadir    = /usr/local/mysql/var3
  17807.      language   = /usr/local/share/mysql/swedish
  17808.      user       = monty
  17809.      
  17810.      [mysqld4]
  17811.      socket     = /tmp/mysql.sock4
  17812.      port       = 3309
  17813.      pid-file   = /usr/local/mysql/var4/hostname.pid4
  17814.      datadir    = /usr/local/mysql/var4
  17815.      language   = /usr/local/share/mysql/estonia
  17816.      user       = tonu
  17817.      
  17818.      [mysqld6]
  17819.      socket     = /tmp/mysql.sock6
  17820.      port       = 3311
  17821.      pid-file   = /usr/local/mysql/var6/hostname.pid6
  17822.      datadir    = /usr/local/mysql/var6
  17823.      language   = /usr/local/share/mysql/japanese
  17824.      user       = jani
  17825.  
  17826. *Note Option files::.
  17827.  
  17828. myisampack, The MySQL Compressed Read-only Table Generator
  17829. ----------------------------------------------------------
  17830.  
  17831. `myisampack' is used to compress MyISAM tables, and `pack_isam' is used
  17832. to compress ISAM tables. Because ISAM tables are deprecated, we will
  17833. only discuss `myisampack' here, but everything said about `myisampack'
  17834. should also be true for `pack_isam'.
  17835.  
  17836. `myisampack' works by compressing each column in the table separately.
  17837. The information needed to decompress columns is read into memory when
  17838. the table is opened. This results in much better performance when
  17839. accessing individual records, because you only have to uncompress
  17840. exactly one record, not a much larger disk block as when using Stacker
  17841. on MS-DOS.  Usually, `myisampack' packs the data file 40%-70%.
  17842.  
  17843. MySQL uses memory mapping (`mmap()') on compressed tables and falls
  17844. back to normal read/write file usage if `mmap()' doesn't work.
  17845.  
  17846. There are currently two limitations with `myisampack':
  17847.    * After packing, the table is read-only.
  17848.  
  17849.    * `myisampack' can also pack `BLOB' or `TEXT' columns. The older
  17850.      `pack_isam' could not do this.
  17851.  
  17852. Fixing these limitations is on our TODO list but with low priority.
  17853.  
  17854. `myisampack' is invoked like this:
  17855.  
  17856.      shell> myisampack [options] filename ...
  17857.  
  17858. Each filename should be the name of an index (`.MYI') file.  If you are
  17859. not in the database directory, you should specify the pathname to the
  17860. file.  It is permissible to omit the `.MYI' extension.
  17861.  
  17862. `myisampack' supports the following options:
  17863.  
  17864. `-b, --backup'
  17865.      Make a backup of the table as `tbl_name.OLD'.
  17866.  
  17867. `-#, --debug=debug_options'
  17868.      Output debug log. The `debug_options' string often is
  17869.      `'d:t:o,filename''.
  17870.  
  17871. `-f, --force'
  17872.      Force packing of the table even if it becomes bigger or if the
  17873.      temporary file exists.  `myisampack' creates a temporary file
  17874.      named `tbl_name.TMD' while it compresses the table.  If you kill
  17875.      `myisampack', the `.TMD' file may not be deleted.  Normally,
  17876.      `myisampack' exits with an error if it finds that `tbl_name.TMD'
  17877.      exists.  With `--force', `myisampack' packs the table anyway.
  17878.  
  17879. `-?, --help'
  17880.      Display a help message and exit.
  17881.  
  17882. `-j big_tbl_name, --join=big_tbl_name'
  17883.      Join all tables named on the command line into a single table
  17884.      `big_tbl_name'.  All tables that are to be combined MUST be
  17885.      identical (same column names and types, same indexes, etc.).
  17886.  
  17887. `-p #, --packlength=#'
  17888.      Specify the record length storage size, in bytes.  The value
  17889.      should be 1, 2, or 3.  (`myisampack' stores all rows with length
  17890.      pointers of 1, 2, or 3 bytes.  In most normal cases, `myisampack'
  17891.      can determine the right length value before it begins packing the
  17892.      file, but it may notice during the packing process that it could
  17893.      have used a shorter length. In this case, `myisampack' will print
  17894.      a note that the next time you pack the same file, you could use a
  17895.      shorter record length.)
  17896.  
  17897. `-s, --silent'
  17898.      Silent mode.  Write output only when errors occur.
  17899.  
  17900. `-t, --test'
  17901.      Don't actually pack table, just test packing it.
  17902.  
  17903. `-T dir_name, --tmp_dir=dir_name'
  17904.      Use the named directory as the location in which to write the
  17905.      temporary table.
  17906.  
  17907. `-v, --verbose'
  17908.      Verbose mode.  Write information about progress and packing result.
  17909.  
  17910. `-V, --version'
  17911.      Display version information and exit.
  17912.  
  17913. `-w, --wait'
  17914.      Wait and retry if table is in use.  If the `mysqld' server was
  17915.      invoked with the `--skip-locking' option, it is not a good idea to
  17916.      invoke `myisampack' if the table might be updated during the
  17917.      packing process.
  17918.  
  17919. The sequence of commands shown below illustrates a typical table
  17920. compression session:
  17921.  
  17922.      shell> ls -l station.*
  17923.      -rw-rw-r--   1 monty    my         994128 Apr 17 19:00 station.MYD
  17924.      -rw-rw-r--   1 monty    my          53248 Apr 17 19:00 station.MYI
  17925.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  17926.      
  17927.      shell> myisamchk -dvv station
  17928.      
  17929.      MyISAM file:     station
  17930.      Isam-version:  2
  17931.      Creation time: 1996-03-13 10:08:58
  17932.      Recover time:  1997-02-02  3:06:43
  17933.      Data records:              1192  Deleted blocks:              0
  17934.      Datafile: Parts:           1192  Deleted data:                0
  17935.      Datafile pointer (bytes):     2  Keyfile pointer (bytes):     2
  17936.      Max datafile length:   54657023  Max keyfile length:   33554431
  17937.      Recordlength:               834
  17938.      Record format: Fixed length
  17939.      
  17940.      table description:
  17941.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  17942.      1   2     4   unique  unsigned long              1024       1024          1
  17943.      2   32    30  multip. text                      10240       1024          1
  17944.      
  17945.      Field Start Length Type
  17946.      1     1     1
  17947.      2     2     4
  17948.      3     6     4
  17949.      4     10    1
  17950.      5     11    20
  17951.      6     31    1
  17952.      7     32    30
  17953.      8     62    35
  17954.      9     97    35
  17955.      10    132   35
  17956.      11    167   4
  17957.      12    171   16
  17958.      13    187   35
  17959.      14    222   4
  17960.      15    226   16
  17961.      16    242   20
  17962.      17    262   20
  17963.      18    282   20
  17964.      19    302   30
  17965.      20    332   4
  17966.      21    336   4
  17967.      22    340   1
  17968.      23    341   8
  17969.      24    349   8
  17970.      25    357   8
  17971.      26    365   2
  17972.      27    367   2
  17973.      28    369   4
  17974.      29    373   4
  17975.      30    377   1
  17976.      31    378   2
  17977.      32    380   8
  17978.      33    388   4
  17979.      34    392   4
  17980.      35    396   4
  17981.      36    400   4
  17982.      37    404   1
  17983.      38    405   4
  17984.      39    409   4
  17985.      40    413   4
  17986.      41    417   4
  17987.      42    421   4
  17988.      43    425   4
  17989.      44    429   20
  17990.      45    449   30
  17991.      46    479   1
  17992.      47    480   1
  17993.      48    481   79
  17994.      49    560   79
  17995.      50    639   79
  17996.      51    718   79
  17997.      52    797   8
  17998.      53    805   1
  17999.      54    806   1
  18000.      55    807   20
  18001.      56    827   4
  18002.      57    831   4
  18003.      
  18004.      shell> myisampack station.MYI
  18005.      Compressing station.MYI: (1192 records)
  18006.      - Calculating statistics
  18007.      
  18008.      normal:     20  empty-space:      16  empty-zero:        12  empty-fill:  11
  18009.      pre-space:   0  end-space:        12  table-lookups:      5  zero:         7
  18010.      Original trees:  57  After join: 17
  18011.      - Compressing file
  18012.      87.14%
  18013.      
  18014.      shell> ls -l station.*
  18015.      -rw-rw-r--   1 monty    my         127874 Apr 17 19:00 station.MYD
  18016.      -rw-rw-r--   1 monty    my          55296 Apr 17 19:04 station.MYI
  18017.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  18018.      
  18019.      shell> myisamchk -dvv station
  18020.      
  18021.      MyISAM file:     station
  18022.      Isam-version:  2
  18023.      Creation time: 1996-03-13 10:08:58
  18024.      Recover time:  1997-04-17 19:04:26
  18025.      Data records:              1192  Deleted blocks:              0
  18026.      Datafile: Parts:           1192  Deleted data:                0
  18027.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     1
  18028.      Max datafile length:   16777215  Max keyfile length:     131071
  18029.      Recordlength:               834
  18030.      Record format: Compressed
  18031.      
  18032.      table description:
  18033.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  18034.      1   2     4   unique  unsigned long             10240       1024          1
  18035.      2   32    30  multip. text                      54272       1024          1
  18036.      
  18037.      Field Start Length Type                         Huff tree  Bits
  18038.      1     1     1      constant                             1     0
  18039.      2     2     4      zerofill(1)                          2     9
  18040.      3     6     4      no zeros, zerofill(1)                2     9
  18041.      4     10    1                                           3     9
  18042.      5     11    20     table-lookup                         4     0
  18043.      6     31    1                                           3     9
  18044.      7     32    30     no endspace, not_always              5     9
  18045.      8     62    35     no endspace, not_always, no empty    6     9
  18046.      9     97    35     no empty                             7     9
  18047.      10    132   35     no endspace, not_always, no empty    6     9
  18048.      11    167   4      zerofill(1)                          2     9
  18049.      12    171   16     no endspace, not_always, no empty    5     9
  18050.      13    187   35     no endspace, not_always, no empty    6     9
  18051.      14    222   4      zerofill(1)                          2     9
  18052.      15    226   16     no endspace, not_always, no empty    5     9
  18053.      16    242   20     no endspace, not_always              8     9
  18054.      17    262   20     no endspace, no empty                8     9
  18055.      18    282   20     no endspace, no empty                5     9
  18056.      19    302   30     no endspace, no empty                6     9
  18057.      20    332   4      always zero                          2     9
  18058.      21    336   4      always zero                          2     9
  18059.      22    340   1                                           3     9
  18060.      23    341   8      table-lookup                         9     0
  18061.      24    349   8      table-lookup                        10     0
  18062.      25    357   8      always zero                          2     9
  18063.      26    365   2                                           2     9
  18064.      27    367   2      no zeros, zerofill(1)                2     9
  18065.      28    369   4      no zeros, zerofill(1)                2     9
  18066.      29    373   4      table-lookup                        11     0
  18067.      30    377   1                                           3     9
  18068.      31    378   2      no zeros, zerofill(1)                2     9
  18069.      32    380   8      no zeros                             2     9
  18070.      33    388   4      always zero                          2     9
  18071.      34    392   4      table-lookup                        12     0
  18072.      35    396   4      no zeros, zerofill(1)               13     9
  18073.      36    400   4      no zeros, zerofill(1)                2     9
  18074.      37    404   1                                           2     9
  18075.      38    405   4      no zeros                             2     9
  18076.      39    409   4      always zero                          2     9
  18077.      40    413   4      no zeros                             2     9
  18078.      41    417   4      always zero                          2     9
  18079.      42    421   4      no zeros                             2     9
  18080.      43    425   4      always zero                          2     9
  18081.      44    429   20     no empty                             3     9
  18082.      45    449   30     no empty                             3     9
  18083.      46    479   1                                          14     4
  18084.      47    480   1                                          14     4
  18085.      48    481   79     no endspace, no empty               15     9
  18086.      49    560   79     no empty                             2     9
  18087.      50    639   79     no empty                             2     9
  18088.      51    718   79     no endspace                         16     9
  18089.      52    797   8      no empty                             2     9
  18090.      53    805   1                                          17     1
  18091.      54    806   1                                           3     9
  18092.      55    807   20     no empty                             3     9
  18093.      56    827   4      no zeros, zerofill(2)                2     9
  18094.      57    831   4      no zeros, zerofill(1)                2     9
  18095.  
  18096. The information printed by `myisampack' is described below:
  18097.  
  18098. `normal'
  18099.      The number of columns for which no extra packing is used.
  18100.  
  18101. `empty-space'
  18102.      The number of columns containing values that are only spaces;
  18103.      these will occupy 1 bit.
  18104.  
  18105. `empty-zero'
  18106.      The number of columns containing values that are only binary 0's;
  18107.      these will occupy 1 bit.
  18108.  
  18109. `empty-fill'
  18110.      The number of integer columns that don't occupy the full byte
  18111.      range of their type; these are changed to a smaller type (for
  18112.      example, an `INTEGER' column may be changed to `MEDIUMINT').
  18113.  
  18114. `pre-space'
  18115.      The number of decimal columns that are stored with leading spaces.
  18116.      In this case, each value will contain a count for the number of
  18117.      leading spaces.
  18118.  
  18119. `end-space'
  18120.      The number of columns that have a lot of trailing spaces.  In this
  18121.      case, each value will contain a count for the number of trailing
  18122.      spaces.
  18123.  
  18124. `table-lookup'
  18125.      The column had only a small number of different values, which were
  18126.      converted to an `ENUM' before Huffman compression.
  18127.  
  18128. `zero'
  18129.      The number of columns for which all values are zero.
  18130.  
  18131. `Original trees'
  18132.      The initial number of Huffman trees.
  18133.  
  18134. `After join'
  18135.      The number of distinct Huffman trees left after joining trees to
  18136.      save some header space.
  18137.  
  18138. After a table has been compressed, `myisamchk -dvv' prints additional
  18139. information about each field:
  18140.  
  18141. `Type'
  18142.      The field type may contain the following descriptors:
  18143.  
  18144.     `constant'
  18145.           All rows have the same value.
  18146.  
  18147.     `no endspace'
  18148.           Don't store endspace.
  18149.  
  18150.     `no endspace, not_always'
  18151.           Don't store endspace and don't do end space compression for
  18152.           all values.
  18153.  
  18154.     `no endspace, no empty'
  18155.           Don't store endspace. Don't store empty values.
  18156.  
  18157.     `table-lookup'
  18158.           The column was converted to an `ENUM'.
  18159.  
  18160.     `zerofill(n)'
  18161.           The most significant `n' bytes in the value are always 0 and
  18162.           are not stored.
  18163.  
  18164.     `no zeros'
  18165.           Don't store zeros.
  18166.  
  18167.     `always zero'
  18168.           0 values are stored in 1 bit.
  18169.  
  18170. `Huff tree'
  18171.      The Huffman tree associated with the field.
  18172.  
  18173. `Bits'
  18174.      The number of bits used in the Huffman tree.
  18175.  
  18176. After you have run `pack_isam'/`myisampack' you must run
  18177. `isamchk'/`myisamchk' to re-create the index.  At this time you can
  18178. also sort the index blocks and create statistics needed for the MySQL
  18179. optimizer to work more efficiently:
  18180.  
  18181.      myisamchk -rq --analyze --sort-index table_name.MYI
  18182.      isamchk   -rq --analyze --sort-index table_name.ISM
  18183.  
  18184. After you have installed the packed table into the MySQL database
  18185. directory you should do `mysqladmin flush-tables' to force `mysqld' to
  18186. start using the new table.
  18187.  
  18188. If you want to unpack a packed table, you can do this with the
  18189. `--unpack' option to `isamchk' or `myisamchk'.
  18190.  
  18191. mysqld-max, An extended mysqld server
  18192. -------------------------------------
  18193.  
  18194. `mysqld-max' is the MySQL server (`mysqld') configured with the
  18195. following configure options:
  18196.  
  18197. *Option*               *Comment*
  18198. -with-server-suffix=-maxAdd a suffix to the `mysqld' version string.
  18199. -with-bdb              Support for Berkeley DB (BDB) tables
  18200. -with-innodb           Support for InnoDB tables.
  18201. CFLAGS=-DUSE_SYMDIR    Symbolic links support for Windows.
  18202.  
  18203. You can find the MySQL-max binaries at
  18204. `http://www.mysql.com/downloads/mysql-max-3.23.html'.
  18205.  
  18206. The Windows MySQL 3.23 binary distribution includes both the standard
  18207. `mysqld.exe' binary and the `mysqld-max.exe' binary.
  18208. `http://www.mysql.com/downloads/mysql-3.23.html'.  *Note Windows
  18209. installation::.
  18210.  
  18211. Note that as Berkeley DB and InnoDB are not available for all platforms,
  18212. some of the `Max' binaries may not have support for both of these.  You
  18213. can check which table types are supported by doing the following query:
  18214.  
  18215.      mysql> show variables like "have_%";
  18216.      +---------------+-------+
  18217.      | Variable_name | Value |
  18218.      +---------------+-------+
  18219.      | have_bdb      | YES   |
  18220.      | have_innodb   | NO    |
  18221.      | have_isam     | YES   |
  18222.      | have_raid     | NO    |
  18223.      | have_ssl      | NO    |
  18224.      +---------------+-------+
  18225.  
  18226. The meaning of the values are:
  18227.  
  18228. *Value*                *Meaning*.
  18229. YES                    The option is activated and usable.
  18230. NO                     MySQL is not compiled with support for this
  18231.                        option.
  18232. DISABLED               The xxxx option is disabled because one started
  18233.                        `mysqld' with `--skip-xxxx' or because one didn't
  18234.                        start `mysqld' with all needed options to enable
  18235.                        the option.  In this case the `hostname.err' file
  18236.                        should contain a reason for why the option is
  18237.                        disabled.
  18238.  
  18239. *NOTE*:  To be able to create InnoDB tables you *MUST* edit your
  18240. startup options to include at least the `innodb_data_file_path' option.
  18241. *Note InnoDB start::.
  18242.  
  18243. To get better performance for BDB tables, you should add some
  18244. configuration options for these too. *Note BDB start::.
  18245.  
  18246. `safe_mysqld' will automatically try to start any `mysqld' binary with
  18247. the `-max' prefix. This makes it very easy to test out a another
  18248. `mysqld' binary in an existing installation.  Just run `configure' with
  18249. the options you want and then install the new `mysqld' binary as
  18250. `mysqld-max' in the same directory where your old `mysqld' binary is.
  18251. *Note `safe_mysqld': safe_mysqld.
  18252.  
  18253. The `mysqld-max' RPM uses the above mentioned `safe_mysqld' feature. It
  18254. just installs the `mysqld-max' executable and `safe_mysqld' will
  18255. automatically use this executable when `safe_mysqld' is restarted.
  18256.  
  18257. The following table shows which table types our standard *MySQL-Max*
  18258. binaries includes:
  18259.  
  18260. *System*                      *BDB*                  *InnoDB*
  18261. AIX 4.3                       N                      Y
  18262. HP-UX 11.0                    N                      Y
  18263. Linux-Alpha                   N                      Y
  18264. Linux-Intel                   Y                      Y
  18265. Linux-Ia64                    N                      Y
  18266. Solaris-intel                 N                      Y
  18267. Solaris-sparc                 Y                      Y
  18268. SCO OSR5                      Y                      Y
  18269. UnixWare                      Y                      Y
  18270. Windows/NT                    Y                      Y
  18271.  
  18272. MySQL Client-Side Scripts and Utilities
  18273. =======================================
  18274.  
  18275. Overview of the Client-Side Scripts and Utilities
  18276. -------------------------------------------------
  18277.  
  18278. All MySQL clients that communicate with the server using the
  18279. `mysqlclient' library use the following environment variables:
  18280.  
  18281. *Name*             *Description*
  18282. `MYSQL_UNIX_PORT'  The default socket; used for connections to
  18283.                    `localhost'
  18284. `MYSQL_TCP_PORT'   The default TCP/IP port
  18285. `MYSQL_PWD'        The default password
  18286. `MYSQL_DEBUG'      Debug-trace options when debugging
  18287. `TMPDIR'           The directory where temporary tables/files are created
  18288.  
  18289. Use of `MYSQL_PWD' is insecure.  *Note Connecting::.
  18290.  
  18291. The `mysql' client uses the file named in the `MYSQL_HISTFILE'
  18292. environment variable to save the command-line history. The default
  18293. value for the history file is `$HOME/.mysql_history', where `$HOME' is
  18294. the value of the `HOME' environment variable. *Note Environment
  18295. variables::.
  18296.  
  18297. All MySQL programs take many different options. However, every MySQL
  18298. program provides a `--help' option that you can use to get a full
  18299. description of the program's different options. For example, try `mysql
  18300. --help'.
  18301.  
  18302. You can override default options for all standard client programs with
  18303. an option file. *Note Option files::.
  18304.  
  18305. The list below briefly describes the MySQL programs:
  18306.  
  18307. `myisamchk'
  18308.      Utility to describe, check, optimize, and repair MySQL tables.
  18309.      Because `myisamchk' has many functions, it is described in its own
  18310.      chapter. *Note MySQL Database Administration::.
  18311.  
  18312. `make_binary_distribution'
  18313.      Makes a binary release of a compiled MySQL. This could be sent by
  18314.      FTP to `/pub/mysql/Incoming' on `support.mysql.com' for the
  18315.      convenience of other MySQL users.
  18316.  
  18317. `msql2mysql'
  18318.      A shell script that converts `mSQL' programs to MySQL. It doesn't
  18319.      handle all cases, but it gives a good start when converting.
  18320.  
  18321. `mysqlaccess'
  18322.      A script that checks the access privileges for a host, user, and
  18323.      database combination.
  18324.  
  18325. `mysqladmin'
  18326.      Utility for performing administrative operations, such as creating
  18327.      or dropping databases, reloading the grant tables, flushing tables
  18328.      to disk, and reopening log files.  `mysqladmin' can also be used
  18329.      to retrieve version, process, and status information from the
  18330.      server.  *Note `mysqladmin': mysqladmin.
  18331.  
  18332. `mysqlbug'
  18333.      The MySQL bug report script.  This script should always be used
  18334.      when filing a bug report to the MySQL list.
  18335.  
  18336. `mysqld'
  18337.      The SQL daemon. This should always be running.
  18338.  
  18339. `mysqldump'
  18340.      Dumps a MySQL database into a file as SQL statements or as
  18341.      tab-separated text files. Enhanced freeware originally by Igor
  18342.      Romanenko.  *Note `mysqldump': mysqldump.
  18343.  
  18344. `mysqlimport'
  18345.      Imports text files into their respective tables using `LOAD DATA
  18346.      INFILE'. *Note `mysqlimport': mysqlimport.
  18347.  
  18348. `mysqlshow'
  18349.      Displays information about databases, tables, columns, and indexes.
  18350.  
  18351. `mysql_install_db'
  18352.      Creates the MySQL grant tables with default privileges. This is
  18353.      usually executed only once, when first installing MySQL on a
  18354.      system.
  18355.  
  18356. `replace'
  18357.      A utility program that is used by `msql2mysql', but that has more
  18358.      general applicability as well.  `replace' changes strings in place
  18359.      in files or on the standard input. Uses a finite state machine to
  18360.      match longer strings first. Can be used to swap strings. For
  18361.      example, this command swaps `a' and `b' in the given files:
  18362.  
  18363.           shell> replace a b b a -- file1 file2 ...
  18364.  
  18365. The Command-line Tool
  18366. ---------------------
  18367.  
  18368. `mysql' is a simple SQL shell (with GNU `readline' capabilities).  It
  18369. supports interactive and non-interactive use. When used interactively,
  18370. query results are presented in an ASCII-table format. When used
  18371. non-interactively (for example, as a filter), the result is presented in
  18372. tab-separated format.  (The output format can be changed using
  18373. command-line options.)  You can run scripts simply like this:
  18374.  
  18375.      shell> mysql database < script.sql > output.tab
  18376.  
  18377. If you have problems due to insufficient memory in the client, use the
  18378. `--quick' option!  This forces `mysql' to use `mysql_use_result()'
  18379. rather than `mysql_store_result()' to retrieve the result set.
  18380.  
  18381. Using `mysql' is very easy. Just start it as follows: `mysql database'
  18382. or `mysql --user=user_name --password=your_password database'. Type a
  18383. SQL statement, end it with `;', `\g', or `\G' and press RETURN/ENTER.
  18384.  
  18385. `mysql' supports the following options:
  18386.  
  18387. `-?, --help'
  18388.      Display this help and exit.
  18389.  
  18390. `-A, --no-auto-rehash'
  18391.      No automatic rehashing. One has to use 'rehash' to get table and
  18392.      field completion. This gives a quicker start of mysql.
  18393.  
  18394. `-B, --batch'
  18395.      Print results with a tab as separator, each row on a new line.
  18396.      Doesn't use history file.
  18397.  
  18398. `--character-sets-dir=...'
  18399.      Directory where character sets are located.
  18400.  
  18401. `-C, --compress'
  18402.      Use compression in server/client protocol.
  18403.  
  18404. `-#, --debug[=...]'
  18405.      Debug log. Default is 'd:t:o,/tmp/mysql.trace'.
  18406.  
  18407. `-D, --database=...'
  18408.      Database to use. This is mainly useful in the `my.cnf' file.
  18409.  
  18410. `--default-character-set=...'
  18411.      Set the default character set.
  18412.  
  18413. `-e, --execute=...'
  18414.      Execute command and quit. (Output like with -batch)
  18415.  
  18416. `-E, --vertical'
  18417.      Print the output of a query (rows) vertically. Without this option
  18418.      you can also force this output by ending your statements with `\G'.
  18419.  
  18420. `-f, --force'
  18421.      Continue even if we get a SQL error.
  18422.  
  18423. `-g, --no-named-commands'
  18424.      Named commands are disabled. Use \* form only, or use named
  18425.      commands only in the beginning of a line ending with a semicolon
  18426.      (;). Since Version 10.9, the client now starts with this option
  18427.      ENABLED by default!  With the -g option, long format commands will
  18428.      still work from the first line, however.
  18429.  
  18430. `-G, --enable-named-commands'
  18431.      Named commands are *enabled*.  Long format commands are allowed as
  18432.      well as shortened \* commands.
  18433.  
  18434. `-i, --ignore-space'
  18435.      Ignore space after function names.
  18436.  
  18437. `-h, --host=...'
  18438.      Connect to the given host.
  18439.  
  18440. `-H, --html'
  18441.      Produce HTML output.
  18442.  
  18443. `-L, --skip-line-numbers'
  18444.      Don't write line number for errors. Useful when one wants to
  18445.      compare result files that includes error messages
  18446.  
  18447. `--no-pager'
  18448.      Disable pager and print to stdout. See interactive help (\h) also.
  18449.  
  18450. `--no-tee'
  18451.      Disable outfile. See interactive help (\h) also.
  18452.  
  18453. `-n, --unbuffered'
  18454.      Flush buffer after each query.
  18455.  
  18456. `-N, --skip-column-names'
  18457.      Don't write column names in results.
  18458.  
  18459. `-O, --set-variable var=option'
  18460.      Give a variable a value. `--help' lists variables.
  18461.  
  18462. `-o, --one-database'
  18463.      Only update the default database. This is useful for skipping
  18464.      updates to other database in the update log.
  18465.  
  18466. ``--pager[=...]''
  18467.      Output type. Default is your `ENV' variable `PAGER'. Valid pagers
  18468.      are less, more, cat [> filename], etc.  See interactive help (\h)
  18469.      also. This option does not work in batch mode. Pager works only in
  18470.      UNIX.
  18471.  
  18472. `-p[password], --password[=...]'
  18473.      Password to use when connecting to server. If a password is not
  18474.      given on the command line, you will be prompted for it.  Note that
  18475.      if you use the short form `-p' you can't have a space between the
  18476.      option and the password.
  18477.  
  18478. `-P  --port=...'
  18479.      TCP/IP port number to use for connection.
  18480.  
  18481. `-q, --quick'
  18482.      Don't cache result, print it row-by-row. This may slow down the
  18483.      server if the output is suspended. Doesn't use history file.
  18484.  
  18485. `-r, --raw'
  18486.      Write column values without escape conversion. Used with `--batch'
  18487.  
  18488. `-s, --silent'
  18489.      Be more silent.
  18490.  
  18491. `-S  --socket=...'
  18492.      Socket file to use for connection.
  18493.  
  18494. `-t  --table'
  18495.      Output in table format. This is default in non-batch mode.
  18496.  
  18497. `-T, --debug-info'
  18498.      Print some debug information at exit.
  18499.  
  18500. `--tee=...'
  18501.      Append everything into outfile. See interactive help (\h) also.
  18502.      Does not work in batch mode.
  18503.  
  18504. `-u, --user=#'
  18505.      User for login if not current user.
  18506.  
  18507. `-U, --safe-updates[=#], --i-am-a-dummy[=#]'
  18508.      Only allow `UPDATE' and `DELETE' that uses keys. See below for
  18509.      more information about this option.  You can reset this option if
  18510.      you have it in your `my.cnf' file by using `--safe-updates=0'.
  18511.  
  18512. `-v, --verbose'
  18513.      More verbose output (-v -v -v gives the table output format).
  18514.  
  18515. `-V, --version'
  18516.      Output version information and exit.
  18517.  
  18518. `-w, --wait'
  18519.      Wait and retry if connection is down instead of aborting.
  18520.  
  18521. You can also set the following variables with `-O' or `--set-variable':
  18522.  
  18523. Variable Name          Default        Description
  18524. connect_timeout        0              Number of seconds before timeout
  18525.                                       connection.
  18526. max_allowed_packet     16777216       Max packetlength to send/receive
  18527.                                       from to server
  18528. net_buffer_length      16384          Buffer for TCP/IP and socket
  18529.                                       communication
  18530. select_limit           1000           Automatic limit for SELECT when
  18531.                                       using -i-am-a-dummy
  18532. max_join_size          1000000        Automatic limit for rows in a join
  18533.                                       when using -i-am-a-dummy.
  18534.  
  18535. If you type 'help' on the command line, `mysql' will print out the
  18536. commands that it supports:
  18537.  
  18538.      mysql> help
  18539.      
  18540.      MySQL commands:
  18541.      help    (\h)    Display this text.
  18542.      ?       (\h)    Synonym for `help'.
  18543.      clear   (\c)    Clear command.
  18544.      connect (\r)    Reconnect to the server. Optional arguments are db and host.
  18545.      edit    (\e)    Edit command with $EDITOR.
  18546.      ego     (\G)    Send command to mysql server, display result vertically.
  18547.      exit    (\q)    Exit mysql. Same as quit.
  18548.      go      (\g)    Send command to mysql server.
  18549.      nopager (\n)    Disable pager, print to stdout.
  18550.      notee   (\t)    Don't write into outfile.
  18551.      pager   (\P)    Set PAGER [to_pager]. Print the query results via PAGER.
  18552.      print   (\p)    Print current command.
  18553.      quit    (\q)    Quit mysql.
  18554.      rehash  (\#)    Rebuild completion hash.
  18555.      source  (\.)    Execute a SQL script file. Takes a file name as an argument.
  18556.      status  (\s)    Get status information from the server.
  18557.      tee     (\T)    Set outfile [to_outfile]. Append everything into given outfile.
  18558.      use     (\u)    Use another database. Takes database name as argument.
  18559.  
  18560. From the above, pager only works in UNIX.
  18561.  
  18562. The `status' command gives you some information about the connection
  18563. and the server you are using. If you are running in the
  18564. `--safe-updates' mode, `status' will also print the values for the
  18565. `mysql' variables that affect your queries.
  18566.  
  18567. A useful startup option for beginners (introduced in MySQL Version
  18568. 3.23.11) is `--safe-updates' (or `--i-am-a-dummy' for users that has at
  18569. some time done a `DELETE FROM table_name' but forgot the `WHERE'
  18570. clause).  When using this option, `mysql' sends the following command
  18571. to the MySQL server when opening the connection:
  18572.  
  18573.      SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=#select_limit#,
  18574.          SQL_MAX_JOIN_SIZE=#max_join_size#"
  18575.  
  18576. where `#select_limit#' and `#max_join_size#' are variables that can be
  18577. set from the `mysql' command line. *Note `SET': SET OPTION.
  18578.  
  18579. The effect of the above is:
  18580.  
  18581.    * You are not allowed to do an `UPDATE' or `DELETE' statement if you
  18582.      don't have a key constraint in the `WHERE' part. One can, however,
  18583.      force an `UPDATE/DELETE' by using `LIMIT':
  18584.           UPDATE table_name SET not_key_column=# WHERE not_key_column=# LIMIT 1;
  18585.  
  18586.    * All big results are automatically limited to `#select_limit#' rows.
  18587.  
  18588.    * `SELECT''s that will probably need to examine more than
  18589.      `#max_join_size' row combinations will be aborted.
  18590.  
  18591. Some useful hints about the `mysql' client:
  18592.  
  18593. Some data is much more readable when displayed vertically, instead of
  18594. the usual horizontal box type output. For example longer text, which
  18595. includes new lines, is often much easier to be read with vertical
  18596. output.
  18597.  
  18598.      mysql> select * from mails where length(txt) < 300 limit 300,1\G
  18599.      *************************** 1. row ***************************
  18600.        msg_nro: 3068
  18601.           date: 2000-03-01 23:29:50
  18602.      time_zone: +0200
  18603.      mail_from: Monty
  18604.          reply: monty@no.spam.com
  18605.        mail_to: "Thimble Smith" <tim@no.spam.com>
  18606.            sbj: UTF-8
  18607.            txt: >>>>> "Thimble" == Thimble Smith writes:
  18608.      
  18609.      Thimble> Hi.  I think this is a good idea.  Is anyone familiar with UTF-8
  18610.      Thimble> or Unicode?  Otherwise I'll put this on my TODO list and see what
  18611.      Thimble> happens.
  18612.      
  18613.      Yes, please do that.
  18614.      
  18615.      Regards,
  18616.      Monty
  18617.           file: inbox-jani-1
  18618.           hash: 190402944
  18619.      1 row in set (0.09 sec)
  18620.  
  18621.    * For logging, you can use the `tee' option. The `tee' can be
  18622.      started with option `--tee=...', or from the command line
  18623.      interactively with command `tee'. All the data displayed on the
  18624.      screen will also be appended into a given file. This can be very
  18625.      useful for debugging purposes also. The `tee' can be disabled from
  18626.      the command line with command `notee'. Executing `tee' again
  18627.      starts logging again. Without a parameter the previous file will be
  18628.      used. Note that `tee' will flush the results into the file after
  18629.      each command, just before the command line appears again waiting
  18630.      for the next command.
  18631.  
  18632.    * Browsing, or searching the results in the interactive mode in UNIX
  18633.      less, more, or any other similar program, is now possible with
  18634.      option `--pager[=...]'. Without argument, `mysql' client will look
  18635.      for environment variable PAGER and set `pager' to that.  `pager'
  18636.      can be started from the interactive command line with command
  18637.      `pager' and disabled with command `nopager'.  The command takes an
  18638.      argument optionally and the `pager' will be set to that. Command
  18639.      `pager' can be called without an argument, but this requires that
  18640.      the option `--pager' was used, or the `pager' will default to
  18641.      stdout. `pager' works only in UNIX, since it uses the popen()
  18642.      function, which doesn't exist in Windows. In Windows, the `tee'
  18643.      option can be used instead, although it may not be as handy as
  18644.      `pager' can be in some situations.
  18645.  
  18646.    * A few tips about `pager': You can use it to write to a file:
  18647.           mysql> pager cat > /tmp/log.txt
  18648.      and the results will only go to a file. You can also pass any
  18649.      options for the programs that you want to use with the `pager':
  18650.           mysql> pager less -n -i -S
  18651.      From the above do note the option '-S'. You may find it very
  18652.      useful when browsing the results; try the option with horizontal
  18653.      output (end commands with '\g', or ';') and with vertical output
  18654.      (end commands with '\G'). Sometimes a very wide result set is hard
  18655.      to be read from the screen, with option -S to less you can browse
  18656.      the results within the interactive less from left to right,
  18657.      preventing lines longer than your screen from being continued to
  18658.      the next line. This can make the result set much more readable.
  18659.      You can swith the mode between on and off within the interactive
  18660.      less with '-S'. See the 'h' for more help about less.
  18661.  
  18662.    * Last (unless you already understood this from the above examples
  18663.      ;) you can combine very complex ways to handle the results, for
  18664.      example the following would send the results to two files in two
  18665.      different directories, on two different hard-disks mounted on /dr1
  18666.      and /dr2, yet let the results still be seen on the screen via less:
  18667.           mysql> pager cat | tee /dr1/tmp/res.txt | tee /dr2/tmp/res2.txt | less -n -i -S
  18668.  
  18669.    * You can also combine the two functions above; have the `tee'
  18670.      enabled, `pager' set to 'less' and you will be able to browse the
  18671.      results in unix 'less' and still have everything appended into a
  18672.      file the same time. The difference between `UNIX tee' used with the
  18673.      `pager' and the `mysql' client in-built `tee', is that the
  18674.      in-built `tee' works even if you don't have the `UNIX tee'
  18675.      available. The in-built `tee' also logs everything that is printed
  18676.      on the screen, where the `UNIX tee' used with `pager' doesn't log
  18677.      quite that much. Last, but not least, the interactive `tee' is
  18678.      more handy to switch on and off, when you want to log something
  18679.      into a file, but want to be able to turn the feature off sometimes.
  18680.  
  18681. mysqladmin, Administrating a MySQL Server
  18682. -----------------------------------------
  18683.  
  18684. A utility for performing administrative operations. The syntax is:
  18685.  
  18686.      shell> mysqladmin [OPTIONS] command [command-option] command ...
  18687.  
  18688. You can get a list of the options your version of `mysqladmin' supports
  18689. by executing `mysqladmin --help'.
  18690.  
  18691. The current `mysqladmin' supports the following commands:
  18692.  
  18693. `create databasename'
  18694.      Create a new database.
  18695.  
  18696. `drop databasename'
  18697.      Delete a database and all its tables.
  18698.  
  18699. `extended-status'
  18700.      Gives an extended status message from the server.
  18701.  
  18702. `flush-hosts'
  18703.      Flush all cached hosts.
  18704.  
  18705. `flush-logs'
  18706.      Flush all logs.
  18707.  
  18708. `flush-tables'
  18709.      Flush all tables.
  18710.  
  18711. `flush-privileges'
  18712.      Reload grant tables (same as reload).
  18713.  
  18714. `kill id,id,...'
  18715.      Kill mysql threads.
  18716.  
  18717. `password'
  18718.      Set a new password. Change old password to new-password.
  18719.  
  18720. `ping'
  18721.      Check if mysqld is alive.
  18722.  
  18723. `processlist'
  18724.      Show list of active threads in server.
  18725.  
  18726. `reload'
  18727.      Reload grant tables.
  18728.  
  18729. `refresh'
  18730.      Flush all tables and close and open logfiles.
  18731.  
  18732. `shutdown'
  18733.      Take server down.
  18734.  
  18735. `slave-start'
  18736.      Start slave replication thread.
  18737.  
  18738. `slave-stop'
  18739.      Stop slave replication thread.
  18740.  
  18741. `status'
  18742.      Gives a short status message from the server.
  18743.  
  18744. `variables'
  18745.      Prints variables available.
  18746.  
  18747. `version'
  18748.      Get version info from server.
  18749.  
  18750. All commands can be shortened to their unique prefix.  For example:
  18751.  
  18752.      shell> mysqladmin proc stat
  18753.      +----+-------+-----------+----+-------------+------+-------+------+
  18754.      | Id | User  | Host      | db | Command     | Time | State | Info |
  18755.      +----+-------+-----------+----+-------------+------+-------+------+
  18756.      | 6  | monty | localhost |    | Processlist | 0    |       |      |
  18757.      +----+-------+-----------+----+-------------+------+-------+------+
  18758.      Uptime: 10077  Threads: 1  Questions: 9  Slow queries: 0  Opens: 6  Flush tables: 1  Open tables: 2  Memory in use: 1092K  Max memory used: 1116K
  18759.  
  18760. The `mysqladmin status' command result has the following columns:
  18761.  
  18762. Uptime                 Number of seconds the MySQL server has been up.
  18763. Threads                Number of active threads (clients).
  18764. Questions              Number of questions from clients since `mysqld'
  18765.                        was started.
  18766. Slow queries           Queries that have taken more than
  18767.                        `long_query_time' seconds. *Note Slow query log::.
  18768. Opens                  How many tables `mysqld' has opened.
  18769. Flush tables           Number of `flush ...', `refresh', and `reload'
  18770.                        commands.
  18771. Open tables            Number of tables that are open now.
  18772. Memory in use          Memory allocated directly by the `mysqld' code
  18773.                        (only available when MySQL is compiled with
  18774.                        -with-debug=full).
  18775. Max memory used        Maximum memory allocated directly by the `mysqld'
  18776.                        code (only available when MySQL is compiled with
  18777.                        -with-debug=full).
  18778.  
  18779. If you do `myslqadmin shutdown' on a socket (in other words, on a the
  18780. computer where `mysqld' is running), `mysqladmin' will wait until the
  18781. MySQL `pid-file' is removed to ensure that the `mysqld' server has
  18782. stopped properly.
  18783.  
  18784. Using `mysqlcheck' for Table Maintenance and Crash Recovery
  18785. -----------------------------------------------------------
  18786.  
  18787. Since MySQL version 3.23.38 you will be able to use a new checking and
  18788. repairing tool for `MyISAM' tables. The difference to `myisamchk' is
  18789. that `mysqlcheck' should be used when the `mysqld' server is running,
  18790. where as `myisamchk' should be used when it is not. The benefit is that
  18791. you no longer have to take the server down for checking or repairing
  18792. your tables.
  18793.  
  18794. `mysqlcheck' uses MySQL server commands `CHECK', `REPAIR', `ANALYZE'
  18795. and `OPTIMIZE' in a convenient way for the user.
  18796.  
  18797. There are three alternative ways to invoke `mysqlcheck':
  18798.  
  18799.      shell> mysqlcheck [OPTIONS] database [tables]
  18800.      shell> mysqlcheck [OPTIONS] --databases DB1 [DB2 DB3...]
  18801.      shell> mysqlcheck [OPTIONS] --all-databases
  18802.  
  18803. So it can be used in a similar way as `mysqldump' when it comes to what
  18804. databases and tables you want to choose.
  18805.  
  18806. `mysqlcheck' does have a special feature compared to the other clients;
  18807. the default behavior, checking tables (-c), can be changed by renaming
  18808. the binary. So if you want to have a tool that repairs tables by
  18809. default, you should just copy `mysqlcheck' to your harddrive with a new
  18810. name, `mysqlrepair', or alternatively make a symbolic link to
  18811. `mysqlrepair' and name the symbolic link as `mysqlrepair'. If you
  18812. invoke `mysqlrepair' now, it will repair tables by default.
  18813.  
  18814. The names that you can use to change `mysqlcheck' default behavior are
  18815. here:
  18816.  
  18817.      mysqlrepair:   The default option will be -r
  18818.      mysqlanalyze:  The default option will be -a
  18819.      mysqloptimize: The default option will be -o
  18820.  
  18821. The options available for `mysqlcheck' are listed here, please check
  18822. what your version supports with `mysqlcheck --help'.
  18823.  
  18824. `-A, --all-databases'
  18825.      Check all the databases. This will be same as -databases with all
  18826.      databases selected
  18827.  
  18828. `-1, --all-in-1'
  18829.      Instead of making one query for each table, execute all queries in
  18830.      1 query separately for each database. Table names will be in a
  18831.      comma separated list.
  18832.  
  18833. `-a, --analyze'
  18834.      Analyze given tables.
  18835.  
  18836. `--auto-repair'
  18837.      If a checked table is corrupted, automatically fix it. Repairing
  18838.      will be done after all tables have been checked, if corrupted ones
  18839.      were found.
  18840.  
  18841. `-#, --debug=...'
  18842.      Output debug log. Often this is 'd:t:o,filename'
  18843.  
  18844. `--character-sets-dir=...'
  18845.      Directory where character sets are
  18846.  
  18847. `-c, --check'
  18848.      Check table for errors
  18849.  
  18850. `-C, --check-only-changed'
  18851.      Check only tables that have changed since last check or haven't
  18852.      been closed properly.
  18853.  
  18854. `--compress'
  18855.      Use compression in server/client protocol.
  18856.  
  18857. `-?, --help'
  18858.      Display this help message and exit.
  18859.  
  18860. `-B, --databases'
  18861.      To check several databases. Note the difference in usage; In this
  18862.      case no tables are given. All name arguments are regarded as
  18863.      database names.
  18864.  
  18865. `--default-character-set=...'
  18866.      Set the default character set
  18867.  
  18868. `-F, --fast'
  18869.      Check only tables that hasn't been closed properly
  18870.  
  18871. `-f, --force'
  18872.      Continue even if we get an sql-error.
  18873.  
  18874. `-e, --extended'
  18875.      If you are using this option with CHECK TABLE, it will ensure that
  18876.      the table is 100 percent consistent, but will take a long time.
  18877.  
  18878.      If you are using this option with REPAIR TABLE, it will run an
  18879.      extended repair on the table, which may not only take a long time
  18880.      to execute, but may produce a lot of garbage rows also!
  18881.  
  18882. `-h, --host=...'
  18883.      Connect to host.
  18884.  
  18885. `-m, --medium-check'
  18886.      Faster than extended-check, but only finds 99.99 percent of all
  18887.      errors. Should be good enough for most cases.
  18888.  
  18889. `-o, --optimize'
  18890.      Optimize table
  18891.  
  18892. `-p, --password[=...]'
  18893.      Password to use when connecting to server. If password is not given
  18894.      it's solicited on the tty.
  18895.  
  18896. `-P, --port=...'
  18897.      Port number to use for connection.
  18898.  
  18899. `-q, --quick'
  18900.      If you are using this option with CHECK TABLE, it prevents the
  18901.      check from scanning the rows to check for wrong links. This is the
  18902.      fastest check.
  18903.  
  18904.      If you are using this option with REPAIR TABLE, it will try to
  18905.      repair only the index tree. This is the fastest repair method for
  18906.      a table.
  18907.  
  18908. `-r, --repair'
  18909.      Can fix almost anything except unique keys that aren't unique.
  18910.  
  18911. `-s, --silent'
  18912.      Print only error messages.
  18913.  
  18914. `-S, --socket=...'
  18915.      Socket file to use for connection.
  18916.  
  18917. `--tables'
  18918.      Overrides option -databases (-B).
  18919.  
  18920. `-u, --user=#'
  18921.      User for login if not current user.
  18922.  
  18923. `-v, --verbose'
  18924.      Print info about the various stages.
  18925.  
  18926. `-V, --version'
  18927.      Output version information and exit.
  18928.  
  18929. mysqldump, Dumping Table Structure and Data
  18930. -------------------------------------------
  18931.  
  18932. Utility to dump a database or a collection of database for backup or for
  18933. transferring the data to another SQL server (not necessarily a MySQL
  18934. server).  The dump will contain SQL statements to create the table
  18935. and/or populate the table.
  18936.  
  18937. If you are doing a backup on the server, you should consider using the
  18938. `mysqlhotcopy' instead. *Note `mysqlhotcopy': mysqlhotcopy.
  18939.  
  18940.      shell> mysqldump [OPTIONS] database [tables]
  18941.      OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
  18942.      OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
  18943.  
  18944. If you don't give any tables or use the `--databases' or
  18945. `--all-databases', the whole database(s) will be dumped.
  18946.  
  18947. You can get a list of the options your version of `mysqldump' supports
  18948. by executing `mysqldump --help'.
  18949.  
  18950. Note that if you run `mysqldump' without `--quick' or `--opt',
  18951. `mysqldump' will load the whole result set into memory before dumping
  18952. the result.  This will probably be a problem if you are dumping a big
  18953. database.
  18954.  
  18955. Note that if you are using a new copy of the `mysqldump' program and
  18956. you are going to do a dump that will be read into a very old MySQL
  18957. server, you should not use the `--opt' or `-e' options.
  18958.  
  18959. `mysqldump' supports the following options:
  18960.  
  18961. `--add-locks'
  18962.      Add `LOCK TABLES' before and `UNLOCK TABLE' after each table dump.
  18963.      (To get faster inserts into MySQL.)
  18964.  
  18965. `--add-drop-table'
  18966.      Add a `drop table' before each create statement.
  18967.  
  18968. `-A, --all-databases'
  18969.      Dump all the databases. This will be same as `--databases' with all
  18970.      databases selected.
  18971.  
  18972. `-a, --all'
  18973.      Include all MySQL-specific create options.
  18974.  
  18975. `--allow-keywords'
  18976.      Allow creation of column names that are keywords.  This works by
  18977.      prefixing each column name with the table name.
  18978.  
  18979. `-c, --complete-insert'
  18980.      Use complete insert statements (with column names).
  18981.  
  18982. `-C, --compress'
  18983.      Compress all information between the client and the server if both
  18984.      support compression.
  18985.  
  18986. `-B, --databases'
  18987.      To dump several databases. Note the difference in usage. In this
  18988.      case no tables are given. All name arguments are regarded as
  18989.      database names.  `USE db_name;' will be included in the output
  18990.      before each new database.
  18991.  
  18992. `--delayed'
  18993.      Insert rows with the `INSERT DELAYED' command.
  18994.  
  18995. `-e, --extended-insert'
  18996.      Use the new multiline `INSERT' syntax. (Gives more compact and
  18997.      faster inserts statements.)
  18998.  
  18999. `-#, --debug[=option_string]'
  19000.      Trace usage of the program (for debugging).
  19001.  
  19002. `--help'
  19003.      Display a help message and exit.
  19004.  
  19005. `--fields-terminated-by=...'
  19006. `--fields-enclosed-by=...'
  19007. `--fields-optionally-enclosed-by=...'
  19008. `--fields-escaped-by=...'
  19009. `--lines-terminated-by=...'
  19010.      These options are used with the `-T' option and have the same
  19011.      meaning as the corresponding clauses for `LOAD DATA INFILE'.
  19012.      *Note `LOAD DATA': LOAD DATA.
  19013.  
  19014. `-F, --flush-logs'
  19015.      Flush log file in the MySQL server before starting the dump.
  19016.  
  19017. `-f, --force,'
  19018.      Continue even if we get a SQL error during a table dump.
  19019.  
  19020. `-h, --host=..'
  19021.      Dump data from the MySQL server on the named host. The default host
  19022.      is `localhost'.
  19023.  
  19024. `-l, --lock-tables.'
  19025.      Lock all tables before starting the dump.  The tables are locked
  19026.      with `READ LOCAL' to allow concurrent inserts in the case of
  19027.      `MyISAM' tables.
  19028.  
  19029. `-n, --no-create-db'
  19030.      'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be
  19031.      put in the output. The above line will be added otherwise, if
  19032.      -databases or -all-databases option was given.
  19033.  
  19034. `-t, --no-create-info'
  19035.      Don't write table creation information (The `CREATE TABLE'
  19036.      statement.)
  19037.  
  19038. `-d, --no-data'
  19039.      Don't write any row information for the table.  This is very
  19040.      useful if you just want to get a dump of the structure for a table!
  19041.  
  19042. `--opt'
  19043.      Same as `--quick --add-drop-table --add-locks --extended-insert
  19044.      --lock-tables'.  Should give you the fastest possible dump for
  19045.      reading into a MySQL server.
  19046.  
  19047. `-pyour_pass, --password[=your_pass]'
  19048.      The password to use when connecting to the server. If you specify
  19049.      no `=your_pass' part, `mysqldump' you will be prompted for a
  19050.      password.
  19051.  
  19052. `-P port_num, --port=port_num'
  19053.      The TCP/IP port number to use for connecting to a host.  (This is
  19054.      used for connections to hosts other than `localhost', for which
  19055.      Unix sockets are used.)
  19056.  
  19057. `-q, --quick'
  19058.      Don't buffer query, dump directly to stdout. Uses
  19059.      `mysql_use_result()' to do this.
  19060.  
  19061. `-r, --result-file=...'
  19062.      Direct output to a given file. This option should be used in MSDOS,
  19063.      because it prevents new line '\n' from being converted to '\n\r'
  19064.      (new line + carriage return).
  19065.  
  19066. `-S /path/to/socket, --socket=/path/to/socket'
  19067.      The socket file to use when connecting to `localhost' (which is the
  19068.      default host).
  19069.  
  19070. `--tables'
  19071.      Overrides option -databases (-B).
  19072.  
  19073. `-T, --tab=path-to-some-directory'
  19074.      Creates a `table_name.sql' file, that contains the SQL CREATE
  19075.      commands, and a `table_name.txt' file, that contains the data, for
  19076.      each give table.  *NOTE*: This only works if `mysqldump' is run on
  19077.      the same machine as the `mysqld' daemon.  The format of the `.txt'
  19078.      file is made according to the `--fields-xxx' and `--lines--xxx'
  19079.      options.
  19080.  
  19081. `-u user_name, --user=user_name'
  19082.      The MySQL user name to use when connecting to the server. The
  19083.      default value is your Unix login name.
  19084.  
  19085. `-O var=option, --set-variable var=option'
  19086.      Set the value of a variable.  The possible variables are listed
  19087.      below.
  19088.  
  19089. `-v, --verbose'
  19090.      Verbose mode.  Print out more information on what the program does.
  19091.  
  19092. `-V, --version'
  19093.      Print version information and exit.
  19094.  
  19095. `-w, --where='where-condition''
  19096.      Dump only selected records. Note that QUOTES are mandatory:
  19097.  
  19098.           "--where=user='jimf'" "-wuserid>1" "-wuserid<1"
  19099.  
  19100. `-O net_buffer_length=#, where # < 16M'
  19101.      When creating multi-row-insert statements (as with option
  19102.      `--extended-insert' or `--opt'), `mysqldump' will create rows up
  19103.      to `net_buffer_length' length. If you increase this variable, you
  19104.      should also ensure that the `max_allowed_packet' variable in the
  19105.      MySQL server is bigger than the `net_buffer_length'.
  19106.  
  19107. The most normal use of `mysqldump' is probably for making a backup of
  19108. whole databases. *Note Backup::.
  19109.  
  19110.      mysqldump --opt database > backup-file.sql
  19111.  
  19112. You can read this back into MySQL with:
  19113.  
  19114.      mysql database < backup-file.sql
  19115.  
  19116. or
  19117.  
  19118.      mysql -e "source /patch-to-backup/backup-file.sql" database
  19119.  
  19120. However, it's also very useful to populate another MySQL server with
  19121. information from a database:
  19122.  
  19123.      mysqldump --opt database | mysql ---host=remote-host -C database
  19124.  
  19125. It is possible to dump several databases with one command:
  19126.  
  19127.      mysqldump --databases database1 [database2 database3...] > my_databases.sql
  19128.  
  19129. If all the databases are wanted, one can use:
  19130.  
  19131.      mysqldump --all-databases > all_databases.sql
  19132.  
  19133. mysqlhotcopy, Copying MySQL Databases and Tables
  19134. ------------------------------------------------
  19135.  
  19136. `mysqlhotcopy' is a perl script that uses `LOCK TABLES', `FLUSH TABLES'
  19137. and `cp' or `scp' to quickly make a backup of a database.  It's the
  19138. fastest way to make a backup of the database, of single tables but it
  19139. can only be run on the same machine where the database directories are.
  19140.  
  19141.      mysqlhotcopy db_name [/path/to/new_directory]
  19142.      
  19143.      mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory
  19144.      
  19145.      mysqlhotcopy db_name./regex/
  19146.  
  19147. `mysqlhotcopy' supports the following options:
  19148.  
  19149. `-?, --help'
  19150.      Display a help screen and exit
  19151.  
  19152. `-u, --user=#'
  19153.      User for database login
  19154.  
  19155. `-p, --password=#'
  19156.      Password to use when connecting to server
  19157.  
  19158. `-P, --port=#'
  19159.      Port to use when connecting to local server
  19160.  
  19161. `-S, --socket=#'
  19162.      Socket to use when connecting to local server
  19163.  
  19164. `--allowold'
  19165.      Don't abort if target already exists (rename it _old)
  19166.  
  19167. `--keepold'
  19168.      Don't delete previous (now renamed) target when done
  19169.  
  19170. `--noindices'
  19171.      Don't include full index files in copy to make the backup smaller
  19172.      and faster The indexes can later be reconstructed with `myisamchk
  19173.      -rq.'.
  19174.  
  19175. `--method=#'
  19176.      Method for copy (`cp' or `scp').
  19177.  
  19178. `-q, --quiet'
  19179.      Be silent except for errors
  19180.  
  19181. `--debug'
  19182.      Enable debug
  19183.  
  19184. `-n, --dryrun'
  19185.      Report actions without doing them
  19186.  
  19187. `--regexp=#'
  19188.      Copy all databases with names matching regexp
  19189.  
  19190. `--suffix=#'
  19191.      Suffix for names of copied databases
  19192.  
  19193. `--checkpoint=#'
  19194.      Insert checkpoint entry into specified db.table
  19195.  
  19196. `--flushlog'
  19197.      Flush logs once all tables are locked.
  19198.  
  19199. `--tmpdir=#'
  19200.      Temporary directory (instead of /tmp).
  19201.  
  19202. You can use `perldoc mysqlhotcopy' to get a more complete documentation
  19203. for `mysqlhotcopy'.
  19204.  
  19205. `mysqlhotcopy' reads the groups `[client]' and  `[mysqlhotcopy]' from
  19206. the option files.
  19207.  
  19208. To be able to execute `mysqlhotcopy' you need write access to the
  19209. backup directory, `SELECT' privilege to the tables you are about to
  19210. copy and the MySQL `Reload' privilege (to be able to execute `FLUSH
  19211. TABLES').
  19212.  
  19213. mysqlimport, Importing Data from Text Files
  19214. -------------------------------------------
  19215.  
  19216. `mysqlimport' provides a command-line interface to the `LOAD DATA
  19217. INFILE' SQL statement.  Most options to `mysqlimport' correspond
  19218. directly to the same options to `LOAD DATA INFILE'.  *Note `LOAD DATA':
  19219. LOAD DATA.
  19220.  
  19221. `mysqlimport' is invoked like this:
  19222.  
  19223.      shell> mysqlimport [options] database textfile1 [textfile2....]
  19224.  
  19225. For each text file named on the command line, `mysqlimport' strips any
  19226. extension from the filename and uses the result to determine which
  19227. table to import the file's contents into.  For example, files named
  19228. `patient.txt', `patient.text', and `patient' would all be imported into
  19229. a table named `patient'.
  19230.  
  19231. `mysqlimport' supports the following options:
  19232.  
  19233. `-c, --columns=...'
  19234.      This option takes a comma-separated list of field names as an
  19235.      argument.  The field list is used to create a proper `LOAD DATA
  19236.      INFILE' command, which is then passed to MySQL. *Note `LOAD DATA':
  19237.      LOAD DATA.
  19238.  
  19239. `-C, --compress'
  19240.      Compress all information between the client and the server if both
  19241.      support compression.
  19242.  
  19243. `-#, --debug[=option_string]'
  19244.      Trace usage of the program (for debugging).
  19245.  
  19246. `-d, --delete'
  19247.      Empty the table before importing the text file.
  19248.  
  19249. `--fields-terminated-by=...'
  19250. `--fields-enclosed-by=...'
  19251. `--fields-optionally-enclosed-by=...'
  19252. `--fields-escaped-by=...'
  19253. `--lines-terminated-by=...'
  19254.      These options have the same meaning as the corresponding clauses
  19255.      for `LOAD DATA INFILE'. *Note `LOAD DATA': LOAD DATA.
  19256.  
  19257. `-f, --force'
  19258.      Ignore errors.  For example, if a table for a text file doesn't
  19259.      exist, continue processing any remaining files.  Without `--force',
  19260.      `mysqlimport' exits if a table doesn't exist.
  19261.  
  19262. `--help'
  19263.      Display a help message and exit.
  19264.  
  19265. `-h host_name, --host=host_name'
  19266.      Import data to the MySQL server on the named host. The default host
  19267.      is `localhost'.
  19268.  
  19269. `-i, --ignore'
  19270.      See the description for the `--replace' option.
  19271.  
  19272. `-l, --lock-tables'
  19273.      Lock *ALL* tables for writing before processing any text files.
  19274.      This ensures that all tables are synchronized on the server.
  19275.  
  19276. `-L, --local'
  19277.      Read input files from the client.  By default, text files are
  19278.      assumed to be on the server if you connect to `localhost' (which
  19279.      is the default host).
  19280.  
  19281. `-pyour_pass, --password[=your_pass]'
  19282.      The password to use when connecting to the server. If you specify
  19283.      no `=your_pass' part, `mysqlimport' you will be prompted for a
  19284.      password.
  19285.  
  19286. `-P port_num, --port=port_num'
  19287.      The TCP/IP port number to use for connecting to a host.  (This is
  19288.      used for connections to hosts other than `localhost', for which
  19289.      Unix sockets are used.)
  19290.  
  19291. `-r, --replace'
  19292.      The `--replace' and `--ignore' options control handling of input
  19293.      records that duplicate existing records on unique key values.  If
  19294.      you specify `--replace', new rows replace existing rows that have
  19295.      the same unique key value. If you specify `--ignore', input rows
  19296.      that duplicate an existing row on a unique key value are skipped.
  19297.      If you don't specify either option, an error occurs when a
  19298.      duplicate key value is found, and the rest of the text file is
  19299.      ignored.
  19300.  
  19301. `-s, --silent'
  19302.      Silent mode.  Write output only when errors occur.
  19303.  
  19304. `-S /path/to/socket, --socket=/path/to/socket'
  19305.      The socket file to use when connecting to `localhost' (which is the
  19306.      default host).
  19307.  
  19308. `-u user_name, --user=user_name'
  19309.      The MySQL user name to use when connecting to the server. The
  19310.      default value is your Unix login name.
  19311.  
  19312. `-v, --verbose'
  19313.      Verbose mode.  Print out more information what the program does.
  19314.  
  19315. `-V, --version'
  19316.      Print version information and exit.
  19317.  
  19318. Here is a sample run using `mysqlimport':
  19319.  
  19320.      $ mysql --version
  19321.      mysql  Ver 9.33 Distrib 3.22.25, for pc-linux-gnu (i686)
  19322.      $ uname -a
  19323.      Linux xxx.com 2.2.5-15 #1 Mon Apr 19 22:21:09 EDT 1999 i586 unknown
  19324.      $ mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
  19325.      $ ed
  19326.      a
  19327.      100     Max Sydow
  19328.      101     Count Dracula
  19329.      .
  19330.      w imptest.txt
  19331.      32
  19332.      q
  19333.      $ od -c imptest.txt
  19334.      0000000   1   0   0  \t   M   a   x       S   y   d   o   w  \n   1   0
  19335.      0000020   1  \t   C   o   u   n   t       D   r   a   c   u   l   a  \n
  19336.      0000040
  19337.      $ mysqlimport --local test imptest.txt
  19338.      test.imptest: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
  19339.      $ mysql -e 'SELECT * FROM imptest' test
  19340.      +------+---------------+
  19341.      | id   | n             |
  19342.      +------+---------------+
  19343.      |  100 | Max Sydow     |
  19344.      |  101 | Count Dracula |
  19345.      +------+---------------+
  19346.  
  19347. Showing Databases, Tables, and Columns
  19348. --------------------------------------
  19349.  
  19350. `mysqlshow' can be used to quickly look at which databases exist, their
  19351. tables, and the table's columns.
  19352.  
  19353. With the `mysql' program you can get the same information with the
  19354. `SHOW' commands.  *Note SHOW::.
  19355.  
  19356. `mysqlshow' is invoked like this:
  19357.  
  19358.      shell> mysqlshow [OPTIONS] [database [table [column]]]
  19359.  
  19360.    * If no database is given, all matching databases are shown.
  19361.  
  19362.    * If no table is given, all matching tables in the database are
  19363.      shown.
  19364.  
  19365.    * If no column is given, all matching columns and column types in
  19366.      the table are shown.
  19367.  
  19368. Note that in newer MySQL versions, you only see those
  19369. database/tables/columns for which you have some privileges.
  19370.  
  19371. If the last argument contains a shell or SQL wild-card (`*', `?', `%'
  19372. or `_') then only what's matched by the wild card is shown.  This may
  19373. cause some confusion when you try to display the columns for a table
  19374. with a `_' as in this case `mysqlshow' only shows you the table names
  19375. that match the pattern.  This is easily fixed by adding an extra `%'
  19376. last on the command line (as a separate argument).
  19377.  
  19378. perror, Explaining Error Codes
  19379. ------------------------------
  19380.  
  19381. `perror' can be used to print error message(s). `perror' can be invoked
  19382. like this:
  19383.  
  19384.      shell> perror [OPTIONS] [ERRORCODE [ERRORCODE...]]
  19385.      
  19386.      For example:
  19387.      
  19388.      shell> perror 64 79
  19389.      Error code  64:  Machine is not on the network
  19390.      Error code  79:  Can not access a needed shared library
  19391.  
  19392. `perror' can be used to display a description for a system error code,
  19393. or an MyISAM/ISAM table handler error code. The error messages are
  19394. mostly system dependent.
  19395.  
  19396. How to Run SQL Commands from a Text File
  19397. ----------------------------------------
  19398.  
  19399. The `mysql' client typically is used interactively, like this:
  19400.  
  19401.      shell> mysql database
  19402.  
  19403. However, it's also possible to put your SQL commands in a file and tell
  19404. `mysql' to read its input from that file.  To do so, create a text file
  19405. `text_file' that contains the commands you wish to execute.  Then
  19406. invoke `mysql' as shown below:
  19407.  
  19408.      shell> mysql database < text_file
  19409.  
  19410. You can also start your text file with a `USE db_name' statement.  In
  19411. this case, it is unnecessary to specify the database name on the command
  19412. line:
  19413.  
  19414.      shell> mysql < text_file
  19415.  
  19416. *Note Client-Side Scripts::.
  19417.  
  19418. The MySQL Log Files
  19419. ===================
  19420.  
  19421. MySQL has several different log files that can help you find out what's
  19422. going on inside `mysqld':
  19423.  
  19424. The error log          Problems encountering starting, running or
  19425.                        stopping `mysqld'.
  19426. The isam log           Logs all changes to the ISAM tables. Used only
  19427.                        for debugging the isam code.
  19428. The query log          Established connections and executed queries.
  19429. The update log         Deprecated: Stores all statements that changes
  19430.                        data
  19431. The binary log         Stores all statements that changes something.
  19432.                        Used also for replication
  19433. The slow log           Stores all queries that took more than
  19434.                        `long_query_time' to execute or didn't use
  19435.                        indexes.
  19436.  
  19437. All logs can be found in the `mysqld' data directory.  You can force
  19438. `mysqld' to reopen the log files (or in some cases switch to a new log)
  19439. by executing `FLUSH LOGS'. *Note FLUSH::.
  19440.  
  19441. The Error Log
  19442. -------------
  19443.  
  19444. `mysqld' writes all errors to the stderr, which the `safe_mysqld'
  19445. script redirects to a file called `'hostname'.err'.  (On Windows,
  19446. `mysqld' writes this directly to `\mysql\data\mysql.err').
  19447.  
  19448. This contains information indicating when `mysqld' was started and
  19449. stopped and also any critical errors found when running.  If `mysqld'
  19450. dies unexpectedly and `safe_mysqld' needs to restart `mysqld',
  19451. `safe_mysqld' will write a `restarted mysqld' row in this file.  This
  19452. log also holds a warning if `mysqld' notices a table that needs to be
  19453. automatically checked or repaired.
  19454.  
  19455. On some operating systems, the error log will contain a stack trace for
  19456. where `mysqld' died. This can be used to find out where `mysqld' died.
  19457. *Note Using stack trace::.
  19458.  
  19459. The General Query Log
  19460. ---------------------
  19461.  
  19462. If you want to know what happens within `mysqld', you should start it
  19463. with `--log[=file]'.  This will log all connections and queries to the
  19464. log file (by default named `'hostname'.log').  This log can be very
  19465. useful when you suspect an error in a client and want to know exactly
  19466. what `mysqld' thought the client sent to it.
  19467.  
  19468. By default, the `mysql.server' script starts the MySQL server with the
  19469. `-l' option.  If you need better performance when you start using MySQL
  19470. in a production environment, you can remove the `-l' option from
  19471. `mysql.server' or change it to `--log-bin'.
  19472.  
  19473. The entries in this log are written as `mysqld' receives the questions.
  19474. This may be different than the order in which the statements are
  19475. executed.  This is in contrast to the update log and the binary log
  19476. which are written after the query is executed, but before any locks are
  19477. released.
  19478.  
  19479. The Update Log
  19480. --------------
  19481.  
  19482. *NOTE*: The update log is replaced by the binary log. *Note Binary
  19483. log::.  With this you can do anything that you can do with the update
  19484. log.
  19485.  
  19486. When started with the `--log-update[=file_name]' option, `mysqld'
  19487. writes a log file containing all SQL commands that update data. If no
  19488. filename is given, it defaults to the name of the host machine. If a
  19489. filename is given, but it doesn't contain a path, the file is written
  19490. in the data directory. If `file_name' doesn't have an extension,
  19491. `mysqld' will create log file names like so: `file_name.###', where
  19492. `###' is a number that is incremented each time you execute `mysqladmin
  19493. refresh', execute `mysqladmin flush-logs', execute the `FLUSH LOGS'
  19494. statement, or restart the server.
  19495.  
  19496. *NOTE:* For the above scheme to work, you should NOT create your own
  19497. files with the same filename as the update log + some extensions that
  19498. may be regarded as a number, in the directory used by the update log!
  19499.  
  19500. If you use the `--log' or `-l' options, `mysqld' writes a general log
  19501. with a filename of `hostname.log', and restarts and refreshes do not
  19502. cause a new log file to be generated (although it is closed and
  19503. reopened). In this case you can copy it (on Unix) by doing:
  19504.  
  19505.      mv hostname.log hostname-old.log
  19506.      mysqladmin flush-logs
  19507.      cp hostname-old.log to-backup-directory
  19508.      rm hostname-old.log
  19509.  
  19510. Update logging is smart because it logs only statements that really
  19511. update data. So an `UPDATE' or a `DELETE' with a `WHERE' that finds no
  19512. rows is not written to the log. It even skips `UPDATE' statements that
  19513. set a column to the value it already has.
  19514.  
  19515. The update logging is done immediately after a query completes but
  19516. before any locks are released or any commit is done. This ensures that
  19517. the log will be logged in the execution order.
  19518.  
  19519. If you want to update a database from update log files, you could do the
  19520. following (assuming your update logs have names of the form
  19521. `file_name.###'):
  19522.  
  19523.      shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
  19524.  
  19525. `ls' is used to get all the log files in the right order.
  19526.  
  19527. This can be useful if you have to revert to backup files after a crash
  19528. and you want to redo the updates that occurred between the time of the
  19529. backup and the crash.
  19530.  
  19531. The Binary Update Log
  19532. ---------------------
  19533.  
  19534. The intention is that the binary log should replace the update log, so
  19535. we recommend you to switch to this log format as soon as possible!
  19536.  
  19537. The binary log contains all information that is available in the update
  19538. log in a more efficient format. It also contains information about how
  19539. long every query that updated the database took.
  19540.  
  19541. The binary log is also used when you are replicating a slave from a
  19542. master.  *Note Replication::.
  19543.  
  19544. When started with the `--log-bin[=file_name]' option, `mysqld' writes a
  19545. log file containing all SQL commands that update data. If no file name
  19546. is given, it defaults to the name of the host machine followed by
  19547. `-bin'. If file name is given, but it doesn't contain a path, the file
  19548. is written in the data directory.
  19549.  
  19550. If you supply an extension to `--log-bin=filename.extension', the
  19551. extension will be silenty removed.
  19552.  
  19553. To the binary log filename `mysqld' will append an extension that is a
  19554. number that is incremented each time you execute `mysqladmin refresh',
  19555. execute `mysqladmin flush-logs', execute the `FLUSH LOGS' statement or
  19556. restart the server.
  19557.  
  19558. You can use the following options to `mysqld' to affect what is logged
  19559. to the binary log:
  19560.  
  19561. `binlog-do-db=database_name'   Tells the master it should log updates
  19562.                               for the specified database, and exclude
  19563.                               all others not explicitly mentioned.
  19564.                               (Example: `binlog-do-db=some_database')
  19565. `binlog-ignore-db=database_name' Tells the master that updates to the
  19566.                               given database should not be logged to the
  19567.                               binary log (Example:
  19568.                               `binlog-ignore-db=some_database')
  19569.  
  19570. To be able to know which different binary log files have been used,
  19571. `mysqld' will also create a binary log index file that contains the
  19572. name of all used binary log files. By default this has the same name as
  19573. the binary log file, with the extension `'.index''.  You can change the
  19574. name of the binary log index file with the `--log-bin-index=[filename]'
  19575. option.
  19576.  
  19577. If you are using replication, you should not delete old binary log
  19578. files until you are sure that no slave will ever need to use them.  One
  19579. way to do this is to do `mysqladmin flush-logs' once a day and then
  19580. remove any logs that are more than 3 days old.
  19581.  
  19582. You can examine the binary log file with the `mysqlbinlog' command.
  19583. For example, you can update a MySQL server from the binary log as
  19584. follows:
  19585.  
  19586.      mysqlbinlog log-file | mysql -h server_name
  19587.  
  19588. You can also use the `mysqlbinlog' program to read the binary log
  19589. directly from a remote MySQL server!
  19590.  
  19591. `mysqlbinlog --help' will give you more information of how to use this
  19592. program!
  19593.  
  19594. If you are using `BEGIN [WORK]' or `SET AUTOCOMMIT=0', you must use the
  19595. MySQL binary log for backups instead of the old update log.
  19596.  
  19597. The binary logging is done immediately after a query completes but
  19598. before any locks are released or any commit is done. This ensures that
  19599. the log will be logged in the execution order.
  19600.  
  19601. All updates (`UPDATE', `DELETE' or `INSERT') that change a
  19602. transactional table (like BDB tables) are cached until a `COMMIT'.  Any
  19603. updates to a non-transactional table are stored in the binary log at
  19604. once.  Every thread will, on start, allocate a buffer of
  19605. `binlog_cache_size' to buffer queries.  If a query is bigger than this,
  19606. the thread will open a temporary file to handle the bigger cache.  The
  19607. temporary file will be deleted when the thread ends.
  19608.  
  19609. The `max_binlog_cache_size' can be used to restrict the total size used
  19610. to cache a multi-transaction query.
  19611.  
  19612. If you are using the update or binary log, concurrent inserts will not
  19613. work together with `CREATE ... INSERT' and `INSERT ... SELECT'.  This
  19614. is to ensure that you can recreate an exact copy of your tables by
  19615. applying the log on a backup.
  19616.  
  19617. The Slow Query Log
  19618. ------------------
  19619.  
  19620. When started with the `--log-slow-queries[=file_name]' option, `mysqld'
  19621. writes a log file containing all SQL commands that took more than
  19622. `long_query_time' to execute. The time to get the initial table locks
  19623. are not counted as execution time.
  19624.  
  19625. The slow query log is logged after the query is executed and after all
  19626. locks has been released. This may be different than the order in which
  19627. the statements are executed.
  19628.  
  19629. If no file name is given, it defaults to the name of the host machine
  19630. suffixed with `-slow.log'. If a filename is given, but doesn't contain
  19631. a path, the file is written in the data directory.
  19632.  
  19633. The slow query log can be used to find queries that take a long time to
  19634. execute and are thus candidates for optimization. With a large log, that
  19635. can become a difficult task. You can pipe the slow query log through the
  19636. `mysqldumpslow' command to get a summary of the queries which appear in
  19637. the log.
  19638.  
  19639. You are using `--log-long-format' then also queries that are not using
  19640. indexes are printed. *Note Command-line options::.
  19641.  
  19642. Log File Maintenance
  19643. --------------------
  19644.  
  19645. MySQL has a lot of log files which make it easy to see what is going.
  19646. *Note Log Files::. One must however from time to time clean up after
  19647. `MysQL' to ensure that the logs don't take up too much disk space.
  19648.  
  19649. When using MySQL with log files, you will, from time to time, want to
  19650. remove/backup old log files and tell MySQL to start logging on new
  19651. files.  *Note Backup::.
  19652.  
  19653. On a Linux (`Redhat') installation, you can use the `mysql-log-rotate'
  19654. script for this. If you installed MySQL from an RPM distribution, the
  19655. script should have been installed automatically.  Note that you should
  19656. be careful with this if you are using the log for replication!
  19657.  
  19658. On other systems you must install a short script yourself that you
  19659. start from `cron' to handle log files.
  19660.  
  19661. You can force MySQL to start using new log files by using `mysqladmin
  19662. flush-logs' or by using the SQL command `FLUSH LOGS'.  If you are using
  19663. MySQL Version 3.21 you must use `mysqladmin refresh'.
  19664.  
  19665. The above command does the following:
  19666.  
  19667.    * If standard logging (`--log') or slow query logging
  19668.      (`--log-slow-queries') is used, closes and reopens the log file.
  19669.      (`mysql.log' and ``hostname`-slow.log' as default).
  19670.  
  19671.    * If update logging (`--log-update') is used, closes the update log
  19672.      and opens a new log file with a higher sequence number.
  19673.  
  19674. If you are using only an update log, you only have to flush the logs
  19675. and then move away the old update log files to a backup.  If you are
  19676. using the normal logging, you can do something like:
  19677.  
  19678.      shell> cd mysql-data-directory
  19679.      shell> mv mysql.log mysql.old
  19680.      shell> mysqladmin flush-logs
  19681.  
  19682. and then take a backup and remove `mysql.old'.
  19683.  
  19684. Replication in MySQL
  19685. ====================
  19686.  
  19687. This chapter describes the various replication features in MySQL.  It
  19688. serves as a reference to the options available with replication.  You
  19689. will be introduced to replication and learn how to implement it.
  19690. Towards the end, there are some frequently asked questions and
  19691. descriptions of problems and how to solve them.
  19692.  
  19693. Introduction
  19694. ------------
  19695.  
  19696. One way replication can be used is to increase both robustness and
  19697. speed. For robustness you can have two systems and can switch to the
  19698. backup if you have problems with the master. The extra speed is
  19699. achieved by sending a part of the non-updating queries to the replica
  19700. server. Of course this only works if non-updating queries dominate, but
  19701. that is the normal case.
  19702.  
  19703. Starting in Version 3.23.15, MySQL supports one-way replication
  19704. internally. One server acts as the master, while the other acts as the
  19705. slave. Note that one server could play the roles of master in one pair
  19706. and slave in the other. The master server keeps a binary log of updates
  19707. (*Note Binary log::.) and an index file to binary logs to keep track of
  19708. log rotation.  The slave, upon connecting, informs the master where it
  19709. left off since the last successfully propagated update, catches up on
  19710. the updates, and then blocks and waits for the master to notify it of
  19711. the new updates.
  19712.  
  19713. Note that if you are replicating a database, all updates to this
  19714. database should be done through the master!
  19715.  
  19716. Another benefit of using replication is that one can get live backups of
  19717. the system by doing a backup on a slave instead of doing it on the
  19718. master. *Note Backup::.
  19719.  
  19720. Replication Implementation Overview
  19721. -----------------------------------
  19722.  
  19723. MySQL replication is based on the server keeping track of all changes
  19724. to your database (updates, deletes, etc) in the binary log. (*Note
  19725. Binary log::.) and the slave server(s) reading the saved queries from
  19726. the master server's binary log so that the slave can execute the same
  19727. queries on its copy of the data.
  19728.  
  19729. It is *very important* to realize that the binary log is simply a
  19730. record starting from a fixed point in time (the moment you enable binary
  19731. logging). Any slaves which you set up will need copies of all the data
  19732. from your master as it existed the moment that you enabled binary
  19733. logging on the master. If you start your slaves with data that doesn't
  19734. agree with what was on the master *when the binary log was started*,
  19735. your slaves may fail.
  19736.  
  19737. A future version (4.0) of MySQL will remove the need to keep a
  19738. (possibly large) snapshot of data for new slaves that you might wish to
  19739. set up through the live backup functionality with no locking required.
  19740. However, at this time, it is necessary to block all writes either with a
  19741. global read lock or by shutting down the master while taking a snapshot.
  19742.  
  19743. Once a slave is properly configured and running, it will simply connect
  19744. to the master and wait for updates to process. If the master goes away
  19745. or the slave loses connectivity with your master, it will keep trying to
  19746. connect every `master-connect-retry' seconds until it is able to
  19747. reconnect and resume listening for updates.
  19748.  
  19749. Each slave keeps track of where it left off. The master server has no
  19750. knowledge of how many slaves there are or which ones are up-to-date at
  19751. any given time.
  19752.  
  19753. The next section explains the master/slave setup process in more detail.
  19754.  
  19755. How To Set Up Replication
  19756. -------------------------
  19757.  
  19758. Below is a quick description of how to set up complete replication on
  19759. your current MySQL server. It assumes you want to replicate all your
  19760. databases and have not configured replication before. You will need to
  19761. shutdown your master server briefly to complete the steps outlined
  19762. below.
  19763.  
  19764.   1. Make sure you have a recent version of MySQL installed on the
  19765.      master and slave(s).
  19766.  
  19767.      Use Version 3.23.29 or higher. Previous releases used a different
  19768.      binary log format and had bugs which have been fixed in newer
  19769.      releases. Please, do not report bugs until you have verified that
  19770.      the problem is present in the latest release.
  19771.  
  19772.   2. Set up special a replication user on the master with the `FILE'
  19773.      privilege and permission to connect from all the slaves. If the
  19774.      user is only doing replication (which is recommended), you don't
  19775.      need to grant any additional privileges.
  19776.  
  19777.      For example, to create a user named `repl' which can access your
  19778.      master from any host, you might use this command:
  19779.  
  19780.           GRANT FILE ON *.* TO repl@"%" IDENTIFIED BY '<password>';
  19781.  
  19782.   3. Shut down MySQL on the master.
  19783.  
  19784.           mysqladmin -u root -p<password> shutdown
  19785.  
  19786.   4. Snapshot all the data on your master server.
  19787.  
  19788.      The easiest way to do this (on Unix) is to simply use *tar* to
  19789.      produce an archive of your entire data directory. The exact data
  19790.      directory location depends on your installation.
  19791.  
  19792.           tar -cvf /tmp/mysql-snapshot.tar /path/to/data-dir
  19793.  
  19794.      Windows users can use WinZip or similar software to create an
  19795.      archive of the data directory.
  19796.  
  19797.   5. In `my.cnf' on the master add `log-bin' and `server-id=unique
  19798.      number' to the `[mysqld]' section and restart it. It is very
  19799.      important that the id of the slave is different from the id of the
  19800.      master. Think of `server-id' as something similar to the IP
  19801.      address - it uniquely identifies the server instance in the
  19802.      community of replication partners.
  19803.  
  19804.           [mysqld]
  19805.           log-bin
  19806.           server-id=1
  19807.  
  19808.   6. Restart MySQL on the master.
  19809.  
  19810.   7. Add the following to `my.cnf' on the slave(s):
  19811.  
  19812.           master-host=<hostname of the master>
  19813.           master-user=<replication user name>
  19814.           master-password=<replication user password>
  19815.           master-port=<TCP/IP port for master>
  19816.           server-id=<some unique number between 2 and 2^32-1>
  19817.  
  19818.      replacing the values in <> with what is relevant to your system.
  19819.  
  19820.      `server-id' must be different for each server participating in
  19821.      replication.  If you don't specify a server-id, it will be set to
  19822.      1 if you have not defined `master-host', else it will be set to 2.
  19823.      Note that in the case of `server-id' omission the master will
  19824.      refuse connections from all slaves, and the slave will refuse to
  19825.      connect to a master. Thus, omitting `server-id' is only good for
  19826.      backup with a binary log.
  19827.  
  19828.   8. Copy the snapshot data into your data directory on your slave(s).
  19829.      Make sure that the privileges on the files and directories are
  19830.      correct. The user which MySQL runs as needs to be able to read and
  19831.      write to them, just as on the master.
  19832.  
  19833.   9. Restart the slave(s).
  19834.  
  19835.  
  19836. After you have done the above, the slave(s) should connect to the master
  19837. and catch up on any updates which happened since the snapshot was taken.
  19838.  
  19839. If you have forgotten to set `server-id' for the slave you will get the
  19840. following error in the error log file:
  19841.  
  19842.      Warning: one should set server_id to a non-0 value if master_host is set.
  19843.      The server will not act as a slave.
  19844.  
  19845. If you have forgot to do this for the master, the slaves will not be
  19846. able to connect to the master.
  19847.  
  19848. If a slave is not able to replicate for any reason, you will find error
  19849. messages in the error log on the slave.
  19850.  
  19851. Once a slave is replicating, you will find a file called `master.info'
  19852. in the same directory as your error log. The `master.info' file is used
  19853. by the slave to keep track of how much of the master's binary log is
  19854. has processed. *Do not* remove or edit the file, unless you really know
  19855. what you are doing. Even in that case, it is preferred that you use
  19856. `CHANGE MASTER TO' command.
  19857.  
  19858. Replication Features and Known Problems
  19859. ---------------------------------------
  19860.  
  19861. Below is an explanation of what is supported and what is not:
  19862.  
  19863.    * Replication will be done correctly with `AUTO_INCREMENT',
  19864.      `LAST_INSERT_ID', and `TIMESTAMP' values.
  19865.  
  19866.    * `RAND()' in updates does not replicate properly. Use
  19867.      `RAND(some_non_rand_expr)' if you are replicating updates with
  19868.      `RAND()'. You can, for example, use `UNIX_TIMESTAMP()' for the
  19869.      argument to `RAND()'.
  19870.  
  19871.    * You have to use the same character set (`--default-character-set')
  19872.      on the master and the slave. If not, you may get duplicate key
  19873.      errors on the slave, because a key that is regarded as unique on
  19874.      the master may not be that in the other character set.
  19875.  
  19876.    * `LOAD DATA INFILE' will be handled properly as long as the file
  19877.      still resides on the master server at the time of update
  19878.      propagation. `LOAD LOCAL DATA INFILE' will be skipped.
  19879.  
  19880.    * Update queries that use user variables are not replication-safe
  19881.      (yet).
  19882.  
  19883.    * `FLUSH' commands are not stored in the binary log and are because
  19884.      of this not replicated to the slaves. This is not normally a
  19885.      problem as `FLUSH' doesn't change anything. This does however mean
  19886.      that if you update the `MySQL' privilege tables directly without
  19887.      using `GRANT' statement and you replicate the `MySQL' privilege
  19888.      database, you must do a `FLUSH PRIVILEGES' on your slaves to put
  19889.      the new privileges into effect.
  19890.  
  19891.    * Temporary tables starting in 3.23.29 are replicated properly with
  19892.      the exception of the case when you shut down slave server ( not
  19893.      just slave thread), you have some temporary tables open, and the
  19894.      are used in subsequent updates.  To deal with this problem, to
  19895.      shut down the slave, do `SLAVE STOP', then check
  19896.      `Slave_open_temp_tables' variable to see if it is 0, then issue
  19897.      `mysqladmin shutdown'. If the number is not 0, restart the slave
  19898.      thread with `SLAVE START' and see if you have better luck next
  19899.      time. There will be a cleaner solution, but it has to wait until
  19900.      version 4.0.  In earlier versions temporary tables are not being
  19901.      replicated properly - we recommend that you either upgrade, or
  19902.      execute `SET SQL_LOG_BIN=0' on your clients before all queries
  19903.      with temp tables.
  19904.  
  19905.    * MySQL only supports one master and many slaves. We will in 4.x add
  19906.      a voting algorithm to automatically change master if something goes
  19907.      wrong with the current master. We will also introduce 'agent'
  19908.      processes to help doing load balancing by sending select queries
  19909.      to different slaves.
  19910.  
  19911.    * Starting in Version 3.23.26, it is safe to connect servers in a
  19912.      circular master-slave relationship with `log-slave-updates'
  19913.      enabled.  Note, however, that many queries will not work right in
  19914.      this kind of setup unless your client code is written to take care
  19915.      of the potential problems that can happen from updates that occur
  19916.      in different sequence on different servers.
  19917.  
  19918.      This means that you can do a setup like the following:
  19919.  
  19920.           A -> B -> C -> A
  19921.  
  19922.      This setup will only works if you only do non conflicting updates
  19923.      between the tables.  In other words, if you insert data in A and
  19924.      C, you should never insert a row in A that may have a conflicting
  19925.      key with a row insert in C.  You should also not update the sam
  19926.      rows on two servers if the order in which the updates are applied
  19927.      matters.
  19928.  
  19929.      Note that the log format has changed in Version 3.23.26 so that
  19930.      pre-3.23.26 slaves will not be able to read it.
  19931.  
  19932.    * If the query on the slave gets an error, the slave thread will
  19933.      terminate, and a message will appear in the `.err' file. You should
  19934.      then connect to the slave manually, fix the cause of the error (for
  19935.      example, non-existent table), and then run `SLAVE START' sql
  19936.      command (available starting in Version 3.23.16). In Version
  19937.      3.23.15, you will have to restart the server.
  19938.  
  19939.    * If connection to the master is lost, the slave will retry
  19940.      immediately, and then in case of failure every
  19941.      `master-connect-retry' (default 60) seconds. Because of this, it
  19942.      is safe to shut down the master, and then restart it after a
  19943.      while. The slave will also be able to deal with network
  19944.      connectivity outages.
  19945.  
  19946.    * Shutting down the slave (cleanly) is also safe, as it keeps track
  19947.      of where it left off.  Unclean shutdowns might produce problems,
  19948.      especially if disk cache was not synced before the system died.
  19949.      Your system fault tolerance will be greatly increased if you have
  19950.      a good UPS.
  19951.  
  19952.    * If the master is listening on a non-standard port, you will also
  19953.      need to specify this with `master-port' parameter in `my.cnf' .
  19954.  
  19955.    * In Version 3.23.15, all of the tables and databases will be
  19956.      replicated. Starting in Version 3.23.16, you can restrict
  19957.      replication to a set of databases with `replicate-do-db'
  19958.      directives in `my.cnf' or just exclude a set of databases with
  19959.      `replicate-ignore-db'. Note that up until Version 3.23.23, there
  19960.      was a bug that did not properly deal with `LOAD DATA INFILE' if
  19961.      you did it in a database that was excluded from replication.
  19962.  
  19963.    * Starting in Version 3.23.16, `SET SQL_LOG_BIN = 0' will turn off
  19964.      replication (binary) logging on the master, and `SET SQL_LOG_BIN =
  19965.      1' will turn in back on - you must have the process privilege to do
  19966.      this.
  19967.  
  19968.    * Starting in Version 3.23.19, you can clean up stale replication
  19969.      leftovers when something goes wrong and you want a clean start
  19970.      with `FLUSH MASTER' and `FLUSH SLAVE' commands. In Version 3.23.26
  19971.      we have renamed them to `RESET MASTER' and `RESET SLAVE'
  19972.      respectively to clarify what they do. The old `FLUSH' variants
  19973.      still work, though, for compatibility.
  19974.  
  19975.    * Starting in Version 3.23.21, you can use `LOAD TABLE FROM MASTER'
  19976.      for network backup and to set up replication initially. We have
  19977.      recently received a number of bug reports concerning it that we
  19978.      are investigating, so we recommend that you use it only in testing
  19979.      until we make it more stable.
  19980.  
  19981.    * Starting in Version 3.23.23, you can change masters and adjust log
  19982.      position with `CHANGE MASTER TO'.
  19983.  
  19984.    * Starting in Version 3.23.23, you tell the master that updates in
  19985.      certain databases should not be logged to the binary log with
  19986.      `binlog-ignore-db'.
  19987.  
  19988.    * Starting in Version 3.23.26, you can use `replicate-rewrite-db' to
  19989.      tell the slave to apply updates from one database on the master to
  19990.      the one with a different name on the slave.
  19991.  
  19992.    * Starting in Version 3.23.28, you can use `PURGE MASTER LOGS TO
  19993.      'log-name'' to get rid of old logs while the slave is running.
  19994.  
  19995. Replication Options in my.cnf
  19996. -----------------------------
  19997.  
  19998. If you are using replication, we recommend you to use MySQL Version
  19999. 3.23.30 or later. Older versions work, but they do have some bugs and
  20000. are missing some features.
  20001.  
  20002. On both master and slave you need to use the `server-id' option.  This
  20003. sets an unique replication id. You should pick a unique value in the
  20004. range between 1 to 2^32-1 for each master and slave.  Example:
  20005. `server-id=3'
  20006.  
  20007. The following table has the options you can use for the *MASTER*:
  20008.  
  20009. *Option*               *Description*
  20010. `log-bin=filename'      Write to a binary update log to the specified
  20011.                        location. Note that if you give it a parameter
  20012.                        with an extension (for example,
  20013.                        `log-bin=/mysql/logs/replication.log' ) versions
  20014.                        up to 3.23.24 will not work right during
  20015.                        replication if you do `FLUSH LOGS' . The problem
  20016.                        is fixed in Version 3.23.25. If you are using
  20017.                        this kind of log name, `FLUSH LOGS' will be
  20018.                        ignored on binlog. To clear the log, run `FLUSH
  20019.                        MASTER', and do not forget to run `FLUSH SLAVE'
  20020.                        on all slaves. In Version 3.23.26 and in later
  20021.                        versions you should use `RESET MASTER' and `RESET
  20022.                        SLAVE'
  20023. `log-bin-index=filename' Because the user could issue the `FLUSH LOGS'
  20024.                        command, we need to know which log is currently
  20025.                        active and which ones have been rotated out and
  20026.                        in what sequence. This information is stored in
  20027.                        the binary log index file.  The default is
  20028.                        `hostname`.index. You can use this option if you
  20029.                        want to be a rebel.
  20030.                        
  20031.                        Example: `log-bin-index=db.index'.
  20032. `sql-bin-update-same'   If set, setting `SQL_LOG_BIN' to a value will
  20033.                        automatically set `SQL_LOG_UPDATE' to the same
  20034.                        value and vice versa.
  20035. `binlog-do-db=database_name' Tells the master that it should log updates to
  20036.                        the binary log if the current database is
  20037.                        'database_name'. All others database are ignored.
  20038.                        Note that if you use this you should ensure that
  20039.                        you only do updates in the current database.
  20040.                        
  20041.                        Example: `binlog-do-db=some_database'.
  20042. `binlog-ignore-db=database_name' Tells the master that updates where the current
  20043.                        database is 'database_name' should not be stored
  20044.                        in the binary log.  Note that if you use this you
  20045.                        should ensure that you only do updates in the
  20046.                        current database.
  20047.                        
  20048.                        Example: `binlog-ignore-db=some_database'
  20049.  
  20050. The following table has the options you can use for the *SLAVE*:
  20051.  
  20052. *Option*               *Description*
  20053. `master-host=host'      Master hostname or IP address for replication.
  20054.                        If not set, the slave thread will not be started.
  20055.                        
  20056.                        Example: `master-host=db-master.mycompany.com'.
  20057. `master-user=username'  The user the slave thread will us for
  20058.                        authentication when connecting to the master. The
  20059.                        user must have `FILE' privilege. If the master
  20060.                        user is not set, user `test' is assumed.
  20061.                        
  20062.                        Example: `master-user=scott'.
  20063. `master-password=password' The password the slave thread will authenticate
  20064.                        with when connecting to the master. If not set,
  20065.                        an empty password is assumed.
  20066.                        
  20067.                        Example: `master-password=tiger'.
  20068. `master-port=portnumber' The port the master is listening on. If not set,
  20069.                        the compiled setting of `MYSQL_PORT' is assumed.
  20070.                        If you have not tinkered with `configure'
  20071.                        options, this should be 3306.
  20072.                        
  20073.                        Example: `master-port=3306'.
  20074. `master-connect-retry=seconds' The number of seconds the slave thread will
  20075.                        sleep before retrying to connect to the master in
  20076.                        case the master goes down or the connection is
  20077.                        lost.  Default is 60.
  20078.                        
  20079.                        Example: `master-connect-retry=60'.
  20080. `master-info-file=filename' The location of the file that remembers where we
  20081.                        left off on the master during the replication
  20082.                        process. The default is master.info in the data
  20083.                        directory.  Sasha: The only reason I see for ever
  20084.                        changing the default is the desire to be
  20085.                        rebelious.
  20086.                        
  20087.                        Example: `master-info-file=master.info'.
  20088. `replicate-do-table=db_name.table_name' Tells the slave thread to restrict replication
  20089.                        to the specified table.  To specify more than one
  20090.                        table, use the directive multiple times, once for
  20091.                        each table.  This will work for cross-database
  20092.                        updates, in contrast to `replicate-do-db'.
  20093.                        
  20094.                        Example: `replicate-do-table=some_db.some_table'.
  20095. `replicate-ignore-table=db_name.table_name' Tells the slave thread to not replicate to the
  20096.                        specified table. To specify more than one table
  20097.                        to ignore, use the directive multiple times, once
  20098.                        for each table. This will work for cross-datbase
  20099.                        updates, in contrast to `replicate-ignore-db'.
  20100.                        
  20101.                        Example:
  20102.                        `replicate-ignore-table=db_name.some_table'.
  20103. `replicate-wild-do-table=db_name.table_name' Tells the slave thread to restrict replication
  20104.                        to the tables that match the specified wildcard
  20105.                        pattern.  To specify more than one table, use the
  20106.                        directive multiple times, once for each table.
  20107.                        This will work for cross-database updates.
  20108.                        
  20109.                        Example: `replicate-wild-do-table=foo%.bar%' will
  20110.                        replicate only updates to tables in all databases
  20111.                        that start with foo and whose table names start
  20112.                        with bar.
  20113. `replicate-wild-ignore-table=db_name.table_name' Tells the slave thread to not replicate to the
  20114.                        tables that match the given wild card pattern. To
  20115.                        specify more than one table to ignore, use the
  20116.                        directive multiple times, once for each table.
  20117.                        This will work for cross-database updates.
  20118.                        
  20119.                        Example: `replicate-wild-ignore-table=foo%.bar%'
  20120.                        will not do updates to tables in databases that
  20121.                        start with foo and whose table names start with
  20122.                        bar.
  20123. `replicate-ignore-db=database_name' Tells the slave thread to not replicate to the
  20124.                        specified database. To specify more than one
  20125.                        database to ignore, use the directive multiple
  20126.                        times, once for each database. This option will
  20127.                        not work if you use cross database updates. If
  20128.                        you need cross database updates to work, make sure
  20129.                        you have 3.23.28 or later, and use
  20130.                        `replicate-wild-ignore-table=db_name.%'
  20131.                        
  20132.                        Example: `replicate-ignore-db=some_db'.
  20133. `replicate-do-db=database_name' Tells the slave thread to restrict replication
  20134.                        to the specified database.  To specify more than
  20135.                        one database, use the directive multiple times,
  20136.                        once for each database. Note that this will only
  20137.                        work if you do not use cross-database queries
  20138.                        such as `UPDATE some_db.some_table SET foo='bar''
  20139.                        while having selected a different or no database.
  20140.                        If you need cross database updates to work, make
  20141.                        sure you have 3.23.28 or later, and use
  20142.                        `replicate-wild-do-table=db_name.%'
  20143.                        
  20144.                        Example: `replicate-do-db=some_db'.
  20145. `log-slave-updates'     Tells the slave to log the updates from the
  20146.                        slave thread to the binary log. Off by default.
  20147.                        You will need to turn it on if you plan to
  20148.                        daisy-chain the slaves.
  20149. `replicate-rewrite-db=from_name->to_name' Updates to a database with a different name than
  20150.                        the original
  20151.                        
  20152.                        Example:
  20153.                        `replicate-rewrite-db=master_db_name->slave_db_name'.
  20154. `skip-slave-start'      Tells the slave server not to start the slave on
  20155.                        the startup.  The user can start it later with
  20156.                        `SLAVE START'.
  20157. `slave_read_timeout=#'  Number of seconds to wait for more data from the
  20158.                        master before aborting the read.
  20159.  
  20160. SQL Commands Related to Replication
  20161. -----------------------------------
  20162.  
  20163. Replication can be controlled through the SQL interface. Below is the
  20164. summary of commands:
  20165.  
  20166. *Command*              *Description*
  20167. `SLAVE START'          Starts the slave thread. (Slave)
  20168. `SLAVE STOP'           Stops the slave thread. (Slave)
  20169. `SET SQL_LOG_BIN=0'    Disables update logging if the user has process
  20170.                        privilege.   Ignored otherwise. (Master)
  20171. `SET SQL_LOG_BIN=1'    Re-enables update logging if the user has process
  20172.                        privilege.   Ignored otherwise. (Master)
  20173. `SET                   Skip the next `n' events from the master. Only
  20174. SQL_SLAVE_SKIP_COUNTER=n'valid when the slave thread is not running,
  20175.                        otherwise, gives an error. Useful for recovering
  20176.                        from replication glitches.
  20177. `RESET MASTER'         Deletes all binary logs listed in the index file,
  20178.                        resetting the binlog index file to be empty. In
  20179.                        pre-3.23.26 versions, `FLUSH MASTER' (Master)
  20180. `RESET SLAVE'          Makes the slave forget its replication position
  20181.                        in the master logs. In pre 3.23.26 versions the
  20182.                        command was called `FLUSH SLAVE'(Slave)
  20183. `LOAD TABLE tblname    Downloads a copy of the table from master to the
  20184. FROM MASTER'           slave. (Slave)
  20185. `CHANGE MASTER TO      Changes the master parameters to the values
  20186. master_def_list'       specified in `master_def_list' and restarts the
  20187.                        slave thread. `master_def_list' is a
  20188.                        comma-separated list of `master_def' where
  20189.                        `master_def' is one of the following:
  20190.                        `MASTER_HOST', `MASTER_USER', `MASTER_PASSWORD',
  20191.                        `MASTER_PORT', `MASTER_CONNECT_RETRY',
  20192.                        `MASTER_LOG_FILE', `MASTER_LOG_POS'. Example:
  20193.                        
  20194.                        
  20195.                             CHANGE MASTER TO
  20196.                               MASTER_HOST='master2.mycompany.com',
  20197.                               MASTER_USER='replication',
  20198.                               MASTER_PASSWORD='bigs3cret',
  20199.                               MASTER_PORT=3306,
  20200.                               MASTER_LOG_FILE='master2-bin.001',
  20201.                               MASTER_LOG_POS=4;
  20202.                        You only need to specify the values that need to
  20203.                        be changed. The values that you omit will stay
  20204.                        the same with the exception of when you change
  20205.                        the host or the port. In that case, the slave
  20206.                        will assume that since you are connecting to a
  20207.                        different host or a different port, the master is
  20208.                        different. Therefore, the old values of log and
  20209.                        position are not applicable anymore, and will
  20210.                        automatically be reset to an empty string and 0,
  20211.                        respectively (the start values). Note that if you
  20212.                        restart the slave, it will remember its last
  20213.                        master.  If this is not desirable, you should
  20214.                        delete the `master.info' file before restarting,
  20215.                        and the slave will read its master from `my.cnf'
  20216.                        or the command line. (Slave)
  20217. `SHOW MASTER STATUS'   Provides status information on the binlog of the
  20218.                        master. (Master)
  20219. `SHOW SLAVE STATUS'    Provides status information on essential
  20220.                        parameters of the slave thread. (Slave)
  20221. `SHOW MASTER LOGS'     Only available starting in Version 3.23.28. Lists
  20222.                        the binary logs on the master. You should use
  20223.                        this command prior to `PURGE MASTER LOGS TO' to
  20224.                        find out how far you should go.
  20225. `PURGE MASTER LOGS TO  Available starting in Version 3.23.28. Deletes
  20226. 'logname''             all the replication logs that are listed in the
  20227.                        log index as being prior to the specified log,
  20228.                        and removed them from the log index, so that the
  20229.                        given log now becomes first. Example:
  20230.                        
  20231.                             PURGE MASTER LOGS TO 'mysql-bin.010'
  20232.                        This command will do nothing and fail with an
  20233.                        error if you have an active slave that is
  20234.                        currently reading one of the logs you are trying
  20235.                        to delete. However, if you have a dormant slave,
  20236.                        and happen to purge one of the logs it wants to
  20237.                        read, the slave will be unable to replicate once
  20238.                        it comes up.  The command is safe to run while
  20239.                        slaves are replicating - you do not need to stop
  20240.                        them.
  20241.                        
  20242.                        You must first check all the slaves with `SHOW
  20243.                        SLAVE STATUS' to see which log they are on, then
  20244.                        do a listing of the logs on the master with `SHOW
  20245.                        MASTER LOGS', find the earliest log among all the
  20246.                        slaves (if all the slaves are up to date, this
  20247.                        will be the last log on the list), backup all the
  20248.                        logs you are about to delete (optional) and purge
  20249.                        up to the target log.
  20250.  
  20251. Replication FAQ
  20252. ---------------
  20253.  
  20254. *Q*: Why do I sometimes see more than one `Binlog_Dump' thread on the
  20255. master after I have restarted the slave?
  20256.  
  20257. *A*: `Binlog_Dump' is a continuous process that is handled by the
  20258. server in the following way:
  20259.  
  20260.    * Catch up on the updates.
  20261.  
  20262.    * Once there are no more updates left, go into `pthread_cond_wait()',
  20263.      from which we can be awakened either by an update or a kill.
  20264.  
  20265.    * On wake up, check the reason. If we are not supposed to die,
  20266.      continue the `Binlog_dump' loop.
  20267.  
  20268.    * If there is some fatal error, such as detecting a dead client,
  20269.      terminate the loop.
  20270.  
  20271. So if the slave thread stops on the slave, the corresponding
  20272. `Binlog_Dump' thread on the master will not notice it until after at
  20273. least one update to the master (or a kill), which is needed to wake it
  20274. up from `pthread_cond_wait()'.  In the meantime, the slave could have
  20275. opened another connection, which resulted in another `Binlog_Dump'
  20276. thread.
  20277.  
  20278. The above problem should not be present in Version 3.23.26 and later
  20279. versions.  In Version 3.23.26 we added `server-id' to each replication
  20280. server, and now all the old zombie threads are killed on the master
  20281. when a new replication thread connects from the same slave
  20282.  
  20283. *Q*: How do I rotate replication logs?
  20284.  
  20285. *A*: In Version 3.23.28 you should use `PURGE MASTER LOGS TO' command
  20286. after determining which logs can be deleted, and optionally backing
  20287. them up first. In earlier versions the process is much more painful,
  20288. and cannot be safely done without stopping all the slaves in the case
  20289. that you plan to re-use log names. You will need to stop the slave
  20290. threads, edit the binary log index file, delete all the old logs,
  20291. restart the master, start slave threads, and then remove the old log
  20292. files.
  20293.  
  20294. *Q*: How do I upgrade on a hot replication setup?
  20295.  
  20296. *A*: If you are upgrading  pre-3.23.26 versions, you should just lock
  20297. the master tables, let the slave catch up, then run `FLUSH MASTER' on
  20298. the master, and `FLUSH SLAVE' on the slave to reset the logs, then
  20299. restart new versions of the master and the slave. Note that the slave
  20300. can stay down for some time - since the master is logging all the
  20301. updates, the slave will be able to catch up once it is up and can
  20302. connect.
  20303.  
  20304. After 3.23.26, we have locked the replication protocol for
  20305. modifications, so you can upgrade masters and slave on the fly to a
  20306. newer 3.23 version and you can have different versions of MySQL running
  20307. on the slave and the master, as long as they are both newer than
  20308. 3.23.26.
  20309.  
  20310. *Q*: What issues should I be aware of when setting up two-way
  20311. replication?
  20312.  
  20313. *A*: MySQL replication currently does not support any locking protocol
  20314. between master and slave to guarantee the atomicity of a distributed
  20315. (cross-server) update. In in other words, it is possible for client A
  20316. to make an update to  co-master 1, and in the meantime, before it
  20317. propagates to co-master 2, client B could make an update to co-master 2
  20318. that will make the update of client A work differently than it did on
  20319. co-master 1. Thus when the update of client A will make it to co-master
  20320. 2, it will produce  tables that will be different than what you have on
  20321. co-master 1, even after all the updates from co-master 2 have also
  20322. propagated. So you should not co-chain two servers in a two-way
  20323. replication relationship, unless you are sure that you updates can
  20324. safely happen in any order, or unless you take care of mis-ordered
  20325. updates somehow in the client code.
  20326.  
  20327. You must also realize that two-way replication actually does not improve
  20328. performance very much, if at all, as far as updates are concerned. Both
  20329. servers need to do the same amount of updates each, as you would have
  20330. one server do. The only difference is that there will be a little less
  20331. lock contention, because the updates originating on another server will
  20332. be serialized in one slave thread. This benefit, though, might be
  20333. offset by network delays.
  20334.  
  20335. *Q*: How can I use replication to improve performance of my system?
  20336.  
  20337. *A*: You should set up one server as the master, and direct all writes
  20338. to it, and configure as many slaves as you have the money and rackspace
  20339. for, distributing the reads among the master and the slaves.  You can
  20340. also start the slaves with `--skip-bdb', `--low-priority-updates' and
  20341. `--delay-key-write-for-all-tables' to get speed improvements for the
  20342. slave.  In this case the slave will use non-transactional `MyISAM'
  20343. tables instead of `BDB' tables to get more speed.
  20344.  
  20345. *Q*: What should I do to prepare my client code to use
  20346. performance-enhancing replication?
  20347.  
  20348. *A*: If the part of your code that is responsible for database access
  20349. has been properly abstracted/modularized, converting it to run with the
  20350. replicated setup should be very smooth and easy - just change the
  20351. implementation of your database access to read from some slave or the
  20352. master, and to always write to the master. If your code does not have
  20353. this level of abstraction, setting up a replicated system will give you
  20354. an opportunity/motivation to it clean up.   You should start by
  20355. creating a wrapper library /module with the following functions:
  20356.  
  20357.    * `safe_writer_connect()'
  20358.  
  20359.    * `safe_reader_connect()'
  20360.  
  20361.    * `safe_reader_query()'
  20362.  
  20363.    * `safe_writer_query()'
  20364.  
  20365. `safe_' means that the function will take care of handling all the
  20366. error conditions.
  20367.  
  20368. You should then convert your client code to use the wrapper library.
  20369. It may be a painful and scary process at first, but it will pay off in
  20370. the long run. All applications that follow the above pattern will be
  20371. able to take advantage of one-master/many slaves solution.  The code
  20372. will be a lot easier to maintain, and adding troubleshooting options
  20373. will be trivial. You will just need to modify one or two functions, for
  20374. example, to log how long each query took, or which query, among your
  20375. many thousands, gave you an error. If you have written a lot of code
  20376. already, you may want to automate the conversion task by using Monty's
  20377. `replace' utility, which comes with the standard distribution of MySQL,
  20378. or just write your own Perl script. Hopefully, your code follows some
  20379. recognizable pattern. If not, then you are probably better off
  20380. re-writing it anyway, or at least going through and manually beating it
  20381. into a pattern.
  20382.  
  20383. Note that, of course, you can use different names for the functions.
  20384. What is important is having unified interface for connecting for reads,
  20385. connecting for writes, doing a read, and doing a write.
  20386.  
  20387. *Q*: When and how much can MySQL replication improve the performance of
  20388. my system?
  20389.  
  20390. *A*: MySQL replication is most beneficial for a system with frequent
  20391. reads and not so frequent writes. In theory, by using a one master/many
  20392. slaves setup you can scale by adding more slaves until you either run
  20393. out of network bandwidth, or your update load grows to the point that
  20394. the master cannot handle it.
  20395.  
  20396. In order to determine how many slaves you can get before the added
  20397. benefits begin to level out, and how much you can improve performance
  20398. of your site, you need to know your query patterns, and empirically
  20399. (by benchmarking) determine the relationship between the throughput on
  20400. reads (reads per second, or `max_reads') and on writes `max_writes') on
  20401. a typical master and a typical slave. The example below will show you a
  20402. rather simplified calculation of what you can get with replication for
  20403. our imagined system.
  20404.  
  20405. Let's say our system load consists of 10% writes and 90% reads, and we
  20406. have determined that `max_reads' = 1200 - 2 * `max_writes', or in other
  20407. words, our system can do 1200 reads per second with no writes, our
  20408. average write is twice as slow as average read, and the relationship is
  20409. linear. Let us suppose that our master and slave are of the same
  20410. capacity, and we have N slaves and 1 master. Then we have for each
  20411. server (master or slave):
  20412.  
  20413. `reads = 1200 - 2 * writes' (from bencmarks)
  20414.  
  20415. `reads = 9* writes / (N + 1) ' (reads split, but writes go to all
  20416. servers)
  20417.  
  20418. `9*writes/(N+1) + 2 * writes = 1200'
  20419.  
  20420. `writes = 1200/(2 + 9/(N+1)'
  20421.  
  20422. So if N = 0, which means we have no replication, our system can handle
  20423. 1200/11, about 109 writes per second (which means we will have 9 times
  20424. as many reads due to the nature of our application).
  20425.  
  20426. If N = 1, we can get up to 184 writes per second.
  20427.  
  20428. If N = 8, we get up to 400.
  20429.  
  20430. If N = 17, 480 writes.
  20431.  
  20432. Eventually as N approaches infinity (and our budget negative infinity),
  20433. we can get very close to 600 writes per second, increasing system
  20434. throughput about 5.5 times. However, with only 8 servers, we increased
  20435. it almost 4 times already.
  20436.  
  20437. Note that our computations assumed infinite network bandwidth, and
  20438. neglected several other factors that could turn out to be significant on
  20439. your system. In many cases, you may not be able to make a computation
  20440. similar to the one above that will accurately predict what will happen
  20441. on your system if you add N replication slaves. However, answering the
  20442. following questions should help you decided whether and how much, if at
  20443. all, the replication will improve the performance of your system:
  20444.  
  20445.    * What is the read/write ratio on your system?
  20446.  
  20447.    * How much more write load can one server handle if you reduce the
  20448.      reads?
  20449.  
  20450.    * How many slaves do you have bandwidth for on your network?
  20451.  
  20452. *Q*: How can I use replication to provide redundancy/high availability?
  20453.  
  20454. *A*: With the currently available features, you would have to set up a
  20455. master and a slave (or several slaves), and write a script that will
  20456. monitor the master to see if it is up, and instruct your applications
  20457. and the slaves of the master change in case of failure. Some
  20458. suggestions:
  20459.  
  20460.    * To tell a slave to change the master use the `CHANGE MASTER TO'
  20461.      command.
  20462.  
  20463.    * A good way to keep your applications informed where the master is
  20464.      by having a dynamic DNS entry for the master. With *bind* you can
  20465.      use `nsupdate' to dynamically update your DNS.
  20466.  
  20467.    * You should run your slaves with the `log-bin' option and without
  20468.      `log-slave-updates'. This way the slave will be ready to become a
  20469.      master as soon as you issue `STOP SLAVE'; `RESET MASTER', and
  20470.      `CHANGE MASTER TO' on the other slaves. It will also help you catch
  20471.      spurious updates that may happen because of misconfiguration of the
  20472.      slave (ideally, you want to configure access rights so that no
  20473.      client can update the slave, except for the slave thread) combined
  20474.      with the bugs in your client programs (they should never update
  20475.      the slave directly).
  20476.  
  20477.  
  20478. We are currently working on integrating an automatic master election
  20479. system into MySQL, but until it is ready, you will have to create your
  20480. own monitoring tools.
  20481.  
  20482. Troubleshooting Replication
  20483. ---------------------------
  20484.  
  20485. If you have followed the instructions, and your replication setup is not
  20486. working, first eliminate the user error factor by checking the
  20487. following:
  20488.  
  20489.    * Is the master logging to the binary log? Check with `SHOW MASTER
  20490.      STATUS'.  If it is, `Position' will be non-zero. If not, verify
  20491.      that you have given the master `log-bin' option and have set
  20492.      `server-id'.
  20493.  
  20494.    * Is the slave running? Check with `SHOW SLAVE STATUS'. The answer
  20495.      is found in `Slave_running' column. If not, verify slave options
  20496.      and check the error log for messages.
  20497.  
  20498.    * If the slave is running, did it establish connection with the
  20499.      master? Do `SHOW PROCESSLIST', find the thread with `system user'
  20500.      value in `User' column and `none' in the `Host' column, and check
  20501.      the `State' column. If it says `connecting to master', verify the
  20502.      privileges for the replication user on the master, master host
  20503.      name, your DNS setup, whether the master is actually running,
  20504.      whether it is reachable from the slave, and if all that seems ok,
  20505.      read the error logs.
  20506.  
  20507.    * If the slave was running, but then stopped, look at SHOW SLAVE
  20508.      STATUS output and check the error logs. It usually happens when
  20509.      some query that succeeded on the master fails on the slave. This
  20510.      should never happen if you have taken a proper snapshot of the
  20511.      master, and never modify the data on the slave outside of the
  20512.      slave thread. If it does, it is a bug, read below on how to report
  20513.      it.
  20514.  
  20515.    * If a query on that succeeded on the master refuses to run on the
  20516.      slave, and a full database resync ( the proper thing to do ) does
  20517.      not seem feasible, try the following:
  20518.         - First see if there is some stray record in the way.
  20519.           Understand how it got there, then delete it and run `SLAVE
  20520.           START'
  20521.  
  20522.         - If the above does not work or does not apply, try to
  20523.           understand if it would be safe to make the update manually (
  20524.           if needed) and then ignore the next query from the master.
  20525.  
  20526.         - If you have decided you can skip the next query, do `SET
  20527.           SQL_SLAVE_SKIP_COUNTER=1; SLAVE START;' to skip a query that
  20528.           does not use auto_increment, or last_insert_id  or `SET
  20529.           SQL_SLAVE_SKIP_COUNTER=2; SLAVE START;' otherwise. The reason
  20530.           auto_increment/last_insert_id queries are different is that
  20531.           they take two events in the binary log of the master.
  20532.  
  20533.         - If you are sure the slave started out perfectly in sync with
  20534.           the master, and no one has updated  the tables involved
  20535.           outside of slave thread, report the bug, so you will not have
  20536.           to do the above tricks again.
  20537.  
  20538.    * Make sure you are not running into an old bug by upgrading to the
  20539.      most recent version.
  20540.  
  20541.    * If all else fails, read the error logs. If they are big, `grep -i
  20542.      slave /path/to/your-log.err' on the slave. There is no generic
  20543.      pattern to search for on the master, as the only errors it logs
  20544.      are general system errors - if it can, it will send the error to
  20545.      the slave when things go wrong.
  20546.  
  20547. When you have determined that there is no user error involved, and
  20548. replication still either does not work at all or is unstable, it is
  20549. time to start working on a bug report. We need to get as much info as
  20550. possible from you to be able to track down the bug. Please do spend
  20551. some time and effort preparing a good bug report. Ideally, we would
  20552. like to have a test case in the format found in `mysql-test/t/rpl*'
  20553. directory of the source tree. If you submit a test case like that, you
  20554. can expect a patch within a day or two in most cases, although, of
  20555. course, you mileage may vary depending on a number of factors.
  20556.  
  20557. Second best option is a just program with easily configurable connection
  20558. arguments for the master and the slave that will demonstrate the
  20559. problem on our systems. You can write one in Perl or in C, depending on
  20560. which language you know better.
  20561.  
  20562. If you have one of the above ways to demonstrate the bug, use
  20563. `mysqlbug' to prepare a bug report and send it to
  20564. <bugs@lists.mysql.com>. If you have a phantom - a problem that does
  20565. occur but you cannot duplicate "at will":
  20566.  
  20567.    * Verify that there is no user error involved. For example, if you
  20568.      update the slave outside of the slave thread, the data will be out
  20569.      of sync, and you can have unique key violations on updates, in
  20570.      which case the slave thread will stop and wait for you to clean up
  20571.      the tables manually to bring them in sync.
  20572.  
  20573.    * Run slave with `log-slave-updates' and `log-bin' - this will keep
  20574.      a log of all updates on the slave.
  20575.  
  20576.    * Save all evidence before resetting the replication. If we have no
  20577.      or only sketchy information, it would take us a while to track
  20578.      down the problem. The evidence you should collect is:
  20579.         - All binary logs on the master
  20580.  
  20581.         - All binary log on the slave
  20582.  
  20583.         - The output of `SHOW MASTER STATUS' on the master at the time
  20584.           you have discovered the problem
  20585.  
  20586.         - The output of `SHOW SLAVE STATUS' on the master at the time
  20587.           you have discovered the problem
  20588.  
  20589.         - Error logs on the master and on the slave
  20590.  
  20591.    * Use `mysqlbinlog' to examine the binary logs. The following should
  20592.      be helpful to find the trouble query, for example:
  20593.           mysqlbinlog -j pos_from_slave_status /path/to/log_from_slave_status | head
  20594.  
  20595. Once you have collected the evidence on the phantom problem, try hard to
  20596. isolate it into a separate test case first. Then report the problem to
  20597. <bugs@lists.mysql.com> with as much info as possible.
  20598.  
  20599. MySQL Optimization
  20600. ******************
  20601.  
  20602. Optimization is a complicated task because it ultimately requires
  20603. understanding of the whole system. While it may be possible to do some
  20604. local optimizations with small knowledge of your system or application,
  20605. the more optimal you want your system to become the more you will have
  20606. to know about it.
  20607.  
  20608. This chapter will try to explain and give some examples of different
  20609. ways to optimize MySQL.  Remember, however, that there are always some
  20610. (increasingly harder) additional ways to make the system even faster.
  20611.  
  20612. Optimization Overview
  20613. =====================
  20614.  
  20615. The most important part for getting a system fast is of course the basic
  20616. design. You also need to know what kinds of things your system will be
  20617. doing, and what your bottlenecks are.
  20618.  
  20619. The most common bottlenecks are:
  20620.    * Disk seeks.  It takes time for the disk to find a piece of data.
  20621.      With modern disks in 1999, the mean time for this is usually lower
  20622.      than 10ms, so we can in theory do about 1000 seeks a second. This
  20623.      time improves slowly with new disks and is very hard to optimize
  20624.      for a single table. The way to optimize this is to spread the data
  20625.      on more than one disk.
  20626.  
  20627.    * Disk reading/writing.  When the disk is at the correct position we
  20628.      need to read the data. With modern disks in 1999, one disk
  20629.      delivers something like 10-20Mb/s. This is easier to optimize than
  20630.      seeks because you can read in parallel from multiple disks.
  20631.  
  20632.    * CPU cycles.  When we have the data in main memory (or if it
  20633.      already were there) we need to process it to get to our result.
  20634.      Having small tables compared to the memory is the most common
  20635.      limiting factor. But then, with small tables speed is usually not
  20636.      the problem.
  20637.  
  20638.    * Memory bandwidth.  When the CPU needs more data than can fit in
  20639.      the CPU cache the main memory bandwidth becomes a bottleneck. This
  20640.      is an uncommon bottleneck for most systems, but one should be
  20641.      aware of it.
  20642.  
  20643. MySQL Design Limitations/Tradeoffs
  20644. ----------------------------------
  20645.  
  20646. Because MySQL uses extremely fast table locking (multiple readers /
  20647. single writers) the biggest remaining problem is a mix of a steady
  20648. stream of inserts and slow selects on the same table.
  20649.  
  20650. We believe that for a huge number of systems the extremely fast
  20651. performance in other cases make this choice a win. This case is usually
  20652. also possible to solve by having multiple copies of the table, but it
  20653. takes more effort and hardware.
  20654.  
  20655. We are also working on some extensions to solve this problem for some
  20656. common application niches.
  20657.  
  20658. Portability
  20659. -----------
  20660.  
  20661. Because all SQL servers implement different parts of SQL, it takes work
  20662. to write portable SQL applications. For very simple selects/inserts it
  20663. is very easy, but the more you need the harder it gets. If you want an
  20664. application that is fast with many databases it becomes even harder!
  20665.  
  20666. To make a complex application portable you need to choose a number of
  20667. SQL servers that it should work with.
  20668.  
  20669. You can use the MySQL crash-me program/web-page
  20670. `http://www.mysql.com/information/crash-me.php' to find functions,
  20671. types, and limits you can use with a selection of database servers.
  20672. Crash-me now tests far from everything possible, but it is still
  20673. comprehensive with about 450 things tested.
  20674.  
  20675. For example, you shouldn't have column names longer than 18 characters
  20676. if you want to be able to use Informix or DB2.
  20677.  
  20678. Both the MySQL benchmarks and crash-me programs are very
  20679. database-independent.  By taking a look at how we have handled this, you
  20680. can get a feeling for what you have to do to write your application
  20681. database-independent.  The benchmarks themselves can be found in the
  20682. `sql-bench' directory in the MySQL source distribution. They are
  20683. written in Perl with DBI database interface (which solves the access
  20684. part of the problem).
  20685.  
  20686. See `http://www.mysql.com/information/benchmarks.html' for the results
  20687. from this benchmark.
  20688.  
  20689. As you can see in these results, all databases have some weak points.
  20690. That is, they have different design compromises that lead to different
  20691. behavior.
  20692.  
  20693. If you strive for database independence, you need to get a good feeling
  20694. for each SQL server's bottlenecks. MySQL is VERY fast in retrieving and
  20695. updating things, but will have a problem in mixing slow readers/writers
  20696. on the same table. Oracle, on the other hand, has a big problem when
  20697. you try to access rows that you have recently updated (until they are
  20698. flushed to disk). Transaction databases in general are not very good at
  20699. generating summary tables from log tables, as in this case row locking
  20700. is almost useless.
  20701.  
  20702. To get your application _really_ database-independent, you need to
  20703. define an easy extendable interface through which you manipulate your
  20704. data. As C++ is available on most systems, it makes sense to use a C++
  20705. classes interface to the databases.
  20706.  
  20707. If you use some specific feature for some database (like the `REPLACE'
  20708. command in MySQL), you should code a method for the other SQL servers
  20709. to implement the same feature (but slower).  With MySQL you can use the
  20710. `/*!  */' syntax to add MySQL-specific keywords to a query.  The code
  20711. inside `/**/' will be treated as a comment (ignored) by most other SQL
  20712. servers.
  20713.  
  20714. If REAL high performance is more important than exactness, as in some
  20715. Web applications, a possibility is to create an application layer that
  20716. caches all results to give you even higher performance. By letting old
  20717. results 'expire' after a while, you can keep the cache reasonably
  20718. fresh.  This is quite nice in case of extremely high load, in which case
  20719. you can dynamically increase the cache and set the expire timeout higher
  20720. until things get back to normal.
  20721.  
  20722. In this case the table creation information should contain information
  20723. of the initial size of the cache and how often the table should normally
  20724. be refreshed.
  20725.  
  20726. What Have We Used MySQL For?
  20727. ----------------------------
  20728.  
  20729. During MySQL initial development, the features of MySQL were made to
  20730. fit our largest customer. They handle data warehousing for a couple of
  20731. the biggest retailers in Sweden.
  20732.  
  20733. From all stores, we get weekly summaries of all bonus card transactions,
  20734. and we are expected to provide useful information for the store owners
  20735. to help them find how their advertisement campaigns are affecting their
  20736. customers.
  20737.  
  20738. The data is quite huge (about 7 million summary transactions per month),
  20739. and we have data for 4-10 years that we need to present to the users.
  20740. We got weekly requests from the customers that they want to get
  20741. 'instant' access to new reports from this data.
  20742.  
  20743. We solved this by storing all information per month in compressed
  20744. 'transaction' tables. We have a set of simple macros (script) that
  20745. generates summary tables grouped by different criteria (product group,
  20746. customer id, store ...) from the transaction tables.  The reports are
  20747. Web pages that are dynamically generated by a small Perl script that
  20748. parses a Web page, executes the SQL statements in it, and inserts the
  20749. results. We would have used PHP or mod_perl instead but they were not
  20750. available at that time.
  20751.  
  20752. For graphical data we wrote a simple tool in `C' that can produce GIFs
  20753. based on the result of a SQL query (with some processing of the
  20754. result). This is also dynamically executed from the Perl script that
  20755. parses the `HTML' files.
  20756.  
  20757. In most cases a new report can simply be done by copying an existing
  20758. script and modifying the SQL query in it.  In some cases, we will need
  20759. to add more fields to an existing summary table or generate a new one,
  20760. but this is also quite simple, as we keep all transactions tables on
  20761. disk.  (Currently we have at least 50G of transactions tables and 200G
  20762. of other customer data.)
  20763.  
  20764. We also let our customers access the summary tables directly with ODBC
  20765. so that the advanced users can themselves experiment with the data.
  20766.  
  20767. We haven't had any problems handling this with quite modest Sun Ultra
  20768. SPARCstation (2x200 Mhz). We recently upgraded one of our servers to a 2
  20769. CPU 400 Mhz UltraSPARC, and we are now planning to start handling
  20770. transactions on the product level, which would mean a ten-fold increase
  20771. of data. We think we can keep up with this by just adding more disk to
  20772. our systems.
  20773.  
  20774. We are also experimenting with Intel-Linux to be able to get more CPU
  20775. power cheaper. Now that we have the binary portable database format (new
  20776. in Version 3.23), we will start to use this for some parts of the
  20777. application.
  20778.  
  20779. Our initial feelings are that Linux will perform much better on
  20780. low-to-medium load and Solaris will perform better when you start to
  20781. get a high load because of extreme disk IO, but we don't yet have
  20782. anything conclusive about this. After some discussion with a Linux
  20783. Kernel developer, this might be a side effect of Linux giving so much
  20784. resources to the batch job that the interactive performance gets very
  20785. low. This makes the machine feel very slow and unresponsive while big
  20786. batches are going. Hopefully this will be better handled in future
  20787. Linux Kernels.
  20788.  
  20789. The MySQL Benchmark Suite
  20790. -------------------------
  20791.  
  20792. This should contain a technical description of the MySQL benchmark
  20793. suite (and `crash-me'), but that description is not written yet.
  20794. Currently, you can get a good idea of the benchmark by looking at the
  20795. code and results in the `sql-bench' directory in any MySQL source
  20796. distributions.
  20797.  
  20798. This benchmark suite is meant to be a benchmark that will tell any user
  20799. what things a given SQL implementation performs well or poorly at.
  20800.  
  20801. Note that this benchmark is single threaded, so it measures the minimum
  20802. time for the operations. We plan to in the future add a lot of
  20803. multi-threaded tests to the benchmark suite.
  20804.  
  20805. For example, (run on the same NT 4.0 machine):
  20806.  
  20807. *Reading 2000000 rows by index* *Seconds*                                   *Seconds*      
  20808. mysql                                       367            249
  20809. mysql_odbc                                  464            
  20810. db2_odbc                                    1206           
  20811. informix_odbc                               121126         
  20812. ms-sql_odbc                                 1634           
  20813. oracle_odbc                                 20800          
  20814. solid_odbc                                  877            
  20815. sybase_odbc                                 17614          
  20816.  
  20817.  
  20818. *Inserting (350768) rows* *Seconds*                                   *Seconds*      
  20819. mysql                                       381            206
  20820. mysql_odbc                                  619            
  20821. db2_odbc                                    3460           
  20822. informix_odbc                               2692           
  20823. ms-sql_odbc                                 4012           
  20824. oracle_odbc                                 11291          
  20825. solid_odbc                                  1801           
  20826. sybase_odbc                                 4802           
  20827.  
  20828.  
  20829. In the above test MySQL was run with a 8M index cache.
  20830.  
  20831. We have gather some more benchmark results at
  20832. `http://www.mysql.com/information/benchmarks.html'.
  20833.  
  20834. Note that Oracle is not included because they asked to be removed. All
  20835. Oracle benchmarks have to be passed by Oracle! We believe that makes
  20836. Oracle benchmarks *VERY* biased because the above benchmarks are
  20837. supposed to show what a standard installation can do for a single
  20838. client.
  20839.  
  20840. To run the benchmark suite, you have to download a MySQL source
  20841. distribution, install the perl DBI driver, the perl DBD driver for the
  20842. database you want to test and then do:
  20843.  
  20844.      cd sql-bench
  20845.      perl run-all-tests --server=#
  20846.  
  20847. where # is one of supported servers. You can get a list of all options
  20848. and supported servers by doing `run-all-tests --help'.
  20849.  
  20850. `crash-me' tries to determine what features a database supports and
  20851. what its capabilities and limitations are by actually running queries.
  20852. For example, it determines:
  20853.  
  20854.    * What column types are supported
  20855.  
  20856.    * How many indexes are supported
  20857.  
  20858.    * What functions are supported
  20859.  
  20860.    * How big a query can be
  20861.  
  20862.    * How big a `VARCHAR' column can be
  20863.  
  20864. We can find the result from crash-me on a lot of different databases at
  20865. `http://www.mysql.com/information/crash-me.php'.
  20866.  
  20867. Using Your Own Benchmarks
  20868. -------------------------
  20869.  
  20870. You should definitely benchmark your application and database to find
  20871. out where the bottlenecks are.  By fixing it (or by replacing the
  20872. bottleneck with a 'dummy module') you can then easily identify the next
  20873. bottleneck (and so on).  Even if the overall performance for your
  20874. application is sufficient, you should at least make a plan for each
  20875. bottleneck, and decide how to solve it if someday you really need the
  20876. extra performance.
  20877.  
  20878. For an example of portable benchmark programs, look at the MySQL
  20879. benchmark suite. *Note MySQL Benchmarks: MySQL Benchmarks. You can take
  20880. any program from this suite and modify it for your needs. By doing
  20881. this, you can try different solutions to your problem and test which is
  20882. really the fastest solution for you.
  20883.  
  20884. It is very common that some problems only occur when the system is very
  20885. heavily loaded. We have had many customers who contact us when they
  20886. have a (tested) system in production and have encountered load
  20887. problems. In every one of these cases so far, it has been problems with
  20888. basic design (table scans are NOT good at high load) or OS/Library
  20889. issues. Most of this would be a *LOT* easier to fix if the systems were
  20890. not already in production.
  20891.  
  20892. To avoid problems like this, you should put some effort into
  20893. benchmarking your whole application under the worst possible load!  You
  20894. can use Super Smack for this, and it is available at:
  20895. `http://www.mysql.com/Downloads/super-smack/super-smack-1.0.tar.gz'.
  20896. As the name suggests, it can bring your system down to its knees if you
  20897. ask it, so make sure to use it only on your development systems.
  20898.  
  20899. Optimizing `SELECT's and Other Queries
  20900. ======================================
  20901.  
  20902. First, one thing that affects all queries: The more complex permission
  20903. system setup you have, the more overhead you get.
  20904.  
  20905. If you do not have any `GRANT' statements done, MySQL will optimize the
  20906. permission checking somewhat. So if you have a very high volume it may
  20907. be worth the time to avoid grants. Otherwise more permission check
  20908. results in a larger overhead.
  20909.  
  20910. If your problem is with some explicit MySQL function, you can always
  20911. time this in the MySQL client:
  20912.  
  20913.      mysql> select benchmark(1000000,1+1);
  20914.      +------------------------+
  20915.      | benchmark(1000000,1+1) |
  20916.      +------------------------+
  20917.      |                      0 |
  20918.      +------------------------+
  20919.      1 row in set (0.32 sec)
  20920.  
  20921. The above shows that MySQL can execute 1,000,000 `+' expressions in
  20922. 0.32 seconds on a `PentiumII 400MHz'.
  20923.  
  20924. All MySQL functions should be very optimized, but there may be some
  20925. exceptions, and the `benchmark(loop_count,expression)' is a great tool
  20926. to find out if this is a problem with your query.
  20927.  
  20928. `EXPLAIN' Syntax (Get Information About a `SELECT')
  20929. ---------------------------------------------------
  20930.  
  20931.          EXPLAIN tbl_name
  20932.      or  EXPLAIN SELECT select_options
  20933.  
  20934. `EXPLAIN tbl_name' is a synonym for `DESCRIBE tbl_name' or `SHOW
  20935. COLUMNS FROM tbl_name'.
  20936.  
  20937. When you precede a `SELECT' statement with the keyword `EXPLAIN', MySQL
  20938. explains how it would process the `SELECT', providing information about
  20939. how tables are joined and in which order.
  20940.  
  20941. With the help of `EXPLAIN', you can see when you must add indexes to
  20942. tables to get a faster `SELECT' that uses indexes to find the records.
  20943. You can also see if the optimizer joins the tables in an optimal order.
  20944. To force the optimizer to use a specific join order for a `SELECT'
  20945. statement, add a `STRAIGHT_JOIN' clause.
  20946.  
  20947. For non-simple joins, `EXPLAIN' returns a row of information for each
  20948. table used in the `SELECT' statement. The tables are listed in the order
  20949. they would be read.  MySQL resolves all joins using a single-sweep
  20950. multi-join method. This means that MySQL reads a row from the first
  20951. table, then finds a matching row in the second table, then in the third
  20952. table and so on. When all tables are processed, it outputs the selected
  20953. columns and backtracks through the table list until a table is found
  20954. for which there are more matching rows. The next row is read from this
  20955. table and the process continues with the next table.
  20956.  
  20957. Output from `EXPLAIN' includes the following columns:
  20958.  
  20959. `table'
  20960.      The table to which the row of output refers.
  20961.  
  20962. `type'
  20963.      The join type.  Information about the various types is given below.
  20964.  
  20965. `possible_keys'
  20966.      The `possible_keys' column indicates which indexes MySQL could use
  20967.      to find the rows in this table. Note that this column is totally
  20968.      independent of the order of the tables. That means that some of
  20969.      the keys in possible_keys may not be usable in practice with the
  20970.      generated table order.
  20971.  
  20972.      If this column is empty, there are no relevant indexes. In this
  20973.      case, you may be able to improve the performance of your query by
  20974.      examining the `WHERE' clause to see if it refers to some column or
  20975.      columns that would be suitable for indexing.  If so, create an
  20976.      appropriate index and check the query with `EXPLAIN' again. *Note
  20977.      ALTER TABLE::.
  20978.  
  20979.      To see what indexes a table has, use `SHOW INDEX FROM tbl_name'.
  20980.  
  20981. `key'
  20982.      The `key' column indicates the key that MySQL actually decided to
  20983.      use. The key is `NULL' if no index was chosen.  If MySQL chooses
  20984.      the wrong index, you can probably force MySQL to use another index
  20985.      by using `myisamchk --analyze', *Note myisamchk syntax::, or by
  20986.      using `USE INDEX/IGNORE INDEX'.  *Note JOIN::.
  20987.  
  20988. `key_len'
  20989.      The `key_len' column indicates the length of the key that MySQL
  20990.      decided to use.  The length is `NULL' if the `key' is `NULL'. Note
  20991.      that this tells us how many parts of a multi-part key MySQL will
  20992.      actually use.
  20993.  
  20994. `ref'
  20995.      The `ref' column shows which columns or constants are used with the
  20996.      `key' to select rows from the table.
  20997.  
  20998. `rows'
  20999.      The `rows' column indicates the number of rows MySQL believes it
  21000.      must examine to execute the query.
  21001.  
  21002. `Extra'
  21003.      This column contains additional information of how MySQL will
  21004.      resolve the query. Here is an explanation of the different text
  21005.      strings that can be found in this column:
  21006.  
  21007.     `Distinct'
  21008.           MySQL will not continue searching for more rows for the
  21009.           current row combination after it has found the first matching
  21010.           row.
  21011.  
  21012.     `Not exists'
  21013.           MySQL was able to do a `LEFT JOIN' optimization on the query
  21014.           and will not examine more rows in this table for the previous
  21015.           row combination after it finds one row that matches the `LEFT
  21016.           JOIN' criteria.
  21017.  
  21018.           Here is an example for this:
  21019.  
  21020.                SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;
  21021.  
  21022.           Assume that `t2.id' is defined with `NOT NULL'.  In this case
  21023.           MySQL will scan `t1' and look up the rows in `t2' through
  21024.           `t1.id'. If MySQL finds a matching row in `t2', it knows that
  21025.           `t2.id' can never be `NULL', and will not scan through the
  21026.           rest of the rows in `t2' that has the same `id'.  In other
  21027.           words, for each row in `t1', MySQL only needs to do a single
  21028.           lookup in `t2', independent of how many matching rows there
  21029.           are in `t2'.
  21030.  
  21031.     ``range checked for each record (index map: #)''
  21032.           MySQL didn't find a real good index to use. It will, instead,
  21033.           for each row combination in the preceding tables, do a check
  21034.           on which index to use (if any), and use this index to
  21035.           retrieve the rows from the table.  This isn't very fast but
  21036.           is faster than having to do a join without an index.
  21037.  
  21038.     `Using filesort'
  21039.           MySQL will need to do an extra pass to find out how to
  21040.           retrieve the rows in sorted order.  The sort is done by going
  21041.           through all rows according to the `join type' and storing the
  21042.           sort key + pointer to the row for all rows that match the
  21043.           `WHERE'. Then the keys are sorted. Finally the rows are
  21044.           retrieved in sorted order.
  21045.  
  21046.     `Using index'
  21047.           The column information is retrieved from the table using only
  21048.           information in the index tree without having to do an
  21049.           additional seek to read the actual row.  This can be done
  21050.           when all the used columns for the table are part of the same
  21051.           index.
  21052.  
  21053.     `Using temporary'
  21054.           To resolve the query MySQL will need to create a temporary
  21055.           table to hold the result.  This typically happens if you do an
  21056.           `ORDER BY' on a different column set than you did a `GROUP
  21057.           BY' on.
  21058.  
  21059.     `Where used'
  21060.           A `WHERE' clause will be used to restrict which rows will be
  21061.           matched against the next table or sent to the client.  If you
  21062.           don't have this information and the table is of type `ALL' or
  21063.           `index', you may have something wrong in your query (if you
  21064.           don't intend to fetch/examine all rows from the table).
  21065.  
  21066.      If you want to get your queries as fast as possible, you should
  21067.      look out for `Using filesort' and `Using temporary'.
  21068.  
  21069. The different join types are listed below, ordered from best to worst
  21070. type:
  21071.  
  21072. `system'
  21073.      The table has only one row (= system table). This is a special
  21074.      case of the `const' join type.
  21075.  
  21076. `const'
  21077.      The table has at most one matching row, which will be read at the
  21078.      start of the query. Because there is only one row, values from the
  21079.      column in this row can be regarded as constants by the rest of the
  21080.      optimizer. `const' tables are very fast as they are read only once!
  21081.  
  21082. `eq_ref'
  21083.      One row will be read from this table for each combination of rows
  21084.      from the previous tables.  This is the best possible join type,
  21085.      other than the `const' types.  It is used when all parts of an
  21086.      index are used by the join and the index is `UNIQUE' or a `PRIMARY
  21087.      KEY'.
  21088.  
  21089. `ref'
  21090.      All rows with matching index values will be read from this table
  21091.      for each combination of rows from the previous tables.  `ref' is
  21092.      used if the join uses only a leftmost prefix of the key, or if the
  21093.      key is not `UNIQUE' or a `PRIMARY KEY' (in other words, if the
  21094.      join cannot select a single row based on the key value).  If the
  21095.      key that is used matches only a few rows, this join type is good.
  21096.  
  21097. `range'
  21098.      Only rows that are in a given range will be retrieved, using an
  21099.      index to select the rows.  The `key' column indicates which index
  21100.      is used.  The `key_len' contains the longest key part that was
  21101.      used.  The `ref' column will be NULL for this type.
  21102.  
  21103. `index'
  21104.      This is the same as `ALL', except that only the index tree is
  21105.      scanned.  This is usually faster than `ALL', as the index file is
  21106.      usually smaller than the data file.
  21107.  
  21108. `ALL'
  21109.      A full table scan will be done for each combination of rows from
  21110.      the previous tables.  This is normally not good if the table is
  21111.      the first table not marked `const', and usually *very* bad in all
  21112.      other cases. You normally can avoid `ALL' by adding more indexes,
  21113.      so that the row can be retrieved based on constant values or
  21114.      column values from earlier tables.
  21115.  
  21116. You can get a good indication of how good a join is by multiplying all
  21117. values in the `rows' column of the `EXPLAIN' output. This should tell
  21118. you roughly how many rows MySQL must examine to execute the query. This
  21119. number is also used when you restrict queries with the `max_join_size'
  21120. variable.  *Note Server parameters::.
  21121.  
  21122. The following example shows how a `JOIN' can be optimized progressively
  21123. using the information provided by `EXPLAIN'.
  21124.  
  21125. Suppose you have the `SELECT' statement shown below, that you examine
  21126. using `EXPLAIN':
  21127.  
  21128.      EXPLAIN SELECT tt.TicketNumber, tt.TimeIn,
  21129.                  tt.ProjectReference, tt.EstimatedShipDate,
  21130.                  tt.ActualShipDate, tt.ClientID,
  21131.                  tt.ServiceCodes, tt.RepetitiveID,
  21132.                  tt.CurrentProcess, tt.CurrentDPPerson,
  21133.                  tt.RecordVolume, tt.DPPrinted, et.COUNTRY,
  21134.                  et_1.COUNTRY, do.CUSTNAME
  21135.              FROM tt, et, et AS et_1, do
  21136.              WHERE tt.SubmitTime IS NULL
  21137.                  AND tt.ActualPC = et.EMPLOYID
  21138.                  AND tt.AssignedPC = et_1.EMPLOYID
  21139.                  AND tt.ClientID = do.CUSTNMBR;
  21140.  
  21141. For this example, assume that:
  21142.  
  21143.    * The columns being compared have been declared as follows:
  21144.  
  21145.      *Table* *Column*      *Column type*
  21146.      `tt'    `ActualPC'    `CHAR(10)'
  21147.      `tt'    `AssignedPC'  `CHAR(10)'
  21148.      `tt'    `ClientID'    `CHAR(10)'
  21149.      `et'    `EMPLOYID'    `CHAR(15)'
  21150.      `do'    `CUSTNMBR'    `CHAR(15)'
  21151.  
  21152.    * The tables have the indexes shown below:
  21153.  
  21154.      *Table* *Index*
  21155.      `tt'    `ActualPC'
  21156.      `tt'    `AssignedPC'
  21157.      `tt'    `ClientID'
  21158.      `et'    `EMPLOYID' (primary key)
  21159.      `do'    `CUSTNMBR' (primary key)
  21160.  
  21161.    * The `tt.ActualPC' values aren't evenly distributed.
  21162.  
  21163. Initially, before any optimizations have been performed, the `EXPLAIN'
  21164. statement produces the following information:
  21165.  
  21166.      table type possible_keys                key  key_len ref  rows  Extra
  21167.      et    ALL  PRIMARY                      NULL NULL    NULL 74
  21168.      do    ALL  PRIMARY                      NULL NULL    NULL 2135
  21169.      et_1  ALL  PRIMARY                      NULL NULL    NULL 74
  21170.      tt    ALL  AssignedPC,ClientID,ActualPC NULL NULL    NULL 3872
  21171.            range checked for each record (key map: 35)
  21172.  
  21173. Because `type' is `ALL' for each table, this output indicates that
  21174. MySQL is doing a full join for all tables!  This will take quite a long
  21175. time, as the product of the number of rows in each table must be
  21176. examined!  For the case at hand, this is `74 * 2135 * 74 * 3872 =
  21177. 45,268,558,720' rows.  If the tables were bigger, you can only imagine
  21178. how long it would take.
  21179.  
  21180. One problem here is that MySQL can't (yet) use indexes on columns
  21181. efficiently if they are declared differently.  In this context,
  21182. `VARCHAR' and `CHAR' are the same unless they are declared as different
  21183. lengths. Because `tt.ActualPC' is declared as `CHAR(10)' and
  21184. `et.EMPLOYID' is declared as `CHAR(15)', there is a length mismatch.
  21185.  
  21186. To fix this disparity between column lengths, use `ALTER TABLE' to
  21187. lengthen `ActualPC' from 10 characters to 15 characters:
  21188.  
  21189.      mysql> ALTER TABLE tt MODIFY ActualPC VARCHAR(15);
  21190.  
  21191. Now `tt.ActualPC' and `et.EMPLOYID' are both `VARCHAR(15)'.  Executing
  21192. the `EXPLAIN' statement again produces this result:
  21193.  
  21194.      table type   possible_keys   key     key_len ref         rows    Extra
  21195.      tt    ALL    AssignedPC,ClientID,ActualPC NULL NULL NULL 3872    where used
  21196.      do    ALL    PRIMARY         NULL    NULL    NULL        2135
  21197.            range checked for each record (key map: 1)
  21198.      et_1  ALL    PRIMARY         NULL    NULL    NULL        74
  21199.            range checked for each record (key map: 1)
  21200.      et    eq_ref PRIMARY         PRIMARY 15      tt.ActualPC 1
  21201.  
  21202. This is not perfect, but is much better (the product of the `rows'
  21203. values is now less by a factor of 74). This version is executed in a
  21204. couple of seconds.
  21205.  
  21206. A second alteration can be made to eliminate the column length
  21207. mismatches for the `tt.AssignedPC = et_1.EMPLOYID' and `tt.ClientID =
  21208. do.CUSTNMBR' comparisons:
  21209.  
  21210.      mysql> ALTER TABLE tt MODIFY AssignedPC VARCHAR(15),
  21211.                            MODIFY ClientID   VARCHAR(15);
  21212.  
  21213. Now `EXPLAIN' produces the output shown below:
  21214.  
  21215.      table type   possible_keys   key     key_len ref            rows     Extra
  21216.      et    ALL    PRIMARY         NULL    NULL    NULL           74
  21217.      tt    ref    AssignedPC,ClientID,ActualPC ActualPC 15 et.EMPLOYID 52 where used
  21218.      et_1  eq_ref PRIMARY         PRIMARY 15      tt.AssignedPC  1
  21219.      do    eq_ref PRIMARY         PRIMARY 15      tt.ClientID    1
  21220.  
  21221. This is almost as good as it can get.
  21222.  
  21223. The remaining problem is that, by default, MySQL assumes that values in
  21224. the `tt.ActualPC' column are evenly distributed, and that isn't the
  21225. case for the `tt' table.  Fortunately, it is easy to tell MySQL about
  21226. this:
  21227.  
  21228.      shell> myisamchk --analyze PATH_TO_MYSQL_DATABASE/tt
  21229.      shell> mysqladmin refresh
  21230.  
  21231. Now the join is perfect, and `EXPLAIN' produces this result:
  21232.  
  21233.      table type   possible_keys   key     key_len ref            rows    Extra
  21234.      tt    ALL    AssignedPC,ClientID,ActualPC NULL NULL NULL    3872    where used
  21235.      et    eq_ref PRIMARY         PRIMARY 15      tt.ActualPC    1
  21236.      et_1  eq_ref PRIMARY         PRIMARY 15      tt.AssignedPC  1
  21237.      do    eq_ref PRIMARY         PRIMARY 15      tt.ClientID    1
  21238.  
  21239. Note that the `rows' column in the output from `EXPLAIN' is an educated
  21240. guess from the MySQL join optimizer. To optimize a query, you should
  21241. check if the numbers are even close to the truth.  If not, you may get
  21242. better performance by using `STRAIGHT_JOIN' in your `SELECT' statement
  21243. and trying to list the tables in a different order in the `FROM' clause.
  21244.  
  21245. Estimating Query Performance
  21246. ----------------------------
  21247.  
  21248. In most cases you can estimate the performance by counting disk seeks.
  21249. For small tables, you can usually find the row in 1 disk seek (as the
  21250. index is probably cached).  For bigger tables, you can estimate that
  21251. (using B++ tree indexes) you will need: `log(row_count) /
  21252. log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) +
  21253. 1' seeks to find a row.
  21254.  
  21255. In MySQL an index block is usually 1024 bytes and the data pointer is
  21256. usually 4 bytes. A 500,000 row table with an index length of 3 (medium
  21257. integer) gives you: `log(500,000)/log(1024/3*2/(3+4)) + 1' = 4 seeks.
  21258.  
  21259. As the above index would require about 500,000 * 7 * 3/2 = 5.2M,
  21260. (assuming that the index buffers are filled to 2/3, which is typical)
  21261. you will probably have much of the index in memory and you will probably
  21262. only need 1-2 calls to read data from the OS to find the row.
  21263.  
  21264. For writes, however, you will need 4 seek requests (as above) to find
  21265. where to place the new index and normally 2 seeks to update the index
  21266. and write the row.
  21267.  
  21268. Note that the above doesn't mean that your application will slowly
  21269. degenerate by N log N!  As long as everything is cached by the OS or SQL
  21270. server things will only go marginally slower while the table gets
  21271. bigger. After the data gets too big to be cached, things will start to
  21272. go much slower until your applications is only bound by disk-seeks
  21273. (which increase by N log N). To avoid this, increase the index cache as
  21274. the data grows. *Note Server parameters::.
  21275.  
  21276. Speed of `SELECT' Queries
  21277. -------------------------
  21278.  
  21279. In general, when you want to make a slow `SELECT ... WHERE' faster, the
  21280. first thing to check is whether or not you can add an index. *Note
  21281. MySQL indexes: MySQL indexes. All references between different tables
  21282. should usually be done with indexes. You can use the `EXPLAIN' command
  21283. to determine which indexes are used for a `SELECT'.  *Note `EXPLAIN':
  21284. EXPLAIN.
  21285.  
  21286. Some general tips:
  21287.  
  21288.    * To help MySQL optimize queries better, run `myisamchk --analyze'
  21289.      on a table after it has been loaded with relevant data. This
  21290.      updates a value for each index part that indicates the average
  21291.      number of rows that have the same value.  (For unique indexes,
  21292.      this is always 1, of course.).  MySQL will use this to decide
  21293.      which index to choose when you connect two tables with 'a
  21294.      non-constant expression'.  You can check the result from the
  21295.      `analyze' run by doing `SHOW INDEX FROM table_name' and examining
  21296.      the `Cardinality' column.
  21297.  
  21298.    * To sort an index and data according to an index, use `myisamchk
  21299.      --sort-index --sort-records=1' (if you want to sort on index 1).
  21300.      If you have a unique index from which you want to read all records
  21301.      in order according to that index, this is a good way to make that
  21302.      faster.  Note, however, that this sorting isn't written optimally
  21303.      and will take a long time for a large table!
  21304.  
  21305. How MySQL Optimizes `WHERE' Clauses
  21306. -----------------------------------
  21307.  
  21308. The `WHERE' optimizations are put in the `SELECT' part here because
  21309. they are mostly used with `SELECT', but the same optimizations apply for
  21310. `WHERE' in `DELETE' and `UPDATE' statements.
  21311.  
  21312. Also note that this section is incomplete. MySQL does many
  21313. optimizations, and we have not had time to document them all.
  21314.  
  21315. Some of the optimizations performed by MySQL are listed below:
  21316.  
  21317.    * Removal of unnecessary parentheses:
  21318.              ((a AND b) AND c OR (((a AND b) AND (c AND d))))
  21319.           -> (a AND b AND c) OR (a AND b AND c AND d)
  21320.  
  21321.    * Constant folding:
  21322.              (a<b AND b=c) AND a=5
  21323.           -> b>5 AND b=c AND a=5
  21324.  
  21325.    * Constant condition removal (needed because of constant folding):
  21326.              (B>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6)
  21327.           -> B=5 OR B=6
  21328.  
  21329.    * Constant expressions used by indexes are evaluated only once.
  21330.  
  21331.    * `COUNT(*)' on a single table without a `WHERE' is retrieved
  21332.      directly from the table information.  This is also done for any
  21333.      `NOT NULL' expression when used with only one table.
  21334.  
  21335.    * Early detection of invalid constant expressions. MySQL quickly
  21336.      detects that some `SELECT' statements are impossible and returns
  21337.      no rows.
  21338.  
  21339.    * `HAVING' is merged with `WHERE' if you don't use `GROUP BY' or
  21340.      group functions (`COUNT()', `MIN()'...).
  21341.  
  21342.    * For each sub-join, a simpler `WHERE' is constructed to get a fast
  21343.      `WHERE' evaluation for each sub-join and also to skip records as
  21344.      soon as possible.
  21345.  
  21346.    * All constant tables are read first, before any other tables in the
  21347.      query.  A constant table is:
  21348.         - An empty table or a table with 1 row.
  21349.  
  21350.         - A table that is used with a `WHERE' clause on a `UNIQUE'
  21351.           index, or a `PRIMARY KEY', where all index parts are used
  21352.           with constant expressions and the index parts are defined as
  21353.           `NOT NULL'.
  21354.      All the following tables are used as constant tables:
  21355.           mysql> SELECT * FROM t WHERE primary_key=1;
  21356.           mysql> SELECT * FROM t1,t2
  21357.                      WHERE t1.primary_key=1 AND t2.primary_key=t1.id;
  21358.  
  21359.    * The best join combination to join the tables is found by trying all
  21360.      possibilities. If all columns in `ORDER BY' and in `GROUP BY' come
  21361.      from the same table, then this table is preferred first when
  21362.      joining.
  21363.  
  21364.    * If there is an `ORDER BY' clause and a different `GROUP BY'
  21365.      clause, or if the `ORDER BY' or `GROUP BY' contains columns from
  21366.      tables other than the first table in the join queue, a temporary
  21367.      table is created.
  21368.  
  21369.    * If you use `SQL_SMALL_RESULT', MySQL will use an in-memory
  21370.      temporary table.
  21371.  
  21372.    * Each table index is queried, and the best index that spans fewer
  21373.      than 30% of the rows is used. If no such index can be found, a
  21374.      quick table scan is used.
  21375.  
  21376.    * In some cases, MySQL can read rows from the index without even
  21377.      consulting the data file.  If all columns used from the index are
  21378.      numeric, then only the index tree is used to resolve the query.
  21379.  
  21380.    * Before each record is output, those that do not match the `HAVING'
  21381.      clause are skipped.
  21382.  
  21383. Some examples of queries that are very fast:
  21384.  
  21385.      mysql> SELECT COUNT(*) FROM tbl_name;
  21386.      mysql> SELECT MIN(key_part1),MAX(key_part1) FROM tbl_name;
  21387.      mysql> SELECT MAX(key_part2) FROM tbl_name
  21388.                 WHERE key_part_1=constant;
  21389.      mysql> SELECT ... FROM tbl_name
  21390.                 ORDER BY key_part1,key_part2,... LIMIT 10;
  21391.      mysql> SELECT ... FROM tbl_name
  21392.                 ORDER BY key_part1 DESC,key_part2 DESC,... LIMIT 10;
  21393.  
  21394. The following queries are resolved using only the index tree (assuming
  21395. the indexed columns are numeric):
  21396.  
  21397.      mysql> SELECT key_part1,key_part2 FROM tbl_name WHERE key_part1=val;
  21398.      mysql> SELECT COUNT(*) FROM tbl_name
  21399.                 WHERE key_part1=val1 AND key_part2=val2;
  21400.      mysql> SELECT key_part2 FROM tbl_name GROUP BY key_part1;
  21401.  
  21402. The following queries use indexing to retrieve the rows in sorted order
  21403. without a separate sorting pass:
  21404.  
  21405.      mysql> SELECT ... FROM tbl_name ORDER BY key_part1,key_part2,... ;
  21406.      mysql> SELECT ... FROM tbl_name ORDER BY key_part1 DESC,key_part2 DESC,... ;
  21407.  
  21408. How MySQL Optimizes `DISTINCT'
  21409. ------------------------------
  21410.  
  21411. `DISTINCT' is converted to a `GROUP BY' on all columns, `DISTINCT'
  21412. combined with `ORDER BY' will in many cases also need a temporary table.
  21413.  
  21414. When combining `LIMIT #' with `DISTINCT', MySQL will stop as soon as it
  21415. finds `#' unique rows.
  21416.  
  21417. If you don't use columns from all used tables, MySQL will stop the
  21418. scanning of the not used tables as soon as it has found the first match.
  21419.  
  21420.      SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;
  21421.  
  21422. In the case, assuming t1 is used before t2 (check with `EXPLAIN'), then
  21423. MySQL will stop reading from t2 (for that particular row in t1) when
  21424. the first row in t2 is found.
  21425.  
  21426. How MySQL Optimizes `LEFT JOIN' and `RIGHT JOIN'
  21427. ------------------------------------------------
  21428.  
  21429. `A LEFT JOIN B' in MySQL is implemented as follows:
  21430.  
  21431.    * The table `B' is set to be dependent on table `A' and all tables
  21432.      that `A' is dependent on.
  21433.  
  21434.    * The table `A' is set to be dependent on all tables (except `B')
  21435.      that are used in the `LEFT JOIN' condition.
  21436.  
  21437.    * All `LEFT JOIN' conditions are moved to the `WHERE' clause.
  21438.  
  21439.    * All standard join optimizations are done, with the exception that
  21440.      a table is always read after all tables it is dependent on.  If
  21441.      there is a circular dependence then MySQL will issue an error.
  21442.  
  21443.    * All standard `WHERE' optimizations are done.
  21444.  
  21445.    * If there is a row in `A' that matches the `WHERE' clause, but there
  21446.      wasn't any row in `B' that matched the `LEFT JOIN' condition, then
  21447.      an extra `B' row is generated with all columns set to `NULL'.
  21448.  
  21449.    * If you use `LEFT JOIN' to find rows that don't exist in some table
  21450.      and you have the following test: `column_name IS NULL' in the
  21451.      `WHERE' part, where column_name is a column that is declared as
  21452.      `NOT NULL', then MySQL will stop searching after more rows (for a
  21453.      particular key combination) after it has found one row that
  21454.      matches the `LEFT JOIN' condition.
  21455.  
  21456. `RIGHT JOIN' is implemented analogously as `LEFT JOIN'.
  21457.  
  21458. The table read order forced by `LEFT JOIN' and `STRAIGHT JOIN' will
  21459. help the join optimizer (which calculates in which order tables should
  21460. be joined) to do its work much more quickly, as there are fewer table
  21461. permutations to check.
  21462.  
  21463. Note that the above means that if you do a query of type:
  21464.  
  21465.      SELECT * FROM a,b LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key) WHERE b.key=d.key
  21466.  
  21467. MySQL will do a full scan on `b' as the `LEFT JOIN' will force it to be
  21468. read before `d'.
  21469.  
  21470. The fix in this case is to change the query to:
  21471.  
  21472.      SELECT * FROM b,a LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key) WHERE b.key=d.key
  21473.  
  21474. How MySQL Optimizes `LIMIT'
  21475. ---------------------------
  21476.  
  21477. In some cases MySQL will handle the query differently when you are
  21478. using `LIMIT #' and not using `HAVING':
  21479.  
  21480.    * If you are selecting only a few rows with `LIMIT', MySQL will use
  21481.      indexes in some cases when it normally would prefer to do a full
  21482.      table scan.
  21483.  
  21484.    * If you use `LIMIT #' with `ORDER BY', MySQL will end the sorting
  21485.      as soon as it has found the first `#' lines instead of sorting the
  21486.      whole table.
  21487.  
  21488.    * When combining `LIMIT #' with `DISTINCT', MySQL will stop as soon
  21489.      as it finds `#' unique rows.
  21490.  
  21491.    * In some cases a `GROUP BY' can be resolved by reading the key in
  21492.      order (or do a sort on the key) and then calculate summaries until
  21493.      the key value changes.  In this case `LIMIT #' will not calculate
  21494.      any unnecessary `GROUP BY''s.
  21495.  
  21496.    * As soon as MySQL has sent the first `#' rows to the client, it
  21497.      will abort the query.
  21498.  
  21499.    * `LIMIT 0' will always quickly return an empty set.  This is useful
  21500.      to check the query and to get the column types of the result
  21501.      columns.
  21502.  
  21503.    * The size of temporary tables uses the `LIMIT #' to calculate how
  21504.      much space is needed to resolve the query.
  21505.  
  21506. Speed of `INSERT' Queries
  21507. -------------------------
  21508.  
  21509. The time to insert a record consists approximately of:
  21510.  
  21511.    * Connect:                 (3)
  21512.  
  21513.    * Sending query to server: (2)
  21514.  
  21515.    * Parsing query:           (2)
  21516.  
  21517.    * Inserting record:        (1 x size of record)
  21518.  
  21519.    * Inserting indexes:       (1 x number of indexes)
  21520.  
  21521.    * Close:                   (1)
  21522.  
  21523. where the numbers are somewhat proportional to the overall time. This
  21524. does not take into consideration the initial overhead to open tables
  21525. (which is done once for each concurrently running query).
  21526.  
  21527. The size of the table slows down the insertion of indexes by N log N
  21528. (B-trees).
  21529.  
  21530. Some ways to speed up inserts:
  21531.  
  21532.    * If you are inserting many rows from the same client at the same
  21533.      time, use multiple value lists `INSERT' statements. This is much
  21534.      faster (many times in some cases) than using separate `INSERT'
  21535.      statements.
  21536.  
  21537.    * If you are inserting a lot of rows from different clients, you can
  21538.      get higher speed by using the `INSERT DELAYED' statement. *Note
  21539.      `INSERT': INSERT.
  21540.  
  21541.    * Note that with `MyISAM' you can insert rows at the same time
  21542.      `SELECT's are running if there are no deleted rows in the tables.
  21543.  
  21544.    * When loading a table from a text file, use `LOAD DATA INFILE'. This
  21545.      is usually 20 times faster than using a lot of `INSERT' statements.
  21546.      *Note `LOAD DATA': LOAD DATA.
  21547.  
  21548.    * It is possible with some extra work to make `LOAD DATA INFILE' run
  21549.      even faster when the table has many indexes. Use the following
  21550.      procedure:
  21551.  
  21552.        1. Optionally create the table with `CREATE TABLE'. For example,
  21553.           using `mysql' or Perl-DBI.
  21554.  
  21555.        2. Execute a `FLUSH TABLES' statement or the shell command
  21556.           `mysqladmin flush-tables'.
  21557.  
  21558.        3. Use `myisamchk --keys-used=0 -rq /path/to/db/tbl_name'. This
  21559.           will remove all usage of all indexes from the table.
  21560.  
  21561.        4. Insert data into the table with `LOAD DATA INFILE'. This will
  21562.           not update any indexes and will therefore be very fast.
  21563.  
  21564.        5. If you are going to only read the table in the future, run
  21565.           `myisampack' on it to make it smaller. *Note Compressed
  21566.           format::.
  21567.  
  21568.        6. Re-create the indexes with `myisamchk -r -q
  21569.           /path/to/db/tbl_name'. This will create the index tree in
  21570.           memory before writing it to disk, which is much faster
  21571.           because it avoids lots of disk seeks. The resulting index
  21572.           tree is also perfectly balanced.
  21573.  
  21574.        7. Execute a `FLUSH TABLES' statement or the shell command
  21575.           `mysqladmin flush-tables'.
  21576.  
  21577.      This procedure will be built into `LOAD DATA INFILE' in some future
  21578.      version of MySQL.
  21579.  
  21580.    * You can speed up insertions by locking your tables:
  21581.  
  21582.           mysql> LOCK TABLES a WRITE;
  21583.           mysql> INSERT INTO a VALUES (1,23),(2,34),(4,33);
  21584.           mysql> INSERT INTO a VALUES (8,26),(6,29);
  21585.           mysql> UNLOCK TABLES;
  21586.  
  21587.      The main speed difference is that the index buffer is flushed to
  21588.      disk only once, after all `INSERT' statements have completed.
  21589.      Normally there would be as many index buffer flushes as there are
  21590.      different `INSERT' statements. Locking is not needed if you can
  21591.      insert all rows with a single statement.
  21592.  
  21593.      Locking will also lower the total time of multi-connection tests,
  21594.      but the maximum wait time for some threads will go up (because
  21595.      they wait for locks).  For example:
  21596.  
  21597.           thread 1 does 1000 inserts
  21598.           thread 2, 3, and 4 does 1 insert
  21599.           thread 5 does 1000 inserts
  21600.  
  21601.      If you don't use locking, 2, 3, and 4 will finish before 1 and 5.
  21602.      If you use locking, 2, 3, and 4 probably will not finish before 1
  21603.      or 5, but the total time should be about 40% faster.
  21604.  
  21605.      As `INSERT', `UPDATE', and `DELETE' operations are very fast in
  21606.      MySQL, you will obtain better overall performance by adding locks
  21607.      around everything that does more than about 5 inserts or updates
  21608.      in a row.  If you do very many inserts in a row, you could do a
  21609.      `LOCK TABLES' followed by an `UNLOCK TABLES' once in a while
  21610.      (about each 1000 rows) to allow other threads access to the table.
  21611.      This would still result in a nice performance gain.
  21612.  
  21613.      Of course, `LOAD DATA INFILE' is much faster for loading data.
  21614.  
  21615. To get some more speed for both `LOAD DATA INFILE' and `INSERT',
  21616. enlarge the key buffer. *Note Server parameters::.
  21617.  
  21618. Speed of `UPDATE' Queries
  21619. -------------------------
  21620.  
  21621. Update queries are optimized as a `SELECT' query with the additional
  21622. overhead of a write. The speed of the write is dependent on the size of
  21623. the data that is being updated and the number of indexes that are
  21624. updated.  Indexes that are not changed will not be updated.
  21625.  
  21626. Also, another way to get fast updates is to delay updates and then do
  21627. many updates in a row later. Doing many updates in a row is much quicker
  21628. than doing one at a time if you lock the table.
  21629.  
  21630. Note that, with dynamic record format, updating a record to a longer
  21631. total length may split the record.  So if you do this often, it is very
  21632. important to `OPTIMIZE TABLE' sometimes.  *Note `OPTIMIZE TABLE':
  21633. OPTIMIZE TABLE.
  21634.  
  21635. Speed of `DELETE' Queries
  21636. -------------------------
  21637.  
  21638. If you want to delete all rows in the table, you should use `TRUNCATE
  21639. TABLE table_name'. *Note TRUNCATE::.
  21640.  
  21641. The time to delete a record is exactly proportional to the number of
  21642. indexes. To delete records more quickly, you can increase the size of
  21643. the index cache. *Note Server parameters::.
  21644.  
  21645. Other Optimization Tips
  21646. -----------------------
  21647.  
  21648. Unsorted tips for faster systems:
  21649.  
  21650.    * Use persistent connections to the database to avoid the connection
  21651.      overhead. If you can't use persistent connections and you are
  21652.      doing a lot of new connections to the database, you may want to
  21653.      change the value of the `thread_cache_size' variable. *Note Server
  21654.      parameters::.
  21655.  
  21656.    * Always check that all your queries really use the indexes you have
  21657.      created in the tables. In MySQL you can do this with the `EXPLAIN'
  21658.      command. *Note Explain: (manual)EXPLAIN.
  21659.  
  21660.    * Try to avoid complex `SELECT' queries on tables that are updated a
  21661.      lot. This is to avoid problems with table locking.
  21662.  
  21663.    * The new `MyISAM' tables can insert rows in a table without deleted
  21664.      rows at the same time another table is reading from it.  If this
  21665.      is important for you, you should consider methods where you don't
  21666.      have to delete rows or run `OPTIMIZE TABLE' after you have deleted
  21667.      a lot of rows.
  21668.  
  21669.    * Use `ALTER TABLE ... ORDER BY expr1,expr2...' if you mostly
  21670.      retrieve rows in expr1,expr2.. order.  By using this option after
  21671.      big changes to the table, you may be able to get higher
  21672.      performance.
  21673.  
  21674.    * In some cases it may make sense to introduce a column that is
  21675.      'hashed' based on information from other columns. If this column
  21676.      is short and reasonably unique it may be much faster than a big
  21677.      index on many columns. In MySQL it's very easy to use this extra
  21678.      column: `SELECT * FROM table_name WHERE hash=MD5(concat(col1,col2))
  21679.      AND col_1='constant' AND col_2='constant''
  21680.  
  21681.    * For tables that change a lot you should try to avoid all `VARCHAR'
  21682.      or `BLOB' columns. You will get dynamic row length as soon as you
  21683.      are using a single `VARCHAR' or `BLOB' column. *Note Table types::.
  21684.  
  21685.    * It's not normally useful to split a table into different tables
  21686.      just because the rows gets 'big'. To access a row, the biggest
  21687.      performance hit is the disk seek to find the first byte of the
  21688.      row. After finding the data most new disks can read the whole row
  21689.      fast enough for most applications. The only cases where it really
  21690.      matters to split up a table is if it's a dynamic row size table
  21691.      (see above) that you can change to a fixed row size, or if you
  21692.      very often need to scan the table and don't need most of the
  21693.      columns. *Note Table types::.
  21694.  
  21695.    * If you very often need to calculate things based on information
  21696.      from a lot of rows (like counts of things), it's probably much
  21697.      better to introduce a new table and update the counter in real
  21698.      time. An update of type `UPDATE table set count=count+1 where
  21699.      index_column=constant' is very fast!
  21700.  
  21701.      This is really important when you use databases like MySQL that
  21702.      only have table locking (multiple readers / single writers). This
  21703.      will also give better performance with most databases, as the row
  21704.      locking manager in this case will have less to do.
  21705.  
  21706.    * If you need to collect statistics from big log tables, use summary
  21707.      tables instead of scanning the whole table. Maintaining the
  21708.      summaries should be much faster than trying to do statistics
  21709.      'live'. It's much faster to regenerate new summary tables from the
  21710.      logs when things change (depending on business decisions) than to
  21711.      have to change the running application!
  21712.  
  21713.    * If possible, one should classify reports as 'live' or
  21714.      'statistical', where data needed for statistical reports are only
  21715.      generated based on summary tables that are generated from the
  21716.      actual data.
  21717.  
  21718.    * Take advantage of the fact that columns have default values. Insert
  21719.      values explicitly only when the value to be inserted differs from
  21720.      the default. This reduces the parsing that MySQL need to do and
  21721.      improves the insert speed.
  21722.  
  21723.    * In some cases it's convenient to pack and store data into a blob.
  21724.      In this case you have to add some extra code in your application
  21725.      to pack/unpack things in the blob, but this may save a lot of
  21726.      accesses at some stage.  This is practical when you have data that
  21727.      doesn't conform to a static table structure.
  21728.  
  21729.    * Normally you should try to keep all data non-redundant (what is
  21730.      called 3rd normal form in database theory), but you should not be
  21731.      afraid of duplicating things or creating summary tables if you
  21732.      need these to gain more speed.
  21733.  
  21734.    * Stored procedures or UDF (user-defined functions) may be a good
  21735.      way to get more performance.  In this case you should, however,
  21736.      always have a way to do this some other (slower) way if you use
  21737.      some database that doesn't support this.
  21738.  
  21739.    * You can always gain something by caching queries/answers in your
  21740.      application and trying to do many inserts/updates at the same
  21741.      time.  If your database supports lock tables (like MySQL and
  21742.      Oracle), this should help to ensure that the index cache is only
  21743.      flushed once after all updates.
  21744.  
  21745.    * Use `INSERT /*! DELAYED */' when you do not need to know when your
  21746.      data is written. This speeds things up because many records can be
  21747.      written with a single disk write.
  21748.  
  21749.    * Use `INSERT /*! LOW_PRIORITY */' when you want your selects to be
  21750.      more important.
  21751.  
  21752.    * Use `SELECT /*! HIGH_PRIORITY */' to get selects that jump the
  21753.      queue. That is, the select is done even if there is somebody
  21754.      waiting to do a write.
  21755.  
  21756.    * Use the multi-line `INSERT' statement to store many rows with one
  21757.      SQL command (many SQL servers supports this).
  21758.  
  21759.    * Use `LOAD DATA INFILE' to load bigger amounts of data. This is
  21760.      faster than normal inserts and will be even faster when `myisamchk'
  21761.      is integrated in `mysqld'.
  21762.  
  21763.    * Use `AUTO_INCREMENT' columns to make unique values.
  21764.  
  21765.    * Use `OPTIMIZE TABLE' once in a while to avoid fragmentation when
  21766.      using dynamic table format. *Note `OPTIMIZE TABLE': OPTIMIZE TABLE.
  21767.  
  21768.    * Use `HEAP' tables to get more speed when possible. *Note Table
  21769.      types::.
  21770.  
  21771.    * When using a normal Web server setup, images should be stored as
  21772.      files. That is, store only a file reference in the database.  The
  21773.      main reason for this is that a normal Web server is much better at
  21774.      caching files than database contents. So it it's much easier to
  21775.      get a fast system if you are using files.
  21776.  
  21777.    * Use in memory tables for non-critical data that are accessed often
  21778.      (like information about the last shown banner for users that don't
  21779.      have cookies).
  21780.  
  21781.    * Columns with identical information in different tables should be
  21782.      declared identical and have identical names. Before Version 3.23
  21783.      you got slow joins otherwise.
  21784.  
  21785.      Try to keep the names simple (use `name' instead of
  21786.      `customer_name' in the customer table). To make your names portable
  21787.      to other SQL servers you should keep them shorter than 18
  21788.      characters.
  21789.  
  21790.    * If you need REALLY high speed, you should take a look at the
  21791.      low-level interfaces for data storage that the different SQL
  21792.      servers support!  For example, by accessing the MySQL `MyISAM'
  21793.      directly, you could get a speed increase of 2-5 times compared to
  21794.      using the SQL interface.  To be able to do this the data must be
  21795.      on the same server as the application, and usually it should only
  21796.      be accessed by one process (because external file locking is
  21797.      really slow).  One could eliminate the above problems by
  21798.      introducing low-level `MyISAM' commands in the MySQL server (this
  21799.      could be one easy way to get more performance if needed).  By
  21800.      carefully designing the database interface, it should be quite
  21801.      easy to support this types of optimization.
  21802.  
  21803.    * In many cases it's faster to access data from a database (using a
  21804.      live connection) than accessing a text file, just because the
  21805.      database is likely to be more compact than the text file (if you
  21806.      are using numerical data), and this will involve fewer disk
  21807.      accesses.  You will also save code because you don't have to parse
  21808.      your text files to find line and column boundaries.
  21809.  
  21810.    * You can also use replication to speed things up. *Note
  21811.      Replication::.
  21812.  
  21813.    * Declaring a table with `DELAY_KEY_WRITE=1' will make the updating
  21814.      of indexes faster, as these are not logged to disk until the file
  21815.      is closed.  The downside is that you should run `myisamchk' on
  21816.      these tables before you start `mysqld' to ensure that they are
  21817.      okay if something killed `mysqld' in the middle.  As the key
  21818.      information can always be generated from the data, you should not
  21819.      lose anything by using `DELAY_KEY_WRITE'.
  21820.  
  21821. Locking Issues
  21822. ==============
  21823.  
  21824. How MySQL Locks Tables
  21825. ----------------------
  21826.  
  21827. You can find a discussion about different locking methods in the
  21828. appendix.  *Note Locking methods::.
  21829.  
  21830. All locking in MySQL is deadlock-free.  This is managed by always
  21831. requesting all needed locks at once at the beginning of a query and
  21832. always locking the tables in the same order.
  21833.  
  21834. The locking method MySQL uses for `WRITE' locks works as follows:
  21835.  
  21836.    * If there are no locks on the table, put a write lock on it.
  21837.  
  21838.    * Otherwise, put the lock request in the write lock queue.
  21839.  
  21840. The locking method MySQL uses for `READ' locks works as follows:
  21841.  
  21842.    * If there are no write locks on the table, put a read lock on it.
  21843.  
  21844.    * Otherwise, put the lock request in the read lock queue.
  21845.  
  21846. When a lock is released, the lock is made available to the threads in
  21847. the write lock queue, then to the threads in the read lock queue.
  21848.  
  21849. This means that if you have many updates on a table, `SELECT'
  21850. statements will wait until there are no more updates.
  21851.  
  21852. To work around this for the case where you want to do many `INSERT' and
  21853. `SELECT' operations on a table, you can insert rows in a temporary
  21854. table and update the real table with the records from the temporary
  21855. table once in a while.
  21856.  
  21857. This can be done with the following code:
  21858.      mysql> LOCK TABLES real_table WRITE, insert_table WRITE;
  21859.      mysql> insert into real_table select * from insert_table;
  21860.      mysql> TRUNCATE TABLE insert_table;
  21861.      mysql> UNLOCK TABLES;
  21862.  
  21863. You can use the `LOW_PRIORITY' options with `INSERT', `UPDATE' or
  21864. `DELETE' or `HIGH_PRIORITY' with `SELECT' if you want to prioritize
  21865. retrieval in some specific cases.  You can also start `mysqld' with
  21866. `--low-priority-updates' to get the same behaveour.
  21867.  
  21868. Using `SQL_BUFFER_RESULT' can also help making table locks shorter.
  21869. *Note SELECT::.
  21870.  
  21871. You could also change the locking code in `mysys/thr_lock.c' to use a
  21872. single queue.  In this case, write locks and read locks would have the
  21873. same priority, which might help some applications.
  21874.  
  21875. Table Locking Issues
  21876. --------------------
  21877.  
  21878. The table locking code in MySQL is deadlock free.
  21879.  
  21880. MySQL uses table locking (instead of row locking or column locking) on
  21881. all table types, except `BDB' tables, to achieve a very high lock
  21882. speed.  For large tables, table locking is MUCH better than row locking
  21883. for most applications, but there are, of course, some pitfalls.
  21884.  
  21885. For `BDB' and `InnoDB' tables, MySQL only uses table locking if you
  21886. explicitely lock the table with `LOCK TABLES' or execute a command that
  21887. will modify every row in the table, like `ALTER TABLE'.  For these
  21888. table types we recommend you to not use `LOCK TABLES' at all.
  21889.  
  21890. In MySQL Version 3.23.7 and above, you can insert rows into `MyISAM'
  21891. tables at the same time other threads are reading from the table.  Note
  21892. that currently this only works if there are no holes after deleted rows
  21893. in the table at the time the insert is made. When all holes has been
  21894. filled with new data, concurrent inserts will automatically be enabled
  21895. again.
  21896.  
  21897. Table locking enables many threads to read from a table at the same
  21898. time, but if a thread wants to write to a table, it must first get
  21899. exclusive access.  During the update, all other threads that want to
  21900. access this particular table will wait until the update is ready.
  21901.  
  21902. As updates on tables normally are considered to be more important than
  21903. `SELECT', all statements that update a table have higher priority than
  21904. statements that retrieve information from a table. This should ensure
  21905. that updates are not 'starved' because one issues a lot of heavy
  21906. queries against a specific table. (You can change this by using
  21907. LOW_PRIORITY with the statement that does the update or `HIGH_PRIORITY'
  21908. with the `SELECT' statement.)
  21909.  
  21910. Starting from MySQL Version 3.23.7 one can use the
  21911. `max_write_lock_count' variable to force MySQL to temporary give all
  21912. `SELECT' statements, that wait for a table, a higher priority after a
  21913. specific number of inserts on a table.
  21914.  
  21915. Table locking is, however, not very good under the following senario:
  21916.  
  21917.    * A client issues a `SELECT' that takes a long time to run.
  21918.  
  21919.    * Another client then issues an `UPDATE' on a used table. This client
  21920.      will wait until the `SELECT' is finished.
  21921.  
  21922.    * Another client issues another `SELECT' statement on the same
  21923.      table. As `UPDATE' has higher priority than `SELECT', this `SELECT'
  21924.      will wait for the `UPDATE' to finish.  It will also wait for the
  21925.      first `SELECT' to finish!
  21926.  
  21927.    * A thread is waiting for something like `full disk', in which case
  21928.      all threads that wants to access the problem table will also be
  21929.      put in a waiting state until more disk space is made available.
  21930.  
  21931. Some possible solutions to this problem are:
  21932.  
  21933.    * Try to get the `SELECT' statements to run faster. You may have to
  21934.      create some summary tables to do this.
  21935.  
  21936.    * Start `mysqld' with `--low-priority-updates'.  This will give all
  21937.      statements that update (modify) a table lower priority than a
  21938.      `SELECT' statement. In this case the last `SELECT' statement in
  21939.      the previous scenario would execute before the `INSERT' statement.
  21940.  
  21941.    * You can give a specific `INSERT', `UPDATE', or `DELETE' statement
  21942.      lower priority with the `LOW_PRIORITY' attribute.
  21943.  
  21944.    * Start `mysqld' with a low value for *max_write_lock_count* to give
  21945.      `READ' locks after a certain number of `WRITE' locks.
  21946.  
  21947.    * You can specify that all updates from a specific thread should be
  21948.      done with low priority by using the SQL command: `SET
  21949.      SQL_LOW_PRIORITY_UPDATES=1'.  *Note `SET OPTION': SET OPTION.
  21950.  
  21951.    * You can specify that a specific `SELECT' is very important with the
  21952.      `HIGH_PRIORITY' attribute. *Note `SELECT': SELECT.
  21953.  
  21954.    * If you have problems with `INSERT' combined with `SELECT', switch
  21955.      to use the new `MyISAM' tables as these support concurrent
  21956.      `SELECT's and `INSERT's.
  21957.  
  21958.    * If you mainly mix `INSERT' and `SELECT' statements, the `DELAYED'
  21959.      attribute to `INSERT' will probably solve your problems.  *Note
  21960.      `INSERT': INSERT.
  21961.  
  21962.    * If you have problems with `SELECT' and `DELETE', the `LIMIT'
  21963.      option to `DELETE' may help. *Note `DELETE': DELETE.
  21964.  
  21965. Optimizing Database Structure
  21966. =============================
  21967.  
  21968. Design Choices
  21969. --------------
  21970.  
  21971. MySQL keeps row data and index data in separate files. Many (almost
  21972. all) other databases mix row and index data in the same file. We
  21973. believe that the MySQL choice is better for a very wide range of modern
  21974. systems.
  21975.  
  21976. Another way to store the row data is to keep the information for each
  21977. column in a separate area (examples are SDBM and Focus). This will
  21978. cause a performance hit for every query that accesses more than one
  21979. column. Because this degenerates so quickly when more than one column
  21980. is accessed, we believe that this model is not good for general purpose
  21981. databases.
  21982.  
  21983. The more common case is that the index and data are stored together
  21984. (like in Oracle/Sybase et al). In this case you will find the row
  21985. information at the leaf page of the index. The good thing with this
  21986. layout is that it, in many cases, depending on how well the index is
  21987. cached, saves a disk read.  The bad things with this layout are:
  21988.  
  21989.    * Table scanning is much slower because you have to read through the
  21990.      indexes to get at the data.
  21991.  
  21992.    * You can't use only the index table to retrieve data for a query.
  21993.  
  21994.    * You lose a lot of space, as you must duplicate indexes from the
  21995.      nodes (as you can't store the row in the nodes).
  21996.  
  21997.    * Deletes will degenerate the table over time (as indexes in nodes
  21998.      are usually not updated on delete).
  21999.  
  22000.    * It's harder to cache ONLY the index data.
  22001.  
  22002. Get Your Data as Small as Possible
  22003. ----------------------------------
  22004.  
  22005. One of the most basic optimization is to get your data (and indexes) to
  22006. take as little space on the disk (and in memory) as possible. This can
  22007. give huge improvements because disk reads are faster and normally less
  22008. main memory will be used. Indexing also takes less resources if done on
  22009. smaller columns.
  22010.  
  22011. MySQL supports a lot of different table types and row formats.
  22012. Choosing the right table format may give you a big performance gain.
  22013. *Note Table types::.
  22014.  
  22015. You can get better performance on a table and minimize storage space
  22016. using the techniques listed below:
  22017.  
  22018.    * Use the most efficient (smallest) types possible. MySQL has many
  22019.      specialized types that save disk space and memory.
  22020.  
  22021.    * Use the smaller integer types if possible to get smaller tables.
  22022.      For example, `MEDIUMINT' is often better than `INT'.
  22023.  
  22024.    * Declare columns to be `NOT NULL' if possible. It makes everything
  22025.      faster and you save one bit per column. Note that if you really
  22026.      need `NULL' in your application you should definitely use it. Just
  22027.      avoid having it on all columns by default.
  22028.  
  22029.    * If you don't have any variable-length columns (`VARCHAR', `TEXT',
  22030.      or `BLOB' columns), a fixed-size record format is used. This is
  22031.      faster but unfortunately may waste some space.  *Note MyISAM table
  22032.      formats::.
  22033.  
  22034.    * The primary index of a table should be as short as possible. This
  22035.      makes identification of one row easy and efficient.
  22036.  
  22037.    * For each table, you have to decide which storage/index method to
  22038.      use. *Note Table types::.
  22039.  
  22040.    * Only create the indexes that you really need. Indexes are good for
  22041.      retrieval but bad when you need to store things fast. If you mostly
  22042.      access a table by searching on a combination of columns, make an
  22043.      index on them. The first index part should be the most used
  22044.      column. If you are ALWAYS using many columns, you should use the
  22045.      column with more duplicates first to get better compression of the
  22046.      index.
  22047.  
  22048.    * If it's very likely that a column has a unique prefix on the first
  22049.      number of characters, it's better to only index this prefix. MySQL
  22050.      supports an index on a part of a character column. Shorter indexes
  22051.      are faster not only because they take less disk space but also
  22052.      because they will give you more hits in the index cache and thus
  22053.      fewer disk seeks. *Note Server parameters::.
  22054.  
  22055.    * In some circumstances it can be beneficial to split into two a
  22056.      table that is scanned very often. This is especially true if it is
  22057.      a dynamic format table and it is possible to use a smaller static
  22058.      format table that can be used to find the relevant rows when
  22059.      scanning the table.
  22060.  
  22061. How MySQL Uses Indexes
  22062. ----------------------
  22063.  
  22064. Indexes are used to find rows with a specific value of one column fast.
  22065. Without an index MySQL has to start with the first record and then read
  22066. through the whole table until it finds the relevant rows. The bigger
  22067. the table, the more this costs. If the table has an index for the
  22068. columns in question, MySQL can quickly get a position to seek to in the
  22069. middle of the data file without having to look at all the data. If a
  22070. table has 1000 rows, this is at least 100 times faster than reading
  22071. sequentially. Note that if you need to access almost all 1000 rows it
  22072. is faster to read sequentially because we then avoid disk seeks.
  22073.  
  22074. All MySQL indexes (`PRIMARY', `UNIQUE', and `INDEX') are stored in
  22075. B-trees. Strings are automatically prefix- and end-space compressed.
  22076. *Note `CREATE INDEX': CREATE INDEX.
  22077.  
  22078. Indexes are used to:
  22079.    * Quickly find the rows that match a `WHERE' clause.
  22080.  
  22081.    * Retrieve rows from other tables when performing joins.
  22082.  
  22083.    * Find the `MAX()' or `MIN()' value for a specific indexed column.
  22084.      This is optimized by a preprocessor that checks if you are using
  22085.      `WHERE' key_part_# = constant on all key parts < N.  In this case
  22086.      MySQL will do a single key lookup and replace the `MIN()'
  22087.      expression with a constant.  If all expressions are replaced with
  22088.      constants, the query will return at once:
  22089.  
  22090.           SELECT MIN(key_part2),MAX(key_part2) FROM table_name where key_part1=10
  22091.  
  22092.    * Sort or group a table if the sorting or grouping is done on a
  22093.      leftmost prefix of a usable key (for example, `ORDER BY
  22094.      key_part_1,key_part_2 '). The key is read in reverse order if all
  22095.      key parts are followed by `DESC'.
  22096.  
  22097.      The index can also be used even if the `ORDER BY' doesn't match
  22098.      the index exactly, as long as all the unused index parts and all
  22099.      the extra are `ORDER BY' columns are constants in the `WHERE'
  22100.      clause. The following queries will use the index to resolve the
  22101.      `ORDER BY' part:
  22102.  
  22103.           SELECT * FROM foo ORDER BY key_part1,key_part2,key_part3;
  22104.           SELECT * FROM foo WHERE column=constant ORDER BY column, key_part1;
  22105.           SELECT * FROM foo WHERE key_part1=const GROUP BY key_part2;
  22106.  
  22107.    * In some cases a query can be optimized to retrieve values without
  22108.      consulting the data file. If all used columns for some table are
  22109.      numeric and form a leftmost prefix for some key, the values may be
  22110.      retrieved from the index tree for greater speed:
  22111.  
  22112.           SELECT key_part3 FROM table_name WHERE key_part1=1
  22113.  
  22114.  
  22115. Suppose you issue the following `SELECT' statement:
  22116.  
  22117.      mysql> SELECT * FROM tbl_name WHERE col1=val1 AND col2=val2;
  22118.  
  22119. If a multiple-column index exists on `col1' and `col2', the appropriate
  22120. rows can be fetched directly. If separate single-column indexes exist
  22121. on `col1' and `col2', the optimizer tries to find the most restrictive
  22122. index by deciding which index will find fewer rows and using that index
  22123. to fetch the rows.
  22124.  
  22125. If the table has a multiple-column index, any leftmost prefix of the
  22126. index can be used by the optimizer to find rows. For example, if you
  22127. have a three-column index on `(col1,col2,col3)', you have indexed
  22128. search capabilities on `(col1)', `(col1,col2)', and `(col1,col2,col3)'.
  22129.  
  22130. MySQL can't use a partial index if the columns don't form a leftmost
  22131. prefix of the index.  Suppose you have the `SELECT' statements shown
  22132. below:
  22133.  
  22134.      mysql> SELECT * FROM tbl_name WHERE col1=val1;
  22135.      mysql> SELECT * FROM tbl_name WHERE col2=val2;
  22136.      mysql> SELECT * FROM tbl_name WHERE col2=val2 AND col3=val3;
  22137.  
  22138. If an index exists on `(col1,col2,col3)', only the first query shown
  22139. above uses the index. The second and third queries do involve indexed
  22140. columns, but `(col2)' and `(col2,col3)' are not leftmost prefixes of
  22141. `(col1,col2,col3)'.
  22142.  
  22143. MySQL also uses indexes for `LIKE' comparisons if the argument to
  22144. `LIKE' is a constant string that doesn't start with a wild-card
  22145. character.  For example, the following `SELECT' statements use indexes:
  22146.  
  22147.      mysql> select * from tbl_name where key_col LIKE "Patrick%";
  22148.      mysql> select * from tbl_name where key_col LIKE "Pat%_ck%";
  22149.  
  22150. In the first statement, only rows with `"Patrick" <= key_col <
  22151. "Patricl"' are considered.  In the second statement, only rows with
  22152. `"Pat" <= key_col < "Pau"' are considered.
  22153.  
  22154. The following `SELECT' statements will not use indexes:
  22155.      mysql> select * from tbl_name where key_col LIKE "%Patrick%";
  22156.      mysql> select * from tbl_name where key_col LIKE other_col;
  22157.  
  22158. In the first statement, the `LIKE' value begins with a wild-card
  22159. character.  In the second statement, the `LIKE' value is not a constant.
  22160.  
  22161. Searching using `column_name IS NULL' will use indexes if column_name
  22162. is an index.
  22163.  
  22164. MySQL normally uses the index that finds the least number of rows. An
  22165. index is used for columns that you compare with the following operators:
  22166. `=', `>', `>=', `<', `<=', `BETWEEN', and a `LIKE' with a non-wild-card
  22167. prefix like `'something%''.
  22168.  
  22169. Any index that doesn't span all `AND' levels in the `WHERE' clause is
  22170. not used to optimize the query. In other words:  To be able to use an
  22171. index, a prefix of the index must be used in every `AND' group.
  22172.  
  22173. The following `WHERE' clauses use indexes:
  22174.      ... WHERE index_part1=1 AND index_part2=2 AND other_column=3
  22175.      ... WHERE index=1 OR A=10 AND index=2      /* index = 1 OR index = 2 */
  22176.      ... WHERE index_part1='hello' AND index_part_3=5
  22177.                /* optimized like "index_part1='hello'" */
  22178.      ... WHERE index1=1 and index2=2 or index1=3 and index3=3;
  22179.                /* Can use index on index1 but not on index2 or index 3 */
  22180.  
  22181. These `WHERE' clauses do *NOT* use indexes:
  22182.      ... WHERE index_part2=1 AND index_part3=2  /* index_part_1 is not used */
  22183.      ... WHERE index=1 OR A=10                  /* Index is not used in both AND parts */
  22184.      ... WHERE index_part1=1 OR index_part2=10  /* No index spans all rows */
  22185.  
  22186. Note that in some cases MySQL will not use an index, even if one would
  22187. be available.  Some of the cases where this happens are:
  22188.  
  22189.    * If the use of the index would require MySQL to access more than 30
  22190.      % of the rows in the table.  (In this case a table scan is
  22191.      probably much faster, as this will require us to do much fewer
  22192.      seeks).  Note that if such a query uses `LIMIT' to only retrieve
  22193.      part of the rows, MySQL will use an index anyway, as it can much
  22194.      more quickly find the few rows to return in the result.
  22195.  
  22196. Column Indexes
  22197. --------------
  22198.  
  22199. All MySQL column types can be indexed.  Use of indexes on the relevant
  22200. columns is the best way to improve the performance of `SELECT'
  22201. operations.
  22202.  
  22203. The maximum number of keys and the maximum index length is defined per
  22204. table handler. *Note Table types::. You can with all table handlers have
  22205. at least 16 keys and a total index length of at least 256 bytes.
  22206.  
  22207. For `CHAR' and `VARCHAR' columns, you can index a prefix of a column.
  22208. This is much faster and requires less disk space than indexing the
  22209. whole column.  The syntax to use in the `CREATE TABLE' statement to
  22210. index a column prefix looks like this:
  22211.  
  22212.      KEY index_name (col_name(length))
  22213.  
  22214. The example below creates an index for the first 10 characters of the
  22215. `name' column:
  22216.  
  22217.      mysql> CREATE TABLE test (
  22218.                 name CHAR(200) NOT NULL,
  22219.                 KEY index_name (name(10)));
  22220.  
  22221. For `BLOB' and `TEXT' columns, you must index a prefix of the column.
  22222. You cannot index the entire column.
  22223.  
  22224. In MySQL Version 3.23.23 or later, you can also create special
  22225. *FULLTEXT* indexes. They are used for full-text search. Only the
  22226. `MyISAM' table type supports `FULLTEXT' indexes. They can be created
  22227. only from `VARCHAR' and `TEXT' columns.  Indexing always happens over
  22228. the entire column and partial indexing is not supported. See *Note
  22229. Fulltext Search:: for details.
  22230.  
  22231. Multiple-Column Indexes
  22232. -----------------------
  22233.  
  22234. MySQL can create indexes on multiple columns.  An index may consist of
  22235. up to 15 columns. (On `CHAR' and `VARCHAR' columns you can also use a
  22236. prefix of the column as a part of an index).
  22237.  
  22238. A multiple-column index can be considered a sorted array containing
  22239. values that are created by concatenating the values of the indexed
  22240. columns.
  22241.  
  22242. MySQL uses multiple-column indexes in such a way that queries are fast
  22243. when you specify a known quantity for the first column of the index in a
  22244. `WHERE' clause, even if you don't specify values for the other columns.
  22245.  
  22246. Suppose a table is created using the following specification:
  22247.  
  22248.      mysql> CREATE TABLE test (
  22249.                 id INT NOT NULL,
  22250.                 last_name CHAR(30) NOT NULL,
  22251.                 first_name CHAR(30) NOT NULL,
  22252.                 PRIMARY KEY (id),
  22253.                 INDEX name (last_name,first_name));
  22254.  
  22255. Then the index `name' is an index over `last_name' and `first_name'.
  22256. The index will be used for queries that specify values in a known range
  22257. for `last_name', or for both `last_name' and `first_name'.  Therefore,
  22258. the `name' index will be used in the following queries:
  22259.  
  22260.      mysql> SELECT * FROM test WHERE last_name="Widenius";
  22261.      
  22262.      mysql> SELECT * FROM test WHERE last_name="Widenius"
  22263.                                AND first_name="Michael";
  22264.      
  22265.      mysql> SELECT * FROM test WHERE last_name="Widenius"
  22266.                                AND (first_name="Michael" OR first_name="Monty");
  22267.      
  22268.      mysql> SELECT * FROM test WHERE last_name="Widenius"
  22269.                                AND first_name >="M" AND first_name < "N";
  22270.  
  22271. However, the `name' index will NOT be used in the following queries:
  22272.  
  22273.      mysql> SELECT * FROM test WHERE first_name="Michael";
  22274.      
  22275.      mysql> SELECT * FROM test WHERE last_name="Widenius"
  22276.                                OR first_name="Michael";
  22277.  
  22278. For more information on the manner in which MySQL uses indexes to
  22279. improve query performance, see *Note MySQL indexes: MySQL indexes.
  22280.  
  22281. How MySQL Opens and Closes Tables
  22282. ---------------------------------
  22283.  
  22284. `table_cache', `max_connections', and `max_tmp_tables' affect the
  22285. maximum number of files the server keeps open.  If you increase one or
  22286. both of these values, you may run up against a limit imposed by your
  22287. operating system on the per-process number of open file descriptors.
  22288. However, you can increase the limit on many systems.  Consult your OS
  22289. documentation to find out how to do this, because the method for
  22290. changing the limit varies widely from system to system.
  22291.  
  22292. `table_cache' is related to `max_connections'.  For example, for 200
  22293. concurrent running connections, you should have a table cache of at
  22294. least `200 * n', where `n' is the maximum number of tables in a join.
  22295. You also need to reserve some extra file descriptors for temporary
  22296. tables and files.
  22297.  
  22298. The cache of open tables can grow to a maximum of `table_cache'
  22299. (default 64; this can be changed with the `-O table_cache=#' option to
  22300. `mysqld').  A table is never closed, except when the cache is full and
  22301. another thread tries to open a table or if you use `mysqladmin refresh'
  22302. or `mysqladmin flush-tables'.
  22303.  
  22304. When the table cache fills up, the server uses the following procedure
  22305. to locate a cache entry to use:
  22306.  
  22307.    * Tables that are not currently in use are released, in
  22308.      least-recently-used order.
  22309.  
  22310.    * If the cache is full and no tables can be released, but a new
  22311.      table needs to be opened, the cache is temporarily extended as
  22312.      necessary.
  22313.  
  22314.    * If the cache is in a temporarily-extended state and a table goes
  22315.      from in-use to not-in-use state, the table is closed and released
  22316.      from the cache.
  22317.  
  22318. A table is opened for each concurrent access. This means that if you
  22319. have two threads accessing the same table or access the table twice in
  22320. the same query (with `AS') the table needs to be opened twice.  The
  22321. first open of any table takes two file descriptors; each additional use
  22322. of the table takes only one file descriptor.  The extra descriptor for
  22323. the first open is used for the index file; this descriptor is shared
  22324. among all threads.
  22325.  
  22326. You can check if your table cache is too small by checking the mysqld
  22327. variable `opened_tables'.  If this is quite big, even if you haven't
  22328. done a lot of `FLUSH TABLES', you should increase your table cache.
  22329. *Note SHOW STATUS::.
  22330.  
  22331. Drawbacks to Creating Large Numbers of Tables in the Same Database
  22332. ------------------------------------------------------------------
  22333.  
  22334. If you have many files in a directory, open, close, and create
  22335. operations will be slow.  If you execute `SELECT' statements on many
  22336. different tables, there will be a little overhead when the table cache
  22337. is full, because for every table that has to be opened, another must be
  22338. closed. You can reduce this overhead by making the table cache larger.
  22339.  
  22340. Why So Many Open tables?
  22341. ------------------------
  22342.  
  22343. When you run `mysqladmin status', you'll see something like this:
  22344.  
  22345.      Uptime: 426 Running threads: 1 Questions: 11082 Reloads: 1 Open tables: 12
  22346.  
  22347. This can be somewhat perplexing if you only have 6 tables.
  22348.  
  22349. MySQL is multithreaded, so it may have many queries on the same table
  22350. simultaneously. To minimize the problem with two threads having
  22351. different states on the same file, the table is opened independently by
  22352. each concurrent thread. This takes some memory and one extra file
  22353. descriptor for the data file. The index file descriptor is shared
  22354. between all threads.
  22355.  
  22356. Optimizing the MySQL Server
  22357. ===========================
  22358.  
  22359. System/Compile Time and Startup Parameter Tuning
  22360. ------------------------------------------------
  22361.  
  22362. We start with the system level things since some of these decisions have
  22363. to be made very early. In other cases a fast look at this part may
  22364. suffice because it not that important for the big gains. However, it is
  22365. always nice to have a feeling about how much one could gain by changing
  22366. things at this level.
  22367.  
  22368. The default OS to use is really important!  To get the most use of
  22369. multiple CPU machines one should use Solaris (because the threads works
  22370. really nice) or Linux (because the 2.2 kernel has really good SMP
  22371. support). Also on 32-bit machines Linux has a 2G file size limit by
  22372. default. Hopefully this will be fixed soon when new filesystems are
  22373. released (XFS/Reiserfs).  If you have a desperate need for files bigger
  22374. than 2G on Linux-intel 32 bit, you should get the LFS patch for the ext2
  22375. file system.
  22376.  
  22377. Because we have not run MySQL in production on that many platforms, we
  22378. advice you to test your intended platform before choosing it, if
  22379. possible.
  22380.  
  22381. Other tips:
  22382.    * If you have enough RAM, you could remove all swap devices. Some
  22383.      operating systems will use a swap device in some contexts even if
  22384.      you have free memory.
  22385.  
  22386.    * Use the `--skip-locking' MySQL option to avoid external locking.
  22387.      Note that this will not impact MySQL's functionality as long as
  22388.      you only run one server. Just remember to take down the server (or
  22389.      lock relevant parts) before you run `myisamchk'. On some system
  22390.      this switch is mandatory because the external locking does not
  22391.      work in any case.
  22392.  
  22393.      The `--skip-locking' option is on by default when compiling with
  22394.      MIT-pthreads, because `flock()' isn't fully supported by
  22395.      MIT-pthreads on all platforms.  It's also on default for Linux as
  22396.      Linux file locking are not yet safe.
  22397.  
  22398.      The only case when you can't use `--skip-locking' is if you run
  22399.      multiple MySQL _servers_ (not clients) on the same data, or run
  22400.      `myisamchk' on the table without first flushing and locking the
  22401.      `mysqld' server tables first.
  22402.  
  22403.      You can still use `LOCK TABLES'/`UNLOCK TABLES' even if you are
  22404.      using `--skip-locking'
  22405.  
  22406. Tuning Server Parameters
  22407. ------------------------
  22408.  
  22409. You can get the default buffer sizes used by the `mysqld' server with
  22410. this command:
  22411.  
  22412.      shell> mysqld --help
  22413.  
  22414. This command produces a list of all `mysqld' options and configurable
  22415. variables. The output includes the default values and looks something
  22416. like this:
  22417.  
  22418.      Possible variables for option --set-variable (-O) are:
  22419.      back_log              current value: 5
  22420.      bdb_cache_size        current value: 1048540
  22421.      binlog_cache_size     current_value: 32768
  22422.      connect_timeout       current value: 5
  22423.      delayed_insert_timeout  current value: 300
  22424.      delayed_insert_limit  current value: 100
  22425.      delayed_queue_size    current value: 1000
  22426.      flush_time            current value: 0
  22427.      interactive_timeout   current value: 28800
  22428.      join_buffer_size      current value: 131072
  22429.      key_buffer_size       current value: 1048540
  22430.      lower_case_table_names  current value: 0
  22431.      long_query_time       current value: 10
  22432.      max_allowed_packet    current value: 1048576
  22433.      max_binlog_cache_size current_value: 4294967295
  22434.      max_connections       current value: 100
  22435.      max_connect_errors    current value: 10
  22436.      max_delayed_threads   current value: 20
  22437.      max_heap_table_size   current value: 16777216
  22438.      max_join_size         current value: 4294967295
  22439.      max_sort_length       current value: 1024
  22440.      max_tmp_tables        current value: 32
  22441.      max_write_lock_count  current value: 4294967295
  22442.      myisam_sort_buffer_size  current value: 8388608
  22443.      net_buffer_length     current value: 16384
  22444.      net_retry_count       current value: 10
  22445.      net_read_timeout      current value: 30
  22446.      net_write_timeout     current value: 60
  22447.      query_buffer_size     current value: 0
  22448.      record_buffer         current value: 131072
  22449.      record_rnd_buffer     current value: 131072
  22450.      slow_launch_time      current value: 2
  22451.      sort_buffer           current value: 2097116
  22452.      table_cache           current value: 64
  22453.      thread_concurrency    current value: 10
  22454.      tmp_table_size        current value: 1048576
  22455.      thread_stack          current value: 131072
  22456.      wait_timeout          current value: 28800
  22457.  
  22458. If there is a `mysqld' server currently running, you can see what
  22459. values it actually is using for the variables by executing this command:
  22460.  
  22461.      shell> mysqladmin variables
  22462.  
  22463. You can find a full description for all variables in the `SHOW
  22464. VARIABLES' section in this manual. *Note SHOW VARIABLES::.
  22465.  
  22466. You can also see some statistics from a running server by issuing the
  22467. command `SHOW STATUS'. *Note SHOW STATUS::.
  22468.  
  22469. MySQL uses algorithms that are very scalable, so you can usually run
  22470. with very little memory. If you, however, give MySQL more memory, you
  22471. will normally also get better performance.
  22472.  
  22473. When tuning a MySQL server, the two most important variables to use are
  22474. `key_buffer_size' and `table_cache'.  You should first feel confident
  22475. that you have these right before trying to change any of the other
  22476. variables.
  22477.  
  22478. If you have much memory (>=256M) and many tables and want maximum
  22479. performance with a moderate number of clients, you should use something
  22480. like this:
  22481.  
  22482.      shell> safe_mysqld -O key_buffer=64M -O table_cache=256 \
  22483.                 -O sort_buffer=4M -O record_buffer=1M &
  22484.  
  22485. If you have only 128M and only a few tables, but you still do a lot of
  22486. sorting, you can use something like:
  22487.  
  22488.      shell> safe_mysqld -O key_buffer=16M -O sort_buffer=1M
  22489.  
  22490. If you have little memory and lots of connections, use something like
  22491. this:
  22492.  
  22493.      shell> safe_mysqld -O key_buffer=512k -O sort_buffer=100k \
  22494.                 -O record_buffer=100k &
  22495.  
  22496. or even:
  22497.  
  22498.      shell> safe_mysqld -O key_buffer=512k -O sort_buffer=16k \
  22499.                 -O table_cache=32 -O record_buffer=8k -O net_buffer=1K &
  22500.  
  22501. If you are doing a `GROUP BY' or `ORDER BY' on files that are much
  22502. bigger than your available memory you should increase the value of
  22503. `record_rnd_buffer' to speed up the reading of rows after the sorting
  22504. is done.
  22505.  
  22506. When you have installed MySQL, the `support-files' directory will
  22507. contain some different `my.cnf' example files, `my-huge.cnf',
  22508. `my-large.cnf', `my-medium.cnf', and `my-small.cnf', you can use as a
  22509. base to optimize your system.
  22510.  
  22511. If there are very many connections, "swapping problems" may occur unless
  22512. `mysqld' has been configured to use very little memory for each
  22513. connection. `mysqld' performs better if you have enough memory for all
  22514. connections, of course.
  22515.  
  22516. Note that if you change an option to `mysqld', it remains in effect only
  22517. for that instance of the server.
  22518.  
  22519. To see the effects of a parameter change, do something like this:
  22520.  
  22521.      shell> mysqld -O key_buffer=32m --help
  22522.  
  22523. Make sure that the `--help' option is last; otherwise, the effect of any
  22524. options listed after it on the command line will not be reflected in the
  22525. output.
  22526.  
  22527. How Compiling and Linking Affects the Speed of MySQL
  22528. ----------------------------------------------------
  22529.  
  22530. Most of the following tests are done on Linux with the MySQL
  22531. benchmarks, but they should give some indication for other operating
  22532. systems and workloads.
  22533.  
  22534. You get the fastest executable when you link with `-static'.
  22535.  
  22536. On Linux, you will get the fastest code when compiling with `pgcc' and
  22537. `-O3'. To compile `sql_yacc.cc' with these options, you need about 200M
  22538. memory because `gcc/pgcc' needs a lot of memory to make all functions
  22539. inline. You should also set `CXX=gcc' when configuring MySQL to avoid
  22540. inclusion of the `libstdc++' library (it is not needed). Note that with
  22541. some versions of `pgcc', the resulting code will only run on true
  22542. Pentium processors, even if you use the compiler option that you want
  22543. the resulting code to be working on all x586 type processors (like AMD).
  22544.  
  22545. By just using a better compiler and/or better compiler options you can
  22546. get a 10-30 % speed increase in your application.  This is particularly
  22547. important if you compile the SQL server yourself!
  22548.  
  22549. We have tested both the Cygnus CodeFusion and Fujitsu compilers, but
  22550. when we tested them, neither was sufficiently bug free to allow MySQL
  22551. to be compiled with optimizations on.
  22552.  
  22553. When you compile MySQL you should only include support for the
  22554. character sets that you are going to use. (Option `--with-charset=xxx').
  22555. The standard MySQL binary distributions are compiled with support for
  22556. all character sets.
  22557.  
  22558. Here is a list of some measurements that we have done:
  22559.    * If you use `pgcc' and compile everything with `-O6', the `mysqld'
  22560.      server is 1% faster than with `gcc' 2.95.2.
  22561.  
  22562.    * If you link dynamically (without `-static'), the result is 13%
  22563.      slower on Linux.  Note that you still can use a dynamic linked
  22564.      MySQL library. It is only the server that is critical for
  22565.      performance.
  22566.  
  22567.    * If you strip your `mysqld' binary with `strip libexec/mysqld', the
  22568.      resulting binary can be up to 4 % faster.
  22569.  
  22570.    * If you connect using TCP/IP rather than Unix sockets, the result
  22571.      is 7.5% slower on the same computer. (If you are connection to
  22572.      `localhost', MySQL will, by default, use sockets).
  22573.  
  22574.    * If you connect using TCP/IP from another computer over a 100M
  22575.      Ethernet, things will be 8-11 % slower.
  22576.  
  22577.    * If you compile with `--with-debug=full', then you will loose 20 %
  22578.      for most queries, but some queries may take substantially longer
  22579.      (The MySQL benchmarks ran 35 % slower) If you use `--with-debug',
  22580.      then you will only loose 15 %.  By starting a `mysqld' version
  22581.      compiled with `--with-debug=full' with `--skip-safemalloc' the end
  22582.      result should be close to when configuring with `--with-debug'.
  22583.  
  22584.    * On a Sun SPARCstation 20, SunPro C++ 4.2 is 5 % faster than `gcc'
  22585.      2.95.2.
  22586.  
  22587.    * Compiling with `gcc' 2.95.2 for ultrasparc with the option
  22588.      `-mcpu=v8 -Wa,-xarch=v8plusa' gives 4 % more performance.
  22589.  
  22590.    * On Solaris 2.5.1, MIT-pthreads is 8-12% slower than Solaris native
  22591.      threads on a single processor. With more load/CPUs the difference
  22592.      should get bigger.
  22593.  
  22594.    * Running with `--log-bin' makes *[MySQL* 1 % slower.
  22595.  
  22596.    * Compiling on Linux-x86 using gcc without frame pointers
  22597.      `-fomit-frame-pointer' or `-fomit-frame-pointer -ffixed-ebp'
  22598.      `mysqld' 1-4% faster.
  22599.  
  22600. The MySQL-Linux distribution provided by MySQL AB used to be compiled
  22601. with `pgcc', but we had to go back to regular gcc because of a bug in
  22602. `pgcc' that would generate the code that does not run on AMD. We will
  22603. continue using gcc until that bug is resolved.  In the meantime, if you
  22604. have a non-AMD machine, you can get a faster binary by compiling with
  22605. `pgcc'.  The standard MySQL Linux binary is linked statically to get it
  22606. faster and more portable.
  22607.  
  22608. How MySQL Uses Memory
  22609. ---------------------
  22610.  
  22611. The list below indicates some of the ways that the `mysqld' server uses
  22612. memory.  Where applicable, the name of the server variable relevant to
  22613. the memory use is given:
  22614.  
  22615.    * The key buffer (variable `key_buffer_size') is shared by all
  22616.      threads; Other buffers used by the server are allocated as needed.
  22617.      *Note Server parameters::.
  22618.  
  22619.    * Each connection uses some thread-specific space: A stack (default
  22620.      64K, variable `thread_stack'), a connection buffer (variable
  22621.      `net_buffer_length'), and a result buffer (variable
  22622.      `net_buffer_length'). The connection buffer and result buffer are
  22623.      dynamically enlarged up to `max_allowed_packet' when needed.  When
  22624.      a query is running, a copy of the current query string is also
  22625.      allocated.
  22626.  
  22627.    * All threads share the same base memory.
  22628.  
  22629.    * Only the compressed ISAM / MyISAM tables are memory mapped.  This
  22630.      is because the 32-bit memory space of 4GB is not large enough for
  22631.      most big tables. When systems with a 64-bit address space become
  22632.      more common we may add general support for memory mapping.
  22633.  
  22634.    * Each request doing a sequential scan over a table allocates a read
  22635.      buffer (variable `record_buffer').
  22636.  
  22637.    * When reading rows in 'random' order (for example after a sort) a
  22638.      random-read buffer is allocated to avoid disk seeks.  (variable
  22639.      `record_rnd_buffer').
  22640.  
  22641.    * All joins are done in one pass, and most joins can be done without
  22642.      even using a temporary table. Most temporary tables are
  22643.      memory-based (HEAP) tables.  Temporary tables with a big record
  22644.      length (calculated as the sum of all column lengths) or that
  22645.      contain `BLOB' columns are stored on disk.
  22646.  
  22647.      One problem in MySQL versions before Version 3.23.2 is that if a
  22648.      HEAP table exceeds the size of `tmp_table_size', you get the error
  22649.      `The table tbl_name is full'. In newer versions this is handled by
  22650.      automatically changing the in-memory (HEAP) table to a disk-based
  22651.      (MyISAM) table as necessary. To work around this problem, you can
  22652.      increase the temporary table size by setting the `tmp_table_size'
  22653.      option to `mysqld', or by setting the SQL option `SQL_BIG_TABLES'
  22654.      in the client program.  *Note `SET OPTION': SET OPTION. In MySQL
  22655.      Version 3.20, the maximum size of the temporary table was
  22656.      `record_buffer*16', so if you are using this version, you have to
  22657.      increase the value of `record_buffer'. You can also start `mysqld'
  22658.      with the `--big-tables' option to always store temporary tables on
  22659.      disk. However, this will affect the speed of many complicated
  22660.      queries.
  22661.  
  22662.    * Most requests doing a sort allocates a sort buffer and 0-2
  22663.      temporary files depending on the result set size. *Note Temporary
  22664.      files::.
  22665.  
  22666.    * Almost all parsing and calculating is done in a local memory
  22667.      store. No memory overhead is needed for small items and the normal
  22668.      slow memory allocation and freeing is avoided. Memory is allocated
  22669.      only for unexpectedly large strings (this is done with `malloc()'
  22670.      and `free()').
  22671.  
  22672.    * Each index file is opened once and the data file is opened once
  22673.      for each concurrently running thread. For each concurrent thread,
  22674.      a table structure, column structures for each column, and a buffer
  22675.      of size `3 * n' is allocated (where `n' is the maximum row length,
  22676.      not counting `BLOB' columns). A `BLOB' uses 5 to 8 bytes plus the
  22677.      length of the `BLOB' data. The `ISAM'/`MyISAM' table handlers will
  22678.      use one extra row buffer for internal usage.
  22679.  
  22680.    * For each table having `BLOB' columns, a buffer is enlarged
  22681.      dynamically to read in larger `BLOB' values. If you scan a table,
  22682.      a buffer as large as the largest `BLOB' value is allocated.
  22683.  
  22684.    * Table handlers for all in-use tables are saved in a cache and
  22685.      managed as a FIFO. Normally the cache has 64 entries. If a table
  22686.      has been used by two running threads at the same time, the cache
  22687.      contains two entries for the table. *Note Table cache::.
  22688.  
  22689.    * A `mysqladmin flush-tables' command closes all tables that are not
  22690.      in use and marks all in-use tables to be closed when the currently
  22691.      executing thread finishes. This will effectively free most in-use
  22692.      memory.
  22693.  
  22694. `ps' and other system status programs may report that `mysqld' uses a
  22695. lot of memory. This may be caused by thread-stacks on different memory
  22696. addresses. For example, the Solaris version of `ps' counts the unused
  22697. memory between stacks as used memory. You can verify this by checking
  22698. available swap with `swap -s'. We have tested `mysqld' with commercial
  22699. memory-leakage detectors, so there should be no memory leaks.
  22700.  
  22701. How MySQL uses DNS
  22702. ------------------
  22703.  
  22704. When a new thread connects to `mysqld', `mysqld' will span a new thread
  22705. to handle the request.  This thread will first check if the hostname is
  22706. in the hostname cache. If not the thread will call `gethostbyaddr_r()'
  22707. and `gethostbyname_r()' to resolve the hostname.
  22708.  
  22709. If the operating system doesn't support the above thread-safe calls, the
  22710. thread will lock a mutex and call `gethostbyaddr()' and
  22711. `gethostbyname()' instead. Note that in this case no other thread can
  22712. resolve other hostnames that is not in the hostname cache until the
  22713. first thread is ready.
  22714.  
  22715. You can disable DNS host lookup by starting `mysqld' with
  22716. `--skip-name-resolve'.  In this case you can however only use IP names
  22717. in the MySQL privilege tables.
  22718.  
  22719. If you have a very slow DNS and many hosts, you can get more
  22720. performance by either disabling DNS lookop with `--skip-name-resolve'
  22721. or by increasing the `HOST_CACHE_SIZE' define (default: 128) and
  22722. recompile `mysqld'.
  22723.  
  22724. You can disable the hostname cache with `--skip-host-cache'. You can
  22725. clear the hostname cache with `FLUSH HOSTS' or `mysqladmin flush-hosts'.
  22726.  
  22727. If you don't want to allow connections over `TCP/IP', you can do this
  22728. by starting `mysqld' with `--skip-networking'.
  22729.  
  22730. `SET' Syntax
  22731. ------------
  22732.  
  22733.      SET [OPTION] SQL_VALUE_OPTION= value, ...
  22734.  
  22735. `SET OPTION' sets various options that affect the operation of the
  22736. server or your client.  Any option you set remains in effect until the
  22737. current session ends, or until you set the option to a different value.
  22738.  
  22739. `CHARACTER SET character_set_name | DEFAULT'
  22740.      This maps all strings from and to the client with the given
  22741.      mapping.  Currently the only option for `character_set_name' is
  22742.      `cp1251_koi8', but you can easily add new mappings by editing the
  22743.      `sql/convert.cc' file in the MySQL source distribution.  The
  22744.      default mapping can be restored by using a `character_set_name'
  22745.      value of `DEFAULT'.
  22746.  
  22747.      Note that the syntax for setting the `CHARACTER SET' option differs
  22748.      from the syntax for setting the other options.
  22749.  
  22750. `PASSWORD = PASSWORD('some password')'
  22751.      Set the password for the current user. Any non-anonymous user can
  22752.      change his own password!
  22753.  
  22754. `PASSWORD FOR user = PASSWORD('some password')'
  22755.      Set the password for a specific user on the current server host.
  22756.      Only a user with access to the `mysql' database can do this.  The
  22757.      user should be given in `user@hostname' format, where `user' and
  22758.      `hostname' are exactly as they are listed in the `User' and `Host'
  22759.      columns of the `mysql.user' table entry.  For example, if you had
  22760.      an entry with `User' and `Host' fields of `'bob'' and
  22761.      `'%.loc.gov'', you would write:
  22762.  
  22763.           mysql> SET PASSWORD FOR bob@"%.loc.gov" = PASSWORD("newpass");
  22764.           
  22765.           or
  22766.           
  22767.           mysql> UPDATE mysql.user SET password=PASSWORD("newpass") where user="bob' and host="%.loc.gov";
  22768.  
  22769. `SQL_AUTO_IS_NULL = 0 | 1'
  22770.      If set to `1' (default) then one can find the last inserted row
  22771.      for a table with an auto_increment row with the following
  22772.      construct: `WHERE auto_increment_column IS NULL'.  This is used by
  22773.      some ODBC programs like Access.
  22774.  
  22775. `AUTOCOMMIT= 0 | 1'
  22776.      If set to `1' all changes to a table will be done at once. To start
  22777.      a multi-command transaction, you have to use the `BEGIN'
  22778.      statement. *Note COMMIT::. If set to `0' you have to use `COMMIT' /
  22779.      `ROLLBACK' to accept/revoke that transaction. *Note COMMIT::.  Note
  22780.      that when you change from not `AUTOCOMMIT' mode to `AUTOCOMMIT'
  22781.      mode, MySQL will do an automatic `COMMIT' on any open transactions.
  22782.  
  22783. `SQL_BIG_TABLES = 0 | 1'
  22784.      If set to `1', all temporary tables are stored on disk rather than
  22785.      in memory.  This will be a little slower, but you will not get the
  22786.      error `The table tbl_name is full' for big `SELECT' operations that
  22787.      require a large temporary table.  The default value for a new
  22788.      connection is `0' (that is, use in-memory temporary tables).
  22789.  
  22790. `SQL_BIG_SELECTS = 0 | 1'
  22791.      If set to `0', MySQL will abort if a `SELECT' is attempted that
  22792.      probably will take a very long time. This is useful when an
  22793.      inadvisable `WHERE' statement has been issued. A big query is
  22794.      defined as a `SELECT' that probably will have to examine more than
  22795.      `max_join_size' rows.  The default value for a new connection is
  22796.      `1' (which will allow all `SELECT' statements).
  22797.  
  22798. `SQL_BUFFER_RESULT = 0 | 1'
  22799.      `SQL_BUFFER_RESULT' will force the result from `SELECT''s to be
  22800.      put into a temporary table. This will help MySQL free the table
  22801.      locks early and will help in cases where it takes a long time to
  22802.      send the result set to the client.
  22803.  
  22804. `SQL_LOW_PRIORITY_UPDATES = 0 | 1'
  22805.      If set to `1', all `INSERT', `UPDATE', `DELETE', and and `LOCK
  22806.      TABLE WRITE' statements wait until there is no pending `SELECT' or
  22807.      `LOCK TABLE READ' on the affected table.
  22808.  
  22809. `SQL_MAX_JOIN_SIZE = value | DEFAULT'
  22810.      Don't allow `SELECT's that will probably need to examine more than
  22811.      `value' row combinations.  By setting this value, you can catch
  22812.      `SELECT's where keys are not used properly and that would probably
  22813.      take a long time. Setting this to a value other than `DEFAULT'
  22814.      will reset the `SQL_BIG_SELECTS' flag.  If you set the
  22815.      `SQL_BIG_SELECTS' flag again, the `SQL_MAX_JOIN_SIZE' variable
  22816.      will be ignored.  You can set a default value for this variable by
  22817.      starting `mysqld' with `-O max_join_size=#'.
  22818.  
  22819. `SQL_SAFE_UPDATES = 0 | 1'
  22820.      If set to `1', MySQL will abort if an `UPDATE' or `DELETE' is
  22821.      attempted that doesn't use a key or `LIMIT' in the `WHERE' clause.
  22822.      This makes it possible to catch wrong updates when creating SQL
  22823.      commands by hand.
  22824.  
  22825. `SQL_SELECT_LIMIT = value | DEFAULT'
  22826.      The maximum number of records to return from `SELECT' statements.
  22827.      If a `SELECT' has a `LIMIT' clause, the `LIMIT' takes precedence
  22828.      over the value of `SQL_SELECT_LIMIT'.  The default value for a new
  22829.      connection is "unlimited." If you have changed the limit, the
  22830.      default value can be restored by using a `SQL_SELECT_LIMIT' value
  22831.      of `DEFAULT'.
  22832.  
  22833. `SQL_LOG_OFF = 0 | 1'
  22834.      If set to `1', no logging will be done to the standard log for this
  22835.      client, if the client has the *process* privilege.  This does not
  22836.      affect the update log!
  22837.  
  22838. `SQL_LOG_UPDATE = 0 | 1'
  22839.      If set to `0', no logging will be done to the update log for the
  22840.      client, if the client has the *process* privilege.  This does not
  22841.      affect the standard log!
  22842.  
  22843. `SQL_QUOTE_SHOW_CREATE = 0 | 1'
  22844.      If set to `1', `SHOW CREATE TABLE' will quote table and column
  22845.      names. This is *on* by default, for replication of tables with
  22846.      fancy column names to work.  *Note `SHOW CREATE TABLE': SHOW
  22847.      CREATE TABLE.
  22848.  
  22849. `TIMESTAMP = timestamp_value | DEFAULT'
  22850.      Set the time for this client.  This is used to get the original
  22851.      timestamp if you use the update log to restore rows.
  22852.      `timestamp_value' should be a UNIX Epoch timestamp, not a MySQL
  22853.      timestamp.
  22854.  
  22855. `LAST_INSERT_ID = #'
  22856.      Set the value to be returned from `LAST_INSERT_ID()'. This is
  22857.      stored in the update log when you use `LAST_INSERT_ID()' in a
  22858.      command that updates a table.
  22859.  
  22860. `INSERT_ID = #'
  22861.      Set the value to be used by the following `INSERT' or `ALTER TABLE'
  22862.      command when inserting an `AUTO_INCREMENT' value.  This is mainly
  22863.      used with the update log.
  22864.  
  22865. Disk Issues
  22866. ===========
  22867.  
  22868.    * As mentioned before, disks seeks are a big performance bottleneck.
  22869.      This problems gets more and more apparent when the data starts to
  22870.      grow so large that effective caching becomes impossible. For large
  22871.      databases, where you access data more or less randomly, you can be
  22872.      sure that you will need at least one disk seek to read and a
  22873.      couple of disk seeks to write things. To minimize this problem,
  22874.      use disks with low seek times.
  22875.  
  22876.    * Increase the number of available disk spindles (and thereby reduce
  22877.      the seek overhead) by either symlink files to different disks or
  22878.      striping the disks.
  22879.  
  22880.     *Using symbolic links*
  22881.           This means that you symlink the index and/or data file(s)
  22882.           from the normal data directory to another disk (that may also
  22883.           be striped). This makes both the seek and read times better
  22884.           (if the disks are not used for other things). *Note Symbolic
  22885.           links::.
  22886.  
  22887.     *Striping*
  22888.           Striping means that you have many disks and put the first
  22889.           block on the first disk, the second block on the second disk,
  22890.           and the Nth on the (N mod number_of_disks) disk, and so on.
  22891.           This means if your normal data size is less than the stripe
  22892.           size (or perfectly aligned) you will get much better
  22893.           performance. Note that striping is very dependent on the OS
  22894.           and stripe-size. So benchmark your application with different
  22895.           stripe-sizes. *Note Custom Benchmarks::.
  22896.  
  22897.           Note that the speed difference for striping is *very*
  22898.           dependent on the parameters. Depending on how you set the
  22899.           striping parameters and number of disks you may get a
  22900.           difference in orders of magnitude. Note that you have to
  22901.           choose to optimize for random or sequential access.
  22902.  
  22903.    * For reliability you may want to use RAID 0+1 (striping +
  22904.      mirroring), but in this case you will need 2*N drives to hold N
  22905.      drives of data. This is probably the best option if you have the
  22906.      money for it!  You may, however, also have to invest in some
  22907.      volume-management software to handle it efficiently.
  22908.  
  22909.    * A good option is to have semi-important data (that can be
  22910.      regenerated) on RAID 0 disk while storing really important data
  22911.      (like host information and logs) on a RAID 0+1 or RAID N disk.
  22912.      RAID N can be a problem if you have many writes because of the
  22913.      time to update the parity bits.
  22914.  
  22915.    * You may also set the parameters for the file system that the
  22916.      database uses. One easy change is to mount the file system with
  22917.      the noatime option. That makes it skip the updating of the last
  22918.      access time in the inode and by this will avoid some disk seeks.
  22919.  
  22920.    * On Linux, you can get much more performance (up to 100 % under
  22921.      load is not uncommon) by using hdpram to configure your disk's
  22922.      interface!  The following should be quite good hdparm options for
  22923.      MySQL (and probably many other applications):
  22924.  
  22925.           hdparm -m 16 -d 1
  22926.  
  22927.      Note that the performance/reliability when using the above depends
  22928.      on your hardware, so we strongly suggest that you test your system
  22929.      thoroughly after using `hdparm'!  Please consult the `hdparm' man
  22930.      page for more information!  If `hdparm' is not used wisely,
  22931.      filesystem corruption may result.  Backup everything before
  22932.      experimenting!
  22933.  
  22934.    * On many operating systems you can mount the disks with the 'async'
  22935.      flag to set the file system to be updated asynchronously.  If your
  22936.      computer is reasonable stable, this should give you more
  22937.      performance without sacrificing too much reliability.  (This flag
  22938.      is on by default on Linux.)
  22939.  
  22940.    * If you don't need to know when a file was last accessed (which is
  22941.      not really useful on a database server), you can mount your file
  22942.      systems with the noatime flag.
  22943.  
  22944. Using Symbolic Links
  22945. --------------------
  22946.  
  22947. You can move tables and databases from the database directory to other
  22948. locations and replace them with symbolic links to the new locations.
  22949. You might want to do this, for example, to move a database to a file
  22950. system with more free space or increase the speed of your system by
  22951. spreading your tables to different disk.
  22952.  
  22953. The recommended may to do this, is to just symlink databases to
  22954. different disk and only symlink tables as a last resort.
  22955.  
  22956. Using Symbolic Links for Databases
  22957. ..................................
  22958.  
  22959. The way to symlink a database is to first create a directory on some
  22960. disk where you have free space and then create a symlink to it from the
  22961. MySQL database directory.
  22962.  
  22963.      shell> mkdir /dr1/databases/test
  22964.      shell> ln -s /dr1/databases/test mysqld-datadir
  22965.  
  22966. MySQL doesn't support that you link one directory to multiple
  22967. databases.  Replacing a database directory with a symbolic link will
  22968. work fine as long as you don't make a symbolic link between databases.
  22969. Suppose you have a database `db1' under the MySQL data directory, and
  22970. then make a symlink `db2' that points to `db1':
  22971.  
  22972.      shell> cd /path/to/datadir
  22973.      shell> ln -s db1 db2
  22974.  
  22975. Now, for any table `tbl_a' in `db1', there also appears to be a table
  22976. `tbl_a' in `db2'.  If one thread updates `db1.tbl_a' and another thread
  22977. updates `db2.tbl_a', there will be problems.
  22978.  
  22979. If you really need this, you must change the following code in
  22980. `mysys/mf_format.c':
  22981.  
  22982.      if (flag & 32 || (!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
  22983.  
  22984. to
  22985.  
  22986.      if (1)
  22987.  
  22988. On Windows you can use internal symbolic links to directories by
  22989. compiling MySQL with `-DUSE_SYMDIR'. This allows you to put different
  22990. databases on different disks. *Note Windows symbolic links::.
  22991.  
  22992. Using Symbolic Links for Tables
  22993. ...............................
  22994.  
  22995. Before MySQL 4.0 you should not symlink tables, if you are not very
  22996. carefully with them. The problem is that if you run `ALTER TABLE',
  22997. `REPAIR TABLE' or `OPTIMIZE TABLE' on a symlinked table, the symlinks
  22998. will be removed and replaced by the original files. This happens
  22999. because the above command works by creating a temporary file in the
  23000. database directory and when the command is complete, replace the
  23001. original file with the temporary file.
  23002.  
  23003. You should not symlink tables on system that doesn't have a fully
  23004. working `realpath()' call. (At least Linux and Solaris support
  23005. `realpath()')
  23006.  
  23007. In MySQL 4.0 symlinks is only fully supported for `MyISAM' tables.  For
  23008. other table types you will probably get strange problems when doing any
  23009. of the above mentioned commands.
  23010.  
  23011. The handling of symbolic links in MySQL 4.0 works the following way
  23012. (this is mostly relevant only for `MyISAM' tables).
  23013.  
  23014.    * In the data directory you will always have the table definition
  23015.      file and the data/index files.
  23016.  
  23017.    * You can symlink the index file and the data file to different
  23018.      directories independent of the other.
  23019.  
  23020.    * The symlinking can be done from the operating system (if `mysqld'
  23021.      is not running) or with the `INDEX/DATA DIRECTORY="path-to-dir"'
  23022.      command in `CREATE TABLE'. *Note CREATE TABLE::.
  23023.  
  23024.    * `myisamchk' will not replace a symlink with the index/file but
  23025.      work directly on the files the symlinks points to. Any temporary
  23026.      files will be created in the same directory where the data/index
  23027.      file is.
  23028.  
  23029.    * When you drop a table that is using symlinks, both the symlink and
  23030.      the file the symlink points to is dropped.  This is a good reason
  23031.      to why you should NOT run `mysqld' as root and not allow persons
  23032.      to have write access to the MySQL database directories.
  23033.  
  23034.    * If you rename a table with `ALTER TABLE RENAME' and you don't
  23035.      change database, the symlink in the database directory will be
  23036.      renamed to the new name and the data/index file will be renamed
  23037.      accordingly.
  23038.  
  23039.    * If you use `ALTER TABLE RENAME' to move a table to another
  23040.      database, then the table will be moved to the other database
  23041.      directory and the old symlinks and the files they pointed to will
  23042.      be deleted.
  23043.  
  23044.    * If you are not using symlinks you should use the `--skip-symlink'
  23045.      option to `mysqld' to ensure that no one can drop or rename a file
  23046.      outside of the `mysqld' data directory.
  23047.  
  23048. Things that are not yet supported:
  23049.  
  23050.    * `ALTER TABLE' ignores all `INDEX/DATA DIRECTORY="path"' options.
  23051.  
  23052.    * `CREATE TABLE' doesn't report if the table has symbolic links.
  23053.  
  23054.    * `mysqldump' doesn't include the symbolic links information in the
  23055.      output.
  23056.  
  23057.    * `BACKUP TABLE' and `RESTORE TABLE' don't respect symbolic links.
  23058.  
  23059. MySQL Language Reference
  23060. ************************
  23061.  
  23062. MySQL has a very complex, but intuitive and easy to learn SQL
  23063. interface.  This chapter describes the various commands, types, and
  23064. functions you will need to know in order to use MySQL efficiently and
  23065. effectively.  This chapter also serves as a reference to all
  23066. functionality included in MySQL.  In order to use this chapter
  23067. effectively, you may find it useful to refer to the various indexes.
  23068.  
  23069. Language Structure
  23070. ==================
  23071.  
  23072. Literals: How to Write Strings and Numbers
  23073. ------------------------------------------
  23074.  
  23075. This section describes the various ways to write strings and numbers in
  23076. MySQL.  It also covers the various nuances and "gotchas" that you may
  23077. run into when dealing with these basic types in MySQL.
  23078.  
  23079. Strings
  23080. .......
  23081.  
  23082. A string is a sequence of characters, surrounded by either single quote
  23083. (`'') or double quote (`"') characters (only the single quote if you
  23084. run in ANSI mode).  Examples:
  23085.  
  23086.      'a string'
  23087.      "another string"
  23088.  
  23089. Within a string, certain sequences have special meaning.  Each of these
  23090. sequences begins with a backslash (`\'), known as the _escape
  23091. character_.  MySQL recognizes the following escape sequences:
  23092.  
  23093. `\0'
  23094.      An ASCII 0 (`NUL') character.
  23095.  
  23096. `\''
  23097.      A single quote (`'') character.
  23098.  
  23099. `\"'
  23100.      A double quote (`"') character.
  23101.  
  23102. `\b'
  23103.      A backspace character.
  23104.  
  23105. `\n'
  23106.      A newline character.
  23107.  
  23108. `\r'
  23109.      A carriage return character.
  23110.  
  23111. `\t'
  23112.      A tab character.
  23113.  
  23114. `\z'
  23115.      ASCII(26) (Control-Z).  This character can be encoded to allow you
  23116.      to go around the problem that ASCII(26) stands for END-OF-FILE on
  23117.      Windows.  (ASCII(26) will cause problems if you try to use `mysql
  23118.      database < filename').
  23119.  
  23120. `\\'
  23121.      A backslash (`\') character.
  23122.  
  23123. `\%'
  23124.      A `%' character. This is used to search for literal instances of
  23125.      `%' in contexts where `%' would otherwise be interpreted as a
  23126.      wild-card character. *Note String comparison functions::.
  23127.  
  23128. `\_'
  23129.      A `_' character. This is used to search for literal instances of
  23130.      `_' in contexts where `_' would otherwise be interpreted as a
  23131.      wild-card character. *Note String comparison functions::.
  23132.  
  23133. Note that if you use `\%' or `\_' in some string contexts, these will
  23134. return the strings `\%' and `\_' and not `%' and `_'.
  23135.  
  23136. There are several ways to include quotes within a string:
  23137.  
  23138.    * A `'' inside a string quoted with `'' may be written as `'''.
  23139.  
  23140.    * A `"' inside a string quoted with `"' may be written as `""'.
  23141.  
  23142.    * You can precede the quote character with an escape character (`\').
  23143.  
  23144.    * A `'' inside a string quoted with `"' needs no special treatment
  23145.      and need not be doubled or escaped.  In the same way, `"' inside a
  23146.      string quoted with `'' needs no special treatment.
  23147.  
  23148. The `SELECT' statements shown below demonstrate how quoting and
  23149. escaping work:
  23150.  
  23151.      mysql> SELECT 'hello', '"hello"', '""hello""', 'hel''lo', '\'hello';
  23152.      +-------+---------+-----------+--------+--------+
  23153.      | hello | "hello" | ""hello"" | hel'lo | 'hello |
  23154.      +-------+---------+-----------+--------+--------+
  23155.      
  23156.      mysql> SELECT "hello", "'hello'", "''hello''", "hel""lo", "\"hello";
  23157.      +-------+---------+-----------+--------+--------+
  23158.      | hello | 'hello' | ''hello'' | hel"lo | "hello |
  23159.      +-------+---------+-----------+--------+--------+
  23160.      
  23161.      mysql> SELECT "This\nIs\nFour\nlines";
  23162.      +--------------------+
  23163.      | This
  23164.      Is
  23165.      Four
  23166.      lines |
  23167.      +--------------------+
  23168.  
  23169. If you want to insert binary data into a `BLOB' column, the following
  23170. characters must be represented by escape sequences:
  23171. `NUL'
  23172.      ASCII 0. You should represent this by `\0' (a backslash and an
  23173.      ASCII `0' character).
  23174.  
  23175. `\'
  23176.      ASCII 92, backslash.  Represent this by `\\'.
  23177.  
  23178. `''
  23179.      ASCII 39, single quote.  Represent this by `\''.
  23180.  
  23181. `"'
  23182.      ASCII 34, double quote.  Represent this by `\"'.
  23183.  
  23184. If you write C code, you can use the C API function
  23185. `mysql_escape_string()' to escape characters for the `INSERT'
  23186. statement.  *Note C API function overview::.  In Perl, you can use the
  23187. `quote' method of the `DBI' package to convert special characters to
  23188. the proper escape sequences.  *Note Perl `DBI' Class: Perl DBI Class.
  23189.  
  23190. You should use an escape function on any string that might contain any
  23191. of the special characters listed above!
  23192.  
  23193. Numbers
  23194. .......
  23195.  
  23196. Integers are represented as a sequence of digits. Floats use `.' as a
  23197. decimal separator.  Either type of number may be preceded by `-' to
  23198. indicate a negative value.
  23199.  
  23200. Examples of valid integers:
  23201.  
  23202.      1221
  23203.      0
  23204.      -32
  23205.  
  23206. Examples of valid floating-point numbers:
  23207.  
  23208.      294.42
  23209.      -32032.6809e+10
  23210.      148.00
  23211.  
  23212. An integer may be used in a floating-point context; it is interpreted
  23213. as the equivalent floating-point number.
  23214.  
  23215. Hexadecimal Values
  23216. ..................
  23217.  
  23218. MySQL supports hexadecimal values.  In number context these act like an
  23219. integer (64-bit precision). In string context these act like a binary
  23220. string where each pair of hex digits is converted to a character:
  23221.  
  23222.      mysql> SELECT 0xa+0;
  23223.             -> 10
  23224.      mysql> select 0x5061756c;
  23225.             -> Paul
  23226.  
  23227. Hexadecimal strings are often used by ODBC to give values for BLOB
  23228. columns.
  23229.  
  23230. `NULL' Values
  23231. .............
  23232.  
  23233. The `NULL' value means "no data" and is different from values such as
  23234. `0' for numeric types or the empty string for string types.  *Note
  23235. Problems with `NULL': Problems with NULL.
  23236.  
  23237. `NULL' may be represented by `\N' when using the text file import or
  23238. export formats (`LOAD DATA INFILE', `SELECT ... INTO OUTFILE').  *Note
  23239. `LOAD DATA': LOAD DATA.
  23240.  
  23241. Database, Table, Index, Column, and Alias Names
  23242. -----------------------------------------------
  23243.  
  23244. Database, table, index, column, and alias names all follow the same
  23245. rules in MySQL.
  23246.  
  23247. Note that the rules changed starting with MySQL Version 3.23.6 when we
  23248. introduced quoting of identifiers (database, table, and column names)
  23249. with ``'. `"' will also work to quote identifiers if you run in ANSI
  23250. mode. *Note ANSI mode::.
  23251.  
  23252. *Identifier**Max        *Allowed characters*
  23253.             length*     
  23254. Database    64          Any character that is allowed in a directory name
  23255.                         except `/' or `.'.
  23256. Table       64          Any character that is allowed in a file name,
  23257.                         except `/' or `.'.
  23258. Column      64          All characters.
  23259. Alias       255         All characters.
  23260.  
  23261. Note that in addition to the above, you can't have ASCII(0) or
  23262. ASCII(255) or the quoting character in an identifier.
  23263.  
  23264. Note that if the identifier is a restricted word or contains special
  23265. characters you must always quote it with ``' when you use it:
  23266.  
  23267.      SELECT * from `select` where `select`.id > 100;
  23268.  
  23269. In previous versions of MySQL, the name rules are as follows:
  23270.  
  23271.    * A name may consist of alphanumeric characters from the current
  23272.      character set and also `_' and `$'. The default character set is
  23273.      ISO-8859-1 Latin1; this may be changed with the
  23274.      `--default-character-set' option to `mysqld'.  *Note Character
  23275.      sets::.
  23276.  
  23277.    * A name may start with any character that is legal in a name.  In
  23278.      particular, a name may start with a number (this differs from many
  23279.      other database systems!).  However, a name cannot consist _only_
  23280.      of numbers.
  23281.  
  23282.    * You cannot use the `.' character in names because it is used to
  23283.      extend the format by which you can refer to columns (see
  23284.      immediately below).
  23285.  
  23286. It is recommended that you do not use names like `1e', because an
  23287. expression like `1e+1' is ambiguous. It may be interpreted as the
  23288. expression `1e + 1' or as the number `1e+1'.
  23289.  
  23290. In MySQL you can refer to a column using any of the following forms:
  23291.  
  23292. *Column reference*        *Meaning*
  23293. `col_name'                Column `col_name' from whichever table used in
  23294.                           the query contains a column of that name.
  23295. `tbl_name.col_name'       Column `col_name' from table `tbl_name' of the
  23296.                           current database.
  23297. `db_name.tbl_name.col_name'Column `col_name' from table `tbl_name' of the
  23298.                           database `db_name'.  This form is available in
  23299.                           MySQL Version 3.22 or later.
  23300. ``column_name`'           A column that is a keyword or contains special
  23301.                           characters.
  23302.  
  23303. You need not specify a `tbl_name' or `db_name.tbl_name' prefix for a
  23304. column reference in a statement unless the reference would be ambiguous.
  23305. For example, suppose tables `t1' and `t2' each contain a column `c',
  23306. and you retrieve `c' in a `SELECT' statement that uses both `t1' and
  23307. `t2'.  In this case, `c' is ambiguous because it is not unique among
  23308. the tables used in the statement, so you must indicate which table you
  23309. mean by writing `t1.c' or `t2.c'.  Similarly, if you are retrieving
  23310. from a table `t' in database `db1' and from a table `t' in database
  23311. `db2', you must refer to columns in those tables as `db1.t.col_name'
  23312. and `db2.t.col_name'.
  23313.  
  23314. The syntax `.tbl_name' means the table `tbl_name' in the current
  23315. database.  This syntax is accepted for ODBC compatibility, because some
  23316. ODBC programs prefix table names with a `.' character.
  23317.  
  23318. Case Sensitivity in Names
  23319. -------------------------
  23320.  
  23321. In MySQL, databases and tables correspond to directories and files
  23322. within those directories.  Consequently, the case sensitivity of the
  23323. underlying operating system determines the case sensitivity of database
  23324. and table names.  This means database and table names are case
  23325. sensitive in Unix and case insensitive in Windows. *Note Extensions to
  23326. ANSI::.
  23327.  
  23328. *NOTE:* Although database and table names are case insensitive for
  23329. Windows, you should not refer to a given database or table using
  23330. different cases within the same query.  The following query would not
  23331. work because it refers to a table both as `my_table' and as `MY_TABLE':
  23332.  
  23333.      mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1;
  23334.  
  23335. Column names are case insensitive in all cases.
  23336.  
  23337. Aliases on tables are case sensitive.  The following query would not
  23338. work because it refers to the alias both as `a' and as `A':
  23339.  
  23340.      mysql> SELECT col_name FROM tbl_name AS a
  23341.                 WHERE a.col_name = 1 OR A.col_name = 2;
  23342.  
  23343. Aliases on columns are case insensitive.
  23344.  
  23345. If you have a problem remembering the used cases for a table names,
  23346. adopt a consistent convention, such as always creating databases and
  23347. tables using lowercase names.
  23348.  
  23349. One way to avoid this problem is to start `mysqld' with `-O
  23350. lower_case_table_names=1'. By default this option is 1 on Windows and 0
  23351. on Unix.
  23352.  
  23353. If `lower_case_table_names' is 1 MySQL will convert all table names to
  23354. lower case on storage and lookup.  Note that if you change this option,
  23355. you need to first convert your old table names to lower case before
  23356. starting `mysqld'.
  23357.  
  23358. User Variables
  23359. --------------
  23360.  
  23361. MySQL supports thread-specific variables with the `@variablename'
  23362. syntax.  A variable name may consist of alphanumeric characters from
  23363. the current character set and also `_', `$', and `.' . The default
  23364. character set is ISO-8859-1 Latin1; this may be changed with the
  23365. `--default-character-set' option to `mysqld'. *Note Character sets::.
  23366.  
  23367. Variables don't have to be initialized.  They contain `NULL' by default
  23368. and can store an integer, real, or string value.  All variables for a
  23369. thread are automatically freed when the thread exits.
  23370.  
  23371. You can set a variable with the `SET' syntax:
  23372.  
  23373.      SET @variable= { integer expression | real expression | string expression }
  23374.      [,@variable= ...].
  23375.  
  23376. You can also set a variable in an expression with the `@variable:=expr'
  23377. syntax:
  23378.  
  23379.      select @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  23380.      +----------------------+------+------+------+
  23381.      | @t1:=(@t2:=1)+@t3:=4 | @t1  | @t2  | @t3  |
  23382.      +----------------------+------+------+------+
  23383.      |                    5 |    5 |    1 |    4 |
  23384.      +----------------------+------+------+------+
  23385.  
  23386. (We had to use the `:=' syntax here, because `=' was reserved for
  23387. comparisons.)
  23388.  
  23389. User variables may be used where expressions are allowed.  Note that
  23390. this does not currently include use in contexts where a number is
  23391. explicitly required, such as in the `LIMIT' clause of a `SELECT'
  23392. statement, or the `IGNORE number LINES' clause of a `LOAD DATA'
  23393. statement.
  23394.  
  23395. *NOTE:*  In a `SELECT' statement, each expression is only evaluated
  23396. when it's sent to the client.  This means that in the `HAVING', `GROUP
  23397. BY', or `ORDER BY' clause, you can't refer to an expression that
  23398. involves variables that are set in the `SELECT' part. For example, the
  23399. following statement will NOT work as expected:
  23400.  
  23401.      SELECT (@aa:=id) AS a, (@aa+3) AS b FROM table_name HAVING b=5;
  23402.  
  23403. The reason is that `@aa' will not contain the value of the current row,
  23404. but the value of `id' for the previous accepted row.
  23405.  
  23406. Comment Syntax
  23407. --------------
  23408.  
  23409. The MySQL server supports the `# to end of line', `-- to end of line'
  23410. and `/* in-line or multiple-line */' comment styles:
  23411.  
  23412.      mysql> select 1+1;     # This comment continues to the end of line
  23413.      mysql> select 1+1;     -- This comment continues to the end of line
  23414.      mysql> select 1 /* this is an in-line comment */ + 1;
  23415.      mysql> select 1+
  23416.      /*
  23417.      this is a
  23418.      multiple-line comment
  23419.      */
  23420.      1;
  23421.  
  23422. Note that the `--' comment style requires you to have at least one space
  23423. after the `--'!
  23424.  
  23425. Although the server understands the comment syntax just described,
  23426. there are some limitations on the way that the `mysql' client parses
  23427. `/* ... */' comments:
  23428.  
  23429.    * Single-quote and double-quote characters are taken to indicate the
  23430.      beginning of a quoted string, even within a comment.  If the quote
  23431.      is not matched by a second quote within the comment, the parser
  23432.      doesn't realize the comment has ended.  If you are running `mysql'
  23433.      interactively, you can tell that it has gotten confused like this
  23434.      because the prompt changes from `mysql>' to `'>' or `">'.
  23435.  
  23436.    * A semicolon is taken to indicate the end of the current SQL
  23437.      statement and anything following it to indicate the beginning of
  23438.      the next statement.
  23439.  
  23440. These limitations apply both when you run `mysql' interactively and
  23441. when you put commands in a file and tell `mysql' to read its input from
  23442. that file with `mysql < some-file'.
  23443.  
  23444. MySQL doesn't support the `--' ANSI SQL comment style.  *Note Missing
  23445. comments::.
  23446.  
  23447. Is MySQL Picky About Reserved Words?
  23448. ------------------------------------
  23449.  
  23450. A common problem stems from trying to create a table with column names
  23451. that use the names of datatypes or functions built into MySQL, such as
  23452. `TIMESTAMP' or `GROUP'.  You're allowed to do it (for example, `ABS' is
  23453. an allowed column name), but whitespace is not allowed between a
  23454. function name and the `(' when using functions whose names are also
  23455. column names.
  23456.  
  23457. The following words are explicitly reserved in MySQL. Most of them are
  23458. forbidden by ANSI SQL92 as column and/or table names (for example,
  23459. `group').  A few are reserved because MySQL needs them and is
  23460. (currently) using a `yacc' parser:
  23461.  
  23462. `action'           `add'              `aggregate'        `all'
  23463. `alter'            `after'            `and'              `as'
  23464. `asc'              `avg'              `avg_row_length'   `auto_increment'
  23465. `between'          `bigint'           `bit'              `binary'
  23466. `blob'             `bool'             `both'             `by'
  23467. `cascade'          `case'             `char'             `character'
  23468. `change'           `check'            `checksum'         `column'
  23469. `columns'          `comment'          `constraint'       `create'
  23470. `cross'            `current_date'     `current_time'     `current_timestamp'
  23471. `data'             `database'         `databases'        `date'
  23472. `datetime'         `day'              `day_hour'         `day_minute'
  23473. `day_second'       `dayofmonth'       `dayofweek'        `dayofyear'
  23474. `dec'              `decimal'          `default'          `delayed'
  23475. `delay_key_write'  `delete'           `desc'             `describe'
  23476. `distinct'         `distinctrow'      `double'           `drop'
  23477. `end'              `else'             `escape'           `escaped'
  23478. `enclosed'         `enum'             `explain'          `exists'
  23479. `fields'           `file'             `first'            `float'
  23480. `float4'           `float8'           `flush'            `foreign'
  23481. `from'             `for'              `full'             `function'
  23482. `global'           `grant'            `grants'           `group'
  23483. `having'           `heap'             `high_priority'    `hour'
  23484. `hour_minute'      `hour_second'      `hosts'            `identified'
  23485. `ignore'           `in'               `index'            `infile'
  23486. `inner'            `insert'           `insert_id'        `int'
  23487. `integer'          `interval'         `int1'             `int2'
  23488. `int3'             `int4'             `int8'             `into'
  23489. `if'               `is'               `isam'             `join'
  23490. `key'              `keys'             `kill'             `last_insert_id'
  23491. `leading'          `left'             `length'           `like'
  23492. `lines'            `limit'            `load'             `local'
  23493. `lock'             `logs'             `long'             `longblob'
  23494. `longtext'         `low_priority'     `max'              `max_rows'
  23495. `match'            `mediumblob'       `mediumtext'       `mediumint'
  23496. `middleint'        `min_rows'         `minute'           `minute_second'
  23497. `modify'           `month'            `monthname'        `myisam'
  23498. `natural'          `numeric'          `no'               `not'
  23499. `null'             `on'               `optimize'         `option'
  23500. `optionally'       `or'               `order'            `outer'
  23501. `outfile'          `pack_keys'        `partial'          `password'
  23502. `precision'        `primary'          `procedure'        `process'
  23503. `processlist'      `privileges'       `read'             `real'
  23504. `references'       `reload'           `regexp'           `rename'
  23505. `replace'          `restrict'         `returns'          `revoke'
  23506. `rlike'            `row'              `rows'             `second'
  23507. `select'           `set'              `show'             `shutdown'
  23508. `smallint'         `soname'           `sql_big_tables'   `sql_big_selects'
  23509. `sql_low_priority_updates'`sql_log_off'      `sql_log_update'   `sql_select_limit'
  23510. `sql_small_result' `sql_big_result'   `sql_warnings'     `straight_join'
  23511. `starting'         `status'           `string'           `table'
  23512. `tables'           `temporary'        `terminated'       `text'
  23513. `then'             `time'             `timestamp'        `tinyblob'
  23514. `tinytext'         `tinyint'          `trailing'         `to'
  23515. `type'             `use'              `using'            `unique'
  23516. `unlock'           `unsigned'         `update'           `usage'
  23517. `values'           `varchar'          `variables'        `varying'
  23518. `varbinary'        `with'             `write'            `when'
  23519. `where'            `year'             `year_month'       `zerofill'
  23520.  
  23521. The following symbols (from the table above) are disallowed by ANSI SQL
  23522. but allowed by MySQL as column/table names. This is because some of
  23523. these names are very natural names and a lot of people have already
  23524. used them.
  23525.  
  23526.    * `ACTION'
  23527.  
  23528.    * `BIT'
  23529.  
  23530.    * `DATE'
  23531.  
  23532.    * `ENUM'
  23533.  
  23534.    * `NO'
  23535.  
  23536.    * `TEXT'
  23537.  
  23538.    * `TIME'
  23539.  
  23540.    * `TIMESTAMP'
  23541.  
  23542. Column Types
  23543. ============
  23544.  
  23545. MySQL supports a number of column types, which may be grouped into
  23546. three categories: numeric types, date and time types, and string
  23547. (character) types.  This section first gives an overview of the types
  23548. available and summarizes the storage requirements for each column type,
  23549. then provides a more detailed description of the properties of the
  23550. types in each category.  The overview is intentionally brief.  The more
  23551. detailed descriptions should be consulted for additional information
  23552. about particular column types, such as the allowable formats in which
  23553. you can specify values.
  23554.  
  23555. The column types supported by MySQL are listed below.  The following
  23556. code letters are used in the descriptions:
  23557.  
  23558. `M'
  23559.      Indicates the maximum display size.  The maximum legal display
  23560.      size is 255.
  23561.  
  23562. `D'
  23563.      Applies to floating-point types and indicates the number of digits
  23564.      following the decimal point.  The maximum possible value is 30, but
  23565.      should be no greater than `M'-2.
  23566.  
  23567. Square brackets (`[' and `]') indicate parts of type specifiers that
  23568. are optional.
  23569.  
  23570. Note that if you specify `ZEROFILL' for a column, MySQL will
  23571. automatically add the `UNSIGNED' attribute to the column.
  23572.  
  23573. `TINYINT[(M)] [UNSIGNED] [ZEROFILL]'
  23574.      A very small integer. The signed range is `-128' to `127'. The
  23575.      unsigned range is `0' to `255'.
  23576.  
  23577. `SMALLINT[(M)] [UNSIGNED] [ZEROFILL]'
  23578.      A small integer. The signed range is `-32768' to `32767'. The
  23579.      unsigned range is `0' to `65535'.
  23580.  
  23581. `MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL]'
  23582.      A medium-size integer. The signed range is `-8388608' to
  23583.      `8388607'. The unsigned range is `0' to `16777215'.
  23584.  
  23585. `INT[(M)] [UNSIGNED] [ZEROFILL]'
  23586.      A normal-size integer. The signed range is `-2147483648' to
  23587.      `2147483647'.  The unsigned range is `0' to `4294967295'.
  23588.  
  23589. `INTEGER[(M)] [UNSIGNED] [ZEROFILL]'
  23590.      This is a synonym for `INT'.
  23591.  
  23592. `BIGINT[(M)] [UNSIGNED] [ZEROFILL]'
  23593.      A large integer. The signed range is `-9223372036854775808' to
  23594.      `9223372036854775807'. The unsigned range is `0' to
  23595.      `18446744073709551615'.
  23596.  
  23597.      Some things you should be aware about `BIGINT' columns:
  23598.  
  23599.         * As all arithmetic is done using signed `BIGINT' or `DOUBLE'
  23600.           values, so you shouldn't use unsigned big integers larger than
  23601.           `9223372036854775807' (63 bits) except with bit functions! If
  23602.           you do that, some of the last digits in the result may be
  23603.           wrong because of rounding errors when converting the `BIGINT'
  23604.           to a `DOUBLE'.
  23605.  
  23606.         * You can always store an exact integer value in a `BIGINT'
  23607.           column by storing it as a string, as there is in this case
  23608.           there will be no intermediate double representation.
  23609.  
  23610.         * `-', `+', and `*' will use `BIGINT' arithmetic when both
  23611.           arguments are `INTEGER' values!  This means that if you
  23612.           multiply two big integers (or results from functions that
  23613.           return integers) you may get unexpected results when the
  23614.           result is larger than `9223372036854775807'.
  23615.  
  23616. `FLOAT(precision) [ZEROFILL]'
  23617.      A floating-point number. Cannot be unsigned.  `precision' can be
  23618.      `<=24' for a single-precision floating-point number and between 25
  23619.      and 53 for a double-precision floating-point number. These types
  23620.      are like the `FLOAT' and `DOUBLE' types described immediately
  23621.      below.  `FLOAT(X)' has the same range as the corresponding `FLOAT'
  23622.      and `DOUBLE' types, but the display size and number of decimals is
  23623.      undefined.
  23624.  
  23625.      In MySQL Version 3.23, this is a true floating-point value.  In
  23626.      earlier MySQL versions, `FLOAT(precision)' always has 2 decimals.
  23627.  
  23628.      Note that using `FLOAT' may give you some unexpected problems as
  23629.      all calculation in MySQL is done with double precision.  *Note No
  23630.      matching rows::.
  23631.  
  23632.      This syntax is provided for ODBC compatibility.
  23633.  
  23634. `FLOAT[(M,D)] [ZEROFILL]'
  23635.      A small (single-precision) floating-point number. Cannot be
  23636.      unsigned.  Allowable values are `-3.402823466E+38' to
  23637.      `-1.175494351E-38', `0', and `1.175494351E-38' to
  23638.      `3.402823466E+38'.  The M is the display width and D is the number
  23639.      of decimals.  `FLOAT' without an argument or with an argument of
  23640.      <= 24 stands for a single-precision floating-point number.
  23641.  
  23642. `DOUBLE[(M,D)] [ZEROFILL]'
  23643.      A normal-size (double-precision) floating-point number. Cannot be
  23644.      unsigned. Allowable values are `-1.7976931348623157E+308' to
  23645.      `-2.2250738585072014E-308', `0', and `2.2250738585072014E-308' to
  23646.      `1.7976931348623157E+308'.  The M is the display width and D is
  23647.      the number of decimals.  `DOUBLE' without an argument or
  23648.      `FLOAT(X)' where 25 <= X <= 53 stands for a double-precision
  23649.      floating-point number.
  23650.  
  23651. `DOUBLE PRECISION[(M,D)] [ZEROFILL]'
  23652. `REAL[(M,D)] [ZEROFILL]'
  23653.      These are synonyms for `DOUBLE'.
  23654.  
  23655. `DECIMAL[(M[,D])] [ZEROFILL]'
  23656.      An unpacked floating-point number.  Cannot be unsigned.  Behaves
  23657.      like a `CHAR' column: "unpacked" means the number is stored as a
  23658.      string, using one character for each digit of the value.  The
  23659.      decimal point and, for negative numbers, the `-' sign, are not
  23660.      counted in M (but space for these are reserved). If `D' is 0,
  23661.      values will have no decimal point or fractional part.  The maximum
  23662.      range of `DECIMAL' values is the same as for `DOUBLE', but the
  23663.      actual range for a given `DECIMAL' column may be constrained by
  23664.      the choice of `M' and `D'.
  23665.  
  23666.      If `D' is left out it's set to 0. If `M' is left out it's set to
  23667.      10.
  23668.  
  23669.      Note that in MySQL Version 3.22 the `M' argument had to includes
  23670.      the space needed for the sign and the decimal point.
  23671.  
  23672. `NUMERIC(M,D) [ZEROFILL]'
  23673.      This is a synonym for `DECIMAL'.
  23674.  
  23675. `DATE'
  23676.      A date.  The supported range is `'1000-01-01'' to `'9999-12-31''.
  23677.      MySQL displays `DATE' values in `'YYYY-MM-DD'' format, but allows
  23678.      you to assign values to `DATE' columns using either strings or
  23679.      numbers. *Note DATETIME::.
  23680.  
  23681. `DATETIME'
  23682.      A date and time combination.  The supported range is `'1000-01-01
  23683.      00:00:00'' to `'9999-12-31 23:59:59''.  MySQL displays `DATETIME'
  23684.      values in `'YYYY-MM-DD HH:MM:SS'' format, but allows you to assign
  23685.      values to `DATETIME' columns using either strings or numbers.
  23686.      *Note DATETIME::.
  23687.  
  23688. `TIMESTAMP[(M)]'
  23689.      A timestamp.  The range is `'1970-01-01 00:00:00'' to sometime in
  23690.      the year `2037'.  MySQL displays `TIMESTAMP' values in
  23691.      `YYYYMMDDHHMMSS', `YYMMDDHHMMSS', `YYYYMMDD', or `YYMMDD' format,
  23692.      depending on whether `M' is `14' (or missing), `12', `8', or `6',
  23693.      but allows you to assign values to `TIMESTAMP' columns using
  23694.      either strings or numbers.  A `TIMESTAMP' column is useful for
  23695.      recording the date and time of an `INSERT' or `UPDATE' operation
  23696.      because it is automatically set to the date and time of the most
  23697.      recent operation if you don't give it a value yourself.  You can
  23698.      also set it to the current date and time by assigning it a `NULL'
  23699.      value.  *Note Date and time types::.
  23700.  
  23701.      A `TIMESTAMP' is always stored in 4 bytes.  The `M' argument only
  23702.      affects how the `TIMESTAMP' column is displayed.
  23703.  
  23704.      Note that `TIMESTAMP(X)' columns where X is 8 or 14 are reported to
  23705.      be numbers while other `TIMESTAMP(X)' columns are reported to be
  23706.      strings.  This is just to ensure that one can reliably dump and
  23707.      restore the table with these types!  *Note DATETIME::.
  23708.  
  23709. `TIME'
  23710.      A time.  The range is `'-838:59:59'' to `'838:59:59''.  MySQL
  23711.      displays `TIME' values in `'HH:MM:SS'' format, but allows you to
  23712.      assign values to `TIME' columns using either strings or numbers.
  23713.      *Note TIME::.
  23714.  
  23715. `YEAR[(2|4)]'
  23716.      A year in 2- or 4-digit format (default is 4-digit).  The
  23717.      allowable values are `1901' to `2155', `0000' in the 4-digit year
  23718.      format, and 1970-2069 if you use the 2-digit format (70-69).
  23719.      MySQL displays `YEAR' values in `YYYY' format, but allows you to
  23720.      assign values to `YEAR' columns using either strings or numbers.
  23721.      (The `YEAR' type is new in MySQL Version 3.22.). *Note YEAR::.
  23722.  
  23723. `[NATIONAL] CHAR(M) [BINARY]'
  23724.      A fixed-length string that is always right-padded with spaces to
  23725.      the specified length when stored. The range of `M' is 1 to 255
  23726.      characters.  Trailing spaces are removed when the value is
  23727.      retrieved. `CHAR' values are sorted and compared in
  23728.      case-insensitive fashion according to the default character set
  23729.      unless the `BINARY' keyword is given.
  23730.  
  23731.      `NATIONAL CHAR' (short form `NCHAR') is the ANSI SQL way to define
  23732.      that a CHAR column should use the default CHARACTER set.  This is
  23733.      the default in MySQL.
  23734.  
  23735.      `CHAR' is a shorthand for `CHARACTER'.
  23736.  
  23737.      MySQL allows you to create a column of type `CHAR(0)'. This is
  23738.      mainly useful when you have to be compliant with some old
  23739.      applications that depend on the existence of a column but that do
  23740.      not actually use the value.  This is also quite nice when you need
  23741.      a column that only can take 2 values: A `CHAR(0)', that is not
  23742.      defined as `NOT NULL', will only occupy one bit and can only take
  23743.      2 values: `NULL' or `""'. *Note CHAR::.
  23744.  
  23745. `BIT'
  23746. `BOOL'
  23747. `CHAR'
  23748.      These three are synonyms for `CHAR(1)'.
  23749.  
  23750. `[NATIONAL] VARCHAR(M) [BINARY]'
  23751.      A variable-length string.  *NOTE:* Trailing spaces are removed when
  23752.      the value is stored (this differs from the ANSI SQL
  23753.      specification). The range of `M' is 1 to 255 characters. `VARCHAR'
  23754.      values are sorted and compared in case-insensitive fashion unless
  23755.      the `BINARY' keyword is given. *Note Silent column changes::.
  23756.  
  23757.      `VARCHAR' is a shorthand for `CHARACTER VARYING'.  *Note CHAR::.
  23758.  
  23759. `TINYBLOB'
  23760. `TINYTEXT'
  23761.      A `BLOB' or `TEXT' column with a maximum length of 255 (2^8 - 1)
  23762.      characters. *Note Silent column changes::. *Note BLOB::.
  23763.  
  23764. `BLOB'
  23765. `TEXT'
  23766.      A `BLOB' or `TEXT' column with a maximum length of 65535 (2^16 - 1)
  23767.      characters. *Note Silent column changes::. *Note BLOB::.
  23768.  
  23769. `MEDIUMBLOB'
  23770. `MEDIUMTEXT'
  23771.      A `BLOB' or `TEXT' column with a maximum length of 16777215 (2^24
  23772.      - 1) characters. *Note Silent column changes::. *Note BLOB::.
  23773.  
  23774. `LONGBLOB'
  23775. `LONGTEXT'
  23776.      A `BLOB' or `TEXT' column with a maximum length of 4294967295
  23777.      (2^32 - 1) characters. *Note Silent column changes::.  Note that
  23778.      because the server/client protocol and MyISAM tables has currently
  23779.      a limit of 16M per communication packet / table row, you can't yet
  23780.      use this the whole range of this type. *Note BLOB::.
  23781.  
  23782. `ENUM('value1','value2',...)'
  23783.      An enumeration.  A string object that can have only one value,
  23784.      chosen from the list of values `'value1'', `'value2'', `...',
  23785.      `NULL' or the special `""' error value.  An `ENUM' can have a
  23786.      maximum of 65535 distinct values. *Note ENUM::.
  23787.  
  23788. `SET('value1','value2',...)'
  23789.      A set.  A string object that can have zero or more values, each of
  23790.      which must be chosen from the list of values `'value1'',
  23791.      `'value2'', `...' A `SET' can have a maximum of 64 members. *Note
  23792.      SET::.
  23793.  
  23794. Numeric Types
  23795. -------------
  23796.  
  23797. MySQL supports all of the ANSI/ISO SQL92 numeric types.  These types
  23798. include the exact numeric data types (`NUMERIC', `DECIMAL', `INTEGER',
  23799. and `SMALLINT'), as well as the approximate numeric data types
  23800. (`FLOAT', `REAL', and `DOUBLE PRECISION'). The keyword `INT' is a
  23801. synonym for `INTEGER', and the keyword `DEC' is a synonym for `DECIMAL'.
  23802.  
  23803. The `NUMERIC' and `DECIMAL' types are implemented as the same type by
  23804. MySQL, as permitted by the SQL92 standard.  They are used for values
  23805. for which it is important to preserve exact precision, for example with
  23806. monetary data.  When declaring a column of one of these types the
  23807. precision and scale can be (and usually is) specified; for example:
  23808.  
  23809.          salary DECIMAL(9,2)
  23810.  
  23811. In this example, `9' (`precision') represents the number of significant
  23812. decimal digits that will be stored for values, and `2' (`scale')
  23813. represents the number of digits that will be stored following the
  23814. decimal point.  In this case, therefore, the range of values that can
  23815. be stored in the `salary' column is from `-9999999.99' to `9999999.99'.
  23816. (MySQL can actually store numbers up to `9999999.99' in this column
  23817. because it doesn't have to store the sign for positive numbers)
  23818.  
  23819. In ANSI/ISO SQL92, the syntax `DECIMAL(p)' is equivalent to
  23820. `DECIMAL(p,0)'.  Similarly, the syntax `DECIMAL' is equivalent to
  23821. `DECIMAL(p,0)', where the implementation is allowed to decide the value
  23822. of `p'.  MySQL does not currently support either of these variant forms
  23823. of the `DECIMAL'/`NUMERIC' data types.  This is not generally a serious
  23824. problem, as the principal benefits of these types derive from the
  23825. ability to control both precision and scale explicitly.
  23826.  
  23827. `DECIMAL' and `NUMERIC' values are stored as strings, rather than as
  23828. binary floating-point numbers, in order to preserve the decimal
  23829. precision of those values.  One character is used for each digit of the
  23830. value, the decimal point (if `scale' > 0), and the `-' sign (for
  23831. negative numbers).  If `scale' is 0, `DECIMAL' and `NUMERIC' values
  23832. contain no decimal point or fractional part.
  23833.  
  23834. The maximum range of `DECIMAL' and `NUMERIC' values is the same as for
  23835. `DOUBLE', but the actual range for a given `DECIMAL' or `NUMERIC'
  23836. column can be constrained by the `precision' or `scale' for a given
  23837. column.  When such a column is assigned a value with more digits
  23838. following the decimal point than are allowed by the specified `scale',
  23839. the value is rounded to that `scale'.  When a `DECIMAL' or `NUMERIC'
  23840. column is assigned a value whose magnitude exceeds the range implied by
  23841. the specified (or defaulted) `precision' and `scale', MySQL stores the
  23842. value representing the corresponding end point of that range.
  23843.  
  23844. As an extension to the ANSI/ISO SQL92 standard, MySQL also supports the
  23845. integral types `TINYINT', `MEDIUMINT', and `BIGINT' as listed in the
  23846. tables above.  Another extension is supported by MySQL for optionally
  23847. specifying the display width of an integral value in parentheses
  23848. following the base keyword for the type (for example, `INT(4)').  This
  23849. optional width specification is used to left-pad the display of values
  23850. whose width is less than the width specified for the column, but does
  23851. not constrain the range of values that can be stored in the column, nor
  23852. the number of digits that will be displayed for values whose width
  23853. exceeds that specified for the column.  When used in conjunction with
  23854. the optional extension attribute `ZEROFILL', the default padding of
  23855. spaces is replaced with zeroes.  For example, for a column declared as
  23856. `INT(5) ZEROFILL', a value of `4' is retrieved as `00004'.  Note that
  23857. if you store larger values than the display width in an integer column,
  23858. you may experience problems when MySQL generates temporary tables for
  23859. some complicated joins, as in these cases MySQL trusts that the data
  23860. did fit into the original column width.
  23861.  
  23862. All integral types can have an optional (non-standard) attribute
  23863. `UNSIGNED'.  Unsigned values can be used when you want to allow only
  23864. positive numbers in a column and you need a little bigger numeric range
  23865. for the column.
  23866.  
  23867. The `FLOAT' type is used to represent approximate numeric data types.
  23868. The ANSI/ISO SQL92 standard allows an optional specification of the
  23869. precision (but not the range of the exponent) in bits following the
  23870. keyword `FLOAT' in parentheses.  The MySQL implementation also supports
  23871. this optional precision specification.  When the keyword `FLOAT' is
  23872. used for a column type without a precision specification, MySQL uses
  23873. four bytes to store the values.  A variant syntax is also supported,
  23874. with two numbers given in parentheses following the `FLOAT' keyword.
  23875. With this option, the first number continues to represent the storage
  23876. requirements for the value in bytes, and the second number specifies
  23877. the number of digits to be stored and displayed following the decimal
  23878. point (as with `DECIMAL' and `NUMERIC').  When MySQL is asked to store
  23879. a number for such a column with more decimal digits following the
  23880. decimal point than specified for the column, the value is rounded to
  23881. eliminate the extra digits when the value is stored.
  23882.  
  23883. The `REAL' and `DOUBLE PRECISION' types do not accept precision
  23884. specifications.  As an extension to the ANSI/ISO SQL92 standard, MySQL
  23885. recognizes `DOUBLE' as a synonym for the `DOUBLE PRECISION' type.  In
  23886. contrast with the standard's requirement that the precision for `REAL'
  23887. be smaller than that used for `DOUBLE PRECISION', MySQL implements both
  23888. as 8-byte double-precision floating-point values (when not running in
  23889. "ANSI mode").  For maximum portability, code requiring storage of
  23890. approximate numeric data values should use `FLOAT' or `DOUBLE
  23891. PRECISION' with no specification of precision or number of decimal
  23892. points.
  23893.  
  23894. When asked to store a value in a numeric column that is outside the
  23895. column type's allowable range, MySQL clips the value to the appropriate
  23896. endpoint of the range and stores the resulting value instead.
  23897.  
  23898. For example, the range of an `INT' column is `-2147483648' to
  23899. `2147483647'.  If you try to insert `-9999999999' into an `INT' column,
  23900. the value is clipped to the lower endpoint of the range, and
  23901. `-2147483648' is stored instead. Similarly, if you try to insert
  23902. `9999999999', `2147483647' is stored instead.
  23903.  
  23904. If the `INT' column is `UNSIGNED', the size of the column's range is
  23905. the same but its endpoints shift up to `0' and `4294967295'.  If you
  23906. try to store `-9999999999' and `9999999999', the values stored in the
  23907. column become `0' and `4294967296'.
  23908.  
  23909. Conversions that occur due to clipping are reported as "warnings" for
  23910. `ALTER TABLE', `LOAD DATA INFILE', `UPDATE', and multi-row `INSERT'
  23911. statements.
  23912.  
  23913. Date and Time Types
  23914. -------------------
  23915.  
  23916. The date and time types are `DATETIME', `DATE', `TIMESTAMP', `TIME',
  23917. and `YEAR'.  Each of these has a range of legal values, as well as a
  23918. "zero" value that is used when you specify a really illegal value.
  23919. Note that MySQL allows you to store certain 'not strictly' legal date
  23920. values, for example `1999-11-31'.  The reason for this is that we think
  23921. it's the responsibility of the application to handle date checking, not
  23922. the SQL servers.  To make the date checking 'fast', MySQL only checks
  23923. that the month is in the range of 0-12 and the day is in the range of
  23924. 0-31. The above ranges are defined this way because MySQL allows you to
  23925. store, in a `DATE' or `DATETIME' column, dates where the day or
  23926. month-day is zero.  This is extremely useful for applications that need
  23927. to store a birth-date for which you don't know the exact date. In this
  23928. case you simply store the date like `1999-00-00' or `1999-01-00'.  (You
  23929. cannot expect to get a correct value from functions like `DATE_SUB()'
  23930. or `DATE_ADD' for dates like these.)
  23931.  
  23932. Here are some general considerations to keep in mind when working with
  23933. date and time types:
  23934.  
  23935.    * MySQL retrieves values for a given date or time type in a standard
  23936.      format, but it attempts to interpret a variety of formats for
  23937.      values that you supply (for example, when you specify a value to
  23938.      be assigned to or compared to a date or time type).  Nevertheless,
  23939.      only the formats described in the following sections are
  23940.      supported.  It is expected that you will supply legal values, and
  23941.      unpredictable results may occur if you use values in other formats.
  23942.  
  23943.    * Although MySQL tries to interpret values in several formats, it
  23944.      always expects the year part of date values to be leftmost.  Dates
  23945.      must be given in year-month-day order (for example, `'98-09-04''),
  23946.      rather than in the month-day-year or day-month-year orders
  23947.      commonly used elsewhere (for example, `'09-04-98'', `'04-09-98'').
  23948.  
  23949.    * MySQL automatically converts a date or time type value to a number
  23950.      if the value is used in a numeric context, and vice versa.
  23951.  
  23952.    * When MySQL encounters a value for a date or time type that is out
  23953.      of range or otherwise illegal for the type (see the start of this
  23954.      section), it converts the value to the "zero" value for that type.
  23955.      (The exception is that out-of-range `TIME' values are clipped to
  23956.      the appropriate endpoint of the `TIME' range.)  The table below
  23957.      shows the format of the "zero" value for each type:
  23958.  
  23959.      *Column type*        *"Zero" value*
  23960.      `DATETIME'           `'0000-00-00 00:00:00''
  23961.      `DATE'               `'0000-00-00''
  23962.      `TIMESTAMP'          `00000000000000' (length depends on display
  23963.                           size)
  23964.      `TIME'               `'00:00:00''
  23965.      `YEAR'               `0000'
  23966.  
  23967.    * The "zero" values are special, but you can store or refer to them
  23968.      explicitly using the values shown in the table.  You can also do
  23969.      this using the values `'0'' or `0', which are easier to write.
  23970.  
  23971.    * "Zero" date or time values used through *MyODBC* are converted
  23972.      automatically to `NULL' in *MyODBC* Version 2.50.12 and above,
  23973.      because ODBC can't handle such values.
  23974.  
  23975. Y2K Issues and Date Types
  23976. .........................
  23977.  
  23978. MySQL itself is Y2K-safe (*note Year 2000 compliance::), but input
  23979. values presented to MySQL may not be.  Any input containing 2-digit
  23980. year values is ambiguous, because the century is unknown.  Such values
  23981. must be interpreted into 4-digit form because MySQL stores years
  23982. internally using four digits.
  23983.  
  23984. For `DATETIME', `DATE', `TIMESTAMP', and `YEAR' types, MySQL interprets
  23985. dates with ambiguous year values using the following rules:
  23986.  
  23987.    * Year values in the range `00-69' are converted to `2000-2069'.
  23988.  
  23989.    * Year values in the range `70-99' are converted to `1970-1999'.
  23990.  
  23991. Remember that these rules provide only reasonable guesses as to what
  23992. your data mean.  If the heuristics used by MySQL don't produce the
  23993. correct values, you should provide unambiguous input containing 4-digit
  23994. year values.
  23995.  
  23996. `ORDER BY' will sort 2-digit `YEAR/DATE/DATETIME' types properly.
  23997.  
  23998. Note also that some functions like `MIN()' and `MAX()' will convert a
  23999. `TIMESTAMP/DATE' to a number. This means that a timestamp with a
  24000. 2-digit year will not work properly with these functions.  The fix in
  24001. this case is to convert the `TIMESTAMP/DATE' to 4-digit year format or
  24002. use something like `MIN(DATE_ADD(timestamp,INTERVAL 0 DAYS))'.
  24003.  
  24004. The `DATETIME', `DATE', and `TIMESTAMP' Types
  24005. .............................................
  24006.  
  24007. The `DATETIME', `DATE', and `TIMESTAMP' types are related.  This
  24008. section describes their characteristics, how they are similar, and how
  24009. they differ.
  24010.  
  24011. The `DATETIME' type is used when you need values that contain both date
  24012. and time information.  MySQL retrieves and displays `DATETIME' values
  24013. in `'YYYY-MM-DD HH:MM:SS'' format.  The supported range is `'1000-01-01
  24014. 00:00:00'' to `'9999-12-31 23:59:59''.  ("Supported" means that
  24015. although earlier values might work, there is no guarantee that they
  24016. will.)
  24017.  
  24018. The `DATE' type is used when you need only a date value, without a time
  24019. part.  MySQL retrieves and displays `DATE' values in `'YYYY-MM-DD''
  24020. format.  The supported range is `'1000-01-01'' to `'9999-12-31''.
  24021.  
  24022. The `TIMESTAMP' column type provides a type that you can use to
  24023. automatically mark `INSERT' or `UPDATE' operations with the current
  24024. date and time.  If you have multiple `TIMESTAMP' columns, only the first
  24025. one is updated automatically.
  24026.  
  24027. Automatic updating of the first `TIMESTAMP' column occurs under any of
  24028. the following conditions:
  24029.  
  24030.    * The column is not specified explicitly in an `INSERT' or `LOAD
  24031.      DATA INFILE' statement.
  24032.  
  24033.    * The column is not specified explicitly in an `UPDATE' statement
  24034.      and some other column changes value.  (Note that an `UPDATE' that
  24035.      sets a column to the value it already has will not cause the
  24036.      `TIMESTAMP' column to be updated, because if you set a column to
  24037.      its current value, MySQL ignores the update for efficiency.)
  24038.  
  24039.    * You explicitly set the `TIMESTAMP' column to `NULL'.
  24040.  
  24041. `TIMESTAMP' columns other than the first may also be set to the current
  24042. date and time.  Just set the column to `NULL' or to `NOW()'.
  24043.  
  24044. You can set any `TIMESTAMP' column to a value different than the current
  24045. date and time by setting it explicitly to the desired value.  This is
  24046. true even for the first `TIMESTAMP' column.  You can use this property
  24047. if, for example, you want a `TIMESTAMP' to be set to the current date
  24048. and time when you create a row, but not to be changed whenever the row
  24049. is updated later:
  24050.  
  24051.    * Let MySQL set the column when the row is created.  This will
  24052.      initialize it to the current date and time.
  24053.  
  24054.    * When you perform subsequent updates to other columns in the row,
  24055.      set the `TIMESTAMP' column explicitly to its current value.
  24056.  
  24057. On the other hand, you may find it just as easy to use a `DATETIME'
  24058. column that you initialize to `NOW()' when the row is created and leave
  24059. alone for subsequent updates.
  24060.  
  24061. `TIMESTAMP' values may range from the beginning of 1970 to sometime in
  24062. the year 2037, with a resolution of one second.  Values are displayed as
  24063. numbers.
  24064.  
  24065. The format in which MySQL retrieves and displays `TIMESTAMP' values
  24066. depends on the display size, as illustrated by the table below.  The
  24067. `full' `TIMESTAMP' format is 14 digits, but `TIMESTAMP' columns may be
  24068. created with shorter display sizes:
  24069.  
  24070. *Column type*          *Display format*
  24071. `TIMESTAMP(14)'        `YYYYMMDDHHMMSS'
  24072. `TIMESTAMP(12)'        `YYMMDDHHMMSS'
  24073. `TIMESTAMP(10)'        `YYMMDDHHMM'
  24074. `TIMESTAMP(8)'         `YYYYMMDD'
  24075. `TIMESTAMP(6)'         `YYMMDD'
  24076. `TIMESTAMP(4)'         `YYMM'
  24077. `TIMESTAMP(2)'         `YY'
  24078.  
  24079. All `TIMESTAMP' columns have the same storage size, regardless of
  24080. display size.  The most common display sizes are 6, 8, 12, and 14.  You
  24081. can specify an arbitrary display size at table creation time, but
  24082. values of 0 or greater than 14 are coerced to 14.  Odd-valued sizes in
  24083. the range from 1 to 13 are coerced to the next higher even number.
  24084.  
  24085. You can specify `DATETIME', `DATE', and `TIMESTAMP' values using any of
  24086. a common set of formats:
  24087.  
  24088.    * As a string in either `'YYYY-MM-DD HH:MM:SS'' or `'YY-MM-DD
  24089.      HH:MM:SS'' format.  A "relaxed" syntax is allowed--any punctuation
  24090.      character may be used as the delimiter between date parts or time
  24091.      parts.  For example, `'98-12-31 11:30:45'', `'98.12.31 11+30+45'',
  24092.      `'98/12/31 11*30*45'', and `'98@12@31 11^30^45'' are equivalent.
  24093.  
  24094.    * As a string in either `'YYYY-MM-DD'' or `'YY-MM-DD'' format.  A
  24095.      "relaxed" syntax is allowed here, too.  For example, `'98-12-31'',
  24096.      `'98.12.31'', `'98/12/31'', and `'98@12@31'' are equivalent.
  24097.  
  24098.    * As a string with no delimiters in either `'YYYYMMDDHHMMSS'' or
  24099.      `'YYMMDDHHMMSS'' format, provided that the string makes sense as a
  24100.      date.  For example, `'19970523091528'' and `'970523091528'' are
  24101.      interpreted as `'1997-05-23 09:15:28'', but `'971122129015'' is
  24102.      illegal (it has a nonsensical minute part) and becomes `'0000-00-00
  24103.      00:00:00''.
  24104.  
  24105.    * As a string with no delimiters in either `'YYYYMMDD'' or `'YYMMDD''
  24106.      format, provided that the string makes sense as a date.  For
  24107.      example, `'19970523'' and `'970523'' are interpreted as
  24108.      `'1997-05-23'', but `'971332'' is illegal (it has nonsensical month
  24109.      and day parts) and becomes `'0000-00-00''.
  24110.  
  24111.    * As a number in either `YYYYMMDDHHMMSS' or `YYMMDDHHMMSS' format,
  24112.      provided that the number makes sense as a date.  For example,
  24113.      `19830905132800' and `830905132800' are interpreted as
  24114.      `'1983-09-05 13:28:00''.
  24115.  
  24116.    * As a number in either `YYYYMMDD' or `YYMMDD' format, provided that
  24117.      the number makes sense as a date.  For example, `19830905' and
  24118.      `830905' are interpreted as `'1983-09-05''.
  24119.  
  24120.    * As the result of a function that returns a value that is acceptable
  24121.      in a `DATETIME', `DATE', or `TIMESTAMP' context, such as `NOW()'
  24122.      or `CURRENT_DATE'.
  24123.  
  24124. Illegal `DATETIME', `DATE', or `TIMESTAMP' values are converted to the
  24125. "zero" value of the appropriate type (`'0000-00-00 00:00:00'',
  24126. `'0000-00-00'', or `00000000000000').
  24127.  
  24128. For values specified as strings that include date part delimiters, it
  24129. is not necessary to specify two digits for month or day values that are
  24130. less than `10'.  `'1979-6-9'' is the same as `'1979-06-09''.  Similarly,
  24131. for values specified as strings that include time part delimiters, it
  24132. is not necessary to specify two digits for hour, month, or second
  24133. values that are less than `10'.  `'1979-10-30 1:2:3'' is the same as
  24134. `'1979-10-30 01:02:03''.
  24135.  
  24136. Values specified as numbers should be 6, 8, 12, or 14 digits long.  If
  24137. the number is 8 or 14 digits long, it is assumed to be in `YYYYMMDD' or
  24138. `YYYYMMDDHHMMSS' format and that the year is given by the first 4
  24139. digits.  If the number is 6 or 12 digits long, it is assumed to be in
  24140. `YYMMDD' or `YYMMDDHHMMSS' format and that the year is given by the
  24141. first 2 digits.  Numbers that are not one of these lengths are
  24142. interpreted as though padded with leading zeros to the closest length.
  24143.  
  24144. Values specified as non-delimited strings are interpreted using their
  24145. length as given.  If the string is 8 or 14 characters long, the year is
  24146. assumed to be given by the first 4 characters.  Otherwise the year is
  24147. assumed to be given by the first 2 characters.  The string is
  24148. interpreted from left to right to find year, month, day, hour, minute,
  24149. and second values, for as many parts as are present in the string.
  24150. This means you should not use strings that have fewer than 6
  24151. characters.  For example, if you specify `'9903'', thinking that will
  24152. represent March, 1999, you will find that MySQL inserts a "zero" date
  24153. into your table.  This is because the year and month values are `99'
  24154. and `03', but the day part is missing (zero), so the value is not a
  24155. legal date.
  24156.  
  24157. `TIMESTAMP' columns store legal values using the full precision with
  24158. which the value was specified, regardless of the display size.  This has
  24159. several implications:
  24160.  
  24161.    * Always specify year, month, and day, even if your column types are
  24162.      `TIMESTAMP(4)' or `TIMESTAMP(2)'.  Otherwise, the value will not
  24163.      be a legal date and `0' will be stored.
  24164.  
  24165.    * If you use `ALTER TABLE' to widen a narrow `TIMESTAMP' column,
  24166.      information will be displayed that previously was "hidden".
  24167.  
  24168.    * Similarly, narrowing a `TIMESTAMP' column does not cause
  24169.      information to be lost, except in the sense that less information
  24170.      is shown when the values are displayed.
  24171.  
  24172.    * Although `TIMESTAMP' values are stored to full precision, the only
  24173.      function that operates directly on the underlying stored value is
  24174.      `UNIX_TIMESTAMP()'.  Other functions operate on the formatted
  24175.      retrieved value.  This means you cannot use functions such as
  24176.      `HOUR()' or `SECOND()' unless the relevant part of the `TIMESTAMP'
  24177.      value is included in the formatted value.  For example, the `HH'
  24178.      part of a `TIMESTAMP' column is not displayed unless the display
  24179.      size is at least 10, so trying to use `HOUR()' on shorter
  24180.      `TIMESTAMP' values produces a meaningless result.
  24181.  
  24182. You can to some extent assign values of one date type to an object of a
  24183. different date type.  However, there may be some alteration of the
  24184. value or loss of information:
  24185.  
  24186.    * If you assign a `DATE' value to a `DATETIME' or `TIMESTAMP'
  24187.      object, the time part of the resulting value is set to
  24188.      `'00:00:00'', because the `DATE' value contains no time
  24189.      information.
  24190.  
  24191.    * If you assign a `DATETIME' or `TIMESTAMP' value to a `DATE'
  24192.      object, the time part of the resulting value is deleted, because
  24193.      the `DATE' type stores no time information.
  24194.  
  24195.    * Remember that although `DATETIME', `DATE', and `TIMESTAMP' values
  24196.      all can be specified using the same set of formats, the types do
  24197.      not all have the same range of values.  For example, `TIMESTAMP'
  24198.      values cannot be earlier than `1970' or later than `2037'.  This
  24199.      means that a date such as `'1968-01-01'', while legal as a
  24200.      `DATETIME' or `DATE' value, is not a valid `TIMESTAMP' value and
  24201.      will be converted to `0' if assigned to such an object.
  24202.  
  24203. Be aware of certain pitfalls when specifying date values:
  24204.  
  24205.    * The relaxed format allowed for values specified as strings can be
  24206.      deceiving.  For example, a value such as `'10:11:12'' might look
  24207.      like a time value because of the `:' delimiter, but if used in a
  24208.      date context will be interpreted as the year `'2010-11-12''.  The
  24209.      value `'10:45:15'' will be converted to `'0000-00-00'' because
  24210.      `'45'' is not a legal month.
  24211.  
  24212.    * Year values specified as two digits are ambiguous, because the
  24213.      century is unknown.  MySQL interprets 2-digit year values using
  24214.      the following rules:
  24215.  
  24216.         - Year values in the range `00-69' are converted to `2000-2069'.
  24217.  
  24218.         - Year values in the range `70-99' are converted to `1970-1999'.
  24219.  
  24220. The `TIME' Type
  24221. ...............
  24222.  
  24223. MySQL retrieves and displays `TIME' values in `'HH:MM:SS'' format (or
  24224. `'HHH:MM:SS'' format for large hours values).  `TIME' values may range
  24225. from `'-838:59:59'' to `'838:59:59''.  The reason the hours part may be
  24226. so large is that the `TIME' type may be used not only to represent a
  24227. time of day (which must be less than 24 hours), but also elapsed time
  24228. or a time interval between two events (which may be much greater than
  24229. 24 hours, or even negative).
  24230.  
  24231. You can specify `TIME' values in a variety of formats:
  24232.  
  24233.    * As a string in `'D HH:MM:SS.fraction'' format.  (Note that MySQL
  24234.      doesn't yet store the fraction for the time column).  One can also
  24235.      use one of the following "relaxed" syntax:
  24236.  
  24237.      `HH:MM:SS.fraction', `HH:MM:SS', `HH:MM', `D HH:MM:SS', `D HH:MM',
  24238.      `D HH' or `SS'.  Here `D' is days between 0-33.
  24239.  
  24240.    * As a string with no delimiters in `'HHMMSS'' format, provided that
  24241.      it makes sense as a time.  For example, `'101112'' is understood as
  24242.      `'10:11:12'', but `'109712'' is illegal (it has a nonsensical
  24243.      minute part) and becomes `'00:00:00''.
  24244.  
  24245.    * As a number in `HHMMSS' format, provided that it makes sense as a
  24246.      time.  For example, `101112' is understood as `'10:11:12''.  The
  24247.      following alternative formats are also understood: `SS',
  24248.      `MMSS',`HHMMSS', `HHMMSS.fraction'.  Note that MySQL doesn't yet
  24249.      store the fraction part.
  24250.  
  24251.    * As the result of a function that returns a value that is acceptable
  24252.      in a `TIME' context, such as `CURRENT_TIME'.
  24253.  
  24254. For `TIME' values specified as strings that include a time part
  24255. delimiter, it is not necessary to specify two digits for hours,
  24256. minutes, or seconds values that are less than `10'.  `'8:3:2'' is the
  24257. same as `'08:03:02''.
  24258.  
  24259. Be careful about assigning "short" `TIME' values to a `TIME' column.
  24260. Without semicolon, MySQL interprets values using the assumption that
  24261. the rightmost digits represent seconds. (MySQL interprets `TIME' values
  24262. as elapsed time rather than as time of day.) For example, you might
  24263. think of `'1112'' and `1112' as meaning `'11:12:00'' (12 minutes after
  24264. 11 o'clock), but MySQL interprets them as `'00:11:12'' (11 minutes, 12
  24265. seconds).  Similarly, `'12'' and `12' are interpreted as `'00:00:12''.
  24266. `TIME' values with semicolon, instead, are always treated as time of
  24267. the day. That is `'11:12'' will mean `'11:12:00'', not `'00:11:12''.
  24268.  
  24269. Values that lie outside the `TIME' range but are otherwise legal are
  24270. clipped to the appropriate endpoint of the range.  For example,
  24271. `'-850:00:00'' and `'850:00:00'' are converted to `'-838:59:59'' and
  24272. `'838:59:59''.
  24273.  
  24274. Illegal `TIME' values are converted to `'00:00:00''.  Note that because
  24275. `'00:00:00'' is itself a legal `TIME' value, there is no way to tell,
  24276. from a value of `'00:00:00'' stored in a table, whether the original
  24277. value was specified as `'00:00:00'' or whether it was illegal.
  24278.  
  24279. The `YEAR' Type
  24280. ...............
  24281.  
  24282. The `YEAR' type is a 1-byte type used for representing years.
  24283.  
  24284. MySQL retrieves and displays `YEAR' values in `YYYY' format.  The range
  24285. is `1901' to `2155'.
  24286.  
  24287. You can specify `YEAR' values in a variety of formats:
  24288.  
  24289.    * As a four-digit string in the range `'1901'' to `'2155''.
  24290.  
  24291.    * As a four-digit number in the range `1901' to `2155'.
  24292.  
  24293.    * As a two-digit string in the range `'00'' to `'99''.  Values in the
  24294.      ranges `'00'' to `'69'' and `'70'' to `'99'' are converted to
  24295.      `YEAR' values in the ranges `2000' to `2069' and `1970' to `1999'.
  24296.  
  24297.    * As a two-digit number in the range `1' to `99'.  Values in the
  24298.      ranges `1' to `69' and `70' to `99' are converted to `YEAR' values
  24299.      in the ranges `2001' to `2069' and `1970' to `1999'.  Note that
  24300.      the range for two-digit numbers is slightly different than the
  24301.      range for two-digit strings, because you cannot specify zero
  24302.      directly as a number and have it be interpreted as `2000'.  You
  24303.      _must_ specify it as a string `'0'' or `'00'' or it will be
  24304.      interpreted as `0000'.
  24305.  
  24306.    * As the result of a function that returns a value that is acceptable
  24307.      in a `YEAR' context, such as `NOW()'.
  24308.  
  24309. Illegal `YEAR' values are converted to `0000'.
  24310.  
  24311. String Types
  24312. ------------
  24313.  
  24314. The string types are `CHAR', `VARCHAR', `BLOB', `TEXT', `ENUM', and
  24315. `SET'.  This section describes how these types work, their storage
  24316. requirements, and how to use them in your queries.
  24317.  
  24318. The `CHAR' and `VARCHAR' Types
  24319. ..............................
  24320.  
  24321. The `CHAR' and `VARCHAR' types are similar, but differ in the way they
  24322. are stored and retrieved.
  24323.  
  24324. The length of a `CHAR' column is fixed to the length that you declare
  24325. when you create the table.  The length can be any value between 1 and
  24326. 255.  (As of MySQL Version 3.23, the length of `CHAR' may be 0 to 255.)
  24327. When `CHAR' values are stored, they are right-padded with spaces to the
  24328. specified length.  When `CHAR' values are retrieved, trailing spaces are
  24329. removed.
  24330.  
  24331. Values in `VARCHAR' columns are variable-length strings.  You can
  24332. declare a `VARCHAR' column to be any length between 1 and 255, just as
  24333. for `CHAR' columns.  However, in contrast to `CHAR', `VARCHAR' values
  24334. are stored using only as many characters as are needed, plus one byte
  24335. to record the length.  Values are not padded; instead, trailing spaces
  24336. are removed when values are stored.  (This space removal differs from
  24337. the ANSI SQL specification.)
  24338.  
  24339. If you assign a value to a `CHAR' or `VARCHAR' column that exceeds the
  24340. column's maximum length, the value is truncated to fit.
  24341.  
  24342. The table below illustrates the differences between the two types of
  24343. columns by showing the result of storing various string values into
  24344. `CHAR(4)' and `VARCHAR(4)' columns:
  24345.  
  24346. *Value*        `CHAR(4)'   *Storage       `VARCHAR(4)'   *Storage required*
  24347.                            required*                     
  24348. `'''           `'    ''    4 bytes        `'''           1 byte
  24349. `'ab''         `'ab  ''    4 bytes        `'ab''         3 bytes
  24350. `'abcd''       `'abcd''    4 bytes        `'abcd''       5 bytes
  24351. `'abcdefgh''   `'abcd''    4 bytes        `'abcd''       5 bytes
  24352.  
  24353. The values retrieved from the `CHAR(4)' and `VARCHAR(4)' columns will
  24354. be the same in each case, because trailing spaces are removed from
  24355. `CHAR' columns upon retrieval.
  24356.  
  24357. Values in `CHAR' and `VARCHAR' columns are sorted and compared in
  24358. case-insensitive fashion, unless the `BINARY' attribute was specified
  24359. when the table was created.  The `BINARY' attribute means that column
  24360. values are sorted and compared in case-sensitive fashion according to
  24361. the ASCII order of the machine where the MySQL server is running.
  24362. `BINARY' doesn't affect how the column is stored or retrieved.
  24363.  
  24364. The `BINARY' attribute is sticky.  This means that if a column marked
  24365. `BINARY' is used in an expression, the whole expression is compared as a
  24366. `BINARY' value.
  24367.  
  24368. MySQL may silently change the type of a `CHAR' or `VARCHAR' column at
  24369. table creation time.  *Note Silent column changes::.
  24370.  
  24371. The `BLOB' and `TEXT' Types
  24372. ...........................
  24373.  
  24374. A `BLOB' is a binary large object that can hold a variable amount of
  24375. data.  The four `BLOB' types `TINYBLOB', `BLOB', `MEDIUMBLOB', and
  24376. `LONGBLOB' differ only in the maximum length of the values they can
  24377. hold.  *Note Storage requirements::.
  24378.  
  24379. The four `TEXT' types `TINYTEXT', `TEXT', `MEDIUMTEXT', and `LONGTEXT'
  24380. correspond to the four `BLOB' types and have the same maximum lengths
  24381. and storage requirements.  The only difference between `BLOB' and
  24382. `TEXT' types is that sorting and comparison is performed in
  24383. case-sensitive fashion for `BLOB' values and case-insensitive fashion
  24384. for `TEXT' values.  In other words, a `TEXT' is a case-insensitive
  24385. `BLOB'.
  24386.  
  24387. If you assign a value to a `BLOB' or `TEXT' column that exceeds the
  24388. column type's maximum length, the value is truncated to fit.
  24389.  
  24390. In most respects, you can regard a `TEXT' column as a `VARCHAR' column
  24391. that can be as big as you like.  Similarly, you can regard a `BLOB'
  24392. column as a `VARCHAR BINARY' column.  The differences are:
  24393.  
  24394.    * You can have indexes on `BLOB' and `TEXT' columns with MySQL
  24395.      Version 3.23.2 and newer. Older versions of MySQL did not support
  24396.      this.
  24397.  
  24398.    * There is no trailing-space removal for `BLOB' and `TEXT' columns
  24399.      when values are stored, as there is for `VARCHAR' columns.
  24400.  
  24401.    * `BLOB' and `TEXT' columns cannot have `DEFAULT' values.
  24402.  
  24403. *MyODBC* defines `BLOB' values as `LONGVARBINARY' and `TEXT' values as
  24404. `LONGVARCHAR'.
  24405.  
  24406. Because `BLOB' and `TEXT' values may be extremely long, you may run up
  24407. against some constraints when using them:
  24408.  
  24409.    * If you want to use `GROUP BY' or `ORDER BY' on a `BLOB' or `TEXT'
  24410.      column, you must convert the column value into a fixed-length
  24411.      object. The standard way to do this is with the `SUBSTRING'
  24412.      function.  For example:
  24413.  
  24414.           mysql> select comment from tbl_name,substring(comment,20) as substr
  24415.                  ORDER BY substr;
  24416.  
  24417.      If you don't do this, only the first `max_sort_length' bytes of the
  24418.      column are used when sorting.  The default value of
  24419.      `max_sort_length' is 1024; this value can be changed using the
  24420.      `-O' option when starting the `mysqld' server. You can group on an
  24421.      expression involving `BLOB' or `TEXT' values by specifying the
  24422.      column position or by using an alias:
  24423.  
  24424.           mysql> select id,substring(blob_col,1,100) from tbl_name
  24425.                      GROUP BY 2;
  24426.           mysql> select id,substring(blob_col,1,100) as b from tbl_name
  24427.                      GROUP BY b;
  24428.  
  24429.    * The maximum size of a `BLOB' or `TEXT' object is determined by its
  24430.      type, but the largest value you can actually transmit between the
  24431.      client and server is determined by the amount of available memory
  24432.      and the size of the communications buffers.  You can change the
  24433.      message buffer size, but you must do so on both the server and
  24434.      client ends. *Note Server parameters::.
  24435.  
  24436. Note that each `BLOB' or `TEXT' value is represented internally by a
  24437. separately allocated object. This is in contrast to all other column
  24438. types, for which storage is allocated once per column when the table is
  24439. opened.
  24440.  
  24441. The `ENUM' Type
  24442. ...............
  24443.  
  24444. An `ENUM' is a string object whose value normally is chosen from a list
  24445. of allowed values that are enumerated explicitly in the column
  24446. specification at table creation time.
  24447.  
  24448. The value may also be the empty string (`""') or `NULL' under certain
  24449. circumstances:
  24450.  
  24451.    * If you insert an invalid value into an `ENUM' (that is, a string
  24452.      not present in the list of allowed values), the empty string is
  24453.      inserted instead as a special error value.
  24454.  
  24455.    * If an `ENUM' is declared `NULL', `NULL' is also a legal value for
  24456.      the column, and the default value is `NULL'.  If an `ENUM' is
  24457.      declared `NOT NULL', the default value is the first element of the
  24458.      list of allowed values.
  24459.  
  24460. Each enumeration value has an index:
  24461.  
  24462.    * Values from the list of allowable elements in the column
  24463.      specification are numbered beginning with 1.
  24464.  
  24465.    * The index value of the empty string error value is 0.  This means
  24466.      that you can use the following `SELECT' statement to find rows
  24467.      into which invalid `ENUM' values were assigned:
  24468.  
  24469.           mysql> SELECT * FROM tbl_name WHERE enum_col=0;
  24470.  
  24471.    * The index of the `NULL' value is `NULL'.
  24472.  
  24473. For example, a column specified as `ENUM("one", "two", "three")' can
  24474. have any of the values shown below.  The index of each value is also
  24475. shown:
  24476.  
  24477. *Value*        *Index*
  24478. `NULL'         `NULL'
  24479. `""'           0
  24480. `"one"'        1
  24481. `"two"'        2
  24482. `"three"'      3
  24483.  
  24484. An enumeration can have a maximum of 65535 elements.
  24485.  
  24486. Lettercase is irrelevant when you assign values to an `ENUM' column.
  24487. However, values retrieved from the column later have lettercase
  24488. matching the values that were used to specify the allowable values at
  24489. table creation time.
  24490.  
  24491. If you retrieve an `ENUM' in a numeric context, the column value's
  24492. index is returned.  For example, you can retrieve numeric values from
  24493. an `ENUM' column like this:
  24494.  
  24495.      mysql> SELECT enum_col+0 FROM tbl_name;
  24496.  
  24497. If you store a number into an `ENUM', the number is treated as an
  24498. index, and the value stored is the enumeration member with that index.
  24499. (However, this will not work with `LOAD DATA', which treats all input
  24500. as strings.)
  24501.  
  24502. `ENUM' values are sorted according to the order in which the enumeration
  24503. members were listed in the column specification.  (In other words,
  24504. `ENUM' values are sorted according to their index numbers.)  For
  24505. example, `"a"' sorts before `"b"' for `ENUM("a", "b")', but `"b"' sorts
  24506. before `"a"' for `ENUM("b", "a")'.  The empty string sorts before
  24507. non-empty strings, and `NULL' values sort before all other enumeration
  24508. values.
  24509.  
  24510. If you want to get all possible values for an `ENUM' column, you should
  24511. use: `SHOW COLUMNS FROM table_name LIKE enum_column_name' and parse the
  24512. `ENUM' definition in the second column.
  24513.  
  24514. The `SET' Type
  24515. ..............
  24516.  
  24517. A `SET' is a string object that can have zero or more values, each of
  24518. which must be chosen from a list of allowed values specified when the
  24519. table is created.  `SET' column values that consist of multiple set
  24520. members are specified with members separated by commas (`,').  A
  24521. consequence of this is that `SET' member values cannot themselves
  24522. contain commas.
  24523.  
  24524. For example, a column specified as `SET("one", "two") NOT NULL' can have
  24525. any of these values:
  24526.  
  24527.      ""
  24528.      "one"
  24529.      "two"
  24530.      "one,two"
  24531.  
  24532. A `SET' can have a maximum of 64 different members.
  24533.  
  24534. MySQL stores `SET' values numerically, with the low-order bit of the
  24535. stored value corresponding to the first set member.  If you retrieve a
  24536. `SET' value in a numeric context, the value retrieved has bits set
  24537. corresponding to the set members that make up the column value.  For
  24538. example, you can retrieve numeric values from a `SET' column like this:
  24539.  
  24540.      mysql> SELECT set_col+0 FROM tbl_name;
  24541.  
  24542. If a number is stored into a `SET' column, the bits that are set in the
  24543. binary representation of the number determine the set members in the
  24544. column value.  Suppose a column is specified as `SET("a","b","c","d")'.
  24545. Then the members have the following bit values:
  24546.  
  24547. `SET'          *Decimal       *Binary value*
  24548. *member*       value*         
  24549. `a'            `1'            `0001'
  24550. `b'            `2'            `0010'
  24551. `c'            `4'            `0100'
  24552. `d'            `8'            `1000'
  24553.  
  24554. If you assign a value of `9' to this column, that is `1001' in binary,
  24555. so the first and fourth `SET' value members `"a"' and `"d"' are
  24556. selected and the resulting value is `"a,d"'.
  24557.  
  24558. For a value containing more than one `SET' element, it does not matter
  24559. what order the elements are listed in when you insert the value.  It
  24560. also does not matter how many times a given element is listed in the
  24561. value.  When the value is retrieved later, each element in the value
  24562. will appear once, with elements listed according to the order in which
  24563. they were specified at table creation time.  For example, if a column
  24564. is specified as `SET("a","b","c","d")', then `"a,d"', `"d,a"', and
  24565. `"d,a,a,d,d"' will all appear as `"a,d"' when retrieved.
  24566.  
  24567. `SET' values are sorted numerically.  `NULL' values sort before
  24568. non-`NULL' `SET' values.
  24569.  
  24570. Normally, you perform a `SELECT' on a `SET' column using the `LIKE'
  24571. operator or the `FIND_IN_SET()' function:
  24572.  
  24573.      mysql> SELECT * FROM tbl_name WHERE set_col LIKE '%value%';
  24574.      mysql> SELECT * FROM tbl_name WHERE FIND_IN_SET('value',set_col)>0;
  24575.  
  24576. But the following will also work:
  24577.  
  24578.      mysql> SELECT * FROM tbl_name WHERE set_col = 'val1,val2';
  24579.      mysql> SELECT * FROM tbl_name WHERE set_col & 1;
  24580.  
  24581. The first of these statements looks for an exact match.  The second
  24582. looks for values containing the first set member.
  24583.  
  24584. If you want to get all possible values for a `SET' column, you should
  24585. use: `SHOW COLUMNS FROM table_name LIKE set_column_name' and parse the
  24586. `SET' definition in the second column.
  24587.  
  24588. Choosing the Right Type for a Column
  24589. ------------------------------------
  24590.  
  24591. For the most efficient use of storage, try to use the most precise type
  24592. in all cases. For example, if an integer column will be used for values
  24593. in the range between `1' and `99999', `MEDIUMINT UNSIGNED' is the best
  24594. type.
  24595.  
  24596. Accurate representation of monetary values is a common problem. In
  24597. MySQL, you should use the `DECIMAL' type. This is stored as a string,
  24598. so no loss of accuracy should occur. If accuracy is not too important,
  24599. the `DOUBLE' type may also be good enough.
  24600.  
  24601. For high precision, you can always convert to a fixed-point type stored
  24602. in a `BIGINT'. This allows you to do all calculations with integers and
  24603. convert results back to floating-point values only when necessary.
  24604.  
  24605. Using Column Types from Other Database Engines
  24606. ----------------------------------------------
  24607.  
  24608. To make it easier to use code written for SQL implementations from other
  24609. vendors, MySQL maps column types as shown in the table below.  These
  24610. mappings make it easier to move table definitions from other database
  24611. engines to MySQL:
  24612.  
  24613. *Other vendor type*           *MySQL type*
  24614. `BINARY(NUM)'                 `CHAR(NUM) BINARY'
  24615. `CHAR VARYING(NUM)'           `VARCHAR(NUM)'
  24616. `FLOAT4'                      `FLOAT'
  24617. `FLOAT8'                      `DOUBLE'
  24618. `INT1'                        `TINYINT'
  24619. `INT2'                        `SMALLINT'
  24620. `INT3'                        `MEDIUMINT'
  24621. `INT4'                        `INT'
  24622. `INT8'                        `BIGINT'
  24623. `LONG VARBINARY'              `MEDIUMBLOB'
  24624. `LONG VARCHAR'                `MEDIUMTEXT'
  24625. `MIDDLEINT'                   `MEDIUMINT'
  24626. `VARBINARY(NUM)'              `VARCHAR(NUM) BINARY'
  24627.  
  24628. Column type mapping occurs at table creation time.  If you create a
  24629. table with types used by other vendors and then issue a `DESCRIBE
  24630. tbl_name' statement, MySQL reports the table structure using the
  24631. equivalent MySQL types.
  24632.  
  24633. Column Type Storage Requirements
  24634. --------------------------------
  24635.  
  24636. The storage requirements for each of the column types supported by
  24637. MySQL are listed below by category.
  24638.  
  24639. Storage requirements for numeric types
  24640. ......................................
  24641.  
  24642. *Column type*                        *Storage required*
  24643. `TINYINT'                            1 byte
  24644. `SMALLINT'                           2 bytes
  24645. `MEDIUMINT'                          3 bytes
  24646. `INT'                                4 bytes
  24647. `INTEGER'                            4 bytes
  24648. `BIGINT'                             8 bytes
  24649. `FLOAT(X)'                           4 if X <= 24 or 8 if 25 <= X <= 53
  24650. `FLOAT'                              4 bytes
  24651. `DOUBLE'                             8 bytes
  24652. `DOUBLE PRECISION'                   8 bytes
  24653. `REAL'                               8 bytes
  24654. `DECIMAL(M,D)'                       `M+2' bytes if D > 0, `M+1' bytes
  24655.                                      if D = 0 (`D'+2, if `M < D')
  24656. `NUMERIC(M,D)'                       `M+2' bytes if D > 0, `M+1' bytes
  24657.                                      if D = 0 (`D'+2, if `M < D')
  24658.  
  24659. Storage requirements for date and time types
  24660. ............................................
  24661.  
  24662. *Column type*                        *Storage required*
  24663. `DATE'                               3 bytes
  24664. `DATETIME'                           8 bytes
  24665. `TIMESTAMP'                          4 bytes
  24666. `TIME'                               3 bytes
  24667. `YEAR'                               1 byte
  24668.  
  24669. Storage requirements for string types
  24670. .....................................
  24671.  
  24672. *Column type*                        *Storage required*
  24673. `CHAR(M)'                            `M' bytes, `1 <= M <= 255'
  24674. `VARCHAR(M)'                         `L'+1 bytes, where `L <= M' and `1
  24675.                                      <= M <= 255'
  24676. `TINYBLOB', `TINYTEXT'               `L'+1 bytes, where `L' < 2^8
  24677. `BLOB', `TEXT'                       `L'+2 bytes, where `L' < 2^16
  24678. `MEDIUMBLOB', `MEDIUMTEXT'           `L'+3 bytes, where `L' < 2^24
  24679. `LONGBLOB', `LONGTEXT'               `L'+4 bytes, where `L' < 2^32
  24680. `ENUM('value1','value2',...)'        1 or 2 bytes, depending on the
  24681.                                      number of enumeration values (65535
  24682.                                      values maximum)
  24683. `SET('value1','value2',...)'         1, 2, 3, 4 or 8 bytes, depending on
  24684.                                      the number of set members (64
  24685.                                      members maximum)
  24686.  
  24687. `VARCHAR' and the `BLOB' and `TEXT' types are variable-length types,
  24688. for which the storage requirements depend on the actual length of
  24689. column values (represented by `L' in the preceding table), rather than
  24690. on the type's maximum possible size.  For example, a `VARCHAR(10)'
  24691. column can hold a string with a maximum length of 10 characters.  The
  24692. actual storage required is the length of the string (`L'), plus 1 byte
  24693. to record the length of the string.  For the string `'abcd'', `L' is 4
  24694. and the storage requirement is 5 bytes.
  24695.  
  24696. The `BLOB' and `TEXT' types require 1, 2, 3, or 4 bytes to record the
  24697. length of the column value, depending on the maximum possible length of
  24698. the type.  *Note BLOB::.
  24699.  
  24700. If a table includes any variable-length column types, the record format
  24701. will also be variable-length.  Note that when a table is created, MySQL
  24702. may, under certain conditions, change a column from a variable-length
  24703. type to a fixed-length type, or vice-versa.  *Note Silent column
  24704. changes::.
  24705.  
  24706. The size of an `ENUM' object is determined by the number of different
  24707. enumeration values.  One byte is used for enumerations with up to 255
  24708. possible values.  Two bytes are used for enumerations with up to 65535
  24709. values. *Note ENUM::.
  24710.  
  24711. The size of a `SET' object is determined by the number of different set
  24712. members.  If the set size is `N', the object occupies `(N+7)/8' bytes,
  24713. rounded up to 1, 2, 3, 4, or 8 bytes.  A `SET' can have a maximum of 64
  24714. members. *Note SET::.
  24715.  
  24716. Functions for Use in `SELECT' and `WHERE' Clauses
  24717. =================================================
  24718.  
  24719. A `select_expression' or `where_definition' in a SQL statement can
  24720. consist of any expression using the functions described below.
  24721.  
  24722. An expression that contains `NULL' always produces a `NULL' value
  24723. unless otherwise indicated in the documentation for the operators and
  24724. functions involved in the expression.
  24725.  
  24726. *NOTE:* There must be no whitespace between a function name and the
  24727. parenthesis following it. This helps the MySQL parser distinguish
  24728. between function calls and references to tables or columns that happen
  24729. to have the same name as a function.  Spaces around arguments are
  24730. permitted, though.
  24731.  
  24732. You can force MySQL to accept spaces after the function name by
  24733. starting `mysqld' with `--ansi' or using the `CLIENT_IGNORE_SPACE' to
  24734. `mysql_connect()', but in this case all function names will become
  24735. reserved words. *Note ANSI mode::.
  24736.  
  24737. For the sake of brevity, examples display the output from the `mysql'
  24738. program in abbreviated form.  So this:
  24739.  
  24740.      mysql> select MOD(29,9);
  24741.      1 rows in set (0.00 sec)
  24742.      
  24743.      +-----------+
  24744.      | mod(29,9) |
  24745.      +-----------+
  24746.      |         2 |
  24747.      +-----------+
  24748.  
  24749. is displayed like this:
  24750.  
  24751.      mysql> select MOD(29,9);
  24752.              -> 2
  24753.  
  24754. Non-Type-Specific Operators and Functions
  24755. -----------------------------------------
  24756.  
  24757. Parenthesis
  24758. ...........
  24759.  
  24760.      ( ... )
  24761.  
  24762. Use parenthesis to force the order of evaluation in an expression.  For
  24763. example:
  24764.  
  24765.      mysql> select 1+2*3;
  24766.              -> 7
  24767.      mysql> select (1+2)*3;
  24768.              -> 9
  24769.  
  24770. Comparison Operators
  24771. ....................
  24772.  
  24773. Comparison operations result in a value of `1' (TRUE), `0' (FALSE), or
  24774. `NULL'. These functions work for both numbers and strings.  Strings are
  24775. automatically converted to numbers and numbers to strings as needed (as
  24776. in Perl).
  24777.  
  24778. MySQL performs comparisons using the following rules:
  24779.  
  24780.    * If one or both arguments are `NULL', the result of the comparison
  24781.      is `NULL', except for the `<=>' operator.
  24782.  
  24783.    * If both arguments in a comparison operation are strings, they are
  24784.      compared as strings.
  24785.  
  24786.    * If both arguments are integers, they are compared as integers.
  24787.  
  24788.    * Hexadecimal values are treated as binary strings if not compared
  24789.      to a number.
  24790.  
  24791.    * If one of the arguments is a `TIMESTAMP' or `DATETIME' column and
  24792.      the other argument is a constant, the constant is converted to a
  24793.      timestamp before the comparison is performed. This is done to be
  24794.      more ODBC-friendly.
  24795.  
  24796.    * In all other cases, the arguments are compared as floating-point
  24797.      (real) numbers.
  24798.  
  24799. By default, string comparisons are done in case-independent fashion
  24800. using the current character set (ISO-8859-1 Latin1 by default, which
  24801. also works excellently for English).
  24802.  
  24803. The examples below illustrate conversion of strings to numbers for
  24804. comparison operations:
  24805.  
  24806.      mysql> SELECT 1 > '6x';
  24807.               -> 0
  24808.      mysql> SELECT 7 > '6x';
  24809.               -> 1
  24810.      mysql> SELECT 0 > 'x6';
  24811.               -> 0
  24812.      mysql> SELECT 0 = 'x6';
  24813.               -> 1
  24814.  
  24815. `='
  24816.      Equal:
  24817.           mysql> select 1 = 0;
  24818.                   -> 0
  24819.           mysql> select '0' = 0;
  24820.                   -> 1
  24821.           mysql> select '0.0' = 0;
  24822.                   -> 1
  24823.           mysql> select '0.01' = 0;
  24824.                   -> 0
  24825.           mysql> select '.01' = 0.01;
  24826.                   -> 1
  24827.  
  24828. `<>'
  24829. `!='
  24830.      Not equal:
  24831.           mysql> select '.01' <> '0.01';
  24832.                   -> 1
  24833.           mysql> select .01 <> '0.01';
  24834.                   -> 0
  24835.           mysql> select 'zapp' <> 'zappp';
  24836.                   -> 1
  24837.  
  24838. `<='
  24839.      Less than or equal:
  24840.           mysql> select 0.1 <= 2;
  24841.                   -> 1
  24842.  
  24843. `<'
  24844.      Less than:
  24845.           mysql> select 2 < 2;
  24846.                   -> 0
  24847.  
  24848. `>='
  24849.      Greater than or equal:
  24850.           mysql> select 2 >= 2;
  24851.                   -> 1
  24852.  
  24853. `>'
  24854.      Greater than:
  24855.           mysql> select 2 > 2;
  24856.                   -> 0
  24857.  
  24858. `<=>'
  24859.      Null safe equal:
  24860.           mysql> select 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
  24861.                   -> 1 1 0
  24862.  
  24863. `IS NULL'
  24864. `IS NOT NULL'
  24865.      Test whether or not a value is or is not `NULL':
  24866.           mysql> select 1 IS NULL, 0 IS NULL, NULL IS NULL;
  24867.                   -> 0 0 1
  24868.           mysql> select 1 IS NOT NULL, 0 IS NOT NULL, NULL IS NOT NULL;
  24869.                   -> 1 1 0
  24870.  
  24871. `expr BETWEEN min AND max'
  24872.      If `expr' is greater than or equal to `min' and `expr' is less
  24873.      than or equal to `max', `BETWEEN' returns `1', otherwise it
  24874.      returns `0'.  This is equivalent to the expression `(min <= expr
  24875.      AND expr <= max)' if all the arguments are of the same type.  The
  24876.      first argument (`expr') determines how the comparison is performed
  24877.      as follows:
  24878.  
  24879.         * If `expr' is a `TIMESTAMP', `DATE', or `DATETIME' column,
  24880.           `MIN()' and `MAX()' are formatted to the same format if they
  24881.           are constants.
  24882.  
  24883.         * If `expr' is a case-insensitive string expression, a
  24884.           case-insensitive string comparison is done.
  24885.  
  24886.         * If `expr' is a case-sensitive string expression, a
  24887.           case-sensitive string comparison is done.
  24888.  
  24889.         * If `expr' is an integer expression, an integer comparison is
  24890.           done.
  24891.  
  24892.         * Otherwise, a floating-point (real) comparison is done.
  24893.  
  24894.           mysql> select 1 BETWEEN 2 AND 3;
  24895.                   -> 0
  24896.           mysql> select 'b' BETWEEN 'a' AND 'c';
  24897.                   -> 1
  24898.           mysql> select 2 BETWEEN 2 AND '3';
  24899.                   -> 1
  24900.           mysql> select 2 BETWEEN 2 AND 'x-3';
  24901.                   -> 0
  24902.  
  24903. `expr IN (value,...)'
  24904.      Returns `1' if `expr' is any of the values in the `IN' list, else
  24905.      returns `0'.  If all values are constants, then all values are
  24906.      evaluated according to the type of `expr' and sorted. The search
  24907.      for the item is then done using a binary search. This means `IN'
  24908.      is very quick if the `IN' value list consists entirely of
  24909.      constants.  If `expr' is a case-sensitive string expression, the
  24910.      string comparison is performed in case-sensitive fashion:
  24911.  
  24912.           mysql> select 2 IN (0,3,5,'wefwf');
  24913.                   -> 0
  24914.           mysql> select 'wefwf' IN (0,3,5,'wefwf');
  24915.                   -> 1
  24916.  
  24917. `expr NOT IN (value,...)'
  24918.      Same as `NOT (expr IN (value,...))'.
  24919.  
  24920. `ISNULL(expr)'
  24921.      If `expr' is `NULL', `ISNULL()' returns `1', otherwise it returns
  24922.      `0':
  24923.           mysql> select ISNULL(1+1);
  24924.                   -> 0
  24925.           mysql> select ISNULL(1/0);
  24926.                   -> 1
  24927.  
  24928.      Note that a comparison of `NULL' values using `=' will always be
  24929.      false!
  24930.  
  24931. `COALESCE(list)'
  24932.      Returns first non-`NULL' element in list:
  24933.  
  24934.           mysql> select COALESCE(NULL,1);
  24935.                   -> 1
  24936.           mysql> select COALESCE(NULL,NULL,NULL);
  24937.                   -> NULL
  24938.  
  24939. `INTERVAL(N,N1,N2,N3,...)'
  24940.      Returns `0' if `N' < `N1', `1' if `N' < `N2' and so on. All
  24941.      arguments are treated as integers.  It is required that `N1' <
  24942.      `N2' < `N3' < `...' < `Nn' for this function to work correctly.
  24943.      This is because a binary search is used (very fast):
  24944.  
  24945.           mysql> select INTERVAL(23, 1, 15, 17, 30, 44, 200);
  24946.                   -> 3
  24947.           mysql> select INTERVAL(10, 1, 10, 100, 1000);
  24948.                   -> 2
  24949.           mysql> select INTERVAL(22, 23, 30, 44, 200);
  24950.                   -> 0
  24951.  
  24952. If you are comparing case sensitive string with any of the standard
  24953. operators (`=', `<>'..., but not `LIKE') end space will be ignored.
  24954.  
  24955.      mysql> select "a" ="A ";
  24956.              -> 1
  24957.  
  24958. Logical Operators
  24959. .................
  24960.  
  24961. All logical functions return `1' (TRUE), `0' (FALSE) or `NULL'
  24962. (unknown, which is in most cases the same as FALSE):
  24963.  
  24964. `NOT'
  24965. `!'
  24966.      Logical NOT. Returns `1' if the argument is `0', otherwise returns
  24967.      `0'.  Exception: `NOT NULL' returns `NULL':
  24968.           mysql> select NOT 1;
  24969.                   -> 0
  24970.           mysql> select NOT NULL;
  24971.                   -> NULL
  24972.           mysql> select ! (1+1);
  24973.                   -> 0
  24974.           mysql> select ! 1+1;
  24975.                   -> 1
  24976.      The last example returns `1' because the expression evaluates the
  24977.      same way as `(!1)+1'.
  24978.  
  24979. `OR'
  24980. `||'
  24981.      Logical OR. Returns `1' if either argument is not `0' and not
  24982.      `NULL':
  24983.           mysql> select 1 || 0;
  24984.                   -> 1
  24985.           mysql> select 0 || 0;
  24986.                   -> 0
  24987.           mysql> select 1 || NULL;
  24988.                   -> 1
  24989.  
  24990. `AND'
  24991. `&&'
  24992.      Logical AND. Returns `0' if either argument is `0' or `NULL',
  24993.      otherwise returns `1':
  24994.           mysql> select 1 && NULL;
  24995.                   -> 0
  24996.           mysql> select 1 && 0;
  24997.                   -> 0
  24998.  
  24999. Control Flow Functions
  25000. ......................
  25001.  
  25002. `IFNULL(expr1,expr2)'
  25003.      If `expr1' is not `NULL', `IFNULL()' returns `expr1', else it
  25004.      returns `expr2'.  `IFNULL()' returns a numeric or string value,
  25005.      depending on the context in which it is used:
  25006.           mysql> select IFNULL(1,0);
  25007.                   -> 1
  25008.           mysql> select IFNULL(NULL,10);
  25009.                   -> 10
  25010.           mysql> select IFNULL(1/0,10);
  25011.                   -> 10
  25012.           mysql> select IFNULL(1/0,'yes');
  25013.                   -> 'yes'
  25014.  
  25015. `NULLIF(expr1,expr2)'
  25016.      If `expr1 = expr2' is true, return `NULL' else return `expr1'.
  25017.      This is the same as `CASE WHEN x = y THEN NULL ELSE x END':
  25018.           mysql> select NULLIF(1,1);
  25019.                   -> NULL
  25020.           mysql> select NULLIF(1,2);
  25021.                   -> 1
  25022.  
  25023.      Note that `expr1' is evaluated twice in MySQL if the arguments are
  25024.      equal.
  25025.  
  25026. `IF(expr1,expr2,expr3)'
  25027.      If `expr1' is TRUE (`expr1 <> 0' and `expr1 <> NULL') then `IF()'
  25028.      returns `expr2', else it returns `expr3'.  `IF()' returns a
  25029.      numeric or string value, depending on the context in which it is
  25030.      used:
  25031.  
  25032.           mysql> select IF(1>2,2,3);
  25033.                   -> 3
  25034.           mysql> select IF(1<2,'yes','no');
  25035.                   -> 'yes'
  25036.           mysql> select IF(strcmp('test','test1'),'no','yes');
  25037.                   -> 'no'
  25038.  
  25039.      `expr1' is evaluated as an integer value, which means that if you
  25040.      are testing floating-point or string values, you should do so
  25041.      using a comparison operation:
  25042.  
  25043.           mysql> select IF(0.1,1,0);
  25044.                   -> 0
  25045.           mysql> select IF(0.1<>0,1,0);
  25046.                   -> 1
  25047.  
  25048.      In the first case above, `IF(0.1)' returns `0' because `0.1' is
  25049.      converted to an integer value, resulting in a test of `IF(0)'.
  25050.      This may not be what you expect.  In the second case, the
  25051.      comparison tests the original floating-point value to see whether
  25052.      it is non-zero.  The result of the comparison is used as an
  25053.      integer.
  25054.  
  25055.      The default return type of `IF()' (which may matter when it is
  25056.      stored into a temporary table) is calculated in MySQL Version 3.23
  25057.      as follows:
  25058.  
  25059.      *Expression*                          *Return value*
  25060.      expr2 or expr3 returns string         string
  25061.      expr2 or expr3 returns a              floating-point
  25062.      floating-point value                  
  25063.      expr2 or expr3 returns an integer     integer
  25064.  
  25065. `CASE value WHEN [compare-value] THEN result [WHEN [compare-value] THEN result ...] [ELSE result] END'
  25066.  
  25067. `CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END'
  25068.      The first version returns the `result' where
  25069.      `value=compare-value'. The second version returns the result for
  25070.      the first condition, which is true. If there was no matching result
  25071.      value, then the result after `ELSE' is returned. If there is no
  25072.      `ELSE' part then `NULL' is returned:
  25073.  
  25074.           mysql> SELECT CASE 1 WHEN 1 THEN "one" WHEN 2 THEN "two" ELSE "more" END;
  25075.                  -> "one"
  25076.           mysql> SELECT CASE WHEN 1>0 THEN "true" ELSE "false" END;
  25077.                  -> "true"
  25078.           mysql> SELECT CASE BINARY "B" when "a" then 1 when "b" then 2 END;
  25079.                  -> NULL
  25080.  
  25081. The type of the return value (`INTEGER', `DOUBLE' or `STRING') is the
  25082. same as the type of the first returned value (the expression after the
  25083. first `THEN').
  25084.  
  25085. String Functions
  25086. ----------------
  25087.  
  25088. String-valued functions return `NULL' if the length of the result would
  25089. be greater than the `max_allowed_packet' server parameter.  *Note
  25090. Server parameters::.
  25091.  
  25092. For functions that operate on string positions, the first position is
  25093. numbered 1.
  25094.  
  25095. `ASCII(str)'
  25096.      Returns the ASCII code value of the leftmost character of the
  25097.      string `str'. Returns `0' if `str' is the empty string.  Returns
  25098.      `NULL' if `str' is `NULL':
  25099.  
  25100.           mysql> select ASCII('2');
  25101.                   -> 50
  25102.           mysql> select ASCII(2);
  25103.                   -> 50
  25104.           mysql> select ASCII('dx');
  25105.                   -> 100
  25106.  
  25107.      See also the `ORD()' function.
  25108.  
  25109. `ORD(str)'
  25110.      If the leftmost character of the string str is a multi-byte
  25111.      character, returns the code of multi-byte character by returning
  25112.      the ASCII code value of the character in the format of: `((first
  25113.      byte ASCII code)*256+(second byte ASCII code))[*256+third byte
  25114.      ASCII code...]'.  If the leftmost character is not a multi-byte
  25115.      character, returns the same value as the like `ASCII()' function
  25116.      does:
  25117.  
  25118.           mysql> select ORD('2');
  25119.                   -> 50
  25120.  
  25121. `CONV(N,from_base,to_base)'
  25122.      Converts numbers between different number bases.  Returns a string
  25123.      representation of the number `N', converted from base `from_base'
  25124.      to base `to_base'.  Returns `NULL' if any argument is `NULL'.  The
  25125.      argument `N' is interpreted as an integer, but may be specified as
  25126.      an integer or a string.  The minimum base is `2' and the maximum
  25127.      base is `36'.  If `to_base' is a negative number, `N' is regarded
  25128.      as a signed number.  Otherwise, `N' is treated as unsigned.
  25129.      `CONV' works with 64-bit precision:
  25130.  
  25131.           mysql> select CONV("a",16,2);
  25132.                   -> '1010'
  25133.           mysql> select CONV("6E",18,8);
  25134.                   -> '172'
  25135.           mysql> select CONV(-17,10,-18);
  25136.                   -> '-H'
  25137.           mysql> select CONV(10+"10"+'10'+0xa,10,10);
  25138.                   -> '40'
  25139.  
  25140. `BIN(N)'
  25141.      Returns a string representation of the binary value of `N', where
  25142.      `N' is a longlong (`BIGINT') number.  This is equivalent to
  25143.      `CONV(N,10,2)'.  Returns `NULL' if `N' is `NULL':
  25144.  
  25145.           mysql> select BIN(12);
  25146.                   -> '1100'
  25147.  
  25148. `OCT(N)'
  25149.      Returns a string representation of the octal value of `N', where
  25150.      `N' is a longlong number.  This is equivalent to `CONV(N,10,8)'.
  25151.      Returns `NULL' if `N' is `NULL':
  25152.  
  25153.           mysql> select OCT(12);
  25154.                   -> '14'
  25155.  
  25156. `HEX(N)'
  25157.      Returns a string representation of the hexadecimal value of `N',
  25158.      where `N' is a longlong (`BIGINT') number.  This is equivalent to
  25159.      `CONV(N,10,16)'.  Returns `NULL' if `N' is `NULL':
  25160.  
  25161.           mysql> select HEX(255);
  25162.                   -> 'FF'
  25163.  
  25164. `CHAR(N,...)'
  25165.      `CHAR()' interprets the arguments as integers and returns a string
  25166.      consisting of the characters given by the ASCII code values of
  25167.      those integers. `NULL' values are skipped:
  25168.  
  25169.           mysql> select CHAR(77,121,83,81,'76');
  25170.                   -> 'MySQL'
  25171.           mysql> select CHAR(77,77.3,'77.3');
  25172.                   -> 'MMM'
  25173.  
  25174. `CONCAT(str1,str2,...)'
  25175.      Returns the string that results from concatenating the arguments.
  25176.      Returns `NULL' if any argument is `NULL'.  May have more than 2
  25177.      arguments.  A numeric argument is converted to the equivalent
  25178.      string form:
  25179.  
  25180.           mysql> select CONCAT('My', 'S', 'QL');
  25181.                   -> 'MySQL'
  25182.           mysql> select CONCAT('My', NULL, 'QL');
  25183.                   -> NULL
  25184.           mysql> select CONCAT(14.