前言

mysql中存在大量的关键字和保留字,在设计字段时应即时规避,防止未来可能出现的一系列sql问题。

笔者正是因为缺乏经验,不清楚这方面约定,耗费了大量精力debug各方源码,徒做无用功。

参考文档

mysql8 参考手册–关键字和保留字

快速查询

如果您想要快速验证某个字段是否关键字或保留字,鼠标点一下当前页面,然后ctrl+F进行搜索,可以直接定位到对应的内容

列表

ACCESSIBLE (R)

ACCOUNT

ACTION

ACTIVE; 在8.0.14中添加(非保留)

ADD (R)

ADMIN; 在8.0.12中变为非保留

AFTER

AGAINST

AGGREGATE

ALGORITHM

ALL (R)

ALTER (R)

ALWAYS

ANALYSE; 在8.0.1中删除

ANALYZE (R)

AND (R)

ANY

ARRAY; 在8.0.17中添加(保留);在8.0.19中变为非保留

AS (R)

ASC (R)

ASCII

ASENSITIVE (R)

AT

AUTOEXTEND_SIZE

AUTO_INCREMENT

AVG

AVG_ROW_LENGTH

BACKUP

BEFORE (R)

BEGIN

BETWEEN (R)

BIGINT (R)

BINARY (R)

BINLOG

BIT

BLOB (R)

BLOCK

BOOL

BOOLEAN

BOTH (R)

BTREE

BUCKETS; 在8.0.2中添加(非保留)

BY (R)

BYTE

CACHE

CALL (R)

CASCADE (R)

CASCADED

CASE (R)

CATALOG_NAME

CHAIN

CHANGE (R)

CHANGED

CHANNEL

CHAR (R)

CHARACTER (R)

CHARSET

CHECK (R)

CHECKSUM

CIPHER

CLASS_ORIGIN

CLIENT

CLONE; 在8.0.3中添加(非保留)

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); 在8.0.1中保留

CUME_DIST(R); 在8.0.2中添加(保留)

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; 在8.0.4中添加(非保留)

DELAYED (R)

DELAY_KEY_WRITE

DELETE (R)

DENSE_RANK(R); 在8.0.2中添加(保留)

DESC (R)

DESCRIBE (R)

DESCRIPTION; 在8.0.4中添加(非保留)

DES_KEY_FILE; 在8.0.3中删除

DETERMINISTIC (R)

DIAGNOSTICS

DIRECTORY

DISABLE

DISCARD

DISK

DISTINCT (R)

DISTINCTROW (R)

DIV (R)

DO

DOUBLE (R)

DROP (R)

DUAL (R)

DUMPFILE

DUPLICATE

DYNAMIC

EACH (R)

ELSE (R)

ELSEIF (R)

EMPTY(R); 在8.0.4中添加(保留)

ENABLE

ENCLOSED (R)

ENCRYPTION

END

ENDS

ENFORCED; 在8.0.16中添加(非保留)

ENGINE

ENGINES

ENUM

ERROR

ERRORS

ESCAPE

ESCAPED (R)

EVENT

EVENTS

EVERY

EXCEPT (R)

EXCHANGE

EXCLUDE; 在8.0.2中添加(非保留)

EXECUTE

EXISTS (R)

EXIT (R)

EXPANSION

EXPIRE

EXPLAIN (R)

EXPORT

EXTENDED

EXTENT_SIZE

FAILED_LOGIN_ATTEMPTS; 在8.0.19中添加(非保留)

FALSE (R)

FAST

FAULTS

FETCH (R)

FIELDS

FILE

FILE_BLOCK_SIZE

FILTER

FIRST

FIRST_VALUE(R); 在8.0.2中添加(保留)

FIXED

FLOAT (R)

FLOAT4 (R)

FLOAT8 (R)

FLUSH

FOLLOWING; 在8.0.2中添加(非保留)

FOLLOWS

FOR (R)

FORCE (R)

FOREIGN (R)

FORMAT

FOUND

FROM (R)

FULL

FULLTEXT (R)

FUNCTION(R); 在8.0.1中保留

GENERAL

GENERATED (R)

GEOMCOLLECTION; 在8.0.11中添加(非保留)

GEOMETRY

GEOMETRYCOLLECTION

GET (R)

GET_FORMAT

GET_MASTER_PUBLIC_KEY; 在8.0.4中添加(保留);在8.0.11中成为非保留

GLOBAL

GRANT (R)

GRANTS

GROUP (R)

GROUPING(R); 在8.0.1中添加(保留)

GROUPS(R); 在8.0.2中添加(保留)

GROUP_REPLICATION

HANDLER

HASH

HAVING (R)

HELP

HIGH_PRIORITY (R)

HISTOGRAM; 在8.0.2中添加(非保留)

HISTORY; 在8.0.3中添加(非保留)

HOST

HOSTS

HOUR

HOUR_MICROSECOND (R)

HOUR_MINUTE (R)

HOUR_SECOND (R)

IDENTIFIED

IF (R)

IGNORE (R)

IGNORE_SERVER_IDS

IMPORT

IN (R)

INACTIVE; 在8.0.14中添加(非保留)

INDEX (R)

INDEXES

INFILE (R)

INITIAL_SIZE

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)

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); 在8.0.4中添加(保留)

JSON_VALUE; 在8.0.21中添加(非保留)

KEY (R)

KEYS (R)

KEY_BLOCK_SIZE

KILL (R)

LAG(R); 在8.0.2中添加(保留)

LANGUAGE

LAST

LAST_VALUE(R); 在8.0.2中添加(保留)

LATERAL(R); 在8.0.14中添加(保留)

LEAD(R); 在8.0.2中添加(保留)

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; 在8.0.1中添加(非保留)

LOCKS

LOGFILE

LOGS

LONG (R)

LONGBLOB (R)

LONGTEXT (R)

LOOP (R)

LOW_PRIORITY (R)

MASTER

MASTER_AUTO_POSITION

MASTER_BIND (R)

MASTER_COMPRESSION_ALGORITHMS; 在8.0.18中添加(非保留)

MASTER_CONNECT_RETRY

MASTER_DELAY

MASTER_HEARTBEAT_PERIOD

MASTER_HOST

MASTER_LOG_FILE

MASTER_LOG_POS

MASTER_PASSWORD

MASTER_PORT

MASTER_PUBLIC_KEY_PATH; 在8.0.4中添加(非保留)

MASTER_RETRY_COUNT

MASTER_SERVER_ID

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; 在8.0.19中添加(非保留)

MASTER_TLS_VERSION

MASTER_USER

MASTER_ZSTD_COMPRESSION_LEVEL; 在8.0.18中添加(非保留)

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; 在8.0.17中添加(保留);在8.0.19中变为非保留

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; 在8.0.4中添加(非保留)

NETWORK_NAMESPACE; 在8.0.16中添加(非保留)

NEVER

NEW

NEXT

NO

NODEGROUP

NONE

NOT (R)

NOWAIT; 在8.0.1中添加(非保留)

NO_WAIT

NO_WRITE_TO_BINLOG (R)

NTH_VALUE(R); 在8.0.2中添加(保留)

NTILE(R); 在8.0.2中添加(保留)

NULL (R)

NULLS; 在8.0.2中添加(非保留)

NUMBER

NUMERIC (R)

NVARCHAR

OF(R); 在8.0.1中添加(保留)

OFF; 在8.0.20中添加(非保留)

OFFSET

OJ; 在8.0.16中添加(非保留)

OLD; 在8.0.14中添加(非保留)

ON (R)

ONE

ONLY

OPEN

OPTIMIZE (R)

OPTIMIZER_COSTS (R)

OPTION (R)

OPTIONAL; 在8.0.13中添加(非保留)

OPTIONALLY (R)

OPTIONS

OR (R)

ORDER (R)

ORDINALITY; 在8.0.4中添加(非保留)

ORGANIZATION; 在8.0.4中添加(非保留)

OTHERS; 在8.0.2中添加(非保留)

OUT (R)

OUTER (R)

OUTFILE (R)

OVER(R); 在8.0.2中添加(保留)

OWNER

PACK_KEYS

PAGE

PARSER

PARTIAL

PARTITION (R)

PARTITIONING

PARTITIONS

PASSWORD

PASSWORD_LOCK_TIME; 在8.0.19中添加(非保留)

PATH; 在8.0.4中添加(非保留)

PERCENT_RANK(R); 在8.0.2中添加(保留)

PERSIST; 在8.0.16中变为非保留

PERSIST_ONLY; 在8.0.2中添加(保留);在8.0.16中变为非保留

PHASE

PLUGIN

PLUGINS

PLUGIN_DIR

POINT

POLYGON

PORT

PRECEDES

PRECEDING; 在8.0.2中添加(非保留)

PRECISION (R)

PREPARE

PRESERVE

PREV

PRIMARY (R)

PRIVILEGES

PRIVILEGE_CHECKS_USER; 在8.0.18中添加(非保留)

PROCEDURE (R)

PROCESS; 在8.0.11中添加(非保留)

PROCESSLIST

PROFILE

PROFILES

PROXY

PURGE (R)

QUARTER

QUERY
QUICK
RANDOM; 在8.0.18中添加(非保留)

RANGE (R)

RANK(R); 在8.0.2中添加(保留)

READ (R)

READS (R)

READ_ONLY

READ_WRITE (R)

REAL (R)

REBUILD

RECOVER

RECURSIVE(R); 在8.0.1中添加(保留)

REDOFILE; 在8.0.3中删除

REDO_BUFFER_SIZE

REDUNDANT

REFERENCE; 在8.0.4中添加(非保留)

REFERENCES (R)

REGEXP (R)

RELAY

RELAYLOG

RELAY_LOG_FILE

RELAY_LOG_POS

RELAY_THREAD

RELEASE (R)

RELOAD

REMOTE; 在8.0.3中添加(非保留);在8.0.14中删除

REMOVE

RENAME (R)

REORGANIZE

REPAIR

REPEAT (R)

REPEATABLE

REPLACE (R)

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; 在8.0.19中添加(非保留)

RESET

RESIGNAL (R)

RESOURCE; 在8.0.3中添加(非保留)

RESPECT; 在8.0.2中添加(非保留)

RESTART; 在8.0.4中添加(非保留)

RESTORE

RESTRICT (R)

RESUME

RETAIN; 在8.0.14中添加(非保留)

RETURN (R)

RETURNED_SQLSTATE

RETURNING; 在8.0.21中添加(非保留)

RETURNS

REUSE; 在8.0.3中添加(非保留)

REVERSE

REVOKE (R)

RIGHT (R)

RLIKE (R)

ROLE; 在8.0.1中变为非保留

ROLLBACK

ROLLUP

ROTATE

ROUTINE

ROW(R); 在8.0.2中保留

ROWS(R); 在8.0.2中保留

ROW_COUNT

ROW_FORMAT

ROW_NUMBER(R); 在8.0.2中添加(保留)

RTREE

SAVEPOINT

SCHEDULE

SCHEMA (R)

SCHEMAS (R)

SCHEMA_NAME

SECOND

SECONDARY; 在8.0.16中添加(非保留)

SECONDARY_ENGINE; 在8.0.13中添加(非保留)

SECONDARY_LOAD; 在8.0.13中添加(非保留)

SECONDARY_UNLOAD; 在8.0.13中添加(非保留)

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; 在8.0.1中添加(非保留)

SLAVE

SLOW

SMALLINT (R)

SNAPSHOT

SOCKET

SOME

SONAME

SOUNDS

SOURCE

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_CACHE; 在8.0.3中删除

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; 在8.0.3中添加(非保留)

SSL (R)

STACKED

START

STARTING (R)

STARTS

STATS_AUTO_RECALC

STATS_PERSISTENT

STATS_SAMPLE_PAGES

STATUS

STOP

STORAGE

STORED (R)

STRAIGHT_JOIN (R)

STREAM; 在8.0.20中添加(非保留)

STRING

SUBCLASS_ORIGIN

SUBJECT

SUBPARTITION

SUBPARTITIONS

SUPER

SUSPEND

SWAPS

SWITCHES

SYSTEM(R); 在8.0.3中添加(保留)

TABLE (R)

TABLES

TABLESPACE

TABLE_CHECKSUM

TABLE_NAME

TEMPORARY

TEMPTABLE

TERMINATED (R)

TEXT

THAN

THEN (R)

THREAD_PRIORITY; 在8.0.3中添加(非保留)

TIES; 在8.0.2中添加(非保留)

TIME

TIMESTAMP

TIMESTAMPADD

TIMESTAMPDIFF

TINYBLOB (R)

TINYINT (R)

TINYTEXT (R)

TO (R)

TRAILING (R)

TRANSACTION

TRIGGER (R)

TRIGGERS

TRUE (R)

TRUNCATE

TYPE

TYPES

UNBOUNDED; 在8.0.2中添加(非保留)

UNCOMMITTED

UNDEFINED

UNDO (R)

UNDOFILE

UNDO_BUFFER_SIZE

UNICODE

UNINSTALL

UNION (R)

UNIQUE (R)

UNKNOWN

UNLOCK (R)

UNSIGNED (R)

UNTIL

UPDATE (R)

UPGRADE

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; 在8.0.3中添加(非保留)

VIEW

VIRTUAL (R)

VISIBLE

WAIT

WARNINGS

WEEK

WEIGHT_STRING

WHEN (R)

WHERE (R)

WHILE (R)

WINDOW(R); 在8.0.2中添加(保留)

WITH (R)

WITHOUT

WORK

WRAPPER

WRITE (R)

X509

XA

XID

XML

XOR (R)

YEAR

YEAR_MONTH (R)

ZEROFILL (R)

下表显示了与MySQL 5.7相比在MySQL 8.0中添加的关键字和保留字。保留的关键字标有(R)

ACTIVE

ADMIN

ARRAY

BUCKETS

CLONE

COMPONENT

CUME_DIST (R)

DEFINITION

DENSE_RANK (R)

DESCRIPTION

EMPTY (右)

ENFORCED

EXCEPT (右)

EXCLUDE

FAILED_LOGIN_ATTEMPTS

FIRST_VALUE (R)
FOLLOWING

GEOMCOLLECTION

GET_MASTER_PUBLIC_KEY

GROUPING (R)

GROUPS (R)

HISTOGRAM

HISTORY

INACTIVE

INVISIBLE

JSON_TABLE (R)

JSON_VALUE

LAG (R)

LAST_VALUE (R)

LATERAL (R)

LEAD (R)

LOCKED

MASTER_COMPRESSION_ALGORITHMS

MASTER_PUBLIC_KEY_PATH

MASTER_TLS_CIPHERSUITES

MASTER_ZSTD_COMPRESSION_LEVEL

MEMBER

NESTED

NETWORK_NAMESPACE

NOWAIT

NTH_VALUE (R)

NTILE (R)

NULLS

OF (R)

OFF

OJ

OLD

OPTIONAL

ORDINALITY

ORGANIZATION

OTHERS

OVER (R)

PASSWORD_LOCK_TIME

PATH

PERCENT_RANK (R)

PERSIST

PERSIST_ONLY

PRECEDING

PRIVILEGE_CHECKS_USER

PROCESS

RANDOM

RANK (R)

RECURSIVE (R)

REFERENCE

REQUIRE_ROW_FORMAT

RESOURCE

RESPECT

RESTART

RETAIN

RETURNING

REUSE

ROLE

ROW_NUMBER (R)

SECONDARY

SECONDARY_ENGINE

SECONDARY_LOAD

SECONDARY_UNLOAD

SKIP

SRID

STREAM

SYSTEM(R)

THREAD_PRIORITY

TIES

UNBOUNDED

VCPU

VISIBLE

WINDOW (R)

MySQL 8.0删除了关键字和保留字
下表显示了与MySQL 5.7相比在MySQL 8.0中删除的关键字和保留词。保留的关键字标有(R)。

ANALYSE

DES_KEY_FILE

PARSE_GCOL_EXPR

REDOFILE

SQL_CACHE


本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!

CentOS安装Hexo教程 上一篇
Jackson常用方法总结 下一篇