在使用MySQL时,有时不小心会将MySQL的关键字设置为表的字段,在进行数据插入的时候总是提示SQL有问题。如果将MySQL中的关键字与保留字设置为表字段时,解决方法为给关键字加上反引号 " `" 。
注意是 反引号 **反引号 ** 反引号 输入法切换到英文状态下,键盘上Esc键下面,数字键1左边,Tab键上面那个键。
当然最好还是在建表的时候尽量避免关键字,因本人使用的是MySQL8,以下为MySQL8中的关键字与保留字。
官网地址:https://dev.mysql.com/doc/refman/8.0/en/keywords.html
MySQL 8.0中的关键字和保留词,以及各个词在版本之间的更改。保留的关键字标有(R)。另外,_FILENAME
是保留的
ACCESSIBLE ® | ACCOUNT | ACTION |
---|---|---|
ACTIVE; added in 8.0.14 (nonreserved) | ADD ® | ADMIN; became nonreserved in 8.0.12 |
AFTER | AGAINST | AGGREGATE |
ALGORITHM | ALL ® | ALTER ® |
ALWAYS | ANALYSE; removed in 8.0.1 | ANALYZE ® |
AND ® | ANY | ARRAY; added in 8.0.17 (reserved); became nonreserved in 8.0.19 |
AS ® | ASC ® | ASCII |
ASENSITIVE ® | AT | ATTRIBUTE; added in 8.0.21 (nonreserved) |
AUTOEXTEND_SIZE | AUTO_INCREMENT | AVG |
AVG_ROW_LENGTH | BACKUP | BEFORE ® |
BEGIN | BETWEEN ® | BIGINT ® |
BINARY ® | BINLOG | BIT |
BLOB ® | BLOCK | BOOL |
BOOLEAN | BOTH ® | BTREE |
BUCKETS; added in 8.0.2 (nonreserved) | BY ® | BYTE |
CACHE | CALL ® | CASCADE ® |
CASCADED | CASE ® | CATALOG_NAME |
CHAIN | CHANGE ® | CHANGED |
CHANNEL | CHAR ® | CHARACTER ® |
CHARSET | CHECK ® | CHECKSUM |
CIPHER | CLASS_ORIGIN | CLIENT |
CLONE; added in 8.0.3 (nonreserved) | CLOSE | COALESCE |
CODE | COLLATE ® | COLLATION |
COLUMN ® | COLUMNS | COLUMN_FORMAT |
COLUMN_NAME | COMMENT | COMMIT |
COMMITTED | COMPACT | COMPLETION |
COMPONENT | COMPRESSED | COMPRESSION |
CONCURRENT | CONDITION ® | CONNECTION |
CONSISTENT | CONSTRAINT ® | CONSTRAINT_CATALOG |
CONSTRAINT_NAME | CONSTRAINT_SCHEMA | CONTAINS |
CONTEXT | CONTINUE ® | CONVERT ® |
CPU | CREATE ® | CROSS ® |
CUBE ®; became reserved in 8.0.1 | CUME_DIST ®; added in 8.0.2 (reserved) | CURRENT |
CURRENT_DATE ® | CURRENT_TIME ® | CURRENT_TIMESTAMP ® |
CURRENT_USER ® | CURSOR ® | CURSOR_NAME |
DATA | DATABASE ® | DATABASES ® |
DATAFILE | DATE | DATETIME |
DAY | DAY_HOUR ® | DAY_MICROSECOND ® |
DAY_MINUTE ® | DAY_SECOND ® | DEALLOCATE |
DEC ® | DECIMAL ® | DECLARE ® |
DEFAULT ® | DEFAULT_AUTH | DEFINER |
DEFINITION; added in 8.0.4 (nonreserved) | DELAYED ® | DELAY_KEY_WRITE |
DELETE ® | DENSE_RANK ®; added in 8.0.2 (reserved) | DESC ® |
DESCRIBE ® | DESCRIPTION; added in 8.0.4 (nonreserved) | DES_KEY_FILE; removed in 8.0.3 |
DETERMINISTIC ® | DIAGNOSTICS | DIRECTORY |
DISABLE | DISCARD | DISK |
DISTINCT ® | DISTINCTROW ® | DIV ® |
DO | DOUBLE ® | DROP ® |
DUAL ® | DUMPFILE | DUPLICATE |
DYNAMIC | EACH ® | ELSE ® |
ELSEIF ® | EMPTY ®; added in 8.0.4 (reserved) | ENABLE |
ENCLOSED ® | ENCRYPTION | END |
ENDS | ENFORCED; added in 8.0.16 (nonreserved) | ENGINE |
ENGINES | ENGINE_ATTRIBUTE; added in 8.0.21 (nonreserved) | ENUM |
ERROR | ERRORS | ESCAPE |
ESCAPED ® | EVENT | EVENTS |
EVERY | EXCEPT ® | EXCHANGE |
EXCLUDE; added in 8.0.2 (nonreserved) | EXECUTE | EXISTS ® |
EXIT ® | EXPANSION | EXPIRE |
EXPLAIN ® | EXPORT | EXTENDED |
EXTENT_SIZE | FAILED_LOGIN_ATTEMPTS; added in 8.0.19 (nonreserved) | FALSE ® |
FAST | FAULTS | FETCH ® |
FIELDS | FILE | FILE_BLOCK_SIZE |
FILTER | FIRST | FIRST_VALUE ®; added in 8.0.2 (reserved) |
FIXED | FLOAT ® | FLOAT4 ® |
FLOAT8 ® | FLUSH | FOLLOWING; added in 8.0.2 (nonreserved) |
FOLLOWS | FOR ® | FORCE ® |
FOREIGN ® | FORMAT | FOUND |
FROM ® | FULL | FULLTEXT ® |
FUNCTION ®; became reserved in 8.0.1 | GENERAL | GENERATED ® |
GEOMCOLLECTION; added in 8.0.11 (nonreserved) | GEOMETRY | GEOMETRYCOLLECTION |
GET ® | GET_FORMAT | GET_MASTER_PUBLIC_KEY; added in 8.0.4 (reserved); became nonreserved in 8.0.11 |
GLOBAL | GRANT ® | GRANTS |
GROUP ® | GROUPING ®; added in 8.0.1 (reserved) | GROUPS ®; added in 8.0.2 (reserved) |
GROUP_REPLICATION | HANDLER | HASH |
HAVING ® | HELP | HIGH_PRIORITY ® |
HISTOGRAM; added in 8.0.2 (nonreserved) | HISTORY; added in 8.0.3 (nonreserved) | HOST |
HOSTS | HOUR | HOUR_MICROSECOND ® |
HOUR_MINUTE ® | HOUR_SECOND ® | IDENTIFIED |
IF ® | IGNORE ® | IGNORE_SERVER_IDS |
IMPORT | IN ® | INACTIVE; added in 8.0.14 (nonreserved) |
INDEX ® | INDEXES | INFILE ® |
INITIAL_SIZE | INNER ® | INOUT ® |
INSENSITIVE ® | INSERT ® | INSERT_METHOD |
INSTALL | INSTANCE | INT ® |
INT1 ® | INT2 ® | INT3 ® |
INT4 ® | INT8 ® | INTEGER ® |
INTERVAL ® | INTO ® | INVISIBLE |
INVOKER | IO | IO_AFTER_GTIDS ® |
IO_BEFORE_GTIDS ® | IO_THREAD | IPC |
IS ® | ISOLATION | ISSUER |
ITERATE ® | JOIN ® | JSON |
JSON_TABLE ®; added in 8.0.4 (reserved) | JSON_VALUE; added in 8.0.21 (nonreserved) | KEY ® |
KEYS ® | KEY_BLOCK_SIZE | KILL ® |
LAG ®; added in 8.0.2 (reserved) | LANGUAGE | LAST |
LAST_VALUE ®; added in 8.0.2 (reserved) | LATERAL ®; added in 8.0.14 (reserved) | LEAD ®; added in 8.0.2 (reserved) |
LEADING ® | LEAVE ® | LEAVES |
LEFT ® | LESS | LEVEL |
LIKE ® | LIMIT ® | LINEAR ® |
LINES ® | LINESTRING | LIST |
LOAD ® | LOCAL | LOCALTIME ® |
LOCALTIMESTAMP ® | LOCK ® | LOCKED; added in 8.0.1 (nonreserved) |
LOCKS | LOGFILE | LOGS |
LONG ® | LONGBLOB ® | LONGTEXT ® |
LOOP ® | LOW_PRIORITY ®MMANAGED; added in 8.0.22 (nonreserved) | MASTER |
MASTER_AUTO_POSITION | MASTER_BIND ® | MASTER_COMPRESSION_ALGORITHMS; added in 8.0.18 (nonreserved) |
MASTER_CONNECT_RETRY | MASTER_DELAY | MASTER_HEARTBEAT_PERIOD |
MASTER_HOST | MASTER_LOG_FILE | MASTER_LOG_POS |
MASTER_PASSWORD | MASTER_PORT | MASTER_PUBLIC_KEY_PATH; added in 8.0.4 (nonreserved) |
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 ® | MASTER_TLS_CIPHERSUITES; added in 8.0.19 (nonreserved) |
MASTER_TLS_VERSION | MASTER_USER | MASTER_ZSTD_COMPRESSION_LEVEL; added in 8.0.18 (nonreserved) |
MATCH ® | MAXVALUE ® | MAX_CONNECTIONS_PER_HOUR |
MAX_QUERIES_PER_HOUR | MAX_ROWS | MAX_SIZE |
MAX_UPDATES_PER_HOUR | MAX_USER_CONNECTIONS | MEDIUM |
MEDIUMBLOB ® | MEDIUMINT ® | MEDIUMTEXT ® |
MEMBER; added in 8.0.17 (reserved); became nonreserved in 8.0.19 | MEMORY | MERGE |
MESSAGE_TEXT | MICROSECOND | MIDDLEINT ® |
MIGRATE | MINUTE | MINUTE_MICROSECOND ® |
MINUTE_SECOND ® | MIN_ROWS | MOD ® |
MODE | MODIFIES ® | MODIFY |
MONTH | MULTILINESTRING | MULTIPOINT |
MULTIPOLYGON | MUTEX | MYSQL_ERRNONNAME |
NAMES | NATIONAL | NATURAL ® |
NCHAR | NDB | NDBCLUSTER |
NESTED; added in 8.0.4 (nonreserved) | NETWORK_NAMESPACE; added in 8.0.16 (nonreserved) | NEVER |
NEW | NEXT | NO |
NODEGROUP | NONE | NOT ® |
NOWAIT; added in 8.0.1 (nonreserved) | NO_WAIT | NO_WRITE_TO_BINLOG ® |
NTH_VALUE ®; added in 8.0.2 (reserved) | NTILE ®; added in 8.0.2 (reserved) | NULL ® |
NULLS; added in 8.0.2 (nonreserved) | NUMBER | NUMERIC ® |
NVARCHAROOF ®; added in 8.0.1 (reserved) | OFF; added in 8.0.20 (nonreserved) | OFFSET |
OJ; added in 8.0.16 (nonreserved) | OLD; added in 8.0.14 (nonreserved) | ON ® |
ONE | ONLY | OPEN |
OPTIMIZE ® | OPTIMIZER_COSTS ® | OPTION ® |
OPTIONAL; added in 8.0.13 (nonreserved) | OPTIONALLY ® | OPTIONS |
OR ® | ORDER ® | ORDINALITY; added in 8.0.4 (nonreserved) |
ORGANIZATION; added in 8.0.4 (nonreserved) | OTHERS; added in 8.0.2 (nonreserved) | OUT ® |
OUTER ® | OUTFILE ® | OVER ®; added in 8.0.2 (reserved) |
OWNERPPACK_KEYS | PAGE | PARSER |
PARTIAL | PARTITION ® | PARTITIONING |
PARTITIONS | PASSWORD | PASSWORD_LOCK_TIME; added in 8.0.19 (nonreserved) |
PATH; added in 8.0.4 (nonreserved) | PERCENT_RANK ®; added in 8.0.2 (reserved) | PERSIST; became nonreserved in 8.0.16 |
PERSIST_ONLY; added in 8.0.2 (reserved); became nonreserved in 8.0.16 | PHASE | PLUGIN |
PLUGINS | PLUGIN_DIR | POINT |
POLYGON | PORT | PRECEDES |
PRECEDING; added in 8.0.2 (nonreserved) | PRECISION ® | PREPARE |
PRESERVE | PREV | PRIMARY ® |
PRIVILEGES | PRIVILEGE_CHECKS_USER; added in 8.0.18 (nonreserved) | PROCEDURE ® |
PROCESS; added in 8.0.11 (nonreserved) | PROCESSLIST | PROFILE |
PROFILES | PROXY | PURGE ®QQUARTER |
QUERY | QUICKRRANDOM; added in 8.0.18 (nonreserved) | RANGE ® |
RANK ®; added in 8.0.2 (reserved) | READ ® | READS ® |
READ_ONLY | READ_WRITE ® | REAL ® |
REBUILD | RECOVER | RECURSIVE ®; added in 8.0.1 (reserved) |
REDOFILE; removed in 8.0.3 | REDO_BUFFER_SIZE | REDUNDANT |
REFERENCE; added in 8.0.4 (nonreserved) | REFERENCES ® | REGEXP ® |
RELAY | RELAYLOG | RELAY_LOG_FILE |
RELAY_LOG_POS | RELAY_THREAD | RELEASE ® |
RELOAD | REMOTE; added in 8.0.3 (nonreserved); removed in 8.0.14 | REMOVE |
RENAME ® | REORGANIZE | REPAIR |
REPEAT ® | REPEATABLE | REPLACE ® |
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 ® |
REQUIRE_ROW_FORMAT; added in 8.0.19 (nonreserved) | RESET | RESIGNAL ® |
RESOURCE; added in 8.0.3 (nonreserved) | RESPECT; added in 8.0.2 (nonreserved) | RESTART; added in 8.0.4 (nonreserved) |
RESTORE | RESTRICT ® | RESUME |
RETAIN; added in 8.0.14 (nonreserved) | RETURN ® | RETURNED_SQLSTATE |
RETURNING; added in 8.0.21 (nonreserved) | RETURNS | REUSE; added in 8.0.3 (nonreserved) |
REVERSE | REVOKE ® | RIGHT ® |
RLIKE ® | ROLE; became nonreserved in 8.0.1 | ROLLBACK |
ROLLUP | ROTATE | ROUTINE |
ROW ®; became reserved in 8.0.2 | ROWS ®; became reserved in 8.0.2 | ROW_COUNT |
ROW_FORMAT | ROW_NUMBER ®; added in 8.0.2 (reserved) | RTREE |
SAVEPOINT | SCHEDULE | SCHEMA ® |
SCHEMAS ® | SCHEMA_NAME | SECOND |
SECONDARY; added in 8.0.16 (nonreserved) | SECONDARY_ENGINE; added in 8.0.13 (nonreserved) | SECONDARY_ENGINE_ATTRIBUTE; added in 8.0.21 (nonreserved) |
SECONDARY_LOAD; added in 8.0.13 (nonreserved) | SECONDARY_UNLOAD; added in 8.0.13 (nonreserved) | SECOND_MICROSECOND ® |
SECURITY | SELECT ® | SENSITIVE ® |
SEPARATOR ® | SERIAL | SERIALIZABLE |
SERVER | SESSION | SET ® |
SHARE | SHOW ® | SHUTDOWN |
SIGNAL ® | SIGNED | SIMPLE |
SKIP; added in 8.0.1 (nonreserved) | SLAVE | SLOW |
SMALLINT ® | SNAPSHOT | SOCKET |
SOME | SONAME | SOUNDS |
SOURCE | SPATIAL ® | SPECIFIC ® |
SQL ® | SQLEXCEPTION ® | SQLSTATE ® |
SQLWARNING ® | SQL_AFTER_GTIDS | SQL_AFTER_MTS_GAPS |
SQL_BEFORE_GTIDS | SQL_BIG_RESULT ® | SQL_BUFFER_RESULT |
SQL_CACHE; removed in 8.0.3 | SQL_CALC_FOUND_ROWS ® | SQL_NO_CACHE |
SQL_SMALL_RESULT ® | 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; added in 8.0.3 (nonreserved) | SSL ® |
STACKED | START | STARTING ® |
STARTS | STATS_AUTO_RECALC | STATS_PERSISTENT |
STATS_SAMPLE_PAGES | STATUS | STOP |
STORAGE | STORED ® | STRAIGHT_JOIN ® |
STREAM; added in 8.0.20 (nonreserved) | STRING | SUBCLASS_ORIGIN |
SUBJECT | SUBPARTITION | SUBPARTITIONS |
SUPER | SUSPEND | SWAPS |
SWITCHES | SYSTEM ®; added in 8.0.3 (reserved) | TABLE ® |
TABLES | TABLESPACE | TABLE_CHECKSUM |
TABLE_NAME | TEMPORARY | TEMPTABLE |
TERMINATED ® | TEXT | THAN |
THEN ® | THREAD_PRIORITY; added in 8.0.3 (nonreserved) | TIES; added in 8.0.2 (nonreserved) |
TIME | TIMESTAMP | TIMESTAMPADD |
TIMESTAMPDIFF | TINYBLOB ® | TINYINT ® |
TINYTEXT ® | TLS; added in 8.0.21 (nonreserved) | TO ® |
TRAILING ® | TRANSACTION | TRIGGER ® |
TRIGGERS | TRUE ® | TRUNCATE |
TYPE | TYPES | UNBOUNDED; added in 8.0.2 (nonreserved) |
UNCOMMITTED | UNDEFINED | UNDO ® |
UNDOFILE | UNDO_BUFFER_SIZE | UNICODE |
UNINSTALL | UNION ® | UNIQUE ® |
UNKNOWN | UNLOCK ® | UNSIGNED ® |
UNTIL | UPDATE ® | UPGRADE |
USAGE ® | USE ® | USER |
USER_RESOURCES | USE_FRM | USING ® |
UTC_DATE ® | UTC_TIME ® | UTC_TIMESTAMP ® |
VALIDATION | VALUE | VALUES ® |
VARBINARY ® | VARCHAR ® | VARCHARACTER ® |
VARIABLES | VARYING ® | VCPU; added in 8.0.3 (nonreserved) |
VIEW | VIRTUAL ® | VISIBLE |
WAIT | WARNINGS | WEEK |
WEIGHT_STRING | WHEN ® | WHERE ® |
WHILE ® | WINDOW ® added in 8.0.2 (reserved) | WITH ® |
WITHOUT | WORK | WRAPPER |
WRITE ® | X509 | XA |
XID | XML | XOR ® |
YEAR | YEAR_MONTH ® | ZEROFILL ® |
与MySQL5.7相比MySQL8中添加的关键字和保留字,保留的关键字标有®
ACTIVE | ADMIN | ARRAY |
---|---|---|
ATTRIBUTE | BUCKETS | CLONE |
COMPONENT | CUME_DIST ® | DEFINITION |
DENSE_RANK ® | DESCRIPTION | EMPTY ® |
ENFORCED | ENGINE_ATTRIBUTE | EXCEPT ® |
EXCLUDE | FAILED_LOGIN_ATTEMPTS | FIRST_VALUE ® |
FOLLOWING | GEOMCOLLECTION | GET_MASTER_PUBLIC_KEY |
GROUPING ® | GROUPS ® | HISTOGRAM |
HISTORY | INACTIVE | INVISIBLE |
JSON_TABLE ® | JSON_VALUE | LAG ® |
LAST_VALUE ® | LATERAL ® | LEAD ® |
LOCKED | MANAGED | MASTER_COMPRESSION_ALGORITHMS |
MASTER_PUBLIC_KEY_PATH | MASTER_TLS_CIPHERSUITES | MASTER_ZSTD_COMPRESSION_LEVEL |
MEMBER | NESTED | NETWORK_NAMESPACE |
NOWAIT | NTH_VALUE ® | NTILE ® |
NULLS | OF ® | OFF |
OJ | OLD | OPTIONAL |
ORDINALITY | ORGANIZATION | OTHERS |
OVER ® | PASSWORD_LOCK_TIME | PATH |
PERCENT_RANK ® | PERSIST | PERSIST_ONLY |
PRECEDING | PRIVILEGE_CHECKS_USER | PROCESS |
RANDOM | RANK ® | RECURSIVE ® |
REFERENCE | REQUIRE_ROW_FORMAT | RESOURCE |
RESPECT | RESTART | RETAIN |
RETURNING | REUSE | ROLE |
ROW_NUMBER ® | SECONDARY | SECONDARY_ENGINE |
SECONDARY_ENGINE_ATTRIBUTE | SECONDARY_LOAD | SECONDARY_UNLOAD |
SKIP | SRID | STREAM |
SYSTEM ® | THREAD_PRIORITY | TIES |
TLS | UNBOUNDED | VCPU |
VISIBLE | WINDOW ® |