[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SET
Syntax
SET [GLOBAL | SESSION] sql_variable=expression, [[GLOBAL | SESSION] sql_variable=expression] ... |
SET
sets various options that affect the operation of the
server or your client.
The following examples shows the different syntaxes one can use to set variables:
In old MySQL versions we allowed the use of the SET OPTION
syntax,
but this syntax is now deprecated.
In MySQL 4.0.3 we added the GLOBAL
and SESSION
options
and access to most important startup variables.
LOCAL
can be used as a synonym for SESSION
.
If you set several variables on the same command line, the last used
GLOBAL | SESSION
mode is used.
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; |
The @@variable_name
syntax is supported to make MySQL syntax
compatible with some other databases.
The different system variables you can set are described in the system variable section of this manual. See section 10.4 System Variables.
If you are using SESSION
(the default), the option you set remains
in effect until the current session ends or until you set the option to
a different value. If you use GLOBAL
, which requires the
SUPER
privilege, the option is remembered and used for new
connections until the server restarts. If you want to make an option
permanent, you should set it in an option file.
See section 4.3.2 Using Option Files.
To avoid incorrect usage, MySQL will produce an error if you use SET
GLOBAL
with a variable that can only be used with SET SESSION
or if
you are not using SET GLOBAL
with a global variable.
If you want to set a SESSION
variable to the GLOBAL
value or a
GLOBAL
value to the MySQL default value, you can set it to
DEFAULT
.
SET max_join_size=DEFAULT; |
This is identical to:
SET @@session.max_join_size=@@global.max_join_size; |
If you want to restrict the maximum value to which a server variable can be set
with the SET
command, you can specify this maximum by using the
--maximum-variable-name
command line option. See section 5.2.1 mysqld
Command-line Options.
You can get a list of most variables with SHOW VARIABLES
.
See section SHOW VARIABLES
. You can get the value for
a specific value with the @@[global.|local.]variable_name
syntax:
SHOW VARIABLES like "max_join_size"; SHOW GLOBAL VARIABLES like "max_join_size"; SELECT @@max_join_size, @@global.max_join_size; |
Here follows a description of the variables that use
a non-standard SET
syntax and some of the other
variables. The other variable definitions can be found in the system
variable section, among the startup options or in the description of
SHOW VARIABLES
.
See section 10.4 System Variables.
See section 5.2.1 mysqld
Command-line Options.
See section SHOW VARIABLES
.
AUTOCOMMIT= 0 | 1
1
, all changes to a table will be done at once. To start
a multi-command transaction, you have to use the BEGIN
statement. See section 13.4.1 START TRANSACTION
, COMMIT
, and ROLLBACK
Syntax. If set to 0
you have to use COMMIT
to accept that transaction or ROLLBACK
to cancel it.
See section 13.4.1 START TRANSACTION
, COMMIT
, and ROLLBACK
Syntax.
Note that when you change AUTOCOMMIT
mode from 0
to 1
,
MySQL performs an automatic COMMIT
of any open transaction.
BIG_TABLES = 0 | 1
1
, all temporary tables are stored on disk rather than in
memory. This will be a little slower, but you will not get the error
The table tbl_name is full
for big SELECT
operations that
require a large temporary table. The default value for a new connection is
0
(that is, use in-memory temporary tables).
This variable previously was named SQL_BIG_TABLES
. In MySQL 4.0, you
should normally never need to set this variable, because MySQL automatically
converts in-memory tables to disk-based tables as necessary.
CHARACTER SET character_set_name | DEFAULT
character_set_name
is
cp1251_koi8
, but you can easily add new mappings by editing the
`sql/convert.cc' file in the MySQL source distribution. The
default mapping can be restored by using a character_set_name
value of
DEFAULT
.
Note that the syntax for setting the CHARACTER SET
option differs
from the syntax for setting the other options.
INSERT_ID = #
INSERT
or ALTER TABLE
command when inserting an AUTO_INCREMENT
value. This is mainly used
with the binary log.
LAST_INSERT_ID = #
LAST_INSERT_ID()
. This is stored in
the binary log when you use LAST_INSERT_ID()
in a command that updates
a table. Setting this variable does not update mysql_insert_id()
.
LOW_PRIORITY_UPDATES = 0 | 1
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
.
MAX_JOIN_SIZE = value | DEFAULT
Don't allow SELECT
statements that will probably need to examine more
than value
row combinations or is likely to do more than value
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. Setting this to a value other than DEFAULT
resets the
SQL_BIG_SELECTS
value to 0
. If you set the
SQL_BIG_SELECTS
value
again, the SQL_MAX_JOIN_SIZE
variable will be ignored. You can
set a default value for this variable by starting mysqld
with the
--max_join_size=value
option. This variable previously was named
SQL_MAX_JOIN_SIZE
.
Note that if a query result already is in the query cache, no result size check is performed, because the result has already been computed and it will not burden the server to send it to the client.
PASSWORD = PASSWORD('some password')
PASSWORD FOR user = PASSWORD('some password')
mysql
database can do this. The user should be
given in user@hostname
format, where user
and hostname
are exactly as they are listed in the User
and Host
columns of
the mysql.user
table entry. For example, if you had an entry with
User
and Host
fields of 'bob'
and '%.loc.gov'
,
you would write:
mysql> SET PASSWORD FOR 'bob'@'%.loc.gov' = PASSWORD('newpass'); |
Which is equivalent to:
mysql> UPDATE mysql.user SET Password=PASSWORD('newpass') -> WHERE User='bob' AND Host='%.loc.gov'; mysql> FLUSH PRIVILEGES; |
QUERY_CACHE_TYPE = OFF | ON | DEMAND
QUERY_CACHE_TYPE = 0 | 1 | 2
Option | Description |
0 or OFF | Don't cache or retrieve results. |
1 or ON | Cache all results except SELECT SQL_NO_CACHE ... queries. |
2 or DEMAND | Cache only SELECT SQL_CACHE ... queries. |
SQL_AUTO_IS_NULL = 0 | 1
1
(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 is used by some
ODBC programs like Access.
SQL_BIG_SELECTS = 0 | 1
0
, MySQL aborts SELECT
statements
that probably will take a very long time (that is, statements for which
the optimizer estimates that the number of of examined rows probably will
exceed 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 MAX_JOIN_SIZE
to a value other than DEFAULT
,
SQL_BIG_SELECTS
will be set to 0
.
SQL_BUFFER_RESULT = 0 | 1
SQL_BUFFER_RESULT
forces the result from SELECT
statements
to be put into a temporary table. This will help MySQL free the
table locks early and will help in cases where it takes a long time to
send the result set to the client.
SQL_LOG_BIN = 0 | 1
0
, no logging is done to the binary log for the client,
if the client has the SUPER
privilege.
SQL_LOG_OFF = 0 | 1
1
, no logging is done to the standard log for this
client, if the client has the SUPER
privilege.
SQL_LOG_UPDATE = 0 | 1
0
, no logging is done to the update log for the client,
if the client has the SUPER
privilege.
This variable is deprecated starting from version 5.0.0 and mapped to
SQL_LOG_BIN
(see section C.1.2 Changes in release 5.0.0 (22 Dec 2003: Alpha)).
SQL_QUOTE_SHOW_CREATE = 0 | 1
1
, SHOW CREATE TABLE
quotes
table and column names. This is on by default,
so that replication of tables with fancy column names will work.
SHOW CREATE TABLE
.
SQL_SAFE_UPDATES = 0 | 1
1
, MySQL aborts UPDATE
or
DELETE
statements that do not use a key or LIMIT
in the
WHERE
clause. This makes it possible to catch wrong updates
when creating SQL statements by hand.
SQL_SELECT_LIMIT = value | DEFAULT
SELECT
statements. If
a SELECT
has a LIMIT
clause, the LIMIT
takes precedence
over the value of SQL_SELECT_LIMIT
. The default value for a new
connection is "unlimited." If you have changed the limit, the default value
can be restored by using a SQL_SELECT_LIMIT
value of DEFAULT
.
TIMESTAMP = timestamp_value | DEFAULT
timestamp_value
should be a
Unix epoch timestamp, not a MySQL timestamp.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |