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. As of MySQL 4.0.3, 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 (omit --verbose before MySQL
4.1.1):
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 (omit --verbose
before MySQL 4.1.1):
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 have been present since at least MySQL 3.22.
The following table lists all available system variables:
For additional system variable information, see these sections:
Section 5.1.4, “Session System Variables”, describes system variables that exist only as session variables (that is, they do not have any global counterpart).
Section 5.1.5, “Using System Variables”, discusses the syntax for setting and displaying system variable values.
Section 5.1.5.2, “Dynamic System Variables”, lists the variables that can be set at runtime.
Information on tuning system variables can be found in Section 7.5.2, “Tuning Server Parameters”.
Section 13.2.5, “InnoDB Startup Options and System Variables”, lists
InnoDB system variables.
Section 15.4.3, “MySQL Cluster System Variables”, lists system variables which are specific to MySQL Cluster.
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.
ansi_mode
This is ON if mysqld
was started with --ansi. See
Section 1.8.3, “Running MySQL in ANSI Mode”. This variable was added in
MySQL 3.23.6 and removed in 3.23.41. See the description for
sql_mode.
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. Relative
pathnames for other variables usually are resolved relative
to the base directory.
The size of the buffer that is allocated for caching indexes
and rows for BDB tables. If you do not
use BDB tables, you should start
mysqld with --skip-bdb
to not allocate memory for this cache. This variable was
added in MySQL 3.23.14.
The base directory for BDB tables. This
should be assigned the same value as the
datadir variable. This variable was added
in MySQL 3.23.14.
The size of the buffer that is allocated for caching indexes
and rows for BDB tables. If you do not
use BDB tables, you should set this to 0
or start mysqld with
--skip-bdb in order not to allocate memory
for this cache. This variable was added in MySQL 3.23.31.
The directory where the BDB storage
engine writes its log files. This variable can be set with
the --bdb-logdir option. This variable was
added in MySQL 3.23.14.
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 ...
This variable was added in MySQL 3.23.29.
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.) This variable was added in MySQL 3.23.29.
The BDB temporary file directory. This
variable was added in MySQL 3.23.14.
bdb_version
See the description for version_bdb.
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, starting from MySQL
4.1.2, 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. This
variable was added in MySQL 3.23.29. See
Section 5.3.4, “The Binary Log”.
MySQL Enterprise.
For recommendations on the optimum setting for
binlog_cache_size subscribe to the
MySQL Enterprise Monitor. For more information, see
http://www.mysql.com/products/enterprise/advisors.html.
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. Before
MySQL 4.0.3. this variable was named
myisam_bulk_insert_tree_size.
The default character set. This variable was added in MySQL
3.23.3, then removed in MySQL 4.1.1 and replaced by the
various
character_set_
variables.
xxx
The character set for statements that arrive from the client. This variable was added in MySQL 4.1.1.
The session value of this variable is set using the
character set requested by the client when the client
connects to the server. (Many clients support a
--default-character-set option to enable
this character set to be specified explicitly. See also
Section 9.1.4, “Connection Character Sets and Collations”.) The global value of
the variable is used to set the session value in cases when
the client-requested value is unknown or not available, or
the server is configured to ignore client requests:
The client is from a version of MySQL older than MySQL 4.1, and thus does not request a character set.
The client requests a character set not known to the
server. For example, a Japanese-enabled client requests
sjis when connecting to a server not
configured with sjis support.
mysqld was started with the
--skip-character-set-client-handshake
option, which causes it to ignore client character set
configuration. This reproduces MySQL 4.0 behavior and is
useful should you wish to upgrade the server without
upgrading all the clients.
The character set used for literals that do not have a character set introducer and for number-to-string conversion. This variable was added in MySQL 4.1.1.
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. This
variable was added in MySQL 4.1.1.
The character set used for returning query results to the client. This variable was added in MySQL 4.1.1.
The server default character set. This variable was added in MySQL 4.1.1.
The character set used by the server for storing
identifiers. The value is always utf8.
This variable was added in MySQL 4.1.1.
The supported character sets. This variable was added in
MySQL 3.23.15 and removed in MySQL 4.1.1. (Use SHOW
CHARACTER SET for a list of character sets.)
The directory where character sets are installed. This variable was added in MySQL 4.1.2.
The collation of the connection character set. This variable was added in MySQL 4.1.1.
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. This variable
was added in MySQL 4.1.1.
The server default collation. This variable was added in MySQL 4.1.1.
If ON (the default), MySQL allows
INSERT and SELECT
statements to run concurrently for MyISAM
tables that have no free blocks in the middle of the data
file. You can turn this option off by starting
mysqld with --safe or
--skip-new. This variable was added in
MySQL 3.23.7.
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. The default value is 5
seconds.
Increasing the connect_timeout value
might help if clients frequently encounter errors of the
form Lost connection to MySQL server at
'.
XXX', system error:
errno
The current character set mapping that was set by
SET CHARACTER SET. This variable was
removed in MySQL 4.1.
datadir
The MySQL data directory. This variable can be set with the
--datadir option.
This variable is unused.
This variable is unused.
The default mode value to use for the
WEEK() function. See
Section 11.6, “Date and Time Functions”. This variable is
available as of MySQL 4.0.14.
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.1.2, “Command Options”, and
Section 13.1.1, “MyISAM Startup Options”.
Note that if you enable external locking with
--external-locking, there is no protection
against index corruption for tables that use delayed key
writes.
This variable was added in MySQL 3.23.8.
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.
How many seconds an INSERT DELAYED
handler thread should wait for INSERT
statements before terminating.
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.
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. This variable was added in MySQL 4.1.0.
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.1.4.2, “What to Do If MySQL Keeps Crashing”. This
variable is set to ON if you start
mysqld with the --flush
option. This variable was added in MySQL 3.22.9.
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. This variable was
added in MySQL 3.22.18.
The list of operators supported by boolean full-text
searches performed using IN BOOLEAN MODE.
See Section 11.8.2, “Boolean Full-Text Searches”. This variable was
added as a read-only variable in MySQL 4.0.1. It can be
modified as of MySQL 4.1.2.
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.
The maximum length of the word to be included in a
FULLTEXT index. This variable was added
in MySQL 4.0.0.
FULLTEXT indexes must be rebuilt after
changing this variable. Use REPAIR TABLE
.
tbl_name QUICK
The minimum length of the word to be included in a
FULLTEXT index. This variable was added
in MySQL 4.0.0.
FULLTEXT indexes must be rebuilt after
changing this variable. Use REPAIR TABLE
.
tbl_name QUICK
The number of top matches to use for full-text searches
performed using WITH QUERY EXPANSION.
This variable was added in MySQL 4.1.1.
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. This variable was added in
MySQL 4.0.10.
FULLTEXT indexes must be rebuilt after
changing this variable or the contents of the stopword
file. Use REPAIR TABLE
.
tbl_name QUICK
The maximum allowed result length in bytes for the
GROUP_CONCAT() function. The
default is 1024. This variable was added in MySQL 4.1.0.
YES if mysqld supports
ARCHIVE tables, NO if
not. This variable was added in MySQL 4.1.3.
YES if mysqld supports
BDB tables. DISABLED
if --skip-bdb is used. This variable was
added in MySQL 3.23.30.
YES if mysqld supports
BLACKHOLE tables, NO
if not. This variable was added in MySQL 4.1.11.
YES if the zlib
compression library is available to the server,
NO if not. If not, the
COMPRESS() and
UNCOMPRESS() functions
cannot be used. This variable was added in MySQL 4.1.1.
YES if the crypt()
system call is available to the server,
NO if not. If not, the
ENCRYPT() function cannot be
used. This variable was added in MySQL 4.0.10.
YES if mysqld supports
ARCHIVE tables, NO if
not. This variable was added in MySQL 4.1.4.
YES if mysqld supports
EXAMPLE tables, NO if
not. This variable was added in MySQL 4.1.4.
YES if the server supports spatial data
types, NO if not. This variable was added
in MySQL 4.1.3.
YES if mysqld supports
InnoDB tables.
DISABLED if
--skip-innodb is used. This variable was
added in MySQL 3.23.37.
YES if mysqld supports
ISAM tables. DISABLED
if --skip-isam is used. This variable was
added in MySQL 3.23.30.
YES if mysqld supports
MERGE tables. DISABLED
if --skip-merge is used. This variable was
added in MySQL 4.1.21.
YES if mysqld supports
SSL (encryption) connections, NO if not.
This variable was added in MySQL 3.23.43.
YES if mysqld supports
the query cache, NO if not. This variable
was added in MySQL 4.0.2.
YES if mysqld supports
the RAID option, NO if
not. This variable was added in MySQL 3.23.30.
YES if RTREE indexes
are available, NO if not. (These are used
for spatial indexes in MyISAM tables.)
This variable was added in MySQL 4.1.3.
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.
This variable was added in MySQL 4.0.0.
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.
This variable was added in MySQL 4.1.2.
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. This variable was added in MySQL 3.23.2.
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. This
variable was added in MySQL 4.1.2.
innodb_
xxx
InnoDB system variables are listed in
Section 13.2.5, “InnoDB Startup Options and System Variables”.
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.
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 and
ISAM 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. The value of this
variable indicates the amount of memory requested.
Internally, the server allocates as much memory as possible
up to this amount, but the actual allocation might be less.
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.13, “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 12.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. From MySQL 4.1.1 on, the buffer block
size is available from the
key_cache_block_size server variable. The
fraction of the buffer in use is:
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.
Before MySQL 4.1.1, key cache blocks are 1024 bytes, and
before MySQL 4.1.2, Key_blocks_unused is
unavailable. The Key_blocks_used variable
can be used as follows to determine the fraction of the key
buffer in use:
(Key_blocks_used × 1024) / key_buffer_size
However, Key_blocks_used indicates the
maximum number of blocks that have ever been in use at once,
so this formula does not necessarily represent the current
fraction of the buffer that is in use.
As of MySQL 4.1, 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”.
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. This variable was added in
MySQL 4.1.1. See Section 7.4.6, “The MyISAM Key Cache”.
The size in bytes of blocks in the key cache. The default
value is 1024. This variable was added in MySQL 4.1.1. See
Section 7.4.6, “The MyISAM Key Cache”.
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. This
variable was added in MySQL 4.1.1. See
Section 7.4.6, “The MyISAM Key Cache”.
language
The language used for error messages.
Whether mysqld was compiled with options for large file support. This variable was added in MySQL 3.23.28.
This variable specifies the locale that controls the
language used to display day and month names and
abbreviations. This variable affects the output from the
DATE_FORMAT(),
DAYNAME() and
MONTHNAME() functions.
Locale names are POSIX-style values such as
'ja_JP' or 'pt_BR'.
The default value is 'en_US' regardless
of your system's locale setting. For further information,
see Section 9.8, “MySQL Server Locale Support”. This variable was
added in MySQL 4.1.21.
The type of license the server has. This variable was added in MySQL 4.0.19.
Whether LOCAL is supported for
LOAD DATA INFILE statements. See
Section 5.4.4, “Security Issues with LOAD DATA LOCAL”. This variable was added
in MySQL 4.0.3.
Whether mysqld was locked in memory with
--memlock. This variable was added in MySQL
3.23.25.
log
Whether logging of all statements to the general query log is enabled. See Section 5.3.2, “The General Query Log”.
Whether the binary log is enabled. This variable was added in MySQL 3.23.14. See Section 5.3.4, “The Binary Log”.
The location of the error log. This variable was added in MySQL 4.0.10.
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. This variable was added in MySQL 3.23.17. See Section 14.8, “Replication Startup Options”.
Whether slow queries should be logged. “Slow”
is determined by the value of the
long_query_time variable. This variable
was added in MySQL 4.0.2. See
Section 5.3.5, “The Slow Query Log”.
Whether the update log is enabled. This variable was added in MySQL 3.22.18. Note that the binary log is preferable to the update log, which is unavailable as of MySQL 5.0. See Section 5.3.3, “The Update Log”.
Whether to produce additional warning messages. This variable was added in MySQL 4.0.3. It is enabled by default as of MySQL 4.0.19 and 4.1.2. As of MySQL 4.0.21 and 4.1.3, the variable can take values greater than 1 and aborted connections are not logged to the error log unless the value is greater than 1.
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.3.5, “The Slow Query Log”.
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 affects only
storage engines that use only table-level locking
(MyISAM, MEMORY,
MERGE). Before MySQL 3.22.5, this
variable was named
sql_low_priority_updates.
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.
This variable was added in MySQL 4.0.19.
If set to 1 table names are stored in lowercase on disk and table name comparisons are not case sensitive. This variable was added in MySQL 3.23.6. If set to 2 (new in 4.0.18), table names are stored as given but compared in lowercase. From MySQL 4.0.2, this option also applies to database names. From 4.1.1, it also applies to table aliases. See Section 8.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).
New in 4.0.18: 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.
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 16MB before MySQL
4.0 and 1GB thereafter. The value should be a multiple of
1024; non-multiples are rounded down to the nearest
multiple.
If a multiple-statement transaction requires more than this
many bytes of memory, the server generates a
Multi-statement transaction required more than
'max_binlog_cache_size' bytes of storage error.
The minimum value is 4096, the maximum and default values
are 4GB. This variable was added in MySQL 3.23.29.
