| Assembler MIPS | Ansi C | Visual Basic | .NET | Java | HTML | ASP | PHP | JavaScript | | HOME |
Table of Contents
Access denied ErrorsThis chapter covers topics that deal with administering a MySQL installation:
Configuring the server
Managing user accounts
Performing backups
The server log files
The query cache
The MySQL server, mysqld, is the main program that does most of the work in a MySQL installation. The server is accompanied by several related scripts that perform setup operations when you install MySQL or that assist you in starting and stopping the server. This section provides an overview of the server and related programs. The following sections provide more detailed information about each of these programs.
Each MySQL program takes many different options. Most programs
provide a --help option that you can use to get a
description of the program's different options. For example, try
mysqld --help.
You can override default option values for MySQL programs by specifying options on the command line or in an option file. Section 4.3, “Specifying Program Options”.
The following list briefly describes the MySQL server and server-related programs:
The SQL daemon (that is, the MySQL server). To use client programs, mysqld must be running, because clients gain access to databases by connecting to the server. See Section 5.2, “mysqld — The MySQL Server”.
A server startup script. mysqld_safe attempts to start mysqld. See Section 5.4.1, “mysqld_safe — MySQL Server Startup Script”.
A server startup script. This script is used on systems that use System V-style run directories containing scripts that start system services for particular run levels. It invokes mysqld_safe to start the MySQL server. See Section 5.4.2, “mysql.server — MySQL Server Startup Script”.
A server startup script that can start or stop multiple
servers installed on the system. See
Section 5.4.3, “mysqld_multi — Manage Multiple MySQL Servers”. An alternative to
mysqld_multi is
mysqlmanager, the MySQL Instance Manager.
See Section 5.5, “mysqlmanager — The MySQL Instance Manager”.
This script creates the MySQL database and initializes the grant tables with default privileges. It is usually executed only once, when first installing MySQL on a system. See Section 2.10.2, “Unix Post-Installation Procedures”.
This program is used after a MySQL upgrade operation. It updates the grant tables with any changes that have been made in newer versions of MySQL. See Section 5.6.1, “mysql_fix_privilege_tables — Upgrade MySQL System Tables”.
Note: As of MySQL 5.1.7, this program has been superseded by mysql_upgrade.
This program is used after a MySQL upgrade operation. It checks tables for incompatibilities and repairs them if necessary, and updates the grant tables with any changes that have been made in newer versions of MySQL. See Section 5.6.2, “mysql_upgrade — Check Tables for MySQL Upgrade”.
The MySQL Instance Manager, a program for monitoring and managing MySQL servers. See Section 5.5, “mysqlmanager — The MySQL Instance Manager”.
There are several other programs that are run on the server host:
mysqld is the MySQL server. The following discussion covers these MySQL server configuration topics:
Startup options that the server supports
Server system variables
Server status variables
How to set the server SQL mode
The server shutdown process
MySQL servers include the BerkeleyDB
(BDB) storage engine whenever possible, but
not all platforms support BDB.
Currently, MySQL Cluster is supported on Linux (on most
platforms), Solaris, Mac OS X, and HP-UX only. Some users have
reported success in using MySQL Cluster built from source on
BSD operating systems, but these are not officially supported
at this time. Note that, even for servers compiled with
Cluster support, the NDB Cluster storage
engine is not enabled by default. You must start the server
with the --ndbcluster option to use it as
part of a MySQL Cluster. (For details, see
Section 17.4, “MySQL Cluster Configuration”.)
The following table shows the platforms for which MySQL server
binaries include support for BDB and
NDB Cluster.
| System | BDB Support | NDB Support |
| AIX 5.2 | N | N |
| HP-UX | Y | Y |
| Linux-IA-64 | N | Y |
| Linux-Intel | Y | Y |
| Mac OS X | N | Y |
| NetWare | N | N |
| SCO 6 | N | N |
| Solaris-SPARC | Y | Y |
| Solaris-Intel | N | Y |
| Solaris-AMD 64 | Y | Y |
| Windows NT/2000/XP | Y | N |
To find out which storage engines your server supports, use
the SHOW ENGINES statement. (See
Section 13.5.4.13, “SHOW ENGINES Syntax”.) For example:
mysql> SHOW ENGINES\G
*************************** 1. row ***************************
Engine: MEMORY
Support: YES
Comment: Hash based, stored in memory, useful for temporary tables
Transactions: NO
XA: NO
Savepoints: NO
*************************** 2. row ***************************
Engine: CSV
Support: YES
Comment: CSV storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** 3. row ***************************
Engine: MRG_MYISAM
Support: YES
Comment: Collection of identical MyISAM tables
Transactions: NO
XA: NO
Savepoints: NO
*************************** 4. row ***************************
Engine: MyISAM
Support: DEFAULT
Comment: Default engine as of MySQL 3.23 with great performance
Transactions: NO
XA: NO
Savepoints: NO
...
The precise output from SHOW ENGINES may
vary according to the MySQL version used (and the features
that are enabled). The Support values in
the output indicate the server's level of support for each
feature, as shown here:
| Value | Meaning |
YES | The feature is supported and is active. |
NO | The feature is not supported. |
DISABLED | The feature is supported but has been disabled. |
A value of NO means that the server was
compiled without support for the feature, so it cannot be
activated at runtime.
A value of DISABLED occurs either because
the server was started with an option that disables the
feature, or because not all options required to enable it were
given. In the latter case, the error log file should contain a
reason indicating why the option is disabled. See
Section 5.12.2, “The Error Log”.
You might also see DISABLED for a storage
engine if the server was compiled to support it, but was
started with a
--skip-
option. For example, engine--skip-innodb disables
the InnoDB engine. For the NDB
Cluster storage engine, DISABLED
means the server was compiled with support for MySQL Cluster,
but was not started with the --ndb-cluster
option.
All MySQL servers support MyISAM tables,
because MyISAM is the default storage
engine.
When you start the mysqld server, you can specify program options using any of the methods described in Section 4.3, “Specifying Program Options”. The most common methods are to provide options in an option file or on the command line. However, in most cases it is desirable to make sure that the server uses the same options each time it runs. The best way to ensure this is to list them in an option file. See Section 4.3.2, “Using Option Files”.
mysqld reads options from the
[mysqld] and [server]
groups. mysqld_safe reads options from the
[mysqld], [server],
[mysqld_safe], and
[safe_mysqld] groups.
mysql.server reads options from the
[mysqld] and
[mysql.server] groups.
An embedded MySQL server usually reads options from the
[server], [embedded],
and
[
groups, where xxxxx_SERVER]xxxxx is the name of
the application into which the server is embedded.
mysqld accepts many command options. For a brief summary, execute mysqld --help. To see the full list, use mysqld --verbose --help.
The following list shows some of the most common server options. Additional options are described in other sections:
Options that affect security: See Section 5.7.3, “Security-Related mysqld Options”.
SSL-related options: See Section 5.9.7.3, “SSL Command Options”.
Binary log control options: See Section 5.12.4, “The Binary Log”.
Replication-related options: See Section 6.9, “Replication Startup Options”.
Options specific to particular storage engines: See
Section 15.1.1, “MyISAM Startup Options”,
Section 15.5.3, “BDB Startup Options”,
Section 15.2.4, “InnoDB Startup Options and System Variables”, and
Section 17.6.5.1, “MySQL Cluster-Related Command Options for mysqld”.
You can also set the values of server system variables by using variable names as options, as described later in this section.
Display a short help message and exit. Use both the
--verbose and --help
options to see the full message.
This option controls whether user-defined functions that
have only an xxx symbol for the main
function can be loaded. By default, the option is off and
only UDFs that have at least one auxiliary symbol can be
loaded; this prevents attempts at loading functions from
shared object files other than those containing legitimate
UDFs. See Section 28.3.4.6, “User-Defined Function Security Precautions”.
Use standard (ANSI) SQL syntax instead of MySQL syntax.
For more precise control over the server SQL mode, use the
--sql-mode option instead. See
Section 1.9.3, “Running MySQL in ANSI Mode”, and
Section 5.2.5, “The Server SQL Mode”.
The path to the MySQL installation directory. All paths are usually resolved relative to this directory.
The IP address to bind to.
--binlog-format={row|statement}
Specify whether to use row-based or statement-based replication (statement-based is default). See Section 6.3, “Row-Based Replication”. This option was added in MySQL 5.1.5.
Specify the maximum size of a row-based binary log event, in bytes. Rows are grouped into events smaller than this size if possible. The value should be a multiple of 256. The default is 1024. See Section 6.3, “Row-Based Replication”. This option was added in MySQL 5.1.5.
This option is used by the mysql_install_db script to create the MySQL privilege tables without having to start a full MySQL server.
The directory where character sets are installed. See Section 5.11.1, “The Character Set Used for Data and Sorting”.
--character-set-client-handshake
Don't ignore character set information sent by the client.
To ignore client information and use the default server
character set, use
--skip-character-set-client-handshake;
this makes MySQL behave like MySQL 4.0.
--character-set-filesystem=
charset_name
The filesystem character set. This option sets the
character_set_filesystem system
variable. It was added in MySQL 5.1.6.
--character-set-server=,
charset_name-C
charset_name
Use charset_name as the default
server character set. See
Section 5.11.1, “The Character Set Used for Data and Sorting”.
Put the mysqld server in a closed
environment during startup by using the
chroot() system call. This is a
recommended security measure. Note that use of this option
somewhat limits LOAD DATA INFILE and
SELECT ... INTO OUTFILE.
--collation-server=
collation_name
Use collation_name as the
default server collation. See
Section 5.11.1, “The Character Set Used for Data and Sorting”.
(Windows only.) Write error log messages to
stderr and stdout
even if --log-error is specified.
mysqld does not close the console
window if this option is used.
Write a core file if mysqld dies. For
some systems, you must also specify the
--core-file-size option to
mysqld_safe. See
Section 5.4.1, “mysqld_safe — MySQL Server Startup Script”. Note that on some systems,
such as Solaris, you do not get a core file if you are
also using the --user option.
The path to the data directory.
--debug[=,
debug_options]-#
[
debug_options]
If MySQL is configured with --with-debug,
you can use this option to get a trace file of what
mysqld is doing. The
debug_options string often is
'd:t:o,.
The default is file_name''d:t:i:o,mysqld.trace'.
See Section E.1.2, “Creating Trace Files”.
--default-character-set=
(DEPRECATED)
charset_name
Use charset_name as the default
character set. This option is deprecated in favor of
--character-set-server. See
Section 5.11.1, “The Character Set Used for Data and Sorting”.
--default-collation=
collation_name
Use collation_name as the
default collation. This option is deprecated in favor of
--collation-server. See
Section 5.11.1, “The Character Set Used for Data and Sorting”.
Set the default storage engine (table type) for tables. See Chapter 15, Storage Engines and Table Types.
This option is a synonym for
--default-storage-engine.
Set the default server time zone. This option sets the
global time_zone system variable. If
this option is not given, the default time zone is the
same as the system time zone (given by the value of the
system_time_zone system variable.
--delay-key-write[={OFF|ON|ALL}]
Specify how to use delayed key writes. Delayed key writing
causes key buffers not to be flushed between writes for
MyISAM tables. OFF
disables delayed key writes. ON enables
delayed key writes for those tables that were created with
the DELAY_KEY_WRITE option.
ALL delays key writes for all
MyISAM tables. See
Section 7.5.2, “Tuning Server Parameters”, and
Section 15.1.1, “MyISAM Startup Options”.
Note: If you set this
variable to ALL, you should not use
MyISAM tables from within another
program (such as another MySQL server or
myisamchk) when the tables are in use.
Doing so leads to index corruption.
Read the default DES keys from this file. These keys are
used by the DES_ENCRYPT() and
DES_DECRYPT() functions.
Enable support for named pipes. This option applies only on Windows NT, 2000, XP, and 2003 systems, and can be used only with the mysqld-nt and server that supports named-pipe connections.
Enable the event scheduler. This option was added in MySQL 5.1.6.
--exit-info[=,
flags]-T [
flags]
This is a bit mask of different flags that you can use for debugging the mysqld server. Do not use this option unless you know exactly what it does!
Enable external locking (system locking), which is
disabled by default as of MySQL 4.0. Note that if you use
this option on a system on which lockd
does not fully work (such as Linux), it is easy for
mysqld to deadlock. This option
previously was named --enable-locking.
Note: If you use this
option to enable updates to MyISAM
tables from many MySQL processes, you must ensure that the
following conditions are satisfied:
You should not use the query cache for queries that use tables that are updated by another process.
You should not use
--delay-key-write=ALL or
DELAY_KEY_WRITE=1 on any shared
tables.
The easiest way to ensure this is to always use
--external-locking together with
--delay-key-write=OFF and
--query-cache-size=0. (This is not done
by default because in many setups it is useful to have a
mixture of the preceding options.)
Flush (synchronize) all changes to disk after each SQL statement. Normally, MySQL does a write of all changes to disk only after each SQL statement and lets the operating system handle the synchronizing to disk. See Section A.4.2, “What to Do If MySQL Keeps Crashing”.
Read SQL statements from this file at startup. Each statement must be on a single line and should not include comments.
--innodb-
xxx
The InnoDB options are listed in
Section 15.2.4, “InnoDB Startup Options and System Variables”.
--language=
lang_name,
-L lang_name
Return client error messages in the given language.
lang_name can be given as the
language name or as the full pathname to the directory
where the language files are installed. See
Section 5.11.2, “Setting the Error Message Language”.
Some hardware/operating system architectures support memory pages greater than the default (usually 4KB). The actual implementation of this support depends on the underlying hardware and OS. Applications that perform a lot of memory accesses may obtain performance improvements by using large pages due to reduced Translation Lookaside Buffer (TLB) misses.
Currently, MySQL supports only the Linux implementation of large pages support (which is called HugeTLB in Linux). We have plans to extend this support to FreeBSD, Solaris and possibly other platforms.
Before large pages can be used on Linux, it is necessary
to configure the HugeTLB memory pool. For reference,
consult the hugetlbpage.txt file in
the Linux kernel source.
This option is disabled by default.
--log[=,
file_name]-l [
file_name]
This option enables logging to the general query log,
which contains entries that record client connections and
SQL statements received from clients. The log output
destination can be selected with the
--log-output option as of MySQL 5.1.6.
Before 5.1.6, logging occurs to the general query log
file. If you omit the filename, MySQL uses
as the filename. See Section 5.12.1, “Server Log Tables”, and
Section 5.12.3, “The General Query Log”.
host_name.log
Enable binary logging. The server logs all statements that change data to the binary log, which is used for backup and replication. See Section 5.12.4, “The Binary Log”.
The option value, if given, is the basename for the log
sequence. The server creates binary log files in sequence
by adding a numeric suffix to the basename. It is
recommended that you specify a basename (see
Section A.8.1, “Open Issues in MySQL”, for the reason). Otherwise,
MySQL uses
as the basename.
host_name-bin
The index file for binary log filenames. See
Section 5.12.4, “The Binary Log”. If you omit the filename,
and if you didn't specify one with
--log-bin, MySQL uses
as the filename.
host_name-bin.index
--log-bin-trust-function-creators[={0|1}]
With no argument or an argument of 1, this option sets the
log_bin_trust_function_creators system
variable to 1. With an argument of 0, this option sets the
system variable to 0.
log_bin_trust_function_creators affects
how MySQL enforces restrictions on stored function
creation. See Section 20.4, “Binary Logging of Stored Routines and Triggers”.
Log errors and startup messages to this file. See
Section 5.12.2, “The Error Log”. If you omit the filename,
MySQL uses
.
If the filename has no extension, the server adds an
extension of host_name.err.err.
Log all MyISAM changes to this file
(used only when debugging MyISAM).
--log-long-format
(DEPRECATED)
Log extra information to the update log, binary update
log, and slow query log, if they have been activated. For
example, the username and timestamp are logged for all
queries. This option is deprecated, as it now represents
the default logging behavior. (See the description for
--log-short-format.) The
--log-queries-not-using-indexes option is
available for the purpose of logging queries that do not
use indexes to the slow query log.
This option determines the destination for general query
log and slow query log output. The option value can be
given as one or more of the words
TABLE, FILE, or
NONE. If the option is given without a
value, the default is TABLE (log to the
general_log and
slow_log tables in the
mysql database).
FILE causes logging to log files. (For
FILE logging, the
--log and -slow-log
options determine the log file location.)
NONE disables logging. If
NONE is present in the option value, it
takes precedence over any other words that are present.
TABLE and FILE can
both be given to select to both log output destinations.
This option selects log output destinations, but does not
enable log output. To do that, use the
--log and
--log-slow-queries options. For more
information, see Section 5.12.1, “Server Log Tables”.
The --log-output option was added in
MySQL 5.1.6.
--log-queries-not-using-indexes
If you are using this option with
--log-slow-queries, queries that do not
use indexes are logged to the slow query log. See
Section 5.12.5, “The Slow Query Log”.
Log less information to the update log, binary update log, and slow query log, if they have been activated. For example, the username and timestamp are not logged for queries.
Log slow administrative statements such as
OPTIMIZE TABLE, ANALYZE
TABLE, and ALTER TABLE to the
slow query log.
--log-slow-queries[=
file_name]
This option enables logging to the slow query log, which
contains entries for all queries that have taken more than
long_query_time seconds to execute. See
the descriptions of the --log-long-format
and --log-short-format options for
details.
The log output destination can be selected with the
--log-output option as of MySQL 5.1.6.
Before 5.1.6, logging occurs to the slow query log file.
If you omit the filename, MySQL uses
as the filename. See Section 5.12.1, “Server Log Tables”, and
Section 5.12.5, “The Slow Query Log”.
host_name-slow.log
--log-warnings[=,
level]-W [
level]
Print out warnings such as Aborted
connection... to the error log. Enabling this
option is recommended, for example, if you use replication
(you get more information about what is happening, such as
messages about network failures and reconnections). This
option is enabled (1) by default, and the default
level value if omitted is 1. To
disable this option, use
--log-warnings=0. Aborted connections are
not logged to the error log unless the value is greater
than 1. See Section A.2.10, “Communication Errors and Aborted Connections”.
Give table-modifying operations
(INSERT, REPLACE,
DELETE, UPDATE)
lower priority than selects. This can also be done via
{INSERT | REPLACE | DELETE | UPDATE} LOW_PRIORITY
... to lower the priority of only one query, or
by SET LOW_PRIORITY_UPDATES=1 to change
the priority in one thread. See
Section 7.3.2, “Table Locking Issues”.
Lock the mysqld process in memory. This
works on systems such as Solaris that support the
mlockall() system call. This might help
if you have a problem where the operating system is
causing mysqld to swap on disk. Note
that use of this option requires that you run the server
as root, which is normally not a good
idea for security reasons. See
Section 5.7.5, “How to Run MySQL as a Normal User”.
--myisam-recover[=
option[,option]...]]
Set the MyISAM storage engine recovery
mode. The option value is any combination of the values of
DEFAULT, BACKUP,
FORCE, or QUICK. If
you specify multiple values, separate them by commas. You
can also use a value of "" to disable
this option. If this option is used, each time
mysqld opens a
MyISAM table, it checks whether the
table is marked as crashed or wasn't closed properly. (The
last option works only if you are running with external
locking disabled.) If this is the case,
mysqld runs a check on the table. If
the table was corrupted, mysqld
attempts to repair it.
The following options affect how the repair works:
| Option | Description |
DEFAULT | The same as not giving any option to --myisam-recover. |
BACKUP | If the data file was changed during recovery, save a backup of the
file as
. |
FORCE | Run recovery even if we would lose more than one row from the
.MYD file. |
QUICK | Don't check the rows in the table if there aren't any delete blocks. |
Before the server automatically repairs a table, it writes
a note about the repair to the error log. If you want to
be able to recover from most problems without user
intervention, you should use the options
BACKUP,FORCE. This forces a repair of a
table even if some rows would be deleted, but it keeps the
old data file as a backup so that you can later examine
what happened.
--ndb-connectstring=
connect_string
When using the NDB storage engine, it
is possible to point out the management server that
distributes the cluster configuration by setting the
connect string option. See
Section 17.4.4.2, “The MySQL Cluster connectstring”, for syntax.
If the binary includes support for the NDB
Cluster storage engine, this option enables the
engine, which is disabled by default. See
Chapter 17, MySQL Cluster.
Force the server to generate short (pre-4.1) password hashes for new passwords. This is useful for compatibility when the server must support older client programs. See Section 5.8.9, “Password Hashing as of MySQL 4.1”.
Only use one thread (for debugging under Linux). This option is available only if the server is built with debugging enabled. See Section E.1, “Debugging a MySQL Server”.
Change the number of file descriptors available to
mysqld. If this option is not set or is
set to 0, mysqld uses the value to
reserve file descriptors with
setrlimit(). If the value is 0,
mysqld reserves
max_connections×5 or
max_connections +
table_open_cache×2 files (whichever is
larger). You should try increasing this value if
mysqld gives you the error Too
many open files.
The pathname of the process ID file. This file is used by other programs such as mysqld_safe to determine the server's process ID.
The port number to use when listening for TCP/IP
connections. The port number must be 1024 or higher unless
the server is started by the root
system user.
On some systems, when the server is stopped, the TCP/IP port might not become available immediately. If the server is restarted quickly afterward, its attempt to reopen the port can fail. This option indicates how many seconds the server should wait for the TCP/IP port to become free if it cannot be opened. The default is not to wait. This option was added in MySQL 5.1.5.
Skip some optimization stages.
If this option is enabled, a user cannot create new MySQL
users by using the GRANT statement, if
the user doesn't have the INSERT
privilege for the mysql.user table or
any column in the table.
Disallow authentication by clients that attempt to use accounts that have old (pre-4.1) passwords.
Enable shared-memory connections by local clients. This option is available only on Windows.
--shared-memory-base-name=
name
The name of shared memory to use for shared-memory
connections. This option is available only on Windows. The
default name is MYSQL. The name is case
sensitive.
Disable the BDB storage engine. This
saves memory and might speed up some operations. Do not
use this option if you require BDB
tables.
Turn off the ability to select and insert at the same time
on MyISAM tables. (This is to be used
only if you think you have found a bug in this feature.)
See Section 7.3.3, “Concurrent Inserts”.
Do not use external locking (system locking). With
external locking disabled, you must shut down the server
to use myisamchk. (See
Section 1.4.3, “MySQL Stability”.) To avoid this requirement,
use the CHECK TABLE and REPAIR
TABLE statements to check and repair
MyISAM tables.
External locking has been disabled by default since MySQL 4.0.
This option causes the server not to use the privilege
system at all, which gives anyone with access to the
server unrestricted access to all
databases. You can cause a running server to
start using the grant tables again by executing
mysqladmin flush-privileges or
mysqladmin reload command from a system
shell, or by issuing a MySQL FLUSH
PRIVILEGES statement after connecting to the
server. This option also suppresses loading of plugins and
user-defined functions (UDFs).
Do not use the internal hostname cache for faster name-to-IP resolution. Instead, query the DNS server every time a client connects. See Section 7.5.6, “How MySQL Uses DNS”.
Disable the InnoDB storage engine. This
saves memory and disk space and might speed up some
operations. Do not use this option if you require
InnoDB tables.
Do not resolve hostnames when checking client connections.
Use only IP numbers. If you use this option, all
Host column values in the grant tables
must be IP numbers or localhost. See
Section 7.5.6, “How MySQL Uses DNS”.
Disable the NDB Cluster storage engine.
This is the default for binaries that were built with
NDB Cluster storage engine support; the
server allocates memory and other resources for this
storage engine only if the --ndbcluster
option is given explicitly. See
Section 17.4.3, “Quick Test Setup of MySQL Cluster”, for an example of
usage.
Don't listen for TCP/IP connections at all. All interaction with mysqld must be made via named pipes or shared memory (on Windows) or Unix socket files (on Unix). This option is highly recommended for systems where only local clients are allowed. See Section 7.5.6, “How MySQL Uses DNS”.
Options that begin with --ssl specify
whether to allow clients to connect via SSL and indicate
where to find SSL keys and certificates. See
Section 5.9.7.3, “SSL Command Options”.
Available on Windows NT-based systems only; instructs the MySQL server not to run as a service.
--symbolic-links,
--skip-symbolic-links
Enable or disable symbolic link support. This option has different effects on Windows and Unix:
On Windows, enabling symbolic links allows you to
establish a symbolic link to a database directory by
creating a
file that contains the path to the real directory. See
Section 7.6.1.3, “Using Symbolic Links for Databases on Windows”.
db_name.sym
On Unix, enabling symbolic links means that you can
link a MyISAM index file or data
file to another directory with the INDEX
DIRECTORY or DATA
DIRECTORY options of the CREATE
TABLE statement. If you delete or rename the
table, the files that its symbolic links point to also
are deleted or renamed. See
Section 7.6.1.2, “Using Symbolic Links for Tables on Unix”.
If MySQL is configured with
--with-debug=full, all MySQL programs
check for memory overruns during each memory allocation
and memory freeing operation. This checking is very slow,
so for the server you can avoid it when you don't need it
by using the --skip-safemalloc option.
With this option, the SHOW DATABASES
statement is allowed only to users who have the
SHOW DATABASES privilege, and the
statement displays all database names. Without this
option, SHOW DATABASES is allowed to
all users, but displays each database name only if the
user has the SHOW DATABASES privilege
or some privilege for the database. Note that
any global privilege is considered a
privilege for the database.
Don't write stack traces. This option is useful when you are running mysqld under a debugger. On some systems, you also must use this option to get a core file. See Section E.1, “Debugging a MySQL Server”.
Disable using thread priorities for faster response time.
On Unix, this option specifies the Unix socket file to use
when listening for local connections. The default value is
/tmp/mysql.sock. On Windows, the
option specifies the pipe name to use when listening for
local connections that use a named pipe. The default value
is MySQL (not case sensitive).
--sql-mode=
value[,value[,value...]]
Set the SQL mode. See Section 5.2.5, “The Server SQL Mode”.
SYSDATE() by default returns the time
at which it executes, not the time at which the statement
in which it occurs begins executing. This differs from the
behavior of NOW(). This option causes
SYSDATE() to be an alias for
NOW(). For information about the
implications for binary logging and replication, see the
description for SYSDATE() in
Section 12.5, “Date and Time Functions” and for
SET TIMESTAMP in
Section 13.5.3, “SET Syntax”.
This option was added in MySQL 5.1.8.
This option causes most temporary files created by the server to use a small set of names, rather than a unique name for each new file. This works around a problem in the Linux kernel dealing with creating many new files with different names. With the old behavior, Linux seems to “leak” memory, because it is being allocated to the directory entry cache rather than to the disk cache.
Sets the default transaction isolation level. The
level value can be
READ-UNCOMMITTED,
READ-COMMITTED,
REPEATABLE-READ, or
SERIALIZABLE. See
Section 13.4.6, “SET TRANSACTION Syntax”.
The path of the directory to use for creating temporary
files. It might be useful if your default
/tmp directory resides on a partition
that is too small to hold temporary tables. This option
accepts several paths that are used in round-robin
fashion. Paths should be separated by colon characters
(‘:’) on Unix and semicolon
characters (‘;’) on
Windows, NetWare, and OS/2. If the MySQL server is acting
as a replication slave, you should not set
--tmpdir to point to a directory on a
memory-based filesystem or to a directory that is cleared
when the server host restarts. For more information about
the storage location of temporary files, see
Section A.4.4, “Where MySQL Stores Temporary Files”. A replication slave
needs some of its temporary files to survive a machine
restart so that it can replicate temporary tables or
LOAD DATA INFILE operations. If files
in the temporary file directory are lost when the server
restarts, replication fails.
--user={,
user_name|user_id}-u
{
user_name|user_id}
Run the mysqld server as the user
having the name user_name or
the numeric user ID user_id.
(“User” in this context refers to a system
login account, not a MySQL user listed in the grant
tables.)
This option is mandatory when
starting mysqld as
root. The server changes its user ID
during its startup sequence, causing it to run as that
particular user rather than as root.
See Section 5.7.1, “General Security Guidelines”.
To avoid a possible security hole where a user adds a
--user=root option to a
my.cnf file (thus causing the server
to run as root),
mysqld uses only the first
--user option specified and produces a
warning if there are multiple --user
options. Options in /etc/my.cnf and
$MYSQL_HOME/my.cnf are processed
before command-line options, so it is recommended that you
put a --user option in
/etc/my.cnf and specify a value other
than root. The option in
/etc/my.cnf is found before any other
--user options, which ensures that the
server runs as a user other than root,
and that a warning results if any other
--user option is found.
Display version information and exit.
You can assign a value to a server system variable by using an
option of the form
--.
For example, var_name=value--key_buffer_size=32M sets the
key_buffer_size variable to a value of
32MB.
Note that when you assign a value to a variable, MySQL might automatically correct the value to stay within a given range, or adjust the value to the closest allowable value if only certain values are allowed.
If you want to restrict the maximum value to which a variable
can be set at runtime with SET, you can
define this by using the
--maximum-
command-line option.
var_name=value
It is also possible to set variables by using
--set-variable=
or var_name=value-O
syntax. This syntax is deprecated.
var_name=value
You can change the values of most system variables for a
running server with the SET statement. See
Section 13.5.3, “SET Syntax”.
Section 5.2.2, “Server System Variables”, provides a full description for all variables, and additional information for setting them at server startup and runtime. Section 7.5.2, “Tuning Server Parameters”, includes information on optimizing the server by tuning system variables.
The mysql server maintains many system
variables that indicate how it is configured. Each system
variable has a default value. System variables can be set at
server startup using options on the command line or in an
option file. Most of them can be changed dynamically while the
server is running by means of the SET
statement, which enables you to modify operation of the server
without having to stop and restart it. You can refer to system
variable values in expressions.
There are several ways to see the names and values of system variables:
To see the values that a server will use based on its compiled-in defaults and any option files that it reads, use this command:
mysqld --verbose --help
To see the values that a server will use based on its compiled-in defaults, ignoring the settings in any option files, use this command:
mysqld --no-defaults --verbose --help
To see the current values used by a running server, use
the SHOW VARIABLES statement.
This section provides a description of each system variable. Variables with no version indicated are present in all MySQL 5.1 releases. For historical information concerning their implementation, please see MySQL 5.0 Reference Manual and MySQL 3.23, 4.0, 4.1 Reference Manual.
For additional system variable information, see these sections:
Section 5.2.3, “Using System Variables”, discusses the syntax for setting and displaying system variable values.
Section 5.2.3.2, “Dynamic System Variables”, lists the variables that can be set at runtime.
Information on tuning sytem variables can be found in Section 7.5.2, “Tuning Server Parameters”.
Section 15.2.4, “InnoDB Startup Options and System Variables”, lists
InnoDB system variables.
Note: Some of the following variable
descriptions refer to “enabling” or
“disabling” a variable. These variables can be
enabled with the SET statement by setting
them to ON or 1, or
disabled by setting them to OFF or
0. However, to set such a variable on the
command line or in an option file, you must set it to
1 or 0; setting it to
ON or OFF will not work.
For example, on the command line,
--delay_key_write=1 works but
--delay_key_write=ON does not.
Values for buffer sizes, lengths, and stack sizes are given in bytes unless otherwise specified.
auto_increment_increment
auto_increment_increment and
auto_increment_offset are intended for
use with master-to-master replication, and can be used to
control the operation of AUTO_INCREMENT
columns. Both variables can be set globally or locally,
and each can assume an integer value between 1 and 65,535
inclusive. Setting the value of either of these two
variables to 0 causes its value to be set to 1 instead.
Attempting to set the value of either of these two
variables to an integer greater than 65,535 or less than 0
causes its value to be set to 65,535 instead. Attempting
to set the value of
auto_increment_increment or
auto_increment_offset to a non-integer
value gives rise to an error, and the actual value of the
variable remains unchanged.
Important:
auto_increment_increment and
auto_increment_offset are not intended
for use with MySQL Cluster replication. Attempting to set
them in a Cluster replication scenario may give rise to
unpredictable (and unrecoverable) errors. The use of these
variables with Cluster replication is therefore not
supported.
These two variables affect
AUTO_INCREMENT column behavior as
follows:
auto_increment_increment controls
the interval between successive column values. For
example:
mysql>SHOW VARIABLES LIKE 'auto_inc%';+--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | +--------------------------+-------+ 2 rows in set (0.00 sec) mysql>CREATE TABLE autoinc1->(col INT NOT NULL AUTO_INCREMENT PRIMARY KEY);Query OK, 0 rows affected (0.04 sec) mysql>SET @@auto_increment_increment=10;Query OK, 0 rows affected (0.00 sec) mysql>SHOW VARIABLES LIKE 'auto_inc%';+--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | auto_increment_increment | 10 | | auto_increment_offset | 1 | +--------------------------+-------+ 2 rows in set (0.01 sec) mysql>INSERT INTO autoinc1 VALUES (NULL), (NULL), (NULL), (NULL);Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql>SELECT col FROM autoinc1;+-----+ | col | +-----+ | 1 | | 11 | | 21 | | 31 | +-----+ 4 rows in set (0.00 sec)
(Note how SHOW VARIABLES is used
here to obtain the current values for these
variables.)
auto_increment_offset determines
the starting point for the
AUTO_INCREMENT column value.
Consider the following, assuming that these statements
are executed during the same session as the example
given in the description for
auto_increment_increment:
mysql>SET @@auto_increment_offset=5;Query OK, 0 rows affected (0.00 sec) mysql>SHOW VARIABLES LIKE 'auto_inc%';+--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | auto_increment_increment | 10 | | auto_increment_offset | 5 | +--------------------------+-------+ 2 rows in set (0.00 sec) mysql>CREATE TABLE autoinc2->(col INT NOT NULL AUTO_INCREMENT PRIMARY KEY);Query OK, 0 rows affected (0.06 sec) mysql>INSERT INTO autoinc2 VALUES (NULL), (NULL), (NULL), (NULL);Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql>SELECT col FROM autoinc2;+-----+ | col | +-----+ | 5 | | 15 | | 25 | | 35 | +-----+ 4 rows in set (0.02 sec)
If the value of
auto_increment_offset is greater
than that of
auto_increment_increment, the value
of auto_increment_offset is
ignored.
Should one or both of these variables be changed and then
new rows inserted into a table containing an
AUTO_INCREMENT column, the results may
seem counterintuitive because the series of
AUTO_INCREMENT values is calculated
without regard to any values already present in the
column, and the next value inserted is the least value in
the series that is greater than the maximum existing value
in the AUTO_INCREMENT column. In other
words, the series is calculated like so:
auto_increment_offset +
N ×
auto_increment_increment
where N is a positive integer
value in the series [1, 2, 3, ...]. For example:
mysql>SHOW VARIABLES LIKE 'auto_inc%';+--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | auto_increment_increment | 10 | | auto_increment_offset | 5 | +--------------------------+-------+ 2 rows in set (0.00 sec) mysql>SELECT col FROM autoinc1;+-----+ | col | +-----+ | 1 | | 11 | | 21 | | 31 | +-----+ 4 rows in set (0.00 sec) mysql>INSERT INTO autoinc1 VALUES (NULL), (NULL), (NULL), (NULL);Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql>SELECT col FROM autoinc1;+-----+ | col | +-----+ | 1 | | 11 | | 21 | | 31 | | 35 | | 45 | | 55 | | 65 | +-----+ 8 rows in set (0.00 sec)
The values shown for
auto_increment_increment and
auto_increment_offset generate the
series 5 + N × 10, that
is, [5, 15, 25, 35, 45, ...]. The greatest value present
in the col column prior to the
INSERT is 31, and the next available
value in the AUTO_INCREMENT series is
35, so the inserted values for col
begin at that point and the results are as shown for the
SELECT query.
It is important to remember that it is not possible to
confine the effects of these two variables to a single
table, and thus they do not take the place of the
sequences offered by some other database management
systems; these variables control the behavior of all
AUTO_INCREMENT columns in
all tables on the MySQL server. If
one of these variables is set globally, its effects
persist until the global value is changed or overridden by
setting them locally, or until mysqld
is restarted. If set locally, the new value affects
AUTO_INCREMENT columns for all tables
into which new rows are inserted by the current user for
the duration of the session, unless the values are changed
during that session.
The default value of
auto_increment_increment is 1. See
Section 6.15, “Auto-Increment in Multiple-Master Replication”.
auto_increment_offset
This variable has a default value of 1. For particulars,
see the description for
auto_increment_increment.
back_log
The number of outstanding connection requests MySQL can
have. This comes into play when the main MySQL thread gets
very many connection requests in a very short time. It
then takes some time (although very little) for the main
thread to check the connection and start a new thread. The
back_log value indicates how many
requests can be stacked during this short time before
MySQL momentarily stops answering new requests. You need
to increase this only if you expect a large number of
connections in a short period of time.
In other words, this value is the size of the listen queue
for incoming TCP/IP connections. Your operating system has
its own limit on the size of this queue. The manual page
for the Unix listen() system call
should have more details. Check your OS documentation for
the maximum value for this variable.
back_log cannot be set higher than your
operating system limit.
basedir
The MySQL installation base directory. This variable can
be set with the --basedir option.
bdb_cache_parts
The number of parts to use for the BDB
cache. Added in MySQL 5.1.2.
bdb_cache_size
The size of the buffer that is allocated for caching
indexes and rows for BDB tables. Some
systems support setting this variable larger than 4GB. If
you don't use BDB tables, you should
start mysqld with
--skip-bdb to not allocate memory for
this cache.
bdb_home
The base directory for BDB tables. This
should be assigned the same value as the
datadir variable.
bdb_log_buffer_size
The size of the buffer that is allocated for caching
indexes and rows for BDB tables. If you
don't use BDB tables, you should set
this to 0 or start mysqld with
--skip-bdb to not allocate memory for
this cache.
bdb_logdir
The directory where the BDB storage
engine writes its log files. This variable can be set with
the --bdb-logdir option.
bdb_max_lock
The maximum number of locks that can be active for a
BDB table (10,000 by default). You
should increase this value if errors such as the following
occur when you perform long transactions or when
mysqld has to examine many rows to
calculate a query:
bdb: Lock table is out of available locks Got error 12 from ...
bdb_region_size
The size of the underlying logging area of the
BDB environment. This is the size of
the memory pool used for storing the filenames used in a
transaction. Added in MySQL 5.1.2.
bdb_shared_data
This is ON if you are using
--bdb-shared-data to start Berkeley DB in
multi-process mode. (Do not use
DB_PRIVATE when initializing Berkeley
DB.)
bdb_tmpdir
The BDB temporary file directory.
binlog_cache_size
The size of the cache to hold the SQL statements for the
binary log during a transaction. A binary log cache is
allocated for each client if the server supports any
transactional storage engines and if the server has the
binary log enabled (--log-bin option). If
you often use large, multiple-statement transactions, you
can increase this cache size to get more performance. The
Binlog_cache_use and
Binlog_cache_disk_use status variables
can be useful for tuning the size of this variable. See
Section 5.12.4, “The Binary Log”.
binlog_format
The binary logging format, either
STATEMENT, ROW, or
MIXED. binlog_format
is set by the --binlog-format option at
startup, or by the binlog_format
variable at runtime (you need the SUPER
privilege to set this variable on a global scope). See
Section 6.3, “Row-Based Replication”. The startup
variable was added in MySQL 5.1.5, and the runtime
variable in MySQL 5.1.8. MIXED was
added in MySQL 5.1.8.
STATEMENT is used by default. If
MIXED is specified, statement-based
replication is used, too, except for cases where only
row-based replication is guaranteed to lead to proper
results. For example, this is the case when statements
contain user-defined functions (UDF) or the
UUID() function. An exception to this
rule is that MIXED always uses
statement-based replication for stored functions and
triggers.
There are exceptions when you cannot switch the replication format at runtime:
From within a stored function or a trigger.
If NDB is enabled.
If the session is currently in row-based replication mode and has open temporary tables.
Trying to switch the format in those cases results in an error.
Before MySQL 5.1.8, switching to row-based replication
format would implicitly set
--log-bin-trust-function-creators=1 and
--innodb_locks_unsafe_for_binlog. MySQL
5.1.8 and later no longer implicitly set these options
when row-based replication is used.
bulk_insert_buffer_size
MyISAM uses a special tree-like cache
to make bulk inserts faster for INSERT ...
SELECT, INSERT ... VALUES (...), (...),
..., and LOAD DATA INFILE
when adding data to non-empty tables. This variable limits
the size of the cache tree in bytes per thread. Setting it
to 0 disables this optimization. The default value is 8MB.
character_set_client
The character set for statements that arrive from the client.
character_set_connection
The character set used for literals that do not have a character set introducer and for number-to-string conversion.
character_set_database
The character set used by the default database. The server
sets this variable whenever the default database changes.
If there is no default database, the variable has the same
value as character_set_server.
character_set_filesystem
The filesystem character set. This variable is used to
interpret string literals that refer to filenames, such as
in the LOAD DATA INFILE and
SELECT ... INTO OUTFILE statements and
the LOAD_FILE() function. Such
filenames are converted from
character_set_client to
character_set_filesystem before the
file opening attempt occurs. The default value is
binary, which means that no conversion
occurs. For systems on which multi-byte filenames are
allowed, a different value may be more appropriate. For
example, if the system represents filenames using UTF-8,
set character_set_filesytem to
'utf8'. This variable was added in
MySQL 5.1.6.
character_set_results
The character set used for returning query results to the client.
character_set_server
The server's default character set.
character_set_system
The character set used by the server for storing
identifiers. The value is always utf8.
character_sets_dir
The directory where character sets are installed.
collation_connection
The collation of the connection character set.
collation_database
The collation used by the default database. The server
sets this variable whenever the default database changes.
If there is no default database, the variable has the same
value as collation_server.
collation_server
The server's default collation.
completion_type
The transaction completion type:
If the value is 0 (the default),
COMMIT and
ROLLBACK are unaffected.
If the value is 1, COMMIT and
ROLLBACK are equivalent to
COMMIT AND CHAIN and
ROLLBACK AND CHAIN, respectively.
(A new transaction starts immediately with the same
isolation level as the just-terminated transaction.)
If the value is 2, COMMIT and
ROLLBACK are equivalent to
COMMIT RELEASE and
ROLLBACK RELEASE, respectively.
(The server disconnects after terminating the
transaction.)
concurrent_insert
If ON (the default), MySQL allows
INSERT and SELECT
statements to run concurrently for
MyISAM tables that have no free blocks
in the middle. You can turn this option off by starting
mysqld with --safe or
--skip-new.
This variable can take three integer values:
| Value | Description |
| 0 | Off |
| 1 | (Default) Enables concurrent insert for MyISAM tables
that don't have holes |
| 2 | Enables concurrent inserts for all MyISAM tables. If
table has a hole and is in use by another thread
the new row will be inserted at end of table. If
table is not in use, MySQL does a normal read lock
and inserts the new row into the hole. |
See also Section 7.3.3, “Concurrent Inserts”.
The number of seconds that the mysqld
server waits for a connect packet before responding with
Bad handshake.
datadir
The MySQL data directory. This variable can be set with
the --datadir option.
date_format
This variable is not implemented.
datetime_format
This variable is not implemented.
default_week_format
The default mode value to use for the
WEEK() function. See
Section 12.5, “Date and Time Functions”.
delay_key_write
This option applies only to MyISAM
tables. It can have one of the following values to affect
handling of the DELAY_KEY_WRITE table
option that can be used in CREATE TABLE
statements.
| Option | Description |
OFF | DELAY_KEY_WRITE is ignored. |
ON | MySQL honors any DELAY_KEY_WRITE option specified in
CREATE TABLE statements. This
is the default value. |
ALL | All new opened tables are treated as if they were created with the
DELAY_KEY_WRITE option enabled. |
If DELAY_KEY_WRITE is enabled for a
table, the key buffer is not flushed for the table on
every index update, but only when the table is closed.
This speeds up writes on keys a lot, but if you use this
feature, you should add automatic checking of all
MyISAM tables by starting the server
with the --myisam-recover option (for
example, --myisam-recover=BACKUP,FORCE).
See Section 5.2.1, “mysqld Command Options”, and
Section 15.1.1, “MyISAM Startup Options”.
Note that enabling external locking with
--external-locking offers no protection
against index corruption for tables that use delayed key
writes.
delayed_insert_limit
After inserting delayed_insert_limit
delayed rows, the INSERT DELAYED
handler thread checks whether there are any
SELECT statements pending. If so, it
allows them to execute before continuing to insert delayed
rows.
delayed_insert_timeout
How many seconds an INSERT DELAYED
handler thread should wait for INSERT
statements before terminating.
delayed_queue_size
This is a per-table limit on the number of rows to queue
when handling INSERT DELAYED
statements. If the queue becomes full, any client that
issues an INSERT DELAYED statement
waits until there is room in the queue again.
div_precision_increment
This variable indicates the number of digits of precision
by which to increase the result of division operations
performed with the / operator. The
default value is 4. The minimum and maximum values are 0
and 30, respectively. The following example illustrates
the effect of increasing the default value.
mysql>SELECT 1/7;+--------+ | 1/7 | +--------+ | 0.1429 | +--------+ mysql>SET div_precision_increment = 12;mysql>SELECT 1/7;+----------------+ | 1/7 | +----------------+ | 0.142857142857 | +----------------+
event_scheduler
Whether the event scheduler is disabled or enabled. By default, the scheduler is disabled. This variable was added in MySQL 5.1.6.
engine_condition_pushdown
This variable applies to NDB. By default it is 0
(OFF): If you execute a query such as
SELECT * FROM t WHERE mycol = 42, where
mycol is a non-indexed column, the
query is executed as a full table scan on every NDB node.
Each node sends every row to the MySQL server, which
applies the WHERE condition. If
engine_condition_pushdown is set to 1
(ON), the condition is “pushed
down” to the storage engine and sent to the NDB
nodes. Each node uses the condition to perform the scan,
and only sends back to the MySQL server the rows that
match the condition.
expire_logs_days
The number of days for automatic binary log removal. The default is 0, which means “no automatic removal.” Possible removals happen at startup and at binary log rotation.
flush
If ON, the server flushes
(synchronizes) all changes to disk after each SQL
statement. Normally, MySQL does a write of all changes to
disk only after each SQL statement and lets the operating
system handle the synchronizing to disk. See
Section A.4.2, “What to Do If MySQL Keeps Crashing”. This variable is set to
ON if you start
mysqld with the
--flush option.
flush_time
If this is set to a non-zero value, all tables are closed
every flush_time seconds to free up
resources and synchronize unflushed data to disk. We
recommend that this option be used only on Windows 9x or
Me, or on systems with minimal resources.
ft_boolean_syntax
The list of operators supported by boolean full-text
searches performed using IN BOOLEAN
MODE. See Section 12.7.1, “Boolean Full-Text Searches”.
The default variable value is
'+ -><()~*:""&|'. The
rules for changing the value are as follows:
Operator function is determined by position within the string.
The replacement value must be 14 characters.
Each character must be an ASCII non-alphanumeric character.
Either the first or second character must be a space.
No duplicates are allowed except the phrase quoting operators in positions 11 and 12. These two characters are not required to be the same, but they are the only two that may be.
Positions 10, 13, and 14 (which by default are set to
‘:’,
‘&’, and
‘|’) are reserved for
future extensions.
ft_max_word_len
The maximum length of the word to be included in a
FULLTEXT index.
Note:
FULLTEXT indexes must be rebuilt after
changing this variable. Use REPAIR TABLE
.
tbl_name QUICK
ft_min_word_len
The minimum length of the word to be included in a
FULLTEXT index.
Note:
FULLTEXT indexes must be rebuilt after
changing this variable. Use REPAIR TABLE
.
tbl_name QUICK
ft_query_expansion_limit
The number of top matches to use for full-text searches
performed using WITH QUERY EXPANSION.
ft_stopword_file
The file from which to read the list of stopwords for
full-text searches. All the words from the file are used;
comments are not honored. By default,
a built-in list of stopwords is used (as defined in the
myisam/ft_static.c file). Setting
this variable to the empty string ('')
disables stopword filtering.
Note:
FULLTEXT indexes must be rebuilt after
changing this variable or the contents of the stopword
file. Use REPAIR TABLE
.
tbl_name QUICK
group_concat_max_len
The maximum allowed result length for the
GROUP_CONCAT() function. The default is
1024.
have_archive
YES if mysqld
supports ARCHIVE tables,
NO if not.
have_bdb
YES if mysqld
supports BDB tables.
DISABLED if --skip-bdb
is used.
have_blackhole_engine
YES if mysqld
supports BLACKHOLE tables,
NO if not.
have_compress
YES if the zlib
compression library is available to the server,
NO if not. If not, the
COMPRESS() and
UNCOMPRESS() functions cannot be used.
have_crypt
YES if the crypt()
system call is available to the server,
NO if not. If not, the
ENCRYPT() function cannot be used.
have_csv
YES if mysqld
supports ARCHIVE tables,
NO if not.
have_dynamic_loading
YES if mysqld
supports dynamic loading of plugins, NO
if not. This variable was added in MySQL 5.1.10.
have_example_engine
YES if mysqld
supports EXAMPLE tables,
NO if not.
have_federated_engine
YES if mysqld
supports FEDERATED tables,
NO if not.
have_geometry
YES if the server supports spatial data
types, NO if not.
have_innodb
YES if mysqld
supports InnoDB tables.
DISABLED if
--skip-innodb is used.
have_ndbcluster
YES if mysqld
supports NDB Cluster tables.
DISABLED if
--skip-ndbcluster is used.
have_partitioning
YES if mysqld
supports partitioning. Added in MySQL 5.1.1 as
have_partition_engine and renamed to
have_partioning in 5.1.6.
have_openssl
YES if mysqld
supports SSL connections, NO if not.
have_query_cache
YES if mysqld
supports the query cache, NO if not.
have_row_based_replication
YES if the server can perform
replication using row-based binary logging. If the value
is NO, the server can use only
statement-based logging. See
Section 6.3, “Row-Based Replication”. This variable was
added in MySQL 5.1.5.
have_rtree_keys
YES if RTREE indexes
are available, NO if not. (These are
used for spatial indexes in MyISAM
tables.)
have_symlink
YES if symbolic link support is
enabled, NO if not. This is required on
Unix for support of the DATA DIRECTORY
and INDEX DIRECTORY table options, and
on Windows for support of data directory symlinks.
init_connect
A string to be executed by the server for each client that
connects. The string consists of one or more SQL
statements. To specify multiple statements, separate them
by semicolon characters. For example, each client begins
by default with autocommit mode enabled. There is no
global system variable to specify that autocommit should
be disabled by default, but
init_connect can be used to achieve the
same effect:
SET GLOBAL init_connect='SET AUTOCOMMIT=0';
This variable can also be set on the command line or in an option file. To set the variable as just shown using an option file, include these lines:
[mysqld] init_connect='SET AUTOCOMMIT=0'
Note that the content of init_connect
is not executed for users that have the
SUPER privilege. This is done so that
an erroneous value for init_connect
does not prevent all clients from connecting. For example,
the value might contain a statement that has a syntax
error, thus causing client connections to fail. Not
executing init_connect for users that
have the SUPER privilege enables them
to open a connection and fix the
init_connect value.
init_file
The name of the file specified with the
--init-file option when you start the
server. This should be a file containing SQL statements
that you want the server to execute when it starts. Each
statement must be on a single line and should not include
comments.
init_slave
This variable is similar to
init_connect, but is a string to be
executed by a slave server each time the SQL thread
starts. The format of the string is the same as for the
init_connect variable.
innodb_
xxx
InnoDB system variables are listed in
Section 15.2.4, “InnoDB Startup Options and System Variables”.
interactive_timeout
The number of seconds the server waits for activity on an
interactive connection before closing it. An interactive
client is defined as a client that uses the
CLIENT_INTERACTIVE option to
mysql_real_connect(). See also
wait_timeout.
join_buffer_size
The size of the buffer that is used for joins that do not
use indexes and thus perform full table scans. Normally,
the best way to get fast joins is to add indexes. Increase
the value of join_buffer_size to get a
faster full join when adding indexes is not possible. One
join buffer is allocated for each full join between two
tables. For a complex join between several tables for
which indexes are not used, multiple join buffers might be
necessary.
Index blocks for MyISAM tables are
buffered and are shared by all threads.
key_buffer_size is the size of the
buffer used for index blocks. The key buffer is also known
as the key cache.
The maximum allowable setting for
key_buffer_size is 4GB. The effective
maximum size might be less, depending on your available
physical RAM and per-process RAM limits imposed by your
operating system or hardware platform.
Increase the value to get better index handling (for all reads and multiple writes) to as much as you can afford. Using a value that is 25% of total memory on a machine that mainly runs MySQL is quite common. However, if you make the value too large (for example, more than 50% of your total memory) your system might start to page and become extremely slow. MySQL relies on the operating system to perform filesystem caching for data reads, so you must leave some room for the filesystem cache. Consider also the memory requirements of other storage engines.
For even more speed when writing many rows at the same
time, use LOCK TABLES. See
Section 7.2.16, “Speed of INSERT Statements”.
You can check the performance of the key buffer by issuing
a SHOW STATUS statement and examining
the Key_read_requests,
Key_reads,
Key_write_requests, and
Key_writes status variables. (See
Section 13.5.4, “SHOW Syntax”.) The
Key_reads/Key_read_requests ratio
should normally be less than 0.01. The
Key_writes/Key_write_requests ratio is
usually near 1 if you are using mostly updates and
deletes, but might be much smaller if you tend to do
updates that affect many rows at the same time or if you
are using the DELAY_KEY_WRITE table
option.
The fraction of the key buffer in use can be determined
using key_buffer_size in conjunction
with the Key_blocks_unused status
variable and the buffer block size, which is available
from the key_cache_block_size system
variable:
1 - ((Key_blocks_unused × key_cache_block_size) / key_buffer_size)
This value is an approximation because some space in the key buffer may be allocated internally for administrative structures.
It is possible to create multiple
MyISAM key caches. The size limit of
4GB applies to each cache individually, not as a group.
See Section 7.4.6, “The MyISAM Key Cache”.
key_cache_age_threshold
This value controls the demotion of buffers from the hot
sub-chain of a key cache to the warm sub-chain. Lower
values cause demotion to happen more quickly. The minimum
value is 100. The default value is 300. See
Section 7.4.6, “The MyISAM Key Cache”.
key_cache_block_size
The size in bytes of blocks in the key cache. The default
value is 1024. See Section 7.4.6, “The MyISAM Key Cache”.
key_cache_division_limit
The division point between the hot and warm sub-chains of
the key cache buffer chain. The value is the percentage of
the buffer chain to use for the warm sub-chain. Allowable
values range from 1 to 100. The default value is 100. See
Section 7.4.6, “The MyISAM Key Cache”.
language
The language used for error messages.
large_file_support
Whether mysqld was compiled with options for large file support.
large_pages
Whether large page support is enabled.
license
The type of license the server has.
local_infile
Whether LOCAL is supported for
LOAD DATA INFILE statements. See
Section 5.7.4, “Security Issues with LOAD DATA LOCAL”.
locked_in_memory
Whether mysqld was locked in memory
with --memlock.
log
Whether logging of all statements to the general query log is enabled. See Section 5.12.3, “The General Query Log”.
log_bin
Whether the binary log is enabled. See Section 5.12.4, “The Binary Log”.
log_bin_trust_function_creators
This variable applies when binary logging is enabled. It
controls whether stored function creators can be trusted
not to create stored functions that will cause unsafe
events to be written to the binary log. If set to 0 (the
default), users are not allowed to create or alter stored
routines unless they have the SUPER
privilege in addition to the CREATE
ROUTINE or ALTER ROUTINE
privilege. A setting of 0 also enforces the restriction
that a function must be declared with the
DETERMINISTIC characteristic, or with
the READS SQL DATA or NO
SQL characteristic. If the variable is set to 1,
MySQL does not enforce these restrictions on stored
function creation. See
Section 20.4, “Binary Logging of Stored Routines and Triggers”.
log_error
The location of the error log.
log_queries_not_using_indexes
Whether queries that do not use indexes are logged to the slow query log. See Section 5.12.5, “The Slow Query Log”. This variable was added in MySQL 5.1.11.
log_slave_updates
Whether updates received by a slave server from a master server should be logged to the slave's own binary log. Binary logging must be enabled on the slave for this variable to have any effect. See Section 6.9, “Replication Startup Options”.
log_slow_queries
Whether slow queries should be logged. “Slow”
is determined by the value of the
long_query_time variable. See
Section 5.12.5, “The Slow Query Log”.
log_warnings
Whether to produce additional warning messages. It is enabled (1) by default. Aborted connections are not logged to the error log unless the value is greater than 1.
long_query_time
If a query takes longer than this many seconds, the server
increments the Slow_queries status
variable. If you are using the
--log-slow-queries option, the query is
logged to the slow query log file. This value is measured
in real time, not CPU time, so a query that is under the
threshold on a lightly loaded system might be above the
threshold on a heavily loaded one. The minimum value is 1.
The default is 10. See Section 5.12.5, “The Slow Query Log”.
low_priority_updates
If set to 1, all
INSERT, UPDATE,
DELETE, and LOCK TABLE
WRITE statements wait until there is no pending
SELECT or LOCK TABLE
READ on the affected table. This variable
previously was named
sql_low_priority_updates.
lower_case_file_system
This variable describes the case sensitivity of filenames
on the filesystem where the data directory is located.
OFF means filenames are case sensitive,
ON means they are not case sensitive.
lower_case_table_names
If set to 1, table names are stored in lowercase on disk and table name comparisons are not case sensitive. If set to 2 table names are stored as given but compared in lowercase. This option also applies to database names and table aliases. See Section 9.2.2, “Identifier Case Sensitivity”.
If you are using InnoDB tables, you
should set this variable to 1 on all platforms to force
names to be converted to lowercase.
You should not set this variable to 0
if you are running MySQL on a system that does not have
case-sensitive filenames (such as Windows or Mac OS X). If
this variable is not set at startup and the filesystem on
which the data directory is located does not have
case-sensitive filenames, MySQL automatically sets
lower_case_table_names to 2.
max_allowed_packet
The maximum size of one packet or any generated/intermediate string.
The packet message buffer is initialized to
net_buffer_length bytes, but can grow
up to max_allowed_packet bytes when
needed. This value by default is small, to catch large
(possibly incorrect) packets.
You must increase this value if you are using large
BLOB columns or long strings. It should
be as big as the largest BLOB you want
to use. The protocol limit for
max_allowed_packet is 1GB.
max_binlog_cache_size
If a multiple-statement transaction requires more than
this amount of memory, the server generates a
Multi-statement transaction required more than
'max_binlog_cache_size' bytes of storage error.
max_binlog_size
If a write to the binary log causes the current log file size to exceed the value of this variable, the server rotates the binary logs (closes the current file and opens the next one). You cannot set this variable to more than 1GB or to less than 4096 bytes. The default value is 1GB.
A transaction is written in one chunk to the binary log,
so it is never split between several binary logs.
Therefore, if you have big transactions, you might see
binary logs larger than
max_binlog_size.
If max_relay_log_size is 0, the value
of max_binlog_size applies to relay
logs as well.
max_connect_errors
If there are more than this number of interrupted
connections from a host, that host is blocked from further
connections. You can unblock blocked hosts with the
FLUSH HOSTS statement.
max_connections
The number of simultaneous client connections allowed.
Increasing this value increases the number of file
descriptors that mysqld requires. See
Section 7.4.8, “How MySQL Opens and Closes Tables”, for comments on file
descriptor limits. See also
Section A.2.6, “Too many connections”.
max_delayed_threads
Do not start more than this number of threads to handle
INSERT DELAYED statements. If you try
to insert data into a new table after all INSERT
DELAYED threads are in use, the row is inserted
as if the DELAYED attribute wasn't
specified. If you set this to 0, MySQL never creates a
thread to handle DELAYED rows; in
effect, this disables DELAYED entirely.
max_error_count
The maximum number of error, warning, and note messages to
be stored for display by the SHOW
ERRORS and SHOW WARNINGS
statements.
max_heap_table_size
This variable sets the maximum size to which
MEMORY tables are allowed to grow. The
value of the variable is used to calculate
MEMORY table
MAX_ROWS values. Setting this variable
has no effect on any existing MEMORY
table, unless the table is re-created with a statement
such as CREATE TABLE or altered with
ALTER TABLE or TRUNCATE
TABLE.
max_insert_delayed_threads
This variable is a synonym for
max_delayed_threads.
max_join_size
Do not allow SELECT statements that
probably need to examine more than
max_join_size rows (for single-table
statements) or row combinations (for multiple-table
statements) or that are likely to do more than
max_join_size disk seeks. By setting
this value, you can catch SELECT
statements where keys are not used properly and that would
probably take a long time. Set it if your users tend to
perform joins that lack a WHERE clause,
that take a long time, or that return millions of rows.
Setting this variable to a value other than
DEFAULT resets the value of
SQL_BIG_SELECTS to
0. If you set the
SQL_BIG_SELECTS value again, the
max_join_size variable is ignored.
If a query result is in the query cache, no result size check is performed, because the result has previously been computed and it does not burden the server to send it to the client.
This variable previously was named
sql_max_join_size.
max_length_for_sort_data
The cutoff on the size of index values that determines
which filesort algorithm to use. See
Section 7.2.12, “ORDER BY Optimization”.
max_prepared_stmt_count
This variable limits the total number of prepared statements in the server. It can be used in environments where there is the potential for denial-of-service attacks based on running the server out of memory by preparing huge numbers of statements. The default value is 16,382. The allowable range of values is from 0 to 1 milliion. If the value is set lower than the current number of prepared statements, existing statements are not affected and can be used, but no new statements can be prepared until the current number drops below the limit. This variable was added in MySQL 5.1.10.
max_relay_log_size
If a write by a replication slave to its relay log causes
the current log file size to exceed the value of this
variable, the slave rotates the relay logs (closes the
current file and opens the next one). If
max_relay_log_size is 0, the server
uses max_binlog_size for both the
binary log and the relay log. If
max_relay_log_size is greater than 0,
it constrains the size of the relay log, which enables you
to have different sizes for the two logs. You must set
max_relay_log_size to between 4096
bytes and 1GB (inclusive), or to 0. The default value is
0. See
Section 6.4, “Replication Implementation Details”.
max_seeks_for_key
Limit the assumed maximum number of seeks when looking up
rows based on a key. The MySQL optimizer assumes that no
more than this number of key seeks are required when
searching for matching rows in a table by scanning an
index, regardless of the actual cardinality of the index
(see Section 13.5.4.17, “SHOW INDEX Syntax”). By setting this to a
low value (say, 100), you can force MySQL to prefer
indexes instead of table scans.
max_sort_length
The number of bytes to use when sorting
BLOB or TEXT values.
Only the first max_sort_length bytes of
each value are used; the rest are ignored.
max_tmp_tables
The maximum number of temporary tables a client can keep open at the same time. (This option does not yet do anything.)
max_user_connections
The maximum number of simultaneous connections allowed to any given MySQL account. A value of 0 means “no limit.”
This variable has both a global scope and a (read-only)
session scope. The session variable has the same value as
the global variable unless the current account has a
non-zero MAX_USER_CONNECTIONS resource
limit. In that case, the session value reflects the
account limit.
max_write_lock_count
After this many write locks, allow some pending read lock requests to be processed in between.
myisam_data_pointer_size
The default pointer size in bytes, to be used by
CREATE TABLE for
MyISAM tables when no
MAX_ROWS option is specified. This
variable cannot be less than 2 or larger than 7. The
default value is 6. See Section A.2.11, “The table is full”.
myisam_max_extra_sort_file_size
(DEPRECATED)
Note: This variable is not supported in MySQL 5.1. See MySQL 5.0 Reference Manual for more information.
myisam_max_sort_file_size
The maximum size of the temporary file that MySQL is
allowed to use while re-creating a
MyISAM index (during REPAIR
TABLE, ALTER TABLE, or
LOAD DATA INFILE). If the file size
would be larger than this value, the index is created
using the key cache instead, which is slower. The value is
given in bytes.
myisam_recover_options
The value of the --myisam-recover option.
See Section 5.2.1, “mysqld Command Options”.
myisam_repair_threads
If this value is greater than 1, MyISAM
table indexes are created in parallel (each index in its
own thread) during the Repair by
sorting process. The default value is 1.
Note: Multi-threaded repair is still beta-quality code.
myisam_sort_buffer_size
The size of the buffer that is allocated when sorting
MyISAM indexes during a REPAIR
TABLE or when creating indexes with
CREATE INDEX or ALTER
TABLE.
myisam_stats_method
How the server treats NULL values when
collecting statistics about the distribution of index
values for MyISAM tables. This variable
has two possible values, nulls_equal
and nulls_unequal. For
nulls_equal, all
NULL index values are considered equal
and form a single value group that has a size equal to the
number of NULL values. For
nulls_unequal, NULL
values are considered unequal, and each
NULL forms a distinct value group of
size 1.
The method that is used for generating table statistics
influences how the optimizer chooses indexes for query
execution, as described in
Section 7.4.7, “MyISAM Index Statistics Collection”.
myisam_use_mmap
Use memory mapping for reading and writing
MyISAM tables. This variable was added
in MySQL 5.1.4.
multi_read_range
Specifies the maximum number of ranges to send to a
storage engine during range selects. The default value is
256. Sending multiple ranges to an engine is a feature
that can improve the performance of certain selects
dramatically, particularly for
NDBCLUSTER. This engine needs to send
the range requests to all nodes, and sending many of those
requests at once reduces the communication costs
significantly.
named_pipe
(Windows only.) Indicates whether the server supports connections over named pipes.
ndb_autoincrement_prefetch_sz
Determines the probability of gaps in an autoincremented
column. Set to 1 to minimize this. Set
to a high value for optimization — makes inserts
faster, but decreases the likelihood that consecutive
autoincrement numbers will be used in a batch of inserts.
Default value: 32. Mimimum value:
1.
ndb_cache_check_time
The number of milliseconds to wait before checking the
NDB query cache. Setting this to
0 (the default and minimum value) means
that the NDB query cache will be
checked for validation on every query.
The recommended maximum value for this variable is
1000, which means that the query cache
is checked once per second. A larger value means the
NDB query cache is less often checked
and invalidated due to updates on a different
mysqld. It is generally not desirable
to set this to a value greater than
2000.
ndb_extra_logging
This variable can be set to a non-zero value to enable
extra NDB logging for debugging or
troubleshooting purposes. The default value is
0.
This variable was added in MySQL 5.1.6.
ndb_force_send
Forces sending of buffers to NDB
immediately, without waiting for other threads. Defaults
to ON.
ndb_index_stat_cache_entries
Sets the granularity of the statistics by determining the
number of starting and ending keys to store in the
statistics memory cache. Zero means no caching takes
place; in this case, the data nodes are always queries
directly. Default value: 32.
ndb_index_stat_enable
Use NDB index statistics in query
optimization. Defaults to ON.
ndb_index_stat_update_freq
How often to query data nodes instead of the statistics
cache. For example, a value of 20 (the
default) means to direct every
20th query to the data nodes.
ndb_report_thresh_binlog_epoch_slip
This is a threshold on the number of epochs to be behind
before reporting binlog status. For example, a value of
3 (the default) means that if the
difference between which epoch has been received from the
storage nodes and which epoch has been applied to the
binlog is 3 or more, a status message will be sent to the
cluster log.
ndb_report_thresh_binlog_mem_usage
This is a threshold on the percentage of free memory
remaining before reporting binlog status. For example, a
value of 10 (the default) means that if
the amount of available memory for receiving binlog data
from the data nodes falls below 10%, a status message will
be sent to the cluster log.
ndb_use_copying_alter_table
Forces NDB to use copying of tables in
the event of problems with online ALTER
TABLE operations. The default value is
OFF.
This variable was added in MySQL 5.1.12.
ndb_use_exact_count
Forces NDB to use an count of records
during SELECT COUNT(*) query planning
to speed up this type of query. The default value is
ON. For faster queries overall, disable
this feature by setting the value of
ndb_use_exact_count to
OFF.
ndb_use_transactions
You can disable NDB transaction support
by setting this variable's values to
OFF (not recommended). The default is
ON.
net_buffer_length
The communication buffer is reset to this size between SQL
statements. This variable should not normally be changed,
but if you have very little memory, you can set it to the
expected length of statements sent by clients. If
statements exceed this length, the buffer is automatically
enlarged, up to max_allowed_packet
bytes.
net_read_timeout
The number of seconds to wait for more data from a
connection before aborting the read. This timeout applies
only to TCP/IP connections, not to connections made via
Unix socket files, named pipes, or shared memory. When the
server is reading from the client,
net_read_timeout is the timeout value
controlling when to abort. When the server is writing to
the client, net_write_timeout is the
timeout value controlling when to abort. See also
slave_net_timeout.
net_retry_count
If a read on a communication port is interrupted, retry this many times before giving up. This value should be set quite high on FreeBSD because internal interrupts are sent to all threads.
net_write_timeout
The number of seconds to wait for a block to be written to
a connection before aborting the write. This timeout
applies only to TCP/IP connections, not to connections
made via Unix socket files, named pipes, or shared memory.
See also net_read_timeout.
new
This variable was used in MySQL 4.0 to turn on some 4.1
behaviors, and is retained for backward compatibility. In
MySQL 5.1, its value is always
OFF.
old_passwords
Whether the server should use pre-4.1-style passwords for
MySQL user accounts. See Section A.2.3, “Client does not support authentication protocol”.
one_shot
This is not a variable, but it can be used when setting
some variables. It is described in
Section 13.5.3, “SET Syntax”.
open_files_limit
The number of files that the operating system allows
mysqld to open. This is the real value
allowed by the system and might be different from the
value you gave using the
--open-files-limit option to
mysqld or
mysqld_safe. The value is 0 on systems
where MySQL can't change the number of open files.
optimizer_prune_level
Controls the heuristics applied during query optimization to prune less-promising partial plans from the optimizer search space. A value of 0 disables heuristics so that the optimizer performs an exhaustive search. A value of 1 causes the optimizer to prune plans based on the number of rows retrieved by intermediate plans.
optimizer_search_depth
The maximum depth of search performed by the query optimizer. Values larger than the number of relations in a query result in better query plans, but take longer to generate an execution plan for a query. Values smaller than the number of relations in a query return an execution plan quicker, but the resulting plan may be far from being optimal. If set to 0, the system automatically picks a reasonable value. If set to the maximum number of tables used in a query plus 2, the optimizer switches to the algorithm used in MySQL 5.0.0 (and previous versions) for performing searches.
pid_file
The pathname of the process ID (PID) file. This variable
can be set with the --pid-file option.
plugin_dir
The pathname of the plugins directory. This variable was added in MySQL 5.1.2.
port
The number of the port on which the server listens for
TCP/IP connections. This variable can be set with the
--port option.
preload_buffer_size
The size of the buffer that is allocated when preloading indexes.
prepared_stmt_count
The current number of prepared statements. (The maximum
number of statements is given by the
max_prepared_stmt_count system
variable.) This variable was added in MySQL 5.1.10.
protocol_version
The version of the client/server protocol used by the MySQL server.
query_alloc_block_size
The allocation size of memory blocks that are allocated for objects created during statement parsing and execution. If you have problems with memory fragmentation, it might help to increase this a bit.
query_cache_limit
Don't cache results that are larger than this number of bytes. The default value is 1MB.
query_cache_min_res_unit
The minimum size (in bytes) for blocks allocated by the query cache. The default value is 4096 (4KB). Tuning information for this variable is given in Section 5.14.3, “Query Cache Configuration”.
query_cache_size
The amount of memory allocated for caching query results.
The default value is 0, which disables the query cache.
The allowable values are multiples of 1024; other values
are rounded down to the nearest multiple. Note that
query_cache_size bytes of memory are
allocated even if query_cache_type is
set to 0. See Section 5.14.3, “Query Cache Configuration”,
for more information.
query_cache_type
Set the query cache type. Setting the
GLOBAL value sets the type for all
clients that connect thereafter. Individual clients can
set the SESSION value to affect their
own use of the query cache. Possible values are shown in
the following table:
| Option | Description |
0 or OFF | Don't cache results in or retrieve results from the query cache. Note
that this does not deallocate the query cache
buffer. To do that, you should set
query_cache_size to 0. |
1 or ON | Cache all query results except for those that begin with SELECT
SQL_NO_CACHE. |
2 or DEMAND | Cache results only for queries that begin with SELECT
SQL_CACHE. |
This variable defaults to ON.
query_cache_wlock_invalidate
Normally, when one client acquires a
WRITE lock on a
MyISAM table, other clients are not
blocked from issuing statements that read from the table
if the query results are present in the query cache.
Setting this variable to 1 causes acquisition of a
WRITE lock for a table to invalidate
any queries in the query cache that refer to the table.
This forces other clients that attempt to access the table
to wait while the lock is in effect.
query_prealloc_size
The size of the persistent buffer used for statement
parsing and execution. This buffer is not freed between
statements. If you are running complex queries, a larger
query_prealloc_size value might be
helpful in improving performance, because it can reduce
the need for the server to perform memory allocation
during query execution operations.
range_alloc_block_size
The size of blocks that are allocated when doing range optimization.
read_buffer_size
Each thread that does a sequential scan allocates a buffer of this size (in bytes) for each table it scans. If you do many sequential scans, you might want to increase this value, which defaults to 131072.
read_only
When the variable is set to ON for a
replication slave server, it causes the slave to allow no
updates except from slave threads or from users that have
the SUPER privilege. This can be useful
to ensure that a slave server accepts updates only from
its master server and not from clients. This variable does
not apply to TEMPORARY tables.
relay_log_purge
Disables or enables automatic purging of relay log files
as soon as they are not needed any more. The default value
is 1 (ON).
read_rnd_buffer_size
When reading rows in sorted order following a key-sorting
operation, the rows are read through this buffer to avoid
disk seeks. Setting the variable to a large value can
improve ORDER BY performance by a lot.
However, this is a buffer allocated for each client, so
you should not set the global variable to a large value.
Instead, change the session variable only from within
those clients that need to run large queries.
rpl_recovery_rank
This variable is unused.
secure_auth
If the MySQL server has been started with the
--secure-auth option, it blocks
connections from all accounts that have passwords stored
in the old (pre-4.1) format. In that case, the value of
this variable is ON, otherwise it is
OFF.
You should enable this option if you want to prevent all use of passwords employing the old format (and hence insecure communication over the network).
Server startup fails with an error if this option is
enabled and the privilege tables are in pre-4.1 format.
See Section A.2.3, “Client does not support authentication protocol”.
server_id
The server ID. This value is set by the
--server-id option. It is used for
replication to enable master and slave servers to identify
themselves uniquely.
shared_memory
(Windows only.) Whether the server allows shared-memory connections.
shared_memory_base_name
(Windows only.) The name of shared memory to use for
shared-memory connections. This is useful when running
multiple MySQL instances on a single physical machine. The
default name is MYSQL. The name is case
sensitive.
This is OFF if
mysqld uses external locking,
ON if external locking is disabled.
skip_networking
This is ON if the server allows only
local (non-TCP/IP) connections. On Unix, local connections
use a Unix socket file. On Windows, local connections use
a named pipe or shared memory. On NetWare, only TCP/IP
connections are supported, so do not set this variable to
ON. This variable can be set to
ON with the
--skip-networking option.
skip_show_database
This prevents people from using the SHOW
DATABASES statement if they do not have the
SHOW DATABASES privilege. This can
improve security if you have concerns about users being
able to see databases belonging to other users. Its effect
depends on the SHOW DATABASES
privilege: If the variable value is ON,
the SHOW DATABASES statement is allowed
only to users who have the SHOW
DATABASES privilege, and the statement displays
all database names. If the value is
OFF, SHOW DATABASES
is allowed to all users, but displays the names of only
those databases for which the user has the SHOW
DATABASES or other privilege.
slave_compressed_protocol
Whether to use compression of the slave/master protocol if both the slave and the master support it.
slave_load_tmpdir
The name of the directory where the slave creates
temporary files for replicating LOAD DATA
INFILE statements.
slave_net_timeout
The number of seconds to wait for more data from a master/slave connection before aborting the read. This timeout applies only to TCP/IP connections, not to connections made via Unix socket files, named pipes, or shared memory.
slave_skip_errors
The replication errors that the slave should skip (ignore).
slave_transaction_retries
If a replication slave SQL thread fails to execute a
transaction because of an InnoDB
deadlock or exceeded InnoDB's
innodb_lock_wait_timeout or
NDBCluster's
TransactionDeadlockDetectionTimeout or
TransactionInactiveTimeout, it
automatically retries
slave_transaction_retries times before
stopping with an error. The default value is 10.
slow_launch_time
If creating a thread takes longer than this many seconds,
the server increments the
Slow_launch_threads status variable.
socket
On Unix platforms, this variable is the name of the socket
file that is used for local client connections. The
default is /tmp/mysql.sock. (For some
distribution formats, the directory might be different,
such as /var/lib/mysql for RPMs.)
On Windows, this variable is the name of the named pipe
that is used for local client connections. The default
value is MySQL (not case sensitive).
sort_buffer_size
Each thread that needs to do a sort allocates a buffer of
this size. Increase this value for faster ORDER
BY or GROUP BY operations.
See Section A.4.4, “Where MySQL Stores Temporary Files”.
sql_mode
The current server SQL mode, which can be set dynamically. See Section 5.2.5, “The Server SQL Mode”.
sql_slave_skip_counter
The number of events from the master that a slave server
should skip. See
Section 13.6.2.6, “SET GLOBAL SQL_SLAVE_SKIP_COUNTER Syntax”.
ssl_ca
The path to a file with a list of trusted SSL CAs. This variable was added in MySQL 5.1.11.
ssl_capath
The path to a directory that contains trusted SSL CA certificates in PEM format. This variable was added in MySQL 5.1.11.
ssl_cert
The name of the SSL certificate file to use for establishing a secure connection. This variable was added in MySQL 5.1.11.
ssl_cipher
A list of allowable ciphers to use for SSL encryption. The
cipher list has the same format as the openssl
ciphers command. This variable was added in
MySQL 5.1.11.
ssl_key
The name of the SSL key file to use for establishing a secure connection. This variable was added in MySQL 5.1.11.
storage_engine
The default storage engine (table type). To set the
storage engine at server startup, use the
--default-storage-engine option. See
Section 5.2.1, “mysqld Command Options”.
sync_binlog
If the value of this variable is positive, the MySQL
server synchronizes its binary log to disk (using
fdatasync()) after every
sync_binlog writes to the binary log.
Note that there is one write to the binary log per
statement if autocommit is enabled, and one write per
transaction otherwise. The default value is 0, which does
no synchronizing to disk. A value of 1 is the safest
choice, because in the event of a crash you lose at most
one statement or transaction from the binary log. However,
it is also the slowest choice (unless the disk has a
battery-backed cache, which makes synchronization very
fast).
If the value of sync_binlog is 0 (the
default), no extra flushing is done. The server relies on
the operating system to flush the file contents
occasionaly as for any other file.
sync_frm
If this variable is set to 1, when any non-temporary table
is created its .frm file is
synchronized to disk (using
fdatasync()). This is slower but safer
in case of a crash. The default is 1.
system_time_zone
The server system time zone. When the server begins
executing, it inherits a time zone setting from the
machine defaults, possibly modified by the environment of
the account used for running the server or the startup
script. The value is used to set
system_time_zone. Typically the time
zone is specified by the TZ environment
variable. It also can be specified using the
--timezone option of the
mysqld_safe script.
The system_time_zone variable differs
from time_zone. Although they might
have the same value, the latter variable is used to
initialize the time zone for each client that connects.
See Section 5.11.8, “MySQL Server Time Zone Support”.
table_cache
This is the old name of
table_open_cache before MySQL 5.1.3.
From 5.1.3 on, use table_open_cache
instead.
table_definition_cache
The number of table definitions that can be stored in the definition cache. If you use a large number of tables, you can create a large table definition cache to speed up opening of tables. The table definition cache takes less space and does not use file descriptors, unlike the normal table cache. This variable was added in MySQL 5.1.3.
table_lock_wait_timeout
Specifies a wait timeout for table-level locks, in
seconds. The default timeout is 50 seconds. The timeout is
active only if the connection has open cursors. This
variable can also be set globally at runtime (you need the
SUPER privilege to do this).
table_open_cache
The number of open tables for all threads. Increasing this
value increases the number of file descriptors that
mysqld requires. You can check whether
you need to increase the table cache by checking the
Opened_tables status variable. See
Section 5.2.4, “Server Status Variables”. If the value of
Opened_tables is large and you don't do
FLUSH TABLES often (which just forces
all tables to be closed and reopened), then you should
increase the value of the
table_open_cache variable. For more
information about the table cache, see
Section 7.4.8, “How MySQL Opens and Closes Tables”. Before MySQL 5.1.3, this
variable is called table_cache.
table_type
This variable is a synonym for
storage_engine. In MySQL
5.1, storage_engine is the
preferred name.
thread_cache_size
How many threads the server should cache for reuse. When a
client disconnects, the client's threads are put in the
cache if there are fewer than
thread_cache_size threads there.
Requests for threads are satisfied by reusing threads
taken from the cache if possible, and only when the cache
is empty is a new thread created. This variable can be
increased to improve performance if you have a lot of new
connections. (Normally, this doesn't provide a notable
performance improvement if you have a good thread
implementation.) By examining the difference between the
Connections and
Threads_created status variables, you
can see how efficient the thread cache is. For details,
see Section 5.2.4, “Server Status Variables”.
thread_concurrency
On Solaris, mysqld calls
thr_setconcurrency() with this value.
This function enables applications to give the threads
system a hint about the desired number of threads that
should be run at the same time.
thread_stack
The stack size for each thread. Many of the limits
detected by the crash-me test are
dependent on this value. The default is large enough for
normal operation. See Section 7.1.4, “The MySQL Benchmark Suite”.
The default is 192KB.
time_format
This variable is not implemented.
time_zone
The current time zone. This variable is used to initialize
the tome zone for each client that connects. By default,
the initial value of this is 'SYSTEM'
(which means, “use the value of
system_time_zone”). The value
can be specified explicitly at server startup with the
--default-time-zone option. See
Section 5.11.8, “MySQL Server Time Zone Support”.
tmp_table_size
The maximum size of in-memory temporary tables. (The
actual limit is determined as the smaller of
max_heap_table_size and
tmp_table_size.) If an in-memory
temporary table exceeds the limit, MySQL automatically
converts it to an on-disk MyISAM table.
Increase the value of tmp_table_size
(and max_heap_table_size if necessary)
if you do many advanced GROUP BY
queries and you have lots of memory.
tmpdir
The directory used for temporary files and temporary
tables. This variable can be set to a list of several
paths that are used in round-robin fashion. Paths should
be separated by colon characters
(‘:’) on Unix and semicolon
characters (‘;’) on
Windows, NetWare, and OS/2.
The multiple-directory feature can be used to spread the
load between several physical disks. If the MySQL server
is acting as a replication slave, you should not set
tmpdir to point to a directory on a
memory-based filesystem or to a directory that is cleared
when the server host restarts. A replication slave needs
some of its temporary files to survive a machine restart
so that it can replicate temporary tables or LOAD
DATA INFILE operations. If files in the
temporary file directory are lost when the server
restarts, replication fails. However, if you are using
MySQL 4.0.0 or later, you can set the slave's temporary
directory using the slave_load_tmpdir
variable. In that case, the slave won't use the general
tmpdir value and you can set
tmpdir to a non-permanent location.
transaction_alloc_block_size
The amount in bytes by which to increase a per-transaction
memory pool which needs memory. See the description of
transaction_prealloc_size.
transaction_prealloc_size
There is a per-transaction memory pool from which various
transaction-related allocations take memory. The initial
size of the pool in bytes is
transaction_prealloc_size. For every
allocation that cannot be satisfied from the pool because
it has insufficient memory available, the pool is
increased by
transaction_alloc_block_size bytes.
When the transaction ends, the pool is truncated to
transaction_prealloc_size bytes.
By making transaction_prealloc_size
sufficiently large to contain all statements within a
single transaction, you can avoid many
malloc() calls.
tx_isolation
The default transaction isolation level. Defaults to
REPEATABLE-READ.
This variable is set by the SET TRANSACTION
ISOLATION LEVEL statement. See
Section 13.4.6, “SET TRANSACTION Syntax”. If you set
tx_isolation directly to an isolation
level name that contains a space, the name should be
enclosed within quotes, with the space replaced by a dash.
For example:
SET tx_isolation = 'READ-COMMITTED';
updatable_views_with_limit
This variable controls whether updates can be made using a
view that does not contain a primary key in the underlying
table, if the update contains a LIMIT
clause. (Such updates often are generated by GUI tools.)
An update is an UPDATE or
DELETE statement. Primary key here
means a PRIMARY KEY, or a
UNIQUE index in which no column can
contain NULL.
The variable can have two values:
1 or YES: Issue
a warning only (not an error message). This is the
default value.
0 or NO:
Prohibit the update.
version
The version number for the server.
version_bdb
The BDB storage engine version.
version_comment
The configure script has a
--with-comment option that allows a
comment to be specified when building MySQL. This variable
contains the value of that comment.
version_compile_machine
The type of machine or architecture on which MySQL was built.
version_compile_os
The type of operating system on which MySQL was built.
wait_timeout
The number of seconds the server waits for activity on a non-interactive connection before closing it. This timeout applies only to TCP/IP connections, not to connections made via Unix socket files, named pipes, or shared memory.
On thread startup, the session
wait_timeout value is initialized from
the global wait_timeout value or from
the global interactive_timeout value,
depending on the type of client (as defined by the
CLIENT_INTERACTIVE connect option to
mysql_real_connect()). See also
interactive_timeout.
The mysql server maintains many system
variables that indicate how it is configured.
Section 5.2.2, “Server System Variables”, describes the
meaning of these variables. Each system variable has a default
value. System variables can be set at server startup using
options on the command line or in an option file. Most of them
can be changed dynamically while the server is running by
means of the SET statement, which enables
you to modify operation of the server without having to stop
and restart it. You can refer to system variable values in
expressions.
The server maintains two kinds of system variables. Global variables affect the overall operation of the server. Session variables affect its operation for individual client connections. A given system variable can have both a global and a session value. Global and session system variables are related as follows:
When the server starts, it initializes all global variables to their default values. These defaults can be changed by options specified on the command line or in an option file. (See Section 4.3, “Specifying Program Options”.)
The server also maintains a set of session variables for
each client that connects. The client's session variables
are initialized at connect time using the current values
of the corresponding global variables. For example, the
client's SQL mode is controlled by the session
sql_mode value, which is initialized
when the client connects to the value of the global
sql_mode value.
System variable values can be set globally at server startup
by using options on the command line or in an option file.
When you use a startup option to set a variable that takes a
numeric value, the value can be given with a suffix of
K, M, or
G (either uppercase or lowercase) to
indicate a multiplier of 1024,
10242 or
10243; that is, units of kilobytes,
megabytes, or gigabygtes, respectively. Thus, the following
command starts the server with a query cache size of 16
megabytes and a maximum packet size of one gigabyte:
mysqld --query_cache_size=16M --max_allowed_packet=1G
Within an option file, those variables are set like this:
[mysqld] query_cache_size=16M max_allowed_packet=1G
The lettercase of suffix letters does not matter;
16M and 16m are
equivalent, as are 1G and
1g.
If you want to restrict the maximum value to which a system
variable can be set at runtime with the SET
statement, you can specify this maximum by using an option of
the form
--maximum-
at server startup. For example, to prevent the value of
var_name=valuequery_cache_size from being increased to
more than 32MB at runtime, use the option
--maximum-query_cache_size=32M.
Many system variables are dynamic and can be changed while the
server runs by using the SET statement. For
a list, see Section 5.2.3.2, “Dynamic System Variables”. To
change a system variable with SET, refer to
it as var_name, optionally preceded
by a modifier:
To indicate explicitly that a variable is a global
variable, precede its name by GLOBAL or
@@global.. The SUPER
privilege is required to set global variables.
To indicate explicitly that a variable is a session
variable, precede its name by SESSION,
@@session., or @@.
Setting a session variable requires no special privilege,
but a client can change only its own session variables,
not those of any other client.
LOCAL and @@local.
are synonyms for SESSION and
@@session..
If no modifier is present, SET changes
the session variable.
A SET statement can contain multiple
variable assignments, separated by commas. If you set several
system variables, the most recent GLOBAL or
SESSION modifier in the statement is used
for following variables that have no modifier specified.
Examples:
SET sort_buffer_size=10000; SET @@local.sort_buffer_size=10000; SET GLOBAL sort_buffer_size=1000000, SESSION sort_buffer_size=1000000; SET @@sort_buffer_size=1000000; SET @@global.sort_buffer_size=1000000, @@local.sort_buffer_size=1000000;
When you assign a value to a system variable with
SET, you cannot use suffix letters in the
value (as can be done with startup options). However, the
value can take the form of an expression:
SET sort_buffer_size = 10 * 1024 * 1024;
The @@
syntax for system variables is supported for compatibility
with some other database systems.
var_name
If you change a session system variable, the value remains in effect until your session ends or until you change the variable to a different value. The change is not visible to other clients.
If you change a global system variable, the value is
remembered and used for new connections until the server
restarts. (To make a global system variable setting permanent,
you should set it in an option file.) The change is visible to
any client that accesses that global variable. However, the
change affects the corresponding session variable only for
clients that connect after the change. The global variable
change does not affect the session variable for any client
that is currently connected (not even that of the client that
issues the SET GLOBAL statement).
To prevent incorrect usage, MySQL produces an error if you use
SET GLOBAL with a variable that can only be
used with SET SESSION or if you do not
specify GLOBAL (or
@@global.) when setting a global variable.
To set a SESSION variable to the
GLOBAL value or a GLOBAL
value to the compiled-in MySQL default value, use the
DEFAULT keyword. For example, the following
two statements are identical in setting the session value of
max_join_size to the global value:
SET max_join_size=DEFAULT; SET @@session.max_join_size=@@global.max_join_size;
Not all system variables can be set to
DEFAULT. In such cases, use of
DEFAULT results in an error.
You can refer to the values of specific global or sesson
system variables in expressions by using one of the
@@-modifiers. For example, you can retrieve
values in a SELECT statement like this:
SELECT @@global.sql_mode, @@session.sql_mode, @@sql_mode;
When you refer to a system variable in an expression as
@@ (that
is, when you do not specify var_name@@global. or
@@session.), MySQL returns the session
value if it exists and the global value otherwise. (This
differs from SET
@@, which always
refers to the session value.)
var_name =
value
Note: Some system variables can be
enabled with the SET statement by setting
them to ON or 1, or
disabled by setting them to OFF or
0. However, to set such a variable on the
command line or in an option file, you must set it to
1 or 0; setting it to
ON or OFF will not work.
For example, on the command line,
--delay_key_write=1 works but
--delay_key_write=ON does not.
To display system variable names and values, use the
SHOW VARIABLES statement.
mysql> SHOW VARIABLES;
+---------------------------------+--------------------------------------+
| Variable_name | Value |
+---------------------------------+--------------------------------------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
| automatic_sp_privileges | ON |
| back_log | 50 |
| basedir | /home/jon/bin/mysql/ |
| binlog_cache_size | 32768 |
| bulk_insert_buffer_size | 8388608 |
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/bin/mysql/share/mysql/charsets/ |
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
...
| innodb_additional_mem_pool_size | 1048576 |
| innodb_autoextend_increment | 8 |
| innodb_buffer_pool_awe_mem_mb | 0 |
| innodb_buffer_pool_size | 8388608 |
| innodb_checksums | ON |
| innodb_commit_concurrency | 0 |
| innodb_concurrency_tickets | 500 |
| innodb_data_file_path | ibdata1:10M:autoextend |
| innodb_data_home_dir | |
...
| version | 5.1.6-alpha-log |
| version_comment | Source distribution |
| version_compile_machine | i686 |
| version_compile_os | suse-linux |
| wait_timeout | 28800 |
+---------------------------------+--------------------------------------+
With a LIKE clause, the statement displays
only those variables that match the pattern. To obtain a
specific variable name, use a LIKE clause
as shown:
SHOW VARIABLES LIKE 'max_join_size'; SHOW SESSION VARIABLES LIKE 'max_join_size';
To get a list of variables whose name match a pattern, use the
‘%’ wildcard character in a
LIKE clause:
SHOW VARIABLES LIKE '%size%'; SHOW GLOBAL VARIABLES LIKE '%size%';
Wildcard characters can be used in any position within the
pattern to be matched. Strictly speaking, because
‘_’ is a wildcard that matches
any single character, you should escape it as
‘\_’ to match it literally. In
practice, this is rarely necessary.
For SHOW VARIABLES, if you specify neither
GLOBAL nor SESSION,
MySQL returns SESSION values.
The reason for requiring the GLOBAL keyword
when setting GLOBAL-only variables but not
when retrieving them is to prevent problems in the future. If
we were to remove a SESSION variable that
has the same name as a GLOBAL variable, a
client with the SUPER privilege might
accidentally change the GLOBAL variable
rather than just the SESSION variable for
its own connection. If we add a SESSION
variable with the same name as a GLOBAL
variable, a client that intends to change the
GLOBAL variable might find only its own
SESSION variable changed.
A structured variable differs from a regular system variable in two respects:
Its value is a structure with components that specify server parameters considered to be closely related.
There might be several instances of a given type of structured variable. Each one has a different name and refers to a different resource maintained by the server.
MySQL 5.1 supports one structured variable type, which specifies parameters governing the operation of key caches. A key cache structured variable has these components:
key_buffer_size
key_cache_block_size
key_cache_division_limit
key_cache_age_threshold
This section describes the syntax for referring to
structured variables. Key cache variables are used for
syntax examples, but specific details about how key caches
operate are found elsewhere, in
Section 7.4.6, “The MyISAM Key Cache”.
To refer to a component of a structured variable instance,
you can use a compound name in
instance_name.component_name
format. Examples:
hot_cache.key_buffer_size hot_cache.key_cache_block_size cold_cache.key_cache_block_size
For each structured system variable, an instance with the
name of default is always predefined. If
you refer to a component of a structured variable without
any instance name, the default instance
is used. Thus, default.key_buffer_size
and key_buffer_size both refer to the
same system variable.
Structured variable instances and components follow these naming rules:
For a given type of structured variable, each instance
must have a name that is unique
within variables of that type.
However, instance names need not be unique
across structured variable types.
For example, each structured variable has an instance
named default, so
default is not unique across variable
types.
The names of the components of each structured variable type must be unique across all system variable names. If this were not true (that is, if two different types of structured variables could share component member names), it would not be clear which default structured variable to use for references to member names that are not qualified by an instance name.
If a structured variable instance name is not legal as
an unquoted identifier, refer to it as a quoted
identifier using backticks. For example,
hot-cache is not legal, but
`hot-cache` is.
global, session,
and local are not legal instance
names. This avoids a conflict with notation such as
@@global.
for referring to non-structured system variables.
var_name
Currently, the first two rules have no possibility of being violated because the only structured variable type is the one for key caches. These rules will assume greater significance if some other type of structured variable is created in the future.
With one exception, you can refer to structured variable components using compound names in any context where simple variable names can occur. For example, you can assign a value to a structured variable using a command-line option:
shell> mysqld --hot_cache.key_buffer_size=64K
In an option file, use this syntax:
[mysqld] hot_cache.key_buffer_size=64K
If you start the server with this option, it creates a key
cache named hot_cache with a size of 64KB
in addition to the default key cache that has a default size
of 8MB.
Suppose that you start the server as follows:
shell>mysqld --key_buffer_size=256K \--extra_cache.key_buffer_size=128K \--extra_cache.key_cache_block_size=2048
In this case, the server sets the size of the default key
cache to 256KB. (You could also have written
--default.key_buffer_size=256K.) In
addition, the server creates a second key cache named
extra_cache that has a size of 128KB,
with the size of block buffers for caching table index
blocks set to 2048 bytes.
The following example starts the server with three different key caches having sizes in a 3:1:1 ratio:
shell>mysqld --key_buffer_size=6M \--hot_cache.key_buffer_size=2M \--cold_cache.key_buffer_size=2M
Structured variable values may be set and retrieved at
runtime as well. For example, to set a key cache named
hot_cache to a size of 10MB, use either
of these statements:
mysql>SET GLOBAL hot_cache.key_buffer_size = 10*1024*1024;mysql>SET @@global.hot_cache.key_buffer_size = 10*1024*1024;
To retrieve the cache size, do this:
mysql> SELECT @@global.hot_cache.key_buffer_size;
However, the following statement does not work. The variable
is not interpreted as a compound name, but as a simple
string for a LIKE pattern-matching
operation:
mysql> SHOW GLOBAL VARIABLES LIKE 'hot_cache.key_buffer_size';
This is the exception to being able to use structured variable names anywhere a simple variable name may occur.
Many server system variables are dynamic and can be set at
runtime using SET GLOBAL or SET
SESSION. You can also obtain their values using
SELECT. See
Section 5.2.3, “Using System Variables”.
The following table shows the full list of all dynamic
system variables. The last column indicates for each
variable whether GLOBAL or
SESSION (or both) apply. The table also
lists session options that can be set with the
SET statement.
Section 13.5.3, “SET Syntax”, discusses these options.
Variables that have a type of “string” take a
string value. Variables that have a type of
“numeric” take a numeric value. Variables that
have a type of “boolean” can be set to 0, 1,
ON or OFF. (If you set
them on the command line or in an option file, use the
numeric values.) Variables that are marked as
“enumeration” normally should be set to one of
the available values for the variable, but can also be set
to the number that corresponds to the desired enumeration
value. For enumerated system variables, the first
enumeration value corresponds to 0. This differs from
ENUM columns, for which the first
enumeration value corresponds to 1.
| Variable Name | Value Type | Type |
autocommit | boolean | SESSION |
big_tables | boolean | SESSION |
binlog_cache_size | numeric | GLOBAL |
binlog_format | string | GLOBAL | SESSION |
bulk_insert_buffer_size | numeric | GLOBAL | SESSION |
character_set_client | string | GLOBAL | SESSION |
character_set_connection | string | GLOBAL | SESSION
|
character_set_filesystem | string | GLOBAL | SESSION |
character_set_results | string | GLOBAL | SESSION |
character_set_server | string | GLOBAL | SESSION |
collation_connection | string | GLOBAL | SESSION |
collation_server | string | GLOBAL | SESSION |
completion_type | numeric | GLOBAL | SESSION |
concurrent_insert | boolean | GLOBAL |
connect_timeout | numeric | GLOBAL |
default_week_format | numeric | GLOBAL | SESSION |
delay_key_write | OFF | ON | ALL | GLOBAL |
delayed_insert_limit | numeric | GLOBAL |
delayed_insert_timeout | numeric | GLOBAL |
delayed_queue_size | numeric | GLOBAL |
div_precision_increment | numeric | GLOBAL | SESSION |
engine_condition_pushdown | boolean | GLOBAL | SESSION |
error_count | numeric | SESSION |
event_scheduler | boolean | GLOBAL |
expire_logs_days | numeric | GLOBAL |
flush | boolean | GLOBAL |
flush_time | numeric | GLOBAL |
foreign_key_checks | boolean | SESSION |
ft_boolean_syntax | numeric | GLOBAL |
group_concat_max_len | numeric | GLOBAL | SESSION |
identity | numeric | SESSION |
innodb_autoextend_increment | numeric | GLOBAL |
innodb_commit_concurrency | numeric | GLOBAL |
innodb_concurrency_tickets | numeric | GLOBAL |
innodb_max_dirty_pages_pct | numeric | GLOBAL |
innodb_max_purge_lag | numeric | GLOBAL |
innodb_support_xa | boolean | GLOBAL | SESSION |
innodb_sync_spin_loops | numeric | GLOBAL |
innodb_table_locks | boolean | GLOBAL | SESSION |
innodb_thread_concurrency | numeric | GLOBAL |
innodb_thread_sleep_delay | numeric | GLOBAL |
insert_id | boolean | SESSION |
interactive_timeout | numeric | GLOBAL | SESSION |
join_buffer_size | numeric | GLOBAL | SESSION |
key_buffer_size | numeric | GLOBAL |
last_insert_id | numeric | SESSION |
local_infile | boolean | GLOBAL |
log_queries_not_using_indexes | boolean | GLOBAL |
log_warnings | numeric | GLOBAL |
long_query_time | numeric | GLOBAL | SESSION |
low_priority_updates | boolean | GLOBAL | SESSION |
max_allowed_packet | numeric | GLOBAL | SESSION |
max_binlog_cache_size | numeric | GLOBAL |
max_binlog_size | numeric | GLOBAL |
max_connect_errors | numeric | GLOBAL |
max_connections | numeric | GLOBAL |
max_delayed_threads | numeric | GLOBAL |
max_error_count | numeric | GLOBAL | SESSION |
max_heap_table_size | numeric | GLOBAL | SESSION |
max_insert_delayed_threads | numeric | GLOBAL |
max_join_size | numeric | GLOBAL | SESSION |
max_prepared_stmt_count | numeric | GLOBAL |
max_relay_log_size | numeric | GLOBAL |
max_seeks_for_key | numeric | GLOBAL | SESSION |
max_sort_length | numeric | GLOBAL | SESSION |
max_tmp_tables | numeric | GLOBAL | SESSION |
max_user_connections | numeric | GLOBAL |
max_write_lock_count | numeric | GLOBAL |
myisam_stats_method | enum | GLOBAL | SESSION |
multi_read_range | numeric | GLOBAL | SESSION |
myisam_data_pointer_size | numeric | GLOBAL |
log_bin_trust_function_creators | boolean | GLOBAL |
myisam_max_sort_file_size | numeric | GLOBAL | SESSION |
myisam_repair_threads | numeric | GLOBAL | SESSION |
myisam_sort_buffer_size | numeric | GLOBAL | SESSION |
myisam_use_mmap | boolean | GLOBAL |
ndb_extra_logging | numeric | GLOBAL |
net_buffer_length | numeric | GLOBAL | SESSION |
net_read_timeout | numeric | GLOBAL | SESSION |
net_retry_count | numeric | GLOBAL | SESSION |
net_write_timeout | numeric | GLOBAL | SESSION |
old_passwords | numeric | GLOBAL | SESSION |
optimizer_prune_level | numeric | GLOBAL | SESSION |
optimizer_search_depth | numeric | GLOBAL | SESSION |
preload_buffer_size | numeric | GLOBAL | SESSION |
query_alloc_block_size | numeric | GLOBAL | SESSION |
query_cache_limit | numeric | GLOBAL |
query_cache_size | numeric | GLOBAL |
query_cache_type | enumeration | GLOBAL | SESSION |
query_cache_wlock_invalidate | boolean | GLOBAL | SESSION |
query_prealloc_size | numeric | GLOBAL | SESSION |
range_alloc_block_size | numeric | GLOBAL | SESSION |
read_buffer_size | numeric | GLOBAL | SESSION |
read_only | numeric | GLOBAL |
read_rnd_buffer_size | numeric | GLOBAL | SESSION |
rpl_recovery_rank | numeric | GLOBAL |
safe_show_database | boolean | GLOBAL |
secure_auth | boolean | GLOBAL |
server_id | numeric | GLOBAL |
slave_compressed_protocol | boolean | GLOBAL |
slave_net_timeout | numeric | GLOBAL |
slave_transaction_retries | numeric | GLOBAL |
slow_launch_time | numeric | GLOBAL |
sort_buffer_size | numeric | GLOBAL | SESSION |
sql_auto_is_null | boolean | SESSION |
sql_big_selects | boolean | SESSION |
sql_big_tables | boolean | SESSION |
sql_buffer_result | boolean | SESSION |
sql_log_bin | boolean | SESSION |
sql_log_off | boolean | SESSION |
sql_log_update | boolean | SESSION |
sql_low_priority_updates | boolean | GLOBAL | SESSION |
sql_max_join_size | numeric | GLOBAL | SESSION |
sql_mode | enumeration | GLOBAL | SESSION |
sql_notes | boolean | SESSION |
sql_quote_show_create | boolean | SESSION |
sql_safe_updates | boolean | SESSION |
sql_select_limit | numeric | SESSION |
sql_slave_skip_counter | numeric | GLOBAL |
updatable_views_with_limit | enumeration | GLOBAL | SESSION |
sql_warnings | boolean | SESSION |
sync_binlog | numeric | GLOBAL |
sync_frm | boolean | GLOBAL |
storage_engine | enumeration | GLOBAL | SESSION |
table_definition_cache | numeric | GLOBAL |
table_open_cache | numeric | GLOBAL |
table_type | enumeration | GLOBAL | SESSION |
thread_cache_size | numeric | GLOBAL |
time_zone | string | GLOBAL | SESSION |
timestamp | boolean | SESSION |
tmp_table_size | enumeration | GLOBAL | SESSION |
transaction_alloc_block_size | numeric | GLOBAL | SESSION |
transaction_prealloc_size | numeric | GLOBAL | SESSION |
tx_isolation | enumeration | GLOBAL | SESSION |
unique_checks | boolean | SESSION |
wait_timeout | numeric | GLOBAL | SESSION |
warning_count | numeric | SESSION |
The server maintains many status variables that provide
information about its operation. You can view these variables
and their values by using the SHOW STATUS
statement:
mysql> SHOW STATUS;
+-----------------------------------+------------+
| Variable_name | Value |
+-----------------------------------+------------+
| Aborted_clients | 0 |
| Aborted_connects | 0 |
| Bytes_received | 155372598 |
| Bytes_sent | 1176560426 |
...
| Connections | 30023 |
| Created_tmp_disk_tables | 0 |
| Created_tmp_files | 3 |
| Created_tmp_tables | 2 |
...
| Threads_created | 217 |
| Threads_running | 88 |
| Uptime | 1389872 |
+-----------------------------------+------------+
Many status variables are reset to 0 by the FLUSH
STATUS statement.
The status variables have the following meanings. Variables with no version indicated were already present prior to MySQL 5.1. For information regarding their implementation history, see MySQL 5.0 Reference Manual.
Aborted_clients
The number of connections that were aborted because the client died without closing the connection properly. See Section A.2.10, “Communication Errors and Aborted Connections”.
Aborted_connects
The number of failed attempts to connect to the MySQL server. See Section A.2.10, “Communication Errors and Aborted Connections”.
Binlog_cache_disk_use
The number of transactions that used the temporary binary
log cache but that exceeded the value of
binlog_cache_size and used a temporary
file to store statements from the transaction.
Binlog_cache_use
The number of transactions that used the temporary binary log cache.
Bytes_received
The number of bytes received from all clients.
Bytes_sent
The number of bytes sent to all clients.
Com_
xxx
The Com_
statement counter variables indicate the number of times
each xxxxxx statement has been
executed. There is one status variable for each type of
statement. For example, Com_delete and
Com_insert count
DELETE and INSERT
statements, respectively.
All of the
Com_stmt_
variables are increased even if a prepared statement
argument is unknown or an error occurred during execution.
In other words, their values correspond to the number of
requests issued, not to the number of requests
successfully completed.
xxx
The
Com_stmt_
status variables are as follows:
xxx
Com_stmt_prepare
Com_stmt_execute
Com_stmt_fetch
Com_stmt_send_long_data
Com_stmt_reset
Com_stmt_close
Those variables stand for prepared statement commands.
Their names refer to the
COM_
command set used in the network layer. In other words,
their values increase whenever prepared statement API
calls such as mysql_stmt_prepare(),
mysql_stmt_execute(), and so forth are
executed. However, xxxCom_stmt_prepare,
Com_stmt_execute and
Com_stmt_close also increase for
PREPARE, EXECUTE, or
DEALLOCATE PREPARE, respectively.
Additionally, the values of the older (available since
MySQL 4.1.3) statement counter variables
Com_prepare_sql,
Com_execute_sql, and
Com_dealloc_sql increase for the
PREPARE, EXECUTE,
and DEALLOCATE PREPARE statements.
Com_stmt_fetch stands for the total
number of network round-trips issued when fetching from
cursors.
Compression
Whether the client connection uses compression in the client/server protocol. Added in MySQL 5.1.2.
Connections
The number of connection attempts (successful or not) to the MySQL server.
Created_tmp_disk_tables
The number of temporary tables on disk created automatically by the server while executing statements.
Created_tmp_files
How many temporary files mysqld has created.
Created_tmp_tables
The number of in-memory temporary tables created
automatically by the server while executing statements. If
Created_tmp_disk_tables is large, you
may want to increase the tmp_table_size
value to cause temporary tables to be memory-based instead
of disk-based.
Delayed_errors
The number of rows written with INSERT
DELAYED for which some error occurred (probably
duplicate key).
Delayed_insert_threads
The number of INSERT DELAYED handler
threads in use.
Delayed_writes
The number of INSERT DELAYED rows
written.
Flush_commands
The number of executed FLUSH
statements.
Handler_commit
The number of internal COMMIT
statements.
Handler_discover
The MySQL server can ask the NDB
Cluster storage engine if it knows about a table
with a given name. This is called discovery.
Handler_discover indicates the number
of times that tables have been discovered via this
mechanism.
Handler_delete
The number of times that rows have been deleted from tables.
Handler_read_first
The number of times the first entry was read from an
index. If this value is high, it suggests that the server
is doing a lot of full index scans; for example,
SELECT col1 FROM foo, assuming that
col1 is indexed.
Handler_read_key
The number of requests to read a row based on a key. If this value is high, it is a good indication that your tables are properly indexed for your queries.
Handler_read_next
The number of requests to read the next row in key order. This value is incremented if you are querying an index column with a range constraint or if you are doing an index scan.
Handler_read_prev
The number of requests to read the previous row in key
order. This read method is mainly used to optimize
ORDER BY ... DESC.
Handler_read_rnd
The number of requests to read a row based on a fixed position. This value is high if you are doing a lot of queries that require sorting of the result. You probably have a lot of queries that require MySQL to scan entire tables or you have joins that don't use keys properly.
Handler_read_rnd_next
The number of requests to read the next row in the data file. This value is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have.
Handler_rollback
The number of internal ROLLBACK
statements.
Handler_update
The number of requests to update a row in a table.
Handler_write
The number of requests to insert a row in a table.
Innodb_buffer_pool_pages_data
The number of pages containing data (dirty or clean).
Innodb_buffer_pool_pages_dirty
The number of pages currently dirty.
Innodb_buffer_pool_pages_flushed
The number of buffer pool page-flush requests.
Innodb_buffer_pool_pages_free
The number of free pages.
Innodb_buffer_pool_pages_latched
The number of latched pages in InnoDB
buffer pool. These are pages currently being read or
written or that cannot be flushed or removed for some
other reason.
Innodb_buffer_pool_pages_misc
The number of pages that are busy because they have been
allocated for administrative overhead such as row locks or
the adaptive hash index. This value can also be calculated
as Innodb_buffer_pool_pages_total
– Innodb_buffer_pool_pages_free
– Innodb_buffer_pool_pages_data.
Innodb_buffer_pool_pages_total
The total size of the buffer pool, in pages.
Innodb_buffer_pool_read_ahead_rnd
The number of “random” read-aheads initiated
by InnoDB. This happens when a query
scans a large portion of a table but in random order.
Innodb_buffer_pool_read_ahead_seq
The number of sequential read-aheads initiated by
InnoDB. This happens when
InnoDB does a sequential full table
scan.
Innodb_buffer_pool_read_requests
The number of logical read requests
InnoDB has done.
Innodb_buffer_pool_reads
The number of logical reads that InnoDB
could not satisfy from the buffer pool and had to do a
single-page read.
Innodb_buffer_pool_wait_free
Normally, writes to the InnoDB buffer
pool happen in the background. However, if it is necessary
to read or create a page and no clean pages are available,
it is also necessary to wait for pages to be flushed
first. This counter counts instances of these waits. If
the buffer pool size has been set properly, this value
should be small.
Innodb_buffer_pool_write_requests
The number writes done to the InnoDB
buffer pool.
Innodb_data_fsyncs
The number of fsync() operations so
far.
Innodb_data_pending_fsyncs
The current number of pending fsync()
operations.
Innodb_data_pending_reads
The current number of pending reads.
Innodb_data_pending_writes
The current number of pending writes.
Innodb_data_read
The amount of data read so far, in bytes.
Innodb_data_reads
The total number of data reads.
Innodb_data_writes
The total number of data writes.
Innodb_data_written
The amount of data written so far, in bytes.
Innodb_dblwr_writes,
Innodb_dblwr_pages_written
The number of doublewrite operations that have been
performed and the number of pages that have been written
for this purpose. See Section 15.2.14.1, “InnoDB Disk I/O”.
Innodb_log_waits
The number of times that the log buffer was too small and a wait was required for it to be flushed before continuing.
Innodb_log_write_requests
The number of log write requests.
Innodb_log_writes
The number of physical writes to the log file.
Innodb_os_log_fsyncs
The number of fsync() writes done to
the log file.
Innodb_os_log_pending_fsyncs
The number of pending log file fsync()
operations.
Innodb_os_log_pending_writes
The number of pending log file writes.
Innodb_os_log_written
The number of bytes written to the log file.
Innodb_page_size
The compiled-in InnoDB page size
(default 16KB). Many values are counted in pages; the page
size allows them to be easily converted to bytes.
Innodb_pages_created
The number of pages created.
Innodb_pages_read
The number of pages read.
Innodb_pages_written
The number of pages written.
Innodb_row_lock_current_waits
The number of row locks currently being waited for.
Innodb_row_lock_time
The total time spent in acquiring row locks, in milliseconds.
Innodb_row_lock_time_avg
The average time to acquire a row lock, in milliseconds.
Innodb_row_lock_time_max
The maximum time to acquire a row lock, in milliseconds.
Innodb_row_lock_waits
The number of times a row lock had to be waited for.
Innodb_rows_deleted
The number of rows deleted from InnoDB
tables.
Innodb_rows_inserted
The number of rows inserted into InnoDB
tables.
Innodb_rows_read
The number of rows read from InnoDB
tables.
Innodb_rows_updated
The number of rows updated in InnoDB
tables.
Key_blocks_not_flushed
The number of key blocks in the key cache that have changed but have not yet been flushed to disk.
Key_blocks_unused
The number of unused blocks in the key cache. You can use
this value to determine how much of the key cache is in
use; see the discussion of
key_buffer_size in
Section 5.2.2, “Server System Variables”.
Key_blocks_used
The number of used blocks in the key cache. This value is a high-water mark that indicates the maximum number of blocks that have ever been in use at one time.
Key_read_requests
The number of requests to read a key block from the cache.
Key_reads
The number of physical reads of a key block from disk. If
Key_reads is large, then your
key_buffer_size value is probably too
small. The cache miss rate can be calculated as
Key_reads/Key_read_requests.
Key_write_requests
The number of requests to write a key block to the cache.
Key_writes
The number of physical writes of a key block to disk.
Last_query_cost
The total cost of the last compiled query as computed by
the query optimizer. This is useful for comparing the cost
of different query plans for the same query. The default
value of 0 means that no query has been compiled yet. The
default value is 0. Last_query_cost has
session scope.
Max_used_connections
The maximum number of connections that have been in use simultaneously since the server started.
Not_flushed_delayed_rows
The number of rows waiting to be written in
INSERT DELAY queues.
Open_files
The number of files that are open.
Open_streams
The number of streams that are open (used mainly for logging).
Open_tables
The number of tables that are open.
Opened_tables
The number of tables that have been opened. If
Opened_tables is big, your
table_open_cache value is probably too
small.
Qcache_free_blocks
The number of free memory blocks in the query cache.
Qcache_free_memory
The amount of free memory for the query cache.
Qcache_hits
The number of query cache hits.
Qcache_inserts
The number of queries added to the query cache.
Qcache_lowmem_prunes
The number of queries that were deleted from the query cache because of low memory.
Qcache_not_cached
The number of non-cached queries (not cacheable, or not
cached due to the query_cache_type
setting).
Qcache_queries_in_cache
The number of queries registered in the query cache.
Qcache_total_blocks
The total number of blocks in the query cache.
Questions
The number of statements that clients have sent to the server.
Rpl_status
The status of fail-safe replication (not yet implemented).
Select_full_join
The number of joins that perform table scans because they do not use indexes. If this value is not 0, you should carefully check the indexes of your tables.
Select_full_range_join
The number of joins that used a range search on a reference table.
Select_range
The number of joins that used ranges on the first table. This is normally not a critical issue even if the value is quite large.
Select_range_check
The number of joins without keys that check for key usage after each row. If this is not 0, you should carefully check the indexes of your tables.
Select_scan
The number of joins that did a full scan of the first table.
Slave_open_temp_tables
The number of temporary tables that the slave SQL thread currently has open.
Slave_running
This is ON if this server is a slave
that is connected to a master.
Slave_retried_transactions
The total number of times since startup that the replication slave SQL thread has retried transactions.
Slow_launch_threads
The number of threads that have taken more than
slow_launch_time seconds to create.
Slow_queries
The number of queries that have taken more than
long_query_time seconds. See
Section 5.12.5, “The Slow Query Log”.
Sort_merge_passes
The number of merge passes that the sort algorithm has had
to do. If this value is large, you should consider
increasing the value of the
sort_buffer_size system variable.
Sort_range
The number of sorts that were done using ranges.
Sort_rows
The number of sorted rows.
Sort_scan
The number of sorts that were done by scanning the table.
Ssl_
xxx
Variables used for SSL connections.
Table_locks_immediate
The number of times that a table lock was acquired immediately.
Table_locks_waited
The number of times that a table lock could not be acquired immediately and a wait was needed. If this is high and you have performance problems, you should first optimize your queries, and then either split your table or tables or use replication.
Threads_cached
The number of threads in the thread cache.
Threads_connected
The number of currently open connections.
Threads_created
The number of threads created to handle connections. If
Threads_created is big, you may want to
increase the thread_cache_size value.
The cache miss rate can be calculated as
Threads_created/Connections.
Threads_running
The number of threads that are not sleeping.
Uptime
The number of seconds that the server has been up.
The MySQL server can operate in different SQL modes, and can apply these modes differently for different clients. This capability enables each application to tailor the server's operating mode to its own requirements.
Modes define what SQL syntax MySQL should support and what kind of data validation checks it should perform. This makes it easier to use MySQL in different environments and to use MySQL together with other database servers.
You can set the default SQL mode by starting
mysqld with the
--sql-mode="
option. modes"modes is a list of
different modes separated by comma
(‘,’) characters. The default
value is empty (no modes set). The
modes value also can be empty
(--sql-mode="") if you want to clear it
explicitly.
You can change the SQL mode at runtime by using a SET
[GLOBAL|SESSION]
sql_mode='
statement to set the modes'sql_mode system value.
Setting the GLOBAL variable requires the
SUPER privilege and affects the operation
of all clients that connect from that time on. Setting the
SESSION variable affects only the current
client. Any client can change its own session
sql_mode value at any time.
You can retrieve the current global or session
sql_mode value with the following
statements:
SELECT @@global.sql_mode; SELECT @@session.sql_mode;
The most important sql_mode values are
probably these:
Change syntax and behavior to be more conformant to standard SQL.
If a value could not be inserted as given into a transactional table, abort the statement. For a non-transactional table, abort the statement if the value occurs in a single-row statement or the first row of a multiple-row statement. More detail is given later in this section.
Make MySQL behave like a “traditional” SQL
database system. A simple description of this mode is
“give an error instead of a warning” when
inserting an incorrect value into a column.
Note: The
INSERT/UPDATE aborts
as soon as the error is noticed. This may not be what you
want if you are using a non-transactional storage engine,
because data changes made prior to the error are not be
rolled back, resulting in a “partially done”
update.
When this manual refers to “strict mode,” it
means a mode where at least one of
STRICT_TRANS_TABLES or
STRICT_ALL_TABLES is enabled.
The following list describes all supported modes:
Don't do full checking of dates. Check only that the month
is in the range from 1 to 12 and the day is in the range
from 1 to 31. This is very convenient for Web applications
where you obtain year, month, and day in three different
fields and you want to store exactly what the user
inserted (without date validation). This mode applies to
DATE and DATETIME
columns. It does not apply TIMESTAMP
columns, which always require a valid date.
The server requires that month and day values be legal,
and not merely in the range 1 to 12 and 1 to 31,
respectively. With strict mode disabled, invalid dates
such as '2004-04-31' are converted to
'0000-00-00' and a warning is
generated. With strict mode enabled, invalid dates
generate an error. To allow such dates, enable
ALLOW_INVALID_DATES.
Treat ‘"’ as an identifier
quote character (like the
‘`’ quote character) and
not as a string quote character. You can still use
‘`’ to quote identifiers
with this mode enabled. With
ANSI_QUOTES enabled, you cannot use
double quotes to quote literal strings, because it is
interpreted as an identifier.
Produce an error in strict mode (otherwise a warning) when
a division by zero (or MOD(X,0)) occurs
during an INSERT or
UPDATE. If this mode is not enabled,
MySQL instead returns NULL for
divisions by zero. For INSERT IGNORE or
UPDATE IGNORE, MySQL generates a
warning for divisions by zero, but the result of the
operation is NULL.
The precedence of the NOT operator is
such that expressions such as NOT a BETWEEN b AND
c are parsed as NOT (a BETWEEN b AND
c). In some older versions of MySQL, the
expression was parsed as (NOT a) BETWEEN b AND
c. The old higher-precedence behavior can be
obtained by enabling the
HIGH_NOT_PRECEDENCE SQL mode.
mysql>SET sql_mode = '';mysql>SELECT NOT 1 BETWEEN -5 AND 5;-> 0 mysql>SET sql_mode = 'broken_not';mysql>SELECT NOT 1 BETWEEN -5 AND 5;-> 1
Allow spaces between a function name and the
‘(’ character. This forces
all function names to be treated as reserved words. As a
result, if you want to access any database, table, or
column name that is a reserved word, you must quote it.
For example, because there is a USER()
function, the name of the user table in
the mysql database and the
User column in that table become
reserved, so you must quote them:
SELECT "User" FROM mysql."user";
The IGNORE_SPACE SQL mode applies to
built-in functions, not to stored routines. it is always
allowable to have spaces after a routine name, regardless
of whether IGNORE_SPACE is enabled.
Prevent GRANT from automatically
creating new users if it would otherwise do so, unless a
non-empty password also is specified.
NO_AUTO_VALUE_ON_ZERO affects handling
of AUTO_INCREMENT columns. Normally,
you generate the next sequence number for the column by
inserting either NULL or
0 into it.
NO_AUTO_VALUE_ON_ZERO suppresses this
behavior for 0 so that only
NULL generates the next sequence
number.
This mode can be useful if 0 has been
stored in a table's AUTO_INCREMENT
column. (Storing 0 is not a recommended
practice, by the way.) For example, if you dump the table
with mysqldump and then reload it,
MySQL normally generates new sequence numbers when it
encounters the 0 values, resulting in a
table with contents different from the one that was
dumped. Enabling NO_AUTO_VALUE_ON_ZERO
before reloading the dump file solves this problem.
mysqldump now automatically includes in
its output a statement that enables
NO_AUTO_VALUE_ON_ZERO, to avoid this
problem.
Disable the use of the backslash character
(‘\’) as an escape
character within strings. With this mode enabled,
backslash becomes any ordinary character like any other.
When creating a table, ignore all INDEX
DIRECTORY and DATA DIRECTORY
directives. This option is useful on slave replication
servers.
NO_ENGINE_SUBSTITUTION
Prevents automatic substitution of the default storage
engine when a statement such as CREATE
TABLE specifies a storage engine that is
disabled or not compiled in.
Do not print MySQL-specific column options in the output
of SHOW CREATE TABLE. This mode is used
by mysqldump in portability mode.
Do not print MySQL-specific index options in the output of
SHOW CREATE TABLE. This mode is used by
mysqldump in portability mode.
Do not print MySQL-specific table options (such as
ENGINE) in the output of SHOW
CREATE TABLE. This mode is used by
mysqldump in portability mode.
In integer subtraction operations, do not mark the result
as UNSIGNED if one of the operands is
unsigned. Note that this makes BIGINT
UNSIGNED not 100% usable in all contexts. See
Section 12.8, “Cast Functions and Operators”.
mysql>t;SET sql_mode = '';mysql>t;SELECT CAST(0 AS UNSIGNED) - 1;+-------------------------+ | CAST(0 AS UNSIGNED) - 1 | +-------------------------+ | 18446744073709551615 | +-------------------------+ mysql>t;SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';mysql>t;SELECT CAST(0 AS UNSIGNED) - 1;+-------------------------+ | CAST(0 AS UNSIGNED) - 1 | +-------------------------+ | -1 | +-------------------------+
In strict mode, don't allow
'0000-00-00' as a valid date. You can
still insert zero dates with the IGNORE
option. When not in strict mode, the date is accepted but
a warning is generated.
In strict mode, don't accept dates where the month or day
part is 0. If used with the IGNORE
option, MySQL inserts a '0000-00-00'
date for any such date. When not in strict mode, the date
is accepted but a warning is generated.
Do not allow queries for which the
SELECT list refers to non-aggregated
columns that are not named in the GROUP
BY clause. The following query is invalid with
this mode enabled because address is
not named in the GROUP BY clause:
SELECT name, address, MAX(age) FROM t GROUP BY name;
As of MySQL 5.1.11, this mode also restricts references to
non-aggregated columns in the HAVING
clause that are not named in the GROUP
BY clause.
Treat || as a string concatenation
operator (same as CONCAT()) rather than
as a synonym for OR.
Treat REAL as a synonym for
FLOAT. By default, MySQL treats
REAL as a synonym for
DOUBLE.
Enable strict mode for all storage engines. Invalid data values are rejected. Additional detail follows.
Enable strict mode for transactional storage engines, and when possible for non-transactional storage engines. Additional details follow.
Strict mode controls how MySQL handles input values that are
invalid or missing. A value can be invalid for several
reasons. For example, it might have the wrong data type for
the column, or it might be out of range. A value is missing
when a new row to be inserted does not contain a value for a
column that has no explicit DEFAULT clause
in its definition.
For transactional tables, an error occurs for invalid or
missing values in a statement when either of the
STRICT_ALL_TABLES or
STRICT_TRANS_TABLES modes are enabled. The
statement is aborted and rolled back.
For non-transactional tables, the behavior is the same for either mode, if the bad value occurs in the first row to be inserted or updated. The statement is aborted and the table remains unchanged. If the statement inserts or modifies multiple rows and the bad value occurs in the second or later row, the result depends on which strict option is enabled:
For STRICT_ALL_TABLES, MySQL returns an
error and ignores the rest of the rows. However, in this
case, the earlier rows still have been inserted or
updated. This means that you might get a partial update,
which might not be what you want. To avoid this, it's best
to use single-row statements because these can be aborted
without changing the table.
For STRICT_TRANS_TABLES, MySQL converts
an invalid value to the closest valid value for the column
and insert the adjusted value. If a value is missing,
MySQL inserts the implicit default value for the column
data type. In either case, MySQL generates a warning
rather than an error and continues processing the
statement. Implicit defaults are described in
Section 11.1.4, “Data Type Default Values”.
Strict mode disallows invalid date values such as
'2004-04-31'. It does not disallow dates
with zero parts such as '2004-04-00' or
“zero” dates. To disallow these as well, enable
the NO_ZERO_IN_DATE and
NO_ZERO_DATE SQL modes in addition to
strict mode.
If you are not using strict mode (that is, neither
STRICT_TRANS_TABLES nor
STRICT_ALL_TABLES is enabled), MySQL
inserts adjusted values for invalid or missing values and
produces warnings. In strict mode, you can produce this
behavior by using INSERT IGNORE or
UPDATE IGNORE. See
Section 13.5.4.30, “SHOW WARNINGS Syntax”.
The following special modes are provided as shorthand for combinations of mode values from the preceding list.
The descriptions include all mode values that are available in the most recent version of MySQL. For older versions, a combination mode does not include individual mode values that are not available except in newer versions.
Equivalent to REAL_AS_FLOAT,
PIPES_AS_CONCAT,
ANSI_QUOTES,
IGNORE_SPACE. See
Section 1.9.3, “Running MySQL in ANSI Mode”.
Equivalent to PIPES_AS_CONCAT,
ANSI_QUOTES,
IGNORE_SPACE,
NO_KEY_OPTIONS,
NO_TABLE_OPTIONS,
NO_FIELD_OPTIONS.
Equivalent to PIPES_AS_CONCAT,
ANSI_QUOTES,
IGNORE_SPACE,
NO_KEY_OPTIONS,
NO_TABLE_OPTIONS,
NO_FIELD_OPTIONS,
NO_AUTO_CREATE_USER.
Equivalent to PIPES_AS_CONCAT,
ANSI_QUOTES,
IGNORE_SPACE,
NO_KEY_OPTIONS,
NO_TABLE_OPTIONS,
NO_FIELD_OPTIONS.
Equivalent to NO_FIELD_OPTIONS,
HIGH_NOT_PRECEDENCE.
Equivalent to NO_FIELD_OPTIONS,
HIGH_NOT_PRECEDENCE.
Equivalent to PIPES_AS_CONCAT,
ANSI_QUOTES,
IGNORE_SPACE,
NO_KEY_OPTIONS,
NO_TABLE_OPTIONS,
NO_FIELD_OPTIONS,
NO_AUTO_CREATE_USER.
Equivalent to PIPES_AS_CONCAT,
ANSI_QUOTES,
IGNORE_SPACE,
NO_KEY_OPTIONS,
NO_TABLE_OPTIONS,
NO_FIELD_OPTIONS.
Equivalent to STRICT_TRANS_TABLES,
STRICT_ALL_TABLES,
NO_ZERO_IN_DATE,
NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,
NO_AUTO_CREATE_USER.
The server shutdown process takes place as follows:
The shutdown process is initiated.
Server shutdown can be initiated several ways. For
example, a user with the SHUTDOWN
privilege can execute a mysqladmin
shutdown command. mysqladmin
can be used on any platform supported by MySQL. Other
operating system-specific shutdown initiation methods are
possible as well: The server shuts down on Unix when it
receives a SIGTERM signal. A server
running as a service on Windows shuts down when the
services manager tells it to.
The server creates a shutdown thread if necessary.
Depending on how shutdown was initiated, the server might
create a thread to handle the shutdown process. If
shutdown was requested by a client, a shutdown thread is
created. If shutdown is the result of receiving a
SIGTERM signal, the signal thread might
handle shutdown itself, or it might create a separate
thread to do so. If the server tries to create a shutdown
thread and cannot (for example, if memory is exhausted),
it issues a diagnostic message that appears in the error
log:
Error: Can't create thread to kill server
The server stops accepting new connections.
To prevent new activity from being initiated during shutdown, the server stops accepting new client connections. It does this by closing the network connections to which it normally listens for connections: the TCP/IP port, the Unix socket file, the Windows named pipe, and shared memory on Windows.
The server terminates current activity.
For each thread that is associated with a client
connection, the connection to the client is broken and the
thread is marked as killed. Threads die when they notice
that they are so marked. Threads for idle connections die
quickly. Threads that currently are processing statements
check their state periodically and take longer to die. For
additional information about thread termination, see
Section 13.5.5.3, “KILL Syntax”, in particular for the instructions
about killed REPAIR TABLE or
OPTIMIZE TABLE operations on
MyISAM tables.
For threads that have an open transaction, the transaction
is rolled back. Note that if a thread is updating a
non-transactional table, an operation such as a
multiple-row UPDATE or
INSERT may leave the table partially
updated, because the operation can terminate before
completion.
If the server is a master replication server, threads associated with currently connected slaves are treated like other client threads. That is, each one is marked as killed and exits when it next checks its state.
If the server is a slave replication server, the I/O and SQL threads, if active, are stopped before client threads are marked as killed. The SQL thread is allowed to finish its current statement (to avoid causing replication problems), and then stops. If the SQL thread was in the middle of a transaction at this point, the transaction is rolled back.
Storage engines are shut down or closed.
At this stage, the table cache is flushed and all open tables are closed.
Each storage engine performs any actions necessary for
tables that it manages. For example,
MyISAM flushes any pending index writes
for a table. InnoDB flushes its buffer
pool to disk, unless
innodb_fast_shutdown is 2, writes the
current LSN to the tablespace, and terminates its own
internal threads.
The server exits.
MySQL Server supports a HELP statement that
returns online information from the MySQL Reference manual
(see Section 13.3.2, “HELP Syntax”). The proper operation of this
statement requires that the help tables in the
mysql database be initialized with help
topic information, which is done by processing the contents of
the fill_help_tables.sql script.
For a MySQL binary distribution on Unix, help table setup occurs when you run mysql_install_db. For an RPM distribution on Linux or binary distribution on Windows, help table setup occurs as part of the MySQL installation process.
For a MySQL source distribution, you can find the
fill_help_tables_sql file in the
scripts directory. To load the file
manually, make sure that you have initialized the
mysql database by running
mysql_install_db, and then process the file
with the mysql client as follows:
shell> mysql -u root mysql < fill_help_tables.sql
If you are working with BitKeeper and a MySQL development
source tree, the tree doesn't contain
fill_help_tables.sql. You can download
the proper file for your version of MySQL from
http://dev.mysql.com/doc/. After downloading and
uncompressing the file, process it with
mysql as just described.
A MySQL-Max server is a version of the mysqld MySQL server that has been built to include additional features. As of MySQL 5.1.9, binary distributions include a mysqld-max server, in addition to the usual mysqld optimized server and the mysqld-debug debugging server.
MySQL AB builds mysqld-max servers by using the following configure options:
--with-server-suffix=-max
This option adds a -max suffix to the
mysqld version string.
--with-bdb
This option enables support for the Berkeley DB
(BDB) storage engine on those platforms for
which BDB is available. (See notes in the
following discussion.)
If you build MySQL using a source distribution, you can build your own Max-like server by enabling the same features at configuration time that binary distributions are built with.
The following table shows the platforms for which MySQL-Max
binaries include support for BDB.
| System | BDB Support |
| AIX 5.2 | N |
| HP-UX | Y |
| Linux-IA-64 | N |
| Linux-Intel | Y |
| Mac OS X | N |
| NetWare | N |
| SCO 6 | N |
| Solaris-SPARC | Y |
| Solaris-Intel | N |
| Solaris-AMD 64 | Y |
| Windows NT/2000/XP | Y |
To find out which storage engines your server supports, use the
SHOW ENGINES statement. (See
Section 13.5.4.13, “SHOW ENGINES Syntax”.)
This section describes several programs that are used to start mysqld, the MySQL server.
mysqld_safe is the recommended way to start a mysqld server on Unix and NetWare. mysqld_safe adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log file. NetWare-specific behaviors are listed later in this section.
mysqld_safe tries to start an executable
named mysqld. To override the default
behavior and specify explicitly the name of the server you
want to run, specify a --mysqld or
--mysqld-version option to
mysqld_safe. You can also use
--ledir to indicate the directory where
mysqld_safe should look for the server.
Many of the options to mysqld_safe are the same as the options to mysqld. See Section 5.2.1, “mysqld Command Options”.
All options specified to mysqld_safe on
the command line are passed to mysqld. If
you want to use any options that are specific to
mysqld_safe and that
mysqld doesn't support, do not specify
them on the command line. Instead, list them in the
[mysqld_safe] group of an option file.
See Section 4.3.2, “Using Option Files”.
mysqld_safe reads all options from the
[mysqld], [server],
and [mysqld_safe] sections in option
files. For backward compatibility, it also reads
[safe_mysqld] sections, although you
should rename such sections to
[mysqld_safe] in MySQL 5.1
installations.
mysqld_safe supports the following options:
Display a help message and exit.
(NetWare only) On NetWare, mysqld_safe provides a screen presence. When you unload (shut down) the mysqld_safe NLM, the screen does not by default go away. Instead, it prompts for user input:
*<NLM has terminated; Press any key to close the screen>*
If you want NetWare to close the screen automatically
instead, use the --autoclose option to
mysqld_safe.
The path to the MySQL installation directory.
The size of the core file that mysqld should be able to create. The option value is passed to ulimit -c.
The path to the data directory.
The name of an option file to be read in addition to the usual option files. This must be the first option on the command line if it is used. If the file does not exist or is otherwise inaccessible, the server will exit with an error.
The name of an option file to be read instead of the usual option files. This must be the first option on the command line if it is used.
If mysqld_safe cannot find the server, use this option to indicate the pathname to the directory where the server is located.
Write the error log to the given file. See Section 5.12.2, “The Error Log”.
The name of the server program (in the
ledir directory) that you want to
start. This option is needed if you use the MySQL binary
distribution but have the data directory outside of the
binary distribution. If mysqld_safe
cannot find the server, use the --ledir
option to indicate the pathname to the directory where
the server is located.
This option is similar to the --mysqld
option, but you specify only the suffix for the server
program name. The basename is assumed to be
mysqld. For example, if you use
--mysqld-version=debug,
mysqld_safe starts the
mysqld-debug program in the
ledir directory. If the argument to
--mysqld-version is empty,
mysqld_safe uses
mysqld in the
ledir directory.
Use the nice program to set the
server's scheduling priority to the given value.
Do not read any option files. This must be the first option on the command line if it is used.
The number of files that mysqld
should be able to open. The option value is passed to
ulimit -n. Note that you need to
start mysqld_safe as
root for this to work properly!
The pathname of the process ID file.
The port number that the server should use when
listening for TCP/IP connections. The port number must
be 1024 or higher unless the server is started by the
root system user.
The Unix socket file that the server should use when listening for local connections.
Set the TZ time zone environment
variable to the given option value. Consult your
operating system documentation for legal time zone
specification formats.
Run the mysqld server as the user
having the name user_name or
the numeric user ID user_id.
(“User” in this context refers to a system
login account, not a MySQL user listed in the grant
tables.)
If you execute mysqld_safe with the
--defaults-file or
--defaults-extra-option option to name an
option file, the option must be the first one given on the
command line or the option file will not be used. For
example, this command will not use the named option file:
mysql> mysqld_safe --port=port_num --defaults-file=file_name
Instead, use the following command:
mysql> mysqld_safe --defaults-file=file_name --port=port_num
The mysqld_safe script is written so that it normally can start a server that was installed from either a source or a binary distribution of MySQL, even though these types of distributions typically install the server in slightly different locations. (See Section 2.1.5, “Installation Layouts”.) mysqld_safe expects one of the following conditions to be true:
The server and databases can be found relative to the
working directory (the directory from which
mysqld_safe is invoked). For binary
distributions, mysqld_safe looks
under its working directory for bin
and data directories. For source
distributions, it looks for libexec
and var directories. This condition
should be met if you execute
mysqld_safe from your MySQL
installation directory (for example,
/usr/local/mysql for a binary
distribution).
If the server and databases cannot be found relative to
the working directory, mysqld_safe
attempts to locate them by absolute pathnames. Typical
locations are /usr/local/libexec
and /usr/local/var. The actual
locations are determined from the values configured into
the distribution at the time it was built. They should
be correct if MySQL is installed in the location
specified at configuration time.
Because mysqld_safe tries to find the server and databases relative to its own working directory, you can install a binary distribution of MySQL anywhere, as long as you run mysqld_safe from the MySQL installation directory:
shell>cdshell>mysql_installation_directorybin/mysqld_safe &
If mysqld_safe fails, even when invoked
from the MySQL installation directory, you can specify the
--ledir and --datadir
options to indicate the directories in which the server and
databases are located on your system.
Normally, you should not edit the
mysqld_safe script. Instead, configure
mysqld_safe by using command-line options
or options in the [mysqld_safe] section
of a my.cnf option file. In rare cases,
it might be necessary to edit mysqld_safe
to get it to start the server properly. However, if you do
this, your modified version of
mysqld_safe might be overwritten if you
upgrade MySQL in the future, so you should make a copy of
your edited version that you can reinstall.
On NetWare, mysqld_safe is a NetWare Loadable Module (NLM) that is ported from the original Unix shell script. It starts the server as follows:
Runs a number of system and option checks.
Runs a check on MyISAM tables.
Provides a screen presence for the MySQL server.
Starts mysqld, monitors it, and restarts it if it terminates in error.
Sends error messages from mysqld to
the
file in the data directory.
host_name.err
Sends mysqld_safe screen output to
the
file in the data directory.
host_name.safe
MySQL distributions on Unix include a script named mysql.server. It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services. It is also used by the Mac OS X Startup Item for MySQL.
mysql.server can be found in the
support-files directory under your
MySQL installation directory or in a MySQL source
distribution.
If you use the Linux server RPM package
(MySQL-server-),
the mysql.server script will be installed
in the VERSION.rpm/etc/init.d directory with the
name mysql. You need not install it
manually. See Section 2.4, “Installing MySQL on Linux”, for more
information on the Linux RPM packages.
Some vendors provide RPM packages that install a startup script under a different name such as mysqld.
If you install MySQL from a source distribution or using a binary distribution format that does not install mysql.server automatically, you can install it manually. Instructions are provided in Section 2.10.2.2, “Starting and Stopping MySQL Automatically”.
mysql.server reads options from the
[mysql.server] and
[mysqld] sections of option files. For
backward compatibility, it also reads
[mysql_server] sections, although you
should rename such sections to
[mysql.server] when using MySQL
5.1.
mysqld_multi is designed to manage several mysqld processes that listen for connections on different Unix socket files and TCP/IP ports. It can start or stop servers, or report their current status. The MySQL Instance Manager is an alternative means of managing multiple servers (see Section 5.5, “mysqlmanager — The MySQL Instance Manager”).
mysqld_multi searches for groups named
[mysqld in
N]my.cnf (or in the file named by the
--config-file option).
N can be any positive integer.
This number is referred to in the following discussion as
the option group number, or GNR.
Group numbers distinguish option groups from one another and
are used as arguments to mysqld_multi to
specify which servers you want to start, stop, or obtain a
status report for. Options listed in these groups are the
same that you would use in the [mysqld]
group used for starting mysqld. (See, for
example, Section 2.10.2.2, “Starting and Stopping MySQL Automatically”.) However, when
using multiple servers, it is necessary that each one use
its own value for options such as the Unix socket file and
TCP/IP port number. For more information on which options
must be unique per server in a multiple-server environment,
see Section 5.13, “Running Multiple MySQL Servers on the Same Machine”.
To invoke mysqld_multi, use the following syntax:
shell> mysqld_multi [options] {start|stop|report} [GNR[,GNR] ...]
start, stop, and
report indicate which operation to
perform. You can perform the designated operation for a
single server or multiple servers, depending on the
GNR list that follows the option
name. If there is no list, mysqld_multi
performs the operation for all servers in the option file.
Each GNR value represents an
option group number or range of group numbers. The value
should be the number at the end of the group name in the
option file. For example, the GNR
for a group named [mysqld17] is
17. To specify a range of numbers,
separate the first and last numbers by a dash. The
GNR value
10-13 represents groups
[mysqld10] through
[mysqld13]. Multiple groups or group
ranges can be specified on the command line, separated by
commas. There must be no whitespace characters (spaces or
tabs) in the GNR list; anything
after a whitespace character is ignored.
This command starts a single server using option group
[mysqld17]:
shell> mysqld_multi start 17
This command stops several servers, using option groups
[mysqld8] and
[mysqld10] through
[mysqld13]:
shell> mysqld_multi stop 8,10-13
For an example of how you might set up an option file, use this command:
shell> mysqld_multi --example
mysqld_multi supports the following options:
Display a help message and exit.
Specify the name of an alternative option file. This
affects where mysqld_multi looks for
[mysqld
option groups. Without this option, all options are read
from the usual N]my.cnf file. The
option does not affect where
mysqld_multi reads its own options,
which are always taken from the
[mysqld_multi] group in the usual
my.cnf file.
Display a sample option file.
Specify the name of the log file. If the file exists, log output is appended to it.
The mysqladmin binary to be used to stop servers.
The mysqld binary to be used. Note
that you can specify mysqld_safe as
the value for this option also. If you use
mysqld_safe to start the server, you
can include the mysqld or
ledir options in the corresponding
[mysqld
option group. These options indicate the name of the
server that mysqld_safe should start
and the pathname of the directory where the server is
located. (See the descriptions for these options in
Section 5.4.1, “mysqld_safe — MySQL Server Startup Script”.) Example:
N]
[mysqld38] mysqld = mysqld-debug ledir = /opt/local/mysql/libexec
Print log information to stdout
rather than to the log file. By default, output goes to
the log file.
The password of the MySQL account to use when invoking mysqladmin. Note that the password value is not optional for this option, unlike for other MySQL programs.
Silent mode; disable warnings.
Connect to each MySQL server via the TCP/IP port instead
of the Unix socket file. (If a socket file is missing,
the server might still be running, but accessible only
via the TCP/IP port.) By default, connections are made
using the Unix socket file. This option affects
stop and report
operations.
The username of the MySQL account to use when invoking mysqladmin.
Be more verbose.
Display version information and exit.
Some notes about mysqld_multi:
Most important: Before using mysqld_multi be sure that you understand the meanings of the options that are passed to the mysqld servers and why you would want to have separate mysqld processes. Beware of the dangers of using multiple mysqld servers with the same data directory. Use separate data directories, unless you know what you are doing. Starting multiple servers with the same data directory does not give you extra performance in a threaded system. See Section 5.13, “Running Multiple MySQL Servers on the Same Machine”.
Important: Make sure
that the data directory for each server is fully
accessible to the Unix account that the specific
mysqld process is started as.
Do not use the Unix
root account for this, unless
you know what you are doing. See
Section 5.7.5, “How to Run MySQL as a Normal User”.
Make sure that the MySQL account used for stopping the
mysqld servers (with the
mysqladmin program) has the same
username and password for each server. Also, make sure
that the account has the SHUTDOWN
privilege. If the servers that you want to manage have
different usernames or passwords for the administrative
accounts, you might want to create an account on each
server that has the same username and password. For
example, you might set up a common
multi_admin account by executing the
following commands for each server:
shell>mysql -u root -S /tmp/mysql.sock -pEnter password: mysql>GRANT SHUTDOWN ON *.*->TO 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';
See Section 5.8.2, “How the Privilege System Works”. You have to do this
for each mysqld server. Change the
connection parameters appropriately when connecting to
each one. Note that the hostname part of the account
name must allow you to connect as
multi_admin from the host where you
want to run mysqld_multi.
The Unix socket file and the TCP/IP port number must be different for every mysqld.
The --pid-file option is very important
if you are using mysqld_safe to start
mysqld (for example,
--mysqld=mysqld_safe) Every
mysqld should have its own process ID
file. The advantage of using
mysqld_safe instead of
mysqld is that
mysqld_safe monitors its
mysqld process and restarts it if the
process terminates due to a signal sent using
kill -9 or for other reasons, such as
a segmentation fault. Please note that the
mysqld_safe script might require that
you start it from a certain place. This means that you
might have to change location to a certain directory
before running mysqld_multi. If you
have problems starting, please see the
mysqld_safe script. Check especially
the lines:
---------------------------------------------------------------- MY_PWD=`pwd` # Check if we are starting this relative (for the binary release) if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \ -x ./bin/mysqld ----------------------------------------------------------------
The test performed by these lines should be successful, or you might encounter problems. See Section 5.4.1, “mysqld_safe — MySQL Server Startup Script”.
You might want to use the --user option
for mysqld, but to do this you need
to run the mysqld_multi script as the
Unix root user. Having the option in
the option file doesn't matter; you just get a warning
if you are not the superuser and the
mysqld processes are started under
your own Unix account.
The following example shows how you might set up an option
file for use with mysqld_multi. The order
in which the mysqld programs are started
or stopped depends on the order in which they appear in the
option file. Group numbers need not form an unbroken
sequence. The first and fifth
[mysqld
groups were intentionally omitted from the example to
illustrate that you can have “gaps” in the
option file. This gives you more flexibility.
N]
# This file should probably be in your home dir (~/.my.cnf) # or /etc/my.cnf # Version 2.1 by Jani Tolonen [mysqld_multi] mysqld = /usr/local/bin/mysqld_safe mysqladmin = /usr/local/bin/mysqladmin user = multi_admin password = multipass [mysqld2] socket = /tmp/mysql.sock2 port = 3307 pid-file = /usr/local/mysql/var2/hostname.pid2 datadir = /usr/local/mysql/var2 language = /usr/local/share/mysql/english user = john [mysqld3] socket = /tmp/mysql.sock3 port = 3308 pid-file = /usr/local/mysql/var3/hostname.pid3 datadir = /usr/local/mysql/var3 language = /usr/local/share/mysql/swedish user = monty [mysqld4] socket = /tmp/mysql.sock4 port = 3309 pid-file = /usr/local/mysql/var4/hostname.pid4 datadir = /usr/local/mysql/var4 language = /usr/local/share/mysql/estonia user = tonu [mysqld6] socket = /tmp/mysql.sock6 port = 3311 pid-file = /usr/local/mysql/var6/hostname.pid6 datadir = /usr/local/mysql/var6 language = /usr/local/share/mysql/japanese user = jani
mysqlmanager is the MySQL Instance Manager (IM). This program is a daemon running on a TCP/IP port that serves to monitor and manage MySQL Database Server instances. MySQL Instance Manager is available for Unix-like operating systems, as well as Windows.
MySQL Instance Manager can be used in place of the
mysqld_safe script to start and stop the
MySQL Server, even from a remote host.
MySQL Instance Manager also implements the functionality (and
most of the syntax) of the mysqld_multi
script. A more detailed description of MySQL Instance Manager
follows.
Normally, the mysqld MySQL Database Server
is started with the mysql.server script,
which usually resides in the /etc/init.d/
folder. This script invokes the mysqld_safe
script by default. However, you can instead use the instance
manager if you modify the my.cnf file by adding
use-manager to the
[mysql.server] section:
[mysql.server] use-manager
The Instance Manager's behavior in this case depends on the
options given in the MySQL configuration file. If there is no
configuration file, the MySQL Instance Manager creates a
server instance named mysqld and attempts
to start it with default (compiled-in) configuration values.
This means that the IM cannot guess the placement of
mysqld if it is not installed in the
default location. If you have installed the MySQL server in a
non-standard location, you should use a configuration file.
See Section 2.1.5, “Installation Layouts”.
If there is a configuration file, the IM reads it to find
[mysqldN] sections (for example,
[mysqld1], [mysqld2],
and so forth). Each such section specifies an instance. When
it starts, the Instance Manager attempts to start all server
instances that it finds. By default, the Instance Manager
stops all server instances when it shuts down.
The [mysqld] section name is deprecated
and should not be used in a configuration file.
Note that there is a special
--mysqld-path=
option that is recognized only by the IM. Use this variable to
let the IM know where the mysqld binary
resides. You should also set path-to-mysqld-binarybasedir and
datadir options for the server.
The typical startup/shutdown cycle for a MySQL server with the MySQL Instance Manager enabled is as follows:
The MySQL Instance Manager is started with /etc/init.d/mysql script.
The MySQL Instance Manager starts all instances and monitors them.
If a server instance fails the MySQL Instance Manager restarts it.
If the MySQL Instance Manager is shut down (for instance with the /etc/init.d/mysql stop command), all instances are shut down by the MySQL Instance Manager.
Communication with the MySQL Instance Manager is handled using the MySQL client-server protocol. As such, you can connect to the IM using the standard mysql client program, as well as the MySQL C API. The IM supports the version of the MySQL client-server protocol used by the client tools and libraries distributed along with MySQL 4.1 or later.
The Instance Manager stores its user information in a
password file. The default name of the password file is
/etc/mysqlmanager.passwd.
Password entries have the following format:
petr:*35110DC9B4D8140F5DE667E28C72DD2597B5C848
If there are no entries in the
/etc/mysqlmanager.passwd file, you
cannot connect to the Instance Manager.
To generate a new entry, invoke Instance Manager with the
--passwd option. Then the output can be
appended to the
/etc/mysqlmanager.passwd file to add a
new user. Here is an example:
shell>mysqlmanager --passwd >> /etc/mysqlmanager.passwdCreating record for new user. Enter user name:mikeEnter password:passwordRe-type password:password
The preceding command causes the following line to be added
to /etc/mysqlmanager.passwd:
mike:*00A51F3F48415C7D4E8908980D443C29C69B60C9
The Instance Manager must be restarted after adding/changing passwords.
To monitor server status, the MySQL Instance Manager will
attempt to connect to the MySQL server instance at regular
intervals using the
MySQL_Instance_Manager@localhost user
account with a password of
check_connection.
You are not required to create a
MySQL_Instance_M@localhost user account
in order for the MySQL Instance Manager to monitor server
status, as a login failure is sufficient to identify that
the server is operational. However, if the account does not
exist, failed connection attempts are logged by the server
to its general query log (see Section 5.12.3, “The General Query Log”).
The MySQL Instance Manager supports a number of command line
options. For a brief listing, invoke
mysqlmanager with the
--help option.
mysqlmanager supports the following options:
Display a help message and exit.
The file in which the angel process records its process ID
when mysqlmanager runs in daemon mode.
By default, this file is named
mysqlmanager.angel.pid. If the
--pid-file option is given, the default
angel PID file becomes the same except that any extension
is replaced with an extension of
.angel.pid. This option was added in
MySQL 5.1.11.
The IP address to bind to.
--debug=
debug_options,
-# debug_options
Write a debugging log. The
debug_options string often is
'd:t:o,.
This option was added in MySQL 5.1.10.
file_name'
On Unix, the pathname of the MySQL Server binary, if no
path was provided in the instance section. Example:
--default-mysqld-path=/usr/sbin/mysqld
Read Instance Manager and MySQL Server settings from the given file. All configuration changes by the Instance Manager will be made to this file. This must be the first option on the command line if it is used.
On Windows, install Instance Manager as a Windows service.
The path to the IM log file. This is used with the --run-as-service option.
The interval in seconds for monitoring instances. The
default value is 20 seconds. Instance Manager tries to
connect to each monitored instance using the non-existing
MySQL_Instance_Manager user account to
check whether it is alive/not hanging. In the case of a
failure to connect, IM performs several attempts to
restart the instance. The nonguarded
option in the appropriate instance section disables this
behavior for a particular instance. The monitoring process
will produce messages in the general query log similar to
the following:
Access denied for user 'MySQL_Instance_M'@'localhost' (using password: YES)
Prepare an entry for the password file and exit.
Look for the Instance Manager users and passwords in this
file. The default file is
/etc/mysqlmanager.passwd.
The process ID file to use. By default, this file is named
mysqlmanager.pid.
The TCP/IP port number to use for incoming connections. (The default port number assigned by IANA is 2273).
Print the current defaults and exit. This must be the first option on the command line if it is used.
On Windows, removes Instance Manager as a Windows service.
This assumes that Instance Manager has been run with
--install previously.
On Unix, daemonize and start the angel process. The angel process is simple and unlikely to crash. It will restart the Instance Manager itself in case of a failure.
On Unix, the socket file to use for incoming connections.
By default, the file is named
/tmp/mysqlmanager.sock.
On Windows, run Instance Manager in standalone mode.
On Unix, the username to start and run the mysqlmanager under. It is recommended to run mysqlmanager under the same user account used to run the mysqld server. (“User” in this context refers to a system login account, not a MySQL user listed in the grant tables.)
Output version information and exit.
The number of seconds to wait for activity on a connection befoe closing it. The default is 28800 seconds (8 hours).
This option was added in MySQL 5.1.7. Before that, the timeout is 30 seconds and cannot be changed.
Instance Manager uses the standard my.cnf
file. It uses the [manager] section to read
options for itself and the [mysqld]
sections to create instances. The [manager]
section contains any of the options listed in
Section 5.5.3, “MySQL Instance Manager Command Options”. Here is an
example [manager] section:
# MySQL Instance Manager options section [manager] default-mysqld-path = /usr/local/mysql/libexec/mysqld socket=/tmp/manager.sock pid-file=/tmp/manager.pid password-file = /home/cps/.mysqlmanager.passwd monitoring-interval = 2 port = 1999 bind-address = 192.168.1.5
The [mysqld] section name causes
unpredictable results when used in conjunction with the
Instance Manager. When using the Instance Manager, check
that no section is named [mysqld].
The MySQL Instance Manager reads and manages the
/etc/my.cnf file only on Unix. On
Windows, MySQL Instance Manager reads the
my.ini file in the directory where
Instance Manager is installed. The default option file
location can be changed with the
--defaults-file=
option.
file_name
Instance sections specify options given to each instance at startup. These are mainly common MySQL server options, but there are some IM-specific options:
mysqld-path =
path
The pathname to the mysqld server binary.
shutdown-delay =
seconds
The number of seconds IM should wait for the instance to
shut down. The default value is 35 seconds. After the
delay expires, the IM assumes that the instance is hanging
and attempts to terminate it. If you use
InnoDB with large tables, you should
increase this value.
nonguarded
This option should be specified if you want to disable IM monitoring functionality for a certain instance.
Here are some sample instance sections:
[mysqld1] mysqld-path=/usr/local/mysql/libexec/mysqld socket=/tmp/mysql.sock port=3307 server_id=1 skip-stack-trace core-file skip-bdb log-bin log-error log=mylog log-slow-queries [mysqld2] nonguarded port=3308 server_id=2 mysqld-path= /home/cps/mysql/trees/mysql-5.1/sql/mysqld socket = /tmp/mysql.sock5 pid-file = /tmp/hostname.pid5 datadir= /home/cps/mysql_data/data_dir1 language=/home/cps/mysql/trees/mysql-5.1/sql/share/english log-bin log=/tmp/fordel.log
Once you've set up a password file for the MySQL Instance Manager and the IM is running, you can connect to it. You can use the mysql client tool connect through a standard MySQL API:
mysql --port=2273 --host=mydomain.org --user=mysql -p
The following list of commands shows the MySQL Instance Manager currently accepts, with samples.
START INSTANCE
instance_name
This command attempts to start an instance.
mysql> START INSTANCE mysqld4;
Query OK, 0 rows affected (0,00 sec)
STOP INSTANCE
instance_name
This command attempts to stop an instance.
mysql> STOP INSTANCE mysqld4;
Query OK, 0 rows affected (0,00 sec)
SHOW INSTANCES
Shows the names of all loaded instances.
mysql> SHOW INSTANCES;
+---------------+---------+
| instance_name | status |
+---------------+---------+
| mysqld3 | offline |
| mysqld4 | online |
| mysqld2 | offline |
+---------------+---------+
3 rows in set (0,04 sec)
SHOW INSTANCE STATUS
instance_name
Shows the status and the version information for an instance.
mysql> SHOW INSTANCE STATUS mysqld3;
+---------------+--------+---------+
| instance_name | status | version |
+---------------+--------+---------+
| mysqld3 | online | unknown |
+---------------+--------+---------+
1 row in set (0.00 sec)
SHOW INSTANCE OPTIONS
instance_name
Shows the options used by an instance.
mysql> SHOW INSTANCE OPTIONS mysqld3;
+---------------+---------------------------------------------------+
| option_name | value |
+---------------+---------------------------------------------------+
| instance_name | mysqld3 |
| mysqld-path | /home/cps/mysql/trees/mysql-4.1/sql/mysqld |
| port | 3309 |
| socket | /tmp/mysql.sock3 |
| pid-file | hostname.pid3 |
| datadir | /home/cps/mysql_data/data_dir1/ |
| language | /home/cps/mysql/trees/mysql-4.1/sql/share/english |
+---------------+---------------------------------------------------+
7 rows in set (0.01 sec)
SHOW
instance_name LOG
FILES
The command lists all log files used by the instance. The
result set contains the path to the log file and the log
file size. If no log file path is specified in the
configuration file (for example,
log=/var/mysql.log), the Instance
Manager tries to guess its placement. If the IM is unable
to guess the logfile placement you should specify the log
file location explicitly by using the appropriate log
option in the instance section of the configuration file.
mysql> SHOW mysqld LOG FILES;
+-------------+------------------------------------+----------+
| Logfile | Path | Filesize |
+-------------+------------------------------------+----------+
| ERROR LOG | /home/cps/var/mysql/owlet.err | 9186 |
| GENERAL LOG | /home/cps/var/mysql/owlet.log | 471503 |
| SLOW LOG | /home/cps/var/mysql/owlet-slow.log | 4463 |
+-------------+------------------------------------+----------+
3 rows in set (0.01 sec)
SHOW
instance_name LOG
{ERROR | SLOW | GENERAL}
size[,offset_from_end]
This command retrieves a portion of the specified log
file. Because most users are interested in the latest log
messages, the size parameter
defines the number of bytes you would like to retrieve
starting from the log end. You can retrieve data from the
middle of the log file by specifying the optional
offset_from_end parameter. The
following example retrieves 21 bytes of data, starting 23
bytes from the end of the log file and ending 2 bytes from
the end of the log file:
mysql> SHOW mysqld LOG GENERAL 21, 2;
+---------------------+
| Log |
+---------------------+
| using password: YES |
+---------------------+
1 row in set (0.00 sec)
SET
instance_name.option_name=option_value
This command edits the specified instance's configuration
file to change or add instance options. The IM assumes
that the configuration file is located at
/etc/my.cnf. You should check that
the file exists and has appropriate permissions.
mysql> SET mysqld2.port=3322;
Query OK, 0 rows affected (0.00 sec)
Changes made to the configuration file do not take effect
until the MySQL server is restarted. In addition, these
changes are not stored in the instance manager's local
cache of instance settings until a FLUSH
INSTANCES command is executed.
UNSET
instance_name.option_name
This command removes an option from an instance's configuration file.
mysql> UNSET mysqld2.port;
Query OK, 0 rows affected (0.00 sec)
Changes made to the configuration file do not take effect
until the MySQL server is restarted. In addition, these
changes are not stored in the instance manager's local
cache of instance settings until a FLUSH
INSTANCES command is executed.
FLUSH INSTANCES
This command forces IM to reread the configuration file and to refresh internal structures. This command should be performed after editing the configuration file. The command does not restart instances.
mysql> FLUSH INSTANCES;
Query OK, 0 rows affected (0.04 sec)
Some releases of MySQL introduce changes to the structure of
the system tables in the mysql database
to add new privileges or support new features. When you
update to a new version of MySQL, you should update your
system tables as well to make sure that their structure is
up to date. Otherwise, there might be capabilities that you
cannot take advantage of. First, make a backup of your
mysql database, and then use the
following procedure.
Note: As of MySQL 5.1.7, mysql_fix_privilege_tables is superseded by mysql_upgrade, which should be used instead. See Section 5.6.2, “mysql_upgrade — Check Tables for MySQL Upgrade”.
On Unix or Unix-like systems, update the system tables by running the mysql_fix_privilege_tables script:
shell> mysql_fix_privilege_tables
You must run this script while the server is running. It
attempts to connect to the server running on the local host
as root. If your root
account requires a password, indicate the password on the
command line like this:
shell> mysql_fix_privilege_tables --password=root_password
The mysql_fix_privilege_tables script
performs any actions necessary to convert your system tables
to the current format. You might see some Duplicate
column name warnings as it runs; you can ignore
them.
After running the script, stop the server and restart it.
On Windows systems, MySQL distributions include a
mysql_fix_privilege_tables.sql SQL
script that you can run using the mysql
client. For example, if your MySQL installation is located
at C:\Program Files\MySQL\MySQL Server
5.1, the commands look like this:
C:\>cd "C:\Program Files\MySQL\MySQL Server 5.1"C:\>bin\mysql -u root -p mysqlmysql>SOURCE scripts/mysql_fix_privilege_tables.sql
The mysql command will prompt you for the
root password; enter it when prompted.
If your installation is located in some other directory, adjust the pathnames appropriately.
As with the Unix procedure, you might see some
Duplicate column name warnings as
mysql processes the statements in the
mysql_fix_privilege_tables.sql script;
you can ignore them.
After running the script, stop the server and restart it.
mysql_upgrade should be executed each time you upgrade MySQL. It checks all tables in all databases for incompatibilities with the current version of MySQL Server. If a table is found to have a possible incompatibility, it is checked. If any problems are found, the table is repaired. mysql_upgrade also upgrades the system tables so that you can take advantage of new privileges or capabilities that might have been added.
All checked and repaired tables are marked with the current MySQL version number. This ensures that next time you run mysql_upgrade with the same version of the server, it can tell whether there is any need to check or repair the table again.
mysql_upgrade also saves the MySQL
version number in a file named
mysql_upgrade.info in the data
directory. This is used to quickly check if all tables have
been checked for this release so that table-checking can be
skipped. To ignore this file, use the
--force option.
To check and repair tables and to upgrade the system tables, mysql_upgrade executes the following commands:
mysqlcheck --check-upgrade --all-databases --auto-repair mysql_fix_privilege_tables
mysql_upgrade supersedes the older mysql_fix_privilege_tables script. In MySQL 5.1.7, mysql_upgrade was added as a shell script and worked only for Unix systems. As of MySQL 5.1.10, mysql_upgrade is an executable binary and is available on all systems. On systems older than those supporting mysql_upgrade, you can execute the mysqlcheck command manually, and then upgrade your system tables as described in Section 5.6.1, “mysql_fix_privilege_tables — Upgrade MySQL System Tables”.
For details about what is checked, see the description of
the FOR UPGRADE option of the
CHECK TABLE statement (see
Section 13.5.2.3, “CHECK TABLE Syntax”).
To use mysql_upgrade, make sure that the server is running, and then invoke it like this:
shell> mysql_upgrade [options]
mysql_upgrade reads options from the
command line and fromm the [mysqld] and
[mysql_upgrade] groups in option files.
It supports the following options:
Display a short help message and exit.
The path to the MySQL installation directory.
The path to the data directory.
Force execution of mysqlcheck even if
mysql_upgrade has already been
executed for the current version of MySQL. (In other
words, this option causes the
mysql_upgrade.info file to be
ignored.)
--user=,
user_name-u
user_name
The MySQL username to use when connecting to the server.
The default username is root.
Verbose mode. Print more information about what the program does.
Other options are passed to mysqlcheck
and to mysql_fix_privilege_tables. For
example, it might be necessary to specify the
--password[=
option.
password]
This section describes some general security issues to be aware of and what you can do to make your MySQL installation more secure against attack or misuse. For information specifically about the access control system that MySQL uses for setting up user accounts and checking database access, see Section 5.8, “The MySQL Access Privilege System”.
Anyone using MySQL on a computer connected to the Internet should read this section to avoid the most common security mistakes.
In discussing security, we emphasize the necessity of fully protecting the entire server host (not just the MySQL server) against all types of applicable attacks: eavesdropping, altering, playback, and denial of service. We do not cover all aspects of availability and fault tolerance here.
MySQL uses security based on Access Control Lists (ACLs) for all connections, queries, and other operations that users can attempt to perform. There is also support for SSL-encrypted connections between MySQL clients and servers. Many of the concepts discussed here are not specific to MySQL at all; the same general ideas apply to almost all applications.
When running MySQL, follow these guidelines whenever possible:
Do not ever give anyone (except MySQL
root accounts) access to the
user table in the
mysql database! This is
critical.
Learn the MySQL access privilege system. The
GRANT and REVOKE
statements are used for controlling access to MySQL. Do not
grant more privileges than necessary. Never grant privileges
to all hosts.
Checklist:
Try mysql -u root. If you are able to
connect successfully to the server without being asked
for a password, anyone can connect to your MySQL server
as the MySQL root user with full
privileges! Review the MySQL installation instructions,
paying particular attention to the information about
setting a root password. See
Section 2.10.3, “Securing the Initial MySQL Accounts”.
Use the SHOW GRANTS statement to
check which accounts have access to what. Then use the
REVOKE statement to remove those
privileges that are not necessary.
Do not store any plain-text passwords in your database. If
your computer becomes compromised, the intruder can take the
full list of passwords and use them. Instead, use
MD5(), SHA1(), or some
other one-way hashing function and store the hash value.
Do not choose passwords from dictionaries. Special programs exist to break passwords. Even passwords like “xfish98” are very bad. Much better is “duag98” which contains the same word “fish” but typed one key to the left on a standard QWERTY keyboard. Another method is to use a password that is taken from the first characters of each word in a sentence (for example, “Mary had a little lamb” results in a password of “Mhall”). The password is easy to remember and type, but difficult to guess for someone who does not know the sentence.
Invest in a firewall. This protects you from at least 50% of all types of exploits in any software. Put MySQL behind the firewall or in a demilitarized zone (DMZ).
Checklist:
Try to scan your ports from the Internet using a tool
such as nmap. MySQL uses port 3306 by
default. This port should not be accessible from
untrusted hosts. Another simple way to check whether or
not your MySQL port is open is to try the following
command from some remote machine, where
server_host is the hostname
or IP number of the host on which your MySQL server
runs:
shell> telnet server_host 3306
If you get a connection and some garbage characters, the port is open, and should be closed on your firewall or router, unless you really have a good reason to keep it open. If telnet hangs or the connection is refused, the port is blocked, which is how you want it to be.
Do not trust any data entered by users of your applications.
They can try to trick your code by entering special or
escaped character sequences in Web forms, URLs, or whatever
application you have built. Be sure that your application
remains secure if a user enters something like
“; DROP DATABASE mysql;”.
This is an extreme example, but large security leaks and
data loss might occur as a result of hackers using similar
techniques, if you do not prepare for them.
A common mistake is to protect only string data values.
Remember to check numeric data as well. If an application
generates a query such as SELECT * FROM table WHERE
ID=234 when a user enters the value
234, the user can enter the value
234 OR 1=1 to cause the application to
generate the query SELECT * FROM table WHERE ID=234
OR 1=1. As a result, the server retrieves every
row in the table. This exposes every row and causes
excessive server load. The simplest way to protect from this
type of attack is to use single quotes around the numeric
constants: SELECT * FROM table WHERE
ID='234'. If the user enters extra information, it
all becomes part of the string. In a numeric context, MySQL
automatically converts this string to a number and strips
any trailing non-numeric characters from it.
Sometimes people think that if a database contains only publicly available data, it need not be protected. This is incorrect. Even if it is allowable to display any row in the database, you should still protect against denial of service attacks (for example, those that are based on the technique in the preceding paragraph that causes the server to waste resources). Otherwise, your server becomes unresponsive to legitimate users.
Checklist:
Try to enter single and double quote marks
(‘'’ and
‘"’) in all of your Web
forms. If you get any kind of MySQL error, investigate
the problem right away.
Try to modify dynamic URLs by adding
%22
(‘"’),
%23
(‘#’), and
%27
(‘'’) to them.
Try to modify data types in dynamic URLs from numeric to character types using the characters shown in the previous examples. Your application should be safe against these and similar attacks.
Try to enter characters, spaces, and special symbols rather than numbers in numeric fields. Your application should remove them before passing them to MySQL or else generate an error. Passing unchecked values to MySQL is very dangerous!
Check the size of data before passing it to MySQL.
Have your application connect to the database using a username different from the one you use for administrative purposes. Do not give your applications any access privileges they do not need.
Many application programming interfaces provide a means of escaping special characters in data values. Properly used, this prevents application users from entering values that cause the application to generate statements that have a different effect than you intend:
MySQL C API: Use the
mysql_real_escape_string() API call.
MySQL++: Use the escape and
quote modifiers for query streams.
PHP: Use the
mysql_real_escape_string() function
(available as of PHP 4.3.0, prior to that PHP version
use mysql_escape_string(), and
prior to PHP 4.0.3, use
addslashes() ). Note that only
mysql_real_escape_string() is
character set-aware; the other functions can be
“bypassed” when using (invalid) multi-byte
character sets. In PHP 5, you can use the
mysqli extension, which supports the
improved MySQL authentication protocol and passwords, as
well as prepared statements with placeholders.
Perl DBI: Use placeholders or the
quote() method.
Ruby DBI: Use placeholders or the
quote() method.
Java JDBC: Use a PreparedStatement
object and placeholders.
Other programming interfaces might have similar capabilities.
Do not transmit plain (unencrypted) data over the Internet. This information is accessible to everyone who has the time and ability to intercept it and use it for their own purposes. Instead, use an encrypted protocol such as SSL or SSH. MySQL supports internal SSL connections as of version 4.0. Another technique is to use SSH port-forwarding to create an encrypted (and compressed) tunnel for the communication.
Learn to use the tcpdump and strings utilities. In most cases, you can check whether MySQL data streams are unencrypted by issuing a command like the following:
shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
(This works under Linux and should work with small modifications under other systems.) Warning: If you do not see plaintext data, this doesn't always mean that the information actually is encrypted. If you need high security, you should consult with a security expert.
When you connect to a MySQL server, you should use a password. The password is not transmitted in clear text over the connection. Password handling during the client connection sequence was upgraded in MySQL 4.1.1 to be very secure. If you are still using pre-4.1.1-style passwords, the encryption algorithm is not as strong as the newer algorithm. With some effort, a clever attacker who can sniff the traffic between the client and the server can crack the password. (See Section 5.8.9, “Password Hashing as of MySQL 4.1”, for a discussion of the different password handling methods.)
All other information is transferred as text, and can be read by anyone who is able to watch the connection. If the connection between the client and the server goes through an untrusted network, and you are concerned about this, you can use the compressed protocol to make traffic much more difficult to decipher. You can also use MySQL's internal SSL support to make the connection even more secure. See Section 5.9.7, “Using Secure Connections”. Alternatively, use SSH to get an encrypted TCP/IP connection between a MySQL server and a MySQL client. You can find an Open Source SSH client at http://www.openssh.org/, and a commercial SSH client at http://www.ssh.com/.
To make a MySQL system secure, you should strongly consider the following suggestions:
Require all MySQL accounts to have a password. A client
program does not necessarily know the identity of the person
running it. It is common for client/server applications that
the user can specify any username to the client program. For
example, anyone can use the mysql program
to connect as any other person simply by invoking it as
mysql -u if
other_user
db_nameother_user has no password. If
all account have a password, connecting using another user's
account becomes much more difficult.
For a discussion of methods for setting passwords, see Section 5.9.5, “Assigning Account Passwords”.
Never run the MySQL server as the Unix
root user. This is extremely dangerous,
because any user with the FILE privilege
is able to cause the server to create files as
root (for example,
~root/.bashrc). To prevent this,
mysqld refuses to run as
root unless that is specified explicitly
using the --user=root option.
mysqld can (and should) be run as an
ordinary, unprivileged user instead. You can create a
separate Unix account named mysql to make
everything even more secure. Use this account only for
administering MySQL. To start mysqld as a
different Unix user, add a user option
that specifies the username in the
[mysqld] group of the
my.cnf option file where you specify
server options. For example:
[mysqld] user=mysql
This causes the server to start as the designated user whether you start it manually or by using mysqld_safe or mysql.server. For more details, see Section 5.7.5, “How to Run MySQL as a Normal User”.
Running mysqld as a Unix user other than
root does not mean that you need to
change the root username in the
user table. Usernames for MySQL
accounts have nothing to do with usernames for Unix
accounts.
Do not allow the use of symlinks to tables. (This capability
can be disabled with the
--skip-symbolic-links option.) This is
especially important if you run mysqld as
root, because anyone that has write
access to the server's data directory then could delete any
file in the system! See
Section 7.6.1.2, “Using Symbolic Links for Tables on Unix”.
Make sure that the only Unix user with read or write privileges in the database directories is the user that mysqld runs as.
Do not grant the PROCESS or
SUPER privilege to non-administrative
users. The output of mysqladmin
processlist and SHOW
PROCESSLIST shows the text of any statements
currently being executed, so any user who is allowed to see
the server process list might be able to see statements
issued by other users such as UPDATE user SET
password=PASSWORD('not_secure').
mysqld reserves an extra connection for
users who have the SUPER privilege, so
that a MySQL root user can log in and
check server activity even if all normal connections are in
use.
The SUPER privilege can be used to
terminate client connections, change server operation by
changing the value of system variables, and control
replication servers.
Do not grant the FILE privilege to
non-administrative users. Any user that has this privilege
can write a file anywhere in the filesystem with the
privileges of the mysqld daemon. To make
this a bit safer, files generated with SELECT ...
INTO OUTFILE do not overwrite existing files and
are writable by everyone.
The FILE privilege may also be used to
read any file that is world-readable or accessible to the
Unix user that the server runs as. With this privilege, you
can read any file into a database table. This could be
abused, for example, by using LOAD DATA
to load /etc/passwd into a table, which
then can be displayed with SELECT.
If you do not trust your DNS, you should use IP numbers rather than hostnames in the grant tables. In any case, you should be very careful about creating grant table entries using hostname values that contain wildcards.
If you want to restrict the number of connections allowed to
a single account, you can do so by setting the
max_user_connections variable in
mysqld. The GRANT
statement also supports resource control options for
limiting the extent of server use allowed to an account. See
Section 13.5.1.3, “GRANT Syntax”.
The following mysqld options affect security:
This option controls whether user-defined functions that
have only an xxx symbol for the main
function can be loaded. By default, the option is off and
only UDFs that have at least one auxiliary symbol can be
loaded; this prevents attempts at loading functions from
shared object files other than those containing legitimate
UDFs. See Section 28.3.4.6, “User-Defined Function Security Precautions”.
If you start the server with
--local-infile=0, clients cannot use
LOCAL in LOAD DATA
statements. See Section 5.7.4, “Security Issues with LOAD DATA LOCAL”.
Force the server to generate short (pre-4.1) password hashes for new passwords. This is useful for compatibility when the server must support older client programs. See Section 5.8.9, “Password Hashing as of MySQL 4.1”.
--safe-show-database
(OBSOLETE)
In previous versions of MySQL, this option caused the
SHOW DATABASES statement to display the
names of only those databases for which the user had some
kind of privilege. In MySQL 5.1, this option is
no longer available as this is now the default behavior, and
there is a SHOW DATABASES privilege that
can be used to control access to database names on a
per-account basis. See Section 13.5.1.3, “GRANT Syntax”.
If this option is enabled, a user cannot create new MySQL
users by using the GRANT statement unless
the user has the INSERT privilege for the
mysql.user table. If you want a user to
have the ability to create new users that have those
privileges that the user has right to grant, you should
grant the user the following privilege:
GRANT INSERT(user) ON mysql.user TO 'user_name'@'host_name';
This ensures that the user cannot change any privilege
columns directly, but has to use the
GRANT statement to give privileges to
other users.
Disallow authentication for accounts that have old (pre-4.1) passwords.
The mysql client also has a
--secure-auth option, which prevents
connections to a server if the server requires a password in
old format for the client account.
This option causes the server not to use the privilege
system at all. This gives anyone with access to the server
unrestricted access to all
databases. You can cause a running server to
start using the grant tables again by executing
mysqladmin flush-privileges or
mysqladmin reload command from a system
shell, or by issuing a MySQL FLUSH
PRIVILEGES statement. This option also suppresses
loading of plugins and user-defined functions (UDFs).
Hostnames are not resolved. All Host
column values in the grant tables must be IP numbers or
localhost.
Do not allow TCP/IP connections over the network. All connections to mysqld must be made via Unix socket files.
With this option, the SHOW DATABASES
statement is allowed only to users who have the
SHOW DATABASES privilege, and the
statement displays all database names. Without this option,
SHOW DATABASES is allowed to all users,
but displays each database name only if the user has the
SHOW DATABASES privilege or some
privilege for the database. Note that any global privilege
is a privilege for the database.
Options that begin with --ssl specify
whether to allow clients to connect via SSL and indicate
where to find SSL keys and certificates. See
Section 5.9.7.3, “SSL Command Options”.
The LOAD DATA statement can load a file that
is located on the server host, or it can load a file that is
located on the client host when the LOCAL
keyword is specified.
There are two potential security issues with supporting the
LOCAL version of LOAD DATA
statements:
The transfer of the file from the client host to the server
host is initiated by the MySQL server. In theory, a patched
server could be built that would tell the client program to
transfer a file of the server's choosing rather than the
file named by the client in the LOAD DATA
statement. Such a server could access any file on the client
host to which the client user has read access.
In a Web environment where the clients are connecting from a
Web server, a user could use LOAD DATA
LOCAL to read any files that the Web server
process has read access to (assuming that a user could run
any command against the SQL server). In this environment,
the client with respect to the MySQL server actually is the
Web server, not the remote program being run by the user who
connects to the Web server.
To deal with these problems, we changed how LOAD DATA
LOCAL is handled as of MySQL 3.23.49 and MySQL 4.0.2
(4.0.13 on Windows):
By default, all MySQL clients and libraries in binary
distributions are compiled with the
--enable-local-infile option, to be
compatible with MySQL 3.23.48 and before.
If you build MySQL from source but do not invoke
configure with the
--enable-local-infile option, LOAD
DATA LOCAL cannot be used by any client unless it
is written explicitly to invoke mysql_options(...
MYSQL_OPT_LOCAL_INFILE, 0). See
Section 26.2.3.48, “mysql_options()”.
You can disable all LOAD DATA LOCAL
commands from the server side by starting
mysqld with the
--local-infile=0 option.
For the mysql command-line client,
LOAD DATA LOCAL can be enabled by
specifying the --local-infile[=1] option,
or disabled with the --local-infile=0
option. Similarly, for mysqlimport, the
--local or -L option
enables local data file loading. In any case, successful use
of a local loading operation requires that the server is
enabled to allow it.
If you use LOAD DATA LOCAL in Perl
scripts or other programs that read the
[client] group from option files, you can
add the local-infile=1 option to that
group. However, to keep this from causing problems for
programs that do not understand
local-infile, specify it using the
loose- prefix:
[client] loose-local-infile=1
If LOAD DATA LOCAL INFILE is disabled,
either in the server or the client, a client that attempts
to issue such a statement receives the following error
message:
ERROR 1148: The used command is not allowed with this MySQL version
On Windows, you can run the server as a Windows service using a normal user account.
On Unix, the MySQL server mysqld can be
started and run by any user. However, you should avoid running
the server as the Unix root user for security
reasons. To change mysqld to run as a normal
unprivileged Unix user user_name, you
must do the following:
Stop the server if it's running (use mysqladmin shutdown).
Change the database directories and files so that
user_name has privileges to read
and write files in them (you might need to do this as the
Unix root user):
shell> chown -R user_name /path/to/mysql/datadir
If you do not do this, the server will not be able to access
databases or tables when it runs as
user_name.
If directories or files within the MySQL data directory are
symbolic links, you'll also need to follow those links and
change the directories and files they point to.
chown -R might not follow symbolic links
for you.
Start the server as user
user_name. If you are using MySQL
3.22 or later, another alternative is to start
mysqld as the Unix
root user and use the
--user=
option. mysqld starts up, then switches
to run as the Unix user user_nameuser_name
before accepting any connections.
To start the server as the given user automatically at
system startup time, specify the username by adding a
user option to the
[mysqld] group of the
/etc/my.cnf option file or the
my.cnf option file in the server's data
directory. For example:
[mysqld]
user=user_name
If your Unix machine itself isn't secured, you should assign
passwords to the MySQL root accounts in the
grant tables. Otherwise, any user with a login account on that
machine can run the mysql client with a
--user=root option and perform any operation.
(It is a good idea to assign passwords to MySQL accounts in any
case, but especially so when other login accounts exist on the
server host.) See Section 2.10, “Post-Installation Setup and Testing”.
Access denied ErrorsMySQL has an advanced but non-standard security and privilege system. The following discussion describes how it works.
The primary function of the MySQL privilege system is to
authenticate a user who connects from a given host and to
associate that user with privileges on a database such as
SELECT, INSERT,
UPDATE, and DELETE.
Additional functionality includes the ability to have anonymous
users and to grant privileges for MySQL-specific functions such
as LOAD DATA INFILE and administrative
operations.
The MySQL privilege system ensures that all users may perform only the operations allowed to them. As a user, when you connect to a MySQL server, your identity is determined by the host from which you connect and the username you specify. When you issue requests after connecting, the system grants privileges according to your identity and what you want to do.
MySQL considers both your hostname and username in identifying
you because there is little reason to assume that a given
username belongs to the same person everywhere on the Internet.
For example, the user joe who connects from
office.example.com need not be the same
person as the user joe who connects from
home.example.com. MySQL handles this by
allowing you to distinguish users on different hosts that happen
to have the same name: You can grant one set of privileges for
connections by joe from
office.example.com, and a different set of
privileges for connections by joe from
home.example.com.
MySQL access control involves two stages when you run a client program that connects to the server:
Stage 1: The server checks whether it should allow you to connect.
Stage 2: Assuming that you can connect, the server checks
each statement you issue to determine whether you have
sufficient privileges to perform it. For example, if you try
to select rows from a table in a database or drop a table
from the database, the server verifies that you have the
SELECT privilege for the table or the
DROP privilege for the database.
If your privileges are changed (either by yourself or someone else) while you are connected, those changes do not necessarily take effect immediately for the next statement that you issue. See Section 5.8.7, “When Privilege Changes Take Effect”, for details.
The server stores privilege information in the grant tables of
the mysql database (that is, in the database
named mysql). The MySQL server reads the
contents of these tables into memory when it starts and re-reads
them under the circumstances indicated in
Section 5.8.7, “When Privilege Changes Take Effect”. Access-control decisions
are based on the in-memory copies of the grant tables.
Normally, you manipulate the contents of the grant tables
indirectly by using statements such as GRANT
and REVOKE to set up accounts and control the
privileges available to each one. See
Section 13.5.1, “Account Management Statements”. The discussion here
describes the underlying structure of the grant tables and how
the server uses their contents when interacting with clients.
The server uses the user,
db, and host tables in the
mysql database at both stages of access
control. The columns in the user and
db tables are shown here. The
host table is similar to the
db table but has a specialized use as
described in Section 5.8.6, “Access Control, Stage 2: Request Verification”.
| Table Name | user | db |
| Scope columns | Host | Host |
User | Db | |
Password | User | |
| Privilege columns | Select_priv | Select_priv |
Insert_priv | Insert_priv | |
Update_priv | Update_priv | |
Delete_priv | Delete_priv | |
Index_priv | Index_priv | |
Alter_priv | Alter_priv | |
Create_priv | Create_priv | |
Drop_priv | Drop_priv | |
Grant_priv | Grant_priv | |
Create_view_priv | Create_view_priv | |
Show_view_priv | Show_view_priv | |
Create_routine_priv | Create_routine_priv | |
Alter_routine_priv | Alter_routine_priv | |
Execute_priv | Execute_priv | |
Trigger_priv | Trigger_priv | |
Event_priv | Event_priv | |
Create_tmp_table_priv | Create_tmp_table_priv | |
Lock_tables_priv | Lock_tables_priv | |
References_priv | References_priv | |
Reload_priv | ||
Shutdown_priv | ||
Process_priv | ||
File_priv | ||
Show_db_priv | ||
Super_priv | ||
Repl_slave_priv | ||
Repl_client_priv | ||
| Security columns | ssl_type | |
ssl_cipher | ||
x509_issuer | ||
x509_subject | ||
| Resource control columns | max_questions | |
max_updates | ||
max_connections | ||
max_user_connections |
The Event_priv and
Trigger_priv columns were added in MySQL
5.1.6.
During the second stage of access control, the server performs
request verification to make sure that each client has
sufficient privileges for each request that it issues. In
addition to the user, db,
and host grant tables, the server may also
consult the tables_priv and
columns_priv tables for requests that involve
tables. The tables_priv and
columns_priv tables provide finer privilege
control at the table and column levels. They have the following
columns:
| Table Name | tables_priv | columns_priv |
| Scope columns | Host | Host |
Db | Db | |
User | User | |
Table_name | Table_name | |
Column_name | ||
| Privilege columns | Table_priv | Column_priv |
Column_priv | ||
| Other columns | Timestamp | Timestamp |
Grantor |
The Timestamp and Grantor
columns currently are unused and are discussed no further here.
For verification of requests that involve stored routines, the
server may consult the procs_priv table. This
table has the following columns:
| Table Name | procs_priv |
| Scope columns | Host |
Db | |
User | |
Routine_name | |
Routine_type | |
| Privilege columns | Proc_priv |
| Other columns | Timestamp |
Grantor |
The Routine_type column is an
ENUM column with values of
'FUNCTION' or 'PROCEDURE'
to indicate the type of routine the row refers to. This column
allows privileges to be granted separately for a function and a
procedure with the same name.
The Timestamp and Grantor
columns currently are unused and are discussed no further here.
Each grant table contains scope columns and privilege columns:
Scope columns determine the scope of each row (entry) in the
tables; that is, the context in which the row applies. For
example, a user table row with
Host and User values
of 'thomas.loc.gov' and
'bob' would be used for authenticating
connections made to the server from the host
thomas.loc.gov by a client that specifies
a username of bob. Similarly, a
db table row with
Host, User, and
Db column values of
'thomas.loc.gov',
'bob' and 'reports'
would be used when bob connects from the
host thomas.loc.gov to access the
reports database. The
tables_priv and
columns_priv tables contain scope columns
indicating tables or table/column combinations to which each
row applies. The procs_priv scope columns
indicate the stored routine to which each row applies.
Privilege columns indicate which privileges are granted by a table row; that is, what operations can be performed. The server combines the information in the various grant tables to form a complete description of a user's privileges. Section 5.8.6, “Access Control, Stage 2: Request Verification”, describes the rules that are used to do this.
Scope columns contain strings. They are declared as shown here; the default value for each is the empty string:
| Column Name | Type |
Host | CHAR(60) |
User | CHAR(16) |
Password | CHAR(16) |
Db | CHAR(64) |
Table_name | CHAR(64) |
Column_name | CHAR(64) |
Routine_name | CHAR(64) |
For access-checking purposes, comparisons of
Host values are case-insensitive.
User, Password,
Db, and Table_name values
are case sensitive. Column_name and
Routine_name values are case insensitive.
In the user, db, and
host tables, each privilege is listed in a
separate column that is declared as ENUM('N','Y')
DEFAULT 'N'. In other words, each privilege can be
disabled or enabled, with the default being disabled.
In the tables_priv,
columns_priv, and
procs_priv tables, the privilege columns are
declared as SET columns. Values in these
columns can contain any combination of the privileges controlled
by the table:
| Table Name | Column Name | Possible Set Elements |
tables_priv | Table_priv | 'Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop',
'Grant', 'References', 'Index', 'Alter', 'Create View',
'Show view', 'Trigger' |
tables_priv | Column_priv | 'Select', 'Insert', 'Update', 'References' |
columns_priv | Column_priv | 'Select', 'Insert', 'Update', 'References' |
procs_priv | Proc_priv | 'Execute', 'Alter Routine', 'Grant' |
Briefly, the server uses the grant tables in the following manner:
The user table scope columns determine
whether to reject or allow incoming connections. For allowed
connections, any privileges granted in the
user table indicate the user's global
(superuser) privileges. Any privilege granted in this table
applies to all databases on the server.
Note: Because any global
privilege is considered a privilege for all databases, any
global privilege enables a user to see all database names
with SHOW DATABASES or by examining the
SCHEMATA table of
INFORMATION_SCHEMA.
The db table scope columns determine
which users can access which databases from which hosts. The
privilege columns determine which operations are allowed. A
privilege granted at the database level applies to the
database and to all its tables.
The host table is used in conjunction
with the db table when you want a given
db table row to apply to several hosts.
For example, if you want a user to be able to use a database
from several hosts in your network, leave the
Host value empty in the user's
db table row, then populate the
host table with a row for each of those
hosts. This mechanism is described more detail in
Section 5.8.6, “Access Control, Stage 2: Request Verification”.
Note: The
host table must be modified directly with
statements such as INSERT,
UPDATE, and DELETE. It
is not affected by statements such as
GRANT and REVOKE that
modify the grant tables indirectly. Most MySQL installations
need not use this table at all.