在使用 php + mysql 程序时,有时候定义的数据表的字段会和 mysql 的关键字发生冲突,造成程序无法运行的错误。而这种错误最典型的就是“SQL Error: 1064, SQLState: 42000错误”。为了防止此错误的出错,下面列出了一些 mysql 的关键字。

mysql 关于关键字冲突的错误

SQL Error: 1064, SQLState: 42000错误

MySQL server version for the right syntax to use near

mysql 关键字表

ADDALL
ALTERANALYZE
ANDAS
ASCASENSITIVE
BEFOREBETWEEN
BIGINTBINARY
BLOBBOTH
BYCALL
CASCADECASE
CHANGECHAR
CHARACTERCHECK
COLLATECOLUMN
CONDITIONCONNECTION
CONSTRAINTCONTINUE
CONVERTCREATE
CROSSCURRENT_DATE
CURRENT_TIMECURRENT_TIMESTAMP
CURRENT_USERCURSOR
DATABASEDATABASES
DAY_HOURDAY_MICROSECOND
DAY_MINUTEDAY_SECOND
DECDECIMAL
DECLAREDEFAULT
DELAYEDDELETE
DESCDESCRIBE
DETERMINISTICDISTINCT
DISTINCTROWDIV
DOUBLEDROP
DUALEACH
ELSEELSEIF
ENCLOSEDESCAPED
EXISTSEXIT
EXPLAINFALSE
FETCHFLOAT
FLOAT4FLOAT8
FORFORCE
FOREIGNFROM
FULLTEXTGOTO
GRANTGROUP
HAVINGHIGH_PRIORITY
HOUR_MICROSECONDHOUR_MINUTE
HOUR_SECONDIF
IGNOREIN
INDEXINFILE
INNERINOUT
INSENSITIVEINSERT
INTINT1
INT2INT3
INT4INT8
INTEGERINTERVAL
INTOIS
ITERATEJOIN
KEYKEYS
KILLLABEL
LEADINGLEAVE
LEFTLIKE
LIMITLINEAR
LINESLOAD
LOCALTIMELOCALTIMESTAMP
LOCKLONG
LONGBLOBLONGTEXT
LOOPLOW_PRIORITY
MATCHMEDIUMBLOB
MEDIUMINTMEDIUMTEXT
MIDDLEINTMINUTE_MICROSECOND
MINUTE_SECONDMOD
MODIFIESNATURAL
NOTNO_WRITE_TO_BINLOG
NULLNUMERIC
NUMERICON
OPTIMIZEOPTION
OPTIONALLYOR
ORDEROUT
OUTEROUTFILE
PRECISIONPRIMARY
PROCEDUREPURGE
RAID0RANGE
READREADS
REALREFERENCES
REGEXPRELEASE
RENAMEREPEAT
REPLACEREQUIRE
RESTRICTRETURN
REVOKERIGHT
RLIKESCHEMA
SCHEMASSECOND_MICROSECOND
SELECTSENSITIVE
SEPARATORSET
SHOWSMALLINT
SPATIALSPECIFIC
SQLSQLEXCEPTION
SQLSTATESQLWARNING
SQL_BIG_RESULTSQL_CALC_FOUND_ROWS
SQL_SMALL_RESULTSSL
STARTINGSTRAIGHT_JOIN
TABLETERMINATED
THENTINYBLOB
TINYINTTINYTEXT
TOTRAILING
TRIGGERTRUE
UNDOUNION
UNIQUEUNLOCK
UNSIGNEDUPDATE
USAGEUSE
USINGUTC_DATE
UTC_TIMEUTC_TIMESTAMP
VALUESVARBINARY
VARCHARVARCHARACTER
VARYINGWHEN
WHEREWHILE
WITHWRITE
X509XOR
YEAR_MONTHZEROFILL