Several system variables exist only as session variables. These
cannot be set at server startup but can be assigned values at
runtime using the SET statement (except for
those that are read only). Most of them are not displayed by
SHOW VARIABLES, but you can obtain their
values using SELECT. This section describes
the session system variables. For information about setting or
displaying their values, see
Section 5.1.5, “Using System Variables”. For example:
mysql> SELECT @@AUTOCOMMIT;
+--------------+
| @@AUTOCOMMIT |
+--------------+
| 1 |
+--------------+
The lettercase of these variables does not matter.
The following table lists the system variables that have only session scope:
| Name | Cmd-Line | Option file | System Var | Dynamic |
|---|---|---|---|---|
| autocommit | Yes | Yes | ||
| big-tables | Yes | Yes | ||
| - Variable: big_tables | Yes | Yes | ||
| error_count | Yes | No | ||
| foreign_key_checks | Yes | Yes | ||
| identity | Yes | Yes | ||
| insert_id | Yes | Yes | ||
| last_insert_id | Yes | Yes | ||
| ndb_table_no_logging | Yes | Yes | ||
| ndb_table_temporary | Yes | Yes | ||
| sql_auto_is_null | Yes | Yes | ||
| sql_big_selects | Yes | Yes | ||
| sql_big_tables | Yes | Yes | ||
| sql_buffer_result | Yes | Yes | ||
| sql_log_bin | Yes | Yes | ||
| sql_log_off | Yes | Yes | ||
| sql_log_update | Yes | Yes | ||
| sql_notes | Yes | Yes | ||
| sql_quote_show_create | Yes | Yes | ||
| sql_safe_updates | Yes | Yes | ||
| sql_warnings | Yes | Yes | ||
| timestamp | Yes | Yes | ||
| transaction_allow_batching | Yes | Yes | ||
| unique_checks | Yes | Yes | ||
| warning_count | Yes | No |
Set the autocommit mode. If set to 1, all changes to a table
take effect immediately. If set to 0 you have to use
COMMIT to accept a transaction or
ROLLBACK to cancel it. By default, client
connections begin with AUTOCOMMIT set to
1. If you change AUTOCOMMIT mode from 0
to 1, MySQL performs an automatic COMMIT
of any open transaction. Another way to begin a transaction
is to use a START TRANSACTION or
BEGIN statement. See
Section 12.4.1, “START TRANSACTION, COMMIT, and
ROLLBACK Syntax”.
BIG_TABLES = {0 | 1}
If set to 1, all temporary tables are stored on disk rather
than in memory. This is a little slower, but the error
The table does not occur for tbl_name is
fullSELECT
operations that require a large temporary table. The default
value for a new connection is 0 (use in-memory temporary
tables). Normally, you should never need to set this
variable, because in-memory tables are automatically
converted to disk-based tables as required.
This variable was formerly named
SQL_BIG_TABLES.
The number of errors that resulted from the last statement
that generated messages. This variable is read only. See
Section 12.5.5.15, “SHOW ERRORS Syntax”.
If set to 1 (the default), foreign key constraints for
InnoDB tables are checked. If set to 0,
they are ignored. Disabling foreign key checking can be
useful for reloading InnoDB tables in an
order different from that required by their parent/child
relationships. See
Section 13.5.6.4, “FOREIGN KEY Constraints”.
Setting FOREIGN_KEY_CHECKS to 0 also
affects data definition statements: DROP
SCHEMA drops a schema even if it contains tables
that have foreign keys that are referred to by tables
outside the schema, and DROP TABLE drops
tables that have foreign keys that are referred to by other
tables.
Setting FOREIGN_KEY_CHECKS to 1 does
not trigger a scan of the existing table data. Therefore,
rows added to the table while
FOREIGN_KEY_CHECKS=0 will not be
verified for consistency.
This variable is a synonym for the
LAST_INSERT_ID variable. It exists for
compatibility with other database systems. You can read its
value with SELECT @@IDENTITY, and set it
using SET IDENTITY.
Set the value to be used by the following
INSERT or ALTER TABLE
statement when inserting an
AUTO_INCREMENT value. This is mainly used
with the binary log.
Set the value to be returned from
LAST_INSERT_ID(). This is
stored in the binary log when you use
LAST_INSERT_ID() in a
statement that updates a table. Setting this variable does
not update the value returned by the
mysql_insert_id() C API
function.
If set to 1 (the default), you can find the last inserted
row for a table that contains an
AUTO_INCREMENT column by using the
following construct:
WHERE auto_increment_column IS NULL
This behavior is used by some ODBC programs, such as Access.
If set to 0, MySQL aborts SELECT
statements that are likely to take a very long time to
execute (that is, statements for which the optimizer
estimates that the number of examined rows exceeds the value
of max_join_size). This is useful when an
inadvisable WHERE statement has been
issued. The default value for a new connection is 1, which
allows all SELECT statements.
If you set the max_join_size system
variable to a value other than DEFAULT,
SQL_BIG_SELECTS is set to 0.
If set to 1, SQL_BUFFER_RESULT forces
results from SELECT statements to be put
into temporary tables. This helps MySQL free the table locks
early and can be beneficial in cases where it takes a long
time to send results to the client. The default value is 0.
If set to 0, no logging is done to the binary log for the
client. The client must have the SUPER
privilege to set this option. The default value is 1.
If set to 1, no logging is done to the general query log for
this client. The client must have the
SUPER privilege to set this option. The
default value is 0.
This variable is deprecated, and is mapped to
SQL_LOG_BIN.
If set to 1 (the default), warnings of
Note level are recorded. If set to 0,
Note warnings are suppressed.
mysqldump includes output to set this
variable to 0 so that reloading the dump file does not
produce warnings for events that do not affect the integrity
of the reload operation.
SQL_QUOTE_SHOW_CREATE = {0 | 1}
If set to 1 (the default), the server quotes identifiers for
SHOW CREATE TABLE and SHOW
CREATE DATABASE statements. If set to 0, quoting
is disabled. This option is enabled by default so that
replication works for identifiers that require quoting. See
Section 12.5.5.9, “SHOW CREATE TABLE Syntax”, and
Section 12.5.5.6, “SHOW CREATE DATABASE Syntax”.
If set to 1, MySQL aborts UPDATE or
DELETE statements that do not use a key
in the WHERE clause or a
LIMIT clause. This makes it possible to
catch UPDATE or DELETE
statements where keys are not used properly and that would
probably change or delete a large number of rows. The
default value is 0.
SQL_SELECT_LIMIT =
{
value | DEFAULT}
The maximum number of rows to return from
SELECT statements. The default value for
a new connection is the maximum number of rows that the
server allows per table, which depends on the server
configuration and may be affected if the server build was
configured with --with-big-tables. Typical
default values are (232)–1
or (264)–1. If you have
changed the limit, the default value can be restored by
assigning a value of DEFAULT.
If a SELECT has a
LIMIT clause, the
LIMIT takes precedence over the value of
SQL_SELECT_LIMIT.
SQL_SELECT_LIMIT does not apply to
SELECT statements executed within stored
routines. It also does not apply to
SELECT statements that do not produce a
result set to be returned to the client. These include
SELECT statements in subqueries,
CREATE TABLE ... SELECT, and
INSERT INTO ... SELECT.
This variable controls whether single-row
INSERT statements produce an information
string if warnings occur. The default is 0. Set the value to
1 to produce an information string.
TIMESTAMP =
{
timestamp_value |
DEFAULT}
Set the time for this client. This is used to get the
original timestamp if you use the binary log to restore
rows. timestamp_value should be a Unix
epoch timestamp, not a MySQL timestamp.
SET TIMESTAMP affects the value returned
by NOW() but not by
SYSDATE(). This means that
timestamp settings in the binary log have no effect on
invocations of SYSDATE().
The server can be started with the
--sysdate-is-now option to cause
SYSDATE() to be an alias for
NOW(), in which case
SET TIMESTAMP affects both functions.
If set to 1 (the default), uniqueness checks for secondary
indexes in InnoDB tables are performed.
If set to 0, storage engines are allowed to assume that
duplicate keys are not present in input data. If you know
for certain that your data does not contain uniqueness
violations, you can set this to 0 to speed up large table
imports to InnoDB.
Note that setting this variable to 0 does not require storage engines to ignore duplicate keys. An engine is still allowed to check for them and issue duplicate-key errors if it detects them.
The number of errors, warnings, and notes that resulted from
the last statement that generated messages. This variable is
read only. See Section 12.5.5.32, “SHOW WARNINGS Syntax”.

User Comments
Add your own comment.