关键字是 SQL 中有意义的单词。某些关键字,如 SELECT
、DELETE
或 BIGINT
,是保留字,需要特殊处理才能用作标识符,如表名和列名。对于内置函数的名称也可能是这种情况。
非保留字关键字允许作为标识符而不加引号。如果按照 第 11.2 节“架构对象名称” 中的说明加上引号,则保留字允许作为标识符
mysql> CREATE TABLE interval (begin INT, end INT);
ERROR 1064 (42000): You have an error in your SQL syntax ...
near 'interval (begin INT, end INT)'
BEGIN
和 END
是关键字,但不是保留字,因此用作标识符时不需要加引号。 INTERVAL
是保留字,用作标识符时必须加引号
mysql> CREATE TABLE `interval` (begin INT, end INT);
Query OK, 0 rows affected (0.01 sec)
例外:限定名称中句点后面的单词必须是标识符,因此即使是保留字也不需要加引号
mysql> CREATE TABLE mydb.interval (begin INT, end INT);
Query OK, 0 rows affected (0.01 sec)
内置函数的名称允许作为标识符,但可能需要小心使用。例如,COUNT
可用作列名。但是,默认情况下,函数调用中函数名称和后面的 (
字符之间不允许有空格。此要求使解析器能够区分名称是在函数调用中使用还是在非函数上下文中使用。有关识别函数名称的更多详细信息,请参见 第 11.2.5 节“函数名称解析和解决”。
INFORMATION_SCHEMA.KEYWORDS
表列出了 MySQL 认为是关键字的单词,并指出了它们是否是保留字。请参见 第 28.3.17 节“INFORMATION_SCHEMA KEYWORDS 表”。
以下列表显示了 MySQL 8.4 中的关键字和保留字,以及各个单词从版本到版本的变化。保留关键字用 (R) 标记。此外,_FILENAME
已保留。
在某个时候,您可能会升级到更高版本,因此最好也了解一下未来的保留字。您可以在涵盖 MySQL 更高版本的文档中找到这些保留字。列表中的大多数保留字都被标准 SQL 禁止用作列或表名(例如,GROUP
)。少数几个被保留,因为 MySQL 需要它们并使用 yacc 解析器。
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
ACCESSIBLE
(R)ACCOUNT
ACTION
ACTIVE
ADD
(R)ADMIN
AFTER
AGAINST
AGGREGATE
ALGORITHM
ALL
(R)ALTER
(R)ALWAYS
ANALYZE
(R)AND
(R)ANY
ARRAY
AS
(R)ASC
(R)ASCII
ASENSITIVE
(R)AT
ATTRIBUTE
AUTHENTICATION
AUTO
AUTOEXTEND_SIZE
AUTO_INCREMENT
AVG
AVG_ROW_LENGTH
BACKUP
BEFORE
(R)BEGIN
BERNOULLI
BETWEEN
(R)BIGINT
(R)BINARY
(R)BINLOG
BIT
BLOB
(R)BLOCK
BOOL
BOOLEAN
BOTH
(R)BTREE
BUCKETS
BULK
BY
(R)BYTE
CACHE
CALL
(R)CASCADE
(R)CASCADED
CASE
(R)CATALOG_NAME
CHAIN
CHALLENGE_RESPONSE
CHANGE
(R)CHANGED
CHANNEL
CHAR
(R)CHARACTER
(R)CHARSET
CHECK
(R)CHECKSUM
CIPHER
CLASS_ORIGIN
CLIENT
CLONE
CLOSE
COALESCE
CODE
COLLATE
(R)COLLATION
COLUMN
(R)COLUMNS
COLUMN_FORMAT
COLUMN_NAME
COMMENT
COMMIT
COMMITTED
COMPACT
COMPLETION
COMPONENT
COMPRESSED
COMPRESSION
CONCURRENT
CONDITION
(R)CONNECTION
CONSISTENT
CONSTRAINT
(R)CONSTRAINT_CATALOG
CONSTRAINT_NAME
CONSTRAINT_SCHEMA
CONTAINS
CONTEXT
CONTINUE
(R)CONVERT
(R)CPU
CREATE
(R)CROSS
(R)CUBE
(R)CUME_DIST
(R)CURRENT
CURRENT_DATE
(R)CURRENT_TIME
(R)CURRENT_TIMESTAMP
(R)CURRENT_USER
(R)CURSOR
(R)CURSOR_NAME
DATA
DATABASE
(R)DATABASES
(R)DATAFILE
DATE
DATETIME
DAY
DAY_HOUR
(R)DAY_MICROSECOND
(R)DAY_MINUTE
(R)DAY_SECOND
(R)DEALLOCATE
DEC
(R)DECIMAL
(R)DECLARE
(R)DEFAULT
(R)DEFAULT_AUTH
DEFINER
DEFINITION
DELAYED
(R)DELAY_KEY_WRITE
DELETE
(R)DENSE_RANK
(R)DESC
(R)DESCRIBE
(R)描述
DETERMINISTIC
(R)诊断
目录
禁用
放弃
磁盘
DISTINCT
(R)DISTINCTROW
(R)DIV
(R)DO
DOUBLE
(R)DROP
(R)DUAL
(R)DUMPFILE
重复
动态
EACH
(R)ELSE
(R)ELSEIF
(R)EMPTY
(R)启用
ENCLOSED
(R)加密
结束
结束
强制
引擎
引擎
ENGINE_ATTRIBUTE
ENUM
错误
错误
转义
ESCAPED
(R)事件
事件
每次
EXCEPT
(R)交换
排除
执行
EXISTS
(R)EXIT
(R)扩展
过期
EXPLAIN
(R)导出
扩展
EXTENT_SIZE
因子
FAILED_LOGIN_ATTEMPTS
FALSE
(R)快速
故障
FETCH
(R)字段
文件
FILE_BLOCK_SIZE
过滤器
完成
首先
FIRST_VALUE
(R)固定
FLOAT
(R)FLOAT4
(R)FLOAT8
(R)刷新
后续
跟随
FOR
(R)FORCE
(R)FOREIGN
(R)格式
已找到
FROM
(R)全部
FULLTEXT
(R)FUNCTION
(R)
常规
生成
GENERATED
(R)GEOMCOLLECTION
GEOMETRY
GEOMETRYCOLLECTION
GET
(R)GET_FORMAT
GET_SOURCE_PUBLIC_KEY
全局
GRANT
(R)授予
GROUP
(R)GROUPING
(R)GROUPS
(R)GROUP_REPLICATION
GTID
GTID_ONLY
HANDLER
HASH
HAVING
(R)HELP
HIGH_PRIORITY
(R)HISTOGRAM
HISTORY
HOST
HOSTS
HOUR
HOUR_MICROSECOND
(R)HOUR_MINUTE
(R)HOUR_SECOND
(R)
IDENTIFIED
IF
(R)IGNORE
(R)IGNORE_SERVER_IDS
IMPORT
IN
(R)INACTIVE
INDEX
(R)INDEXES
INFILE
(R)INITIAL
INITIAL_SIZE
INITIATE
INNER
(R)INOUT
(R)INSENSITIVE
(R)INSERT
(R)INSERT_METHOD
INSTALL
INSTANCE
INT
(R)INT1
(R)INT2
(R)INT3
(R)INT4
(R)INT8
(R)INTEGER
(R)INTERSECT
(R)INTERVAL
(R)INTO
(R)INVISIBLE
INVOKER
IO
IO_AFTER_GTIDS
(R)IO_BEFORE_GTIDS
(R)IO_THREAD
IPC
IS
(R)ISOLATION
ISSUER
ITERATE
(R)
JOIN
(R)JSON
JSON_TABLE
(R)JSON_VALUE
KEY
(R)KEYRING
KEYS
(R)KEY_BLOCK_SIZE
KILL
(R)
LAG
(R)LANGUAGE
LAST
LAST_VALUE
(R)LATERAL
(R)LEAD
(R)LEADING
(R)LEAVE
(R)LEAVES
LEFT
(R)LESS
LEVEL
LIKE
(R)LIMIT
(R)LINEAR
(R)LINES
(R)LINESTRING
LIST
LOAD
(R)LOCAL
LOCALTIME
(R)LOCALTIMESTAMP
(R)LOCK
(R)LOCKED
LOCKS
LOG
LOGFILE
LOGS
LONG
(R)LONGBLOB
(R)LONGTEXT
(R)LOOP
(R)LOW_PRIORITY
(R)
MANUAL
(R)MASTER
MATCH
(R)MAXVALUE
(R)MAX_CONNECTIONS_PER_HOUR
MAX_QUERIES_PER_HOUR
MAX_ROWS
MAX_SIZE
MAX_UPDATES_PER_HOUR
MAX_USER_CONNECTIONS
MEDIUM
MEDIUMBLOB
(R)MEDIUMINT
(R)MEDIUMTEXT
(R)MEMBER
MEMORY
MERGE
MESSAGE_TEXT
MICROSECOND
MIDDLEINT
(R)MIGRATE
MINUTE
MINUTE_MICROSECOND
(R)MINUTE_SECOND
(R)MIN_ROWS
MOD
(R)MODE
MODIFIES
(R)MODIFY
MONTH
MULTILINESTRING
MULTIPOINT
MULTIPOLYGON
MUTEX
MYSQL_ERRNO
NAME
NAMES
NATIONAL
NATURAL
(R)NCHAR
NDB
NDBCLUSTER
NESTED
NETWORK_NAMESPACE
NEVER
NEW
NEXT
NO
NODEGROUP
NONE
NOT
(R)NOWAIT
NO_WAIT
NO_WRITE_TO_BINLOG
(R)NTH_VALUE
(R)NTILE
(R)NULL
(R)NULLS
NUMBER
NUMERIC
(R)NVARCHAR
OF
(R)OFF
OFFSET
OJ
OLD
ON
(R)ONE
ONLY
OPEN
OPTIMIZE
(R)OPTIMIZER_COSTS
(R)OPTION
(R)OPTIONAL
OPTIONALLY
(R)OPTIONS
OR
(R)ORDER
(R)ORDINALITY
ORGANIZATION
其他
OUT
(R)OUTER
(R)OUTFILE
(R)OVER
(R)所有者
PACK_KEYS
PAGE
PARALLEL
(R)PARSER
PARSE_TREE
PARTIAL
PARTITION
(R)PARTITIONING
PARTITIONS
PASSWORD
PASSWORD_LOCK_TIME
PATH
PERCENT_RANK
(R)PERSIST
PERSIST_ONLY
PHASE
PLUGIN
PLUGINS
PLUGIN_DIR
POINT
POLYGON
PORT
PRECEDES
PRECEDING
PRECISION
(R)PREPARE
PRESERVE
PREV
PRIMARY
(R)PRIVILEGES
PRIVILEGE_CHECKS_USER
PROCEDURE
(R)PROCESS
PROCESSLIST
PROFILE
PROFILES
PROXY
PURGE
(R)
QUALIFY
(R)QUARTER
QUERY
QUICK
RANDOM
RANGE
(R)RANK
(R)READ
(R)READS
(R)READ_ONLY
READ_WRITE
(R)REAL
(R)REBUILD
RECOVER
RECURSIVE
(R)REDO_BUFFER_SIZE
REDUNDANT
REFERENCE
REFERENCES
(R)REGEXP
(R)REGISTRATION
RELAY
RELAYLOG
RELAY_LOG_FILE
RELAY_LOG_POS
RELAY_THREAD
RELEASE
(R)RELOAD
REMOVE
RENAME
(R)REORGANIZE
REPAIR
REPEAT
(R)REPEATABLE
REPLACE
(R)REPLICA
REPLICAS
REPLICATE_DO_DB
REPLICATE_DO_TABLE
REPLICATE_IGNORE_DB
REPLICATE_IGNORE_TABLE
REPLICATE_REWRITE_DB
REPLICATE_WILD_DO_TABLE
REPLICATE_WILD_IGNORE_TABLE
REPLICATION
REQUIRE
(R)REQUIRE_ROW_FORMAT
RESET
RESIGNAL
(R)RESOURCE
RESPECT
RESTART
RESTORE
RESTRICT
(R)RESUME
RETAIN
RETURN
(R)RETURNED_SQLSTATE
RETURNING
RETURNS
REUSE
REVERSE
REVOKE
(R)RIGHT
(R)RLIKE
(R)ROLE
ROLLBACK
ROLLUP
ROTATE
ROUTINE
ROW
(R)ROWS
(R)ROW_COUNT
ROW_FORMAT
ROW_NUMBER
(R)RTREE
S3
SAVEPOINT
SCHEDULE
SCHEMA
(R)SCHEMAS
(R)SCHEMA_NAME
SECOND
SECONDARY
SECONDARY_ENGINE
SECONDARY_ENGINE_ATTRIBUTE
SECONDARY_LOAD
SECONDARY_UNLOAD
SECOND_MICROSECOND
(R)SECURITY
SELECT
(R)SENSITIVE
(R)SEPARATOR
(R)SERIAL
SERIALIZABLE
SERVER
SESSION
SET
(R)SHARE
SHOW
(R)SHUTDOWN
SIGNAL
(R)SIGNED
SIMPLE
SKIP
SLAVE
SLOW
SMALLINT
(R)SNAPSHOT
SOCKET
SOME
SONAME
SOUNDS
SOURCE
SOURCE_AUTO_POSITION
SOURCE_BIND
SOURCE_COMPRESSION_ALGORITHMS
SOURCE_CONNECT_RETRY
SOURCE_DELAY
SOURCE_HEARTBEAT_PERIOD
SOURCE_HOST
SOURCE_LOG_FILE
SOURCE_LOG_POS
SOURCE_PASSWORD
SOURCE_PORT
SOURCE_PUBLIC_KEY_PATH
SOURCE_RETRY_COUNT
SOURCE_SSL
SOURCE_SSL_CA
SOURCE_SSL_CAPATH
SOURCE_SSL_CERT
SOURCE_SSL_CIPHER
SOURCE_SSL_CRL
SOURCE_SSL_CRLPATH
SOURCE_SSL_KEY
SOURCE_SSL_VERIFY_SERVER_CERT
SOURCE_TLS_CIPHERSUITES
SOURCE_TLS_VERSION
SOURCE_USER
SOURCE_ZSTD_COMPRESSION_LEVEL
SPATIAL
(R)SPECIFIC
(R)SQL
(R)SQLEXCEPTION
(R)SQLSTATE
(R)SQLWARNING
(R)SQL_AFTER_GTIDS
SQL_AFTER_MTS_GAPS
SQL_BEFORE_GTIDS
SQL_BIG_RESULT
(R)SQL_BUFFER_RESULT
SQL_CALC_FOUND_ROWS
(R)SQL_NO_CACHE
SQL_SMALL_RESULT
(R)SQL_THREAD
SQL_TSI_DAY
SQL_TSI_HOUR
SQL_TSI_MINUTE
SQL_TSI_MONTH
SQL_TSI_QUARTER
SQL_TSI_SECOND
SQL_TSI_WEEK
SQL_TSI_YEAR
SRID
SSL
(R)STACKED
START
STARTING
(R)STARTS
STATS_AUTO_RECALC
STATS_PERSISTENT
STATS_SAMPLE_PAGES
STATUS
STOP
STORAGE
STORED
(R)STRAIGHT_JOIN
(R)STREAM
STRING
SUBCLASS_ORIGIN
SUBJECT
SUBPARTITION
SUBPARTITIONS
SUPER
SUSPEND
SWAPS
SWITCHES
SYSTEM
(R)
TABLE
(R)TABLES
TABLESAMPLE
(R)TABLESPACE
TABLE_CHECKSUM
TABLE_NAME
TEMPORARY
TEMPTABLE
TERMINATED
(R)TEXT
THAN
THEN
(R)THREAD_PRIORITY
TIES
TIME
TIMESTAMP
TIMESTAMPADD
TIMESTAMPDIFF
TINYBLOB
(R)TINYINT
(R)TINYTEXT
(R)TLS
TO
(R)TRAILING
(R)TRANSACTION
TRIGGER
(R)TRIGGERS
TRUE
(R)TRUNCATE
TYPE
TYPES
UNBOUNDED
UNCOMMITTED
UNDEFINED
UNDO
(R)UNDOFILE
UNDO_BUFFER_SIZE
UNICODE
UNINSTALL
UNION
(R)UNIQUE
(R)UNKNOWN
UNLOCK
(R)UNREGISTER
UNSIGNED
(R)UNTIL
UPDATE
(R)UPGRADE
URL
USAGE
(R)USE
(R)USER
USER_RESOURCES
USE_FRM
USING
(R)UTC_DATE
(R)UTC_TIME
(R)UTC_TIMESTAMP
(R)
VALIDATION
VALUE
VALUES
(R)VARBINARY
(R)VARCHAR
(R)VARCHARACTER
(R)VARIABLES
VARYING
(R)VCPU
VIEW
VIRTUAL
(R)VISIBLE
WAIT
WARNINGS
WEEK
WEIGHT_STRING
WHEN
(R)WHERE
(R)WHILE
(R)WINDOW
(R)WITH
(R)WITHOUT
WORK
WRAPPER
WRITE
(R)
X509
XA
XID
XML
XOR
(R)
YEAR
YEAR_MONTH
(R)
ZEROFILL
(R)ZONE
以下列表显示了与 MySQL 8.0 相比,在 MySQL 8.4 中添加的关键字和保留字。保留关键字用 (R) 标记。
A | B | G | L | M | P | Q | S | T
AUTO
BERNOULLI
GTID
LOG
MANUAL
(R)
PARALLEL
(R)PARSE_TREE
QUALIFY
(R)
S3
TABLESAMPLE
(R)
以下列表显示了与 MySQL 8.0 相比,在 MySQL 8.4 中删除的关键字和保留字。保留关键字用 (R) 标记。
GET_MASTER_PUBLIC_KEY
MASTER_AUTO_POSITION
MASTER_BIND
(R)MASTER_COMPRESSION_ALGORITHMS
MASTER_CONNECT_RETRY
MASTER_DELAY
MASTER_HEARTBEAT_PERIOD
MASTER_HOST
MASTER_LOG_FILE
MASTER_LOG_POS
MASTER_PASSWORD
MASTER_PORT
MASTER_PUBLIC_KEY_PATH
MASTER_RETRY_COUNT
MASTER_SSL
MASTER_SSL_CA
MASTER_SSL_CAPATH
MASTER_SSL_CERT
MASTER_SSL_CIPHER
MASTER_SSL_CRL
MASTER_SSL_CRLPATH
MASTER_SSL_KEY
MASTER_SSL_VERIFY_SERVER_CERT
(R)MASTER_TLS_CIPHERSUITES
MASTER_TLS_VERSION
MASTER_USER
MASTER_ZSTD_COMPRESSION_LEVEL