InnoDB
CREATE
DROP
TRUNCATE TABLE
InnoDB
COMMIT
START TRANSACTION ...
COMMIT
DROP TABLE
DROP TABLE
DROP TABLE
MySQL的> CREATE TABLE t1 (c1 INT);
MySQL的> DROP TABLE t1, t2;
错误1051(未知42s02):表”测试。t2'mysql > SHOW TABLES;
|表出发_ in _测试|出发| T1 |出发
DROP TABLE
MySQL的> CREATE TABLE t1 (c1 INT);
MySQL的> DROP TABLE t1, t2;
错误1051(未知42s02):表”测试。t2'mysql > SHOW TABLES;
空集(0.001秒)
DROP TABLE
DROP
TABLE
DROP DATABASE
DROP DATABASE
DROP TABLE
DROP DATABASE
DROP TABLE
DROP DATABASE
CREATE TABLE
ALTER TABLE
RENAME TABLE
TRUNCATE TABLE
CREATE TABLESPACE
DROP TABLESPACE
RENAME
TABLE
DROP VIEW
DROP VIEW
MySQL的> CREATE VIEW test.viewA AS SELECT * FROM t;
MySQL的> DROP VIEW test.viewA, test.viewB;
错误1051(未知42s02):表”测试。viewb'mysql > SHOW FULL TABLES IN test WHERE TABLE_TYPE LIKE 'VIEW';
---------------- ------------ | tables_in_test | table_type | ---------------- ------------ |一|观| ---------------- ------------
DROP VIEW
MySQL的> CREATE VIEW test.viewA AS SELECT * FROM t;
MySQL的> DROP VIEW test.viewA, test.viewB;
错误1051(未知42s02):表”测试。viewb'mysql > SHOW FULL TABLES IN test WHERE TABLE_TYPE LIKE 'VIEW';
空集(0.001秒)
CREATE USER
MySQL的> CREATE USER userA;
MySQL的> CREATE USER userA, userB;
错误1396(hy000):操作创建用户失败的用户“@ % 'mysql > SELECT User FROM mysql.user WHERE User LIKE 'user%';
用户| ------- | ------- | usera | -------
CREATE USER
MySQL的> CREATE USER userA;
MySQL的> CREATE USER userA, userB;
错误1396(hy000):操作创建用户失败的用户“@ % 'mysql > SELECT User FROM mysql.user WHERE User LIKE 'user%';
用户| ------- | ------- | usera | | USERb | -------
IF EXISTS
InnoDB
InnoDB
mysql.ibd
mysql.innodb_ddl_log
innodb_print_ddl_logs
mysql.innodb_ddl_log
innodb_flush_log_at_trx_commit
InnoDB
ALTER TABLE
mysql.innodb_ddl_log
CREATE
TABLE
mysql.innodb_ddl_log
DROP
TABLE
TRUNCATE
TABLE
mysql.innodb_ddl_log
mysql.innodb_ddl_log
InnoDB
mysql.innodb_ddl_log
innodb_print_ddl_logs
stderr
InnoDB
mysql.innodb_ddl_log
mysql.innodb_ddl_log
mysql.innodb_ddl_log
创建表mysql.innodb_ddl_log(id bigint符号的非空auto_increment主键,thread_id bigint unsigned int类型的符号不空,不空,space_id int unsigned int,page_no符号,index_id bigint符号,table_id bigint符号,old_file_path varchar(512)整理utf8_bin,new_file_path varchar(512)整理utf8_bin,关键(thread_id));
id
thread_id
type
DELETE
DROP
space_id
page_no
index_id
table_id
old_file_path
new_file_path
innodb_print_ddl_logs
CREATE TABLE
mysql> SET GLOBAL innodb_print_ddl_logs=1;mysql> CREATE TABLE t1 (c1 INT) ENGINE = InnoDB;
[Note] [000000] InnoDB: DDL log insert : [DDL record: DELETE SPACE, id=18, thread_id=7, space_id=5, old_file_path=./test/t1.ibd] [Note] [000000] InnoDB: DDL log delete : by id 18 [Note] [000000] InnoDB: DDL log insert : [DDL record: REMOVE CACHE, id=19, thread_id=7, table_id=1058, new_file_path=test/t1] [Note] [000000] InnoDB: DDL log delete : by id 19 [Note] [000000] InnoDB: DDL log insert : [DDL record: FREE, id=20, thread_id=7, space_id=5, index_id=132, page_no=4] [Note] [000000] InnoDB: DDL log delete : by id 20 [Note] [000000] InnoDB: DDL log post ddl : begin for thread id : 7 [Note] [000000] InnoDB: DDL log post ddl : end for thread id : 7
ALTER {DATABASE | SCHEMA} [db_name
]alter_specification
...alter_specification
: [DEFAULT] CHARACTER SET [=]charset_name
| [DEFAULT] COLLATE [=]collation_name
ALTER DATABASE
ALTER DATABASE
ALTER
ALTER
SCHEMA
ALTER
DATABASE
CHARACTER SET
SHOW CHARACTER
SET
SHOW COLLATION
ALTER [DEFINER = {user
| CURRENT_USER }] EVENTevent_name
[ON SCHEDULEschedule
] [ON COMPLETION [NOT] PRESERVE] [RENAME TOnew_event_name
] [ENABLE | DISABLE | DISABLE ON SLAVE] [COMMENT 'string
'] [DOevent_body
]
ALTER EVENT
ON SCHEDULE
COMMENT
DISABLE
DO
CREATE EVENT
EVENT
ALTER
EVENT
ALTER EVENT
MySQL的> ALTER EVENT no_such_event
> ON SCHEDULE
> EVERY '2:3' DAY_HOUR;
1 . Error 1517(HY000):unknown ' s no dech such such a event .
myevent
CREATE EVENT myevent ON SCHEDULE EVERY 6 HOUR COMMENT 'A sample comment.' DO UPDATE myschema.mytable SET mycol = mycol + 1;
myevent
改变事件事件的时间表每12小时开始current_timestamp间隔4小时;
myevent
ALTER EVENT
改变在current_timestamp间隔1天的日程安排表myschema.mytable事件做事件;
ALTER
EVENT
CREATE
EVENT
myevent
ALTER EVENT
Alter event Myevent Myevent;
ON SCHEDULE
timestamp
interval
ALTER EVENT
CREATE EVENT
ALTER EVENT
ALTER EVENT
DO
ALTER
EVENT
myevent
ALTER EVENT myevent RENAME TO yourevent;
ALTER EVENT ... RENAME TO ...
db_name.event_name
另一个事件olddb.myevent重命名to newdb.myevent;
EVENT
newdb
RENAME EVENT
DISABLE ON SLAVE
DISABLE
ALTER FUNCTIONfunc_name
[characteristic
...]characteristic
: COMMENT 'string
' | LANGUAGE SQL | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA } | SQL SECURITY { DEFINER | INVOKER }
ALTER FUNCTION
DROP
FUNCTION
CREATE
FUNCTION
ALTER ROUTINE
ALTER FUNCTION
SUPER
ALTER INSTANCE ROTATE INNODB MASTER KEY
ALTER INSTANCE
ALTER INSTANCE ROTATE INNODB MASTER KEY
keyring_file
ENCRYPTION_KEY_ADMIN
SUPER
ALTER INSTANCE ROTATE INNODB MASTER KEY
CREATE TABLE
... ENCRYPTION
ALTER TABLE ...
ENCRYPTION
ALTER INSTANCE
ALTER INSTANCE ROTATE INNODB MASTER
KEY
keyring_file
ALTER PROCEDUREproc_name
[characteristic
...]characteristic
: COMMENT 'string
' | LANGUAGE SQL | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA } | SQL SECURITY { DEFINER | INVOKER }
ALTER PROCEDURE
DROP
PROCEDURE
CREATE
PROCEDURE
ALTER ROUTINE
automatic_sp_privileges
ALTER SERVERserver_name
OPTIONS (option
[,option
] ...)
server_name
CREATE SERVER
SUPER
USER
对服务器的选择(使用情况);
ALTER SERVER
ALTER SERVER
ALTER TABLEtbl_name
[alter_specification
[,alter_specification
] ...] [partition_options
]alter_specification
:table_options
| ADD [COLUMN]col_name
column_definition
[FIRST | AFTERcol_name
] | ADD [COLUMN] (col_name
column_definition
,...) | ADD {INDEX|KEY} [index_name
] [index_type
] (key_part
,...) [index_option
] ... | ADD [CONSTRAINT [symbol
]] PRIMARY KEY [index_type
] (key_part
,...) [index_option
] ... | ADD [CONSTRAINT [symbol
]] UNIQUE [INDEX|KEY] [index_name
] [index_type
] (key_part
,...) [index_option
] ... | ADD FULLTEXT [INDEX|KEY] [index_name
] (key_part
,...) [index_option
] ... | ADD SPATIAL [INDEX|KEY] [index_name
] (key_part
,...) [index_option
] ... | ADD [CONSTRAINT [symbol
]] FOREIGN KEY [index_name
] (key_part
,...)reference_definition
| ALGORITHM [=] {DEFAULT|INSTANT|INPLACE|COPY} | ALTER [COLUMN]col_name
{SET DEFAULTliteral
| DROP DEFAULT} | ALTER INDEXindex_name
{VISIBLE | INVISIBLE} | CHANGE [COLUMN]old_col_name
new_col_name
column_definition
[FIRST|AFTERcol_name
] | [DEFAULT] CHARACTER SET [=]charset_name
[COLLATE [=]collation_name
] | CONVERT TO CHARACTER SETcharset_name
[COLLATEcollation_name
] | {DISABLE|ENABLE} KEYS | {DISCARD|IMPORT} TABLESPACE | DROP [COLUMN]col_name
| DROP {INDEX|KEY}index_name
| DROP PRIMARY KEY | DROP FOREIGN KEYfk_symbol
| FORCE | LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE} | MODIFY [COLUMN]col_name
column_definition
[FIRST | AFTERcol_name
] | ORDER BYcol_name
[,col_name
] ... | RENAME COLUMNold_col_name
TOnew_col_name
| RENAME {INDEX|KEY}old_index_name
TOnew_index_name
| RENAME [TO|AS]new_tbl_name
| {WITHOUT|WITH} VALIDATION | ADD PARTITION (partition_definition
) | DROP PARTITIONpartition_names
| DISCARD PARTITION {partition_names
| ALL} TABLESPACE | IMPORT PARTITION {partition_names
| ALL} TABLESPACE | TRUNCATE PARTITION {partition_names
| ALL} | COALESCE PARTITIONnumber
| REORGANIZE PARTITIONpartition_names
INTO (partition_definitions
) | EXCHANGE PARTITIONpartition_name
WITH TABLEtbl_name
[{WITH|WITHOUT} VALIDATION] | ANALYZE PARTITION {partition_names
| ALL} | CHECK PARTITION {partition_names
| ALL} | OPTIMIZE PARTITION {partition_names
| ALL} | REBUILD PARTITION {partition_names
| ALL} | REPAIR PARTITION {partition_names
| ALL} | REMOVE PARTITIONING | UPGRADE PARTITIONINGkey_part
: {col_name
[(length
)] | (expr
)} [ASC | DESC]index_type
: USING {BTREE | HASH}index_option
: KEY_BLOCK_SIZE [=]value
|index_type
| WITH PARSERparser_name
| COMMENT 'string
' | {VISIBLE | INVISIBLE}table_options
:table_option
[[,]table_option
] ...table_option
: AUTO_INCREMENT [=]value
| AVG_ROW_LENGTH [=]value
| [DEFAULT] CHARACTER SET [=]charset_name
| CHECKSUM [=] {0 | 1} | [DEFAULT] COLLATE [=]collation_name
| COMMENT [=] 'string
' | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'} | CONNECTION [=] 'connect_string
' | {DATA|INDEX} DIRECTORY [=] 'absolute path to directory
' | DELAY_KEY_WRITE [=] {0 | 1} | ENCRYPTION [=] {'Y' | 'N'} | ENGINE [=]engine_name
| INSERT_METHOD [=] { NO | FIRST | LAST } | KEY_BLOCK_SIZE [=]value
| MAX_ROWS [=]value
| MIN_ROWS [=]value
| PACK_KEYS [=] {0 | 1 | DEFAULT} | PASSWORD [=] 'string
' | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT} | STATS_AUTO_RECALC [=] {DEFAULT|0|1} | STATS_PERSISTENT [=] {DEFAULT|0|1} | STATS_SAMPLE_PAGES [=]value
| TABLESPACEtablespace_name
| UNION [=] (tbl_name
[,tbl_name
]...)partition_options
: (seeCREATE TABLE
options)
ALTER TABLE
ALTER TABLE
ALTER
CREATE
INSERT
ALTER
DROP
ALTER
CREATE
INSERT
ALTER TABLE
CREATE TABLE
column_definition
CHANGE
CREATE
TABLE
COLUMN
RENAME
ADD
DROP
ALTER
TABLE
ALTER TABLE
修改表T2降柱C,降D列;
ALTER TABLE
SHOW WARNINGS
ALTER TABLE
mysql_info()
ALTER TABLE
ALTER
TABLE
table_options
CREATE
TABLE
AUTO_INCREMENT
MAX_ROWS
TABLESPACE
ALTER TABLE
INDEX DIRECTORY
ALTER TABLE
ALTER
TABLE
t1
InnoDB
ALTER TABLE t1 ENGINE = InnoDB;
InnoDB
ENGINE
ALTER TABLE
ALTER
TABLE
tbl_name
ENGINE=INNODBALTER
TABLE
ALTER TABLE
tbl_name
FORCE
ALTER TABLE
tbl_name
ENGINE=INNODBALTER TABLE
tbl_name
FORCE
NO_ENGINE_SUBSTITUTION
ALTER TABLE
BLACKHOLE
InnoDB
ALTER TABLE t1 ROW_FORMAT = COMPRESSED;
InnoDB
t1
ALTER TABLE t1 ENCRYPTION='Y';ALTER TABLE t1 ENCRYPTION='N';
ALTER TABLE t1 AUTO_INCREMENT = 13;
InnoDB
AUTO_INCREMENT
ALTER TABLE t1 CHARACTER SET = utf8;
ALTER TABLE t1 COMMENT = 'New table comment';
ALTER TABLE
InnoDB
ALTER TABLE tbl_name
TABLESPACE [=]
tablespace_name
tbl_name
ALTER TABLE ... TABLESPACE
ALTER TABLE ... TABLESPACE
DATA DIRECTORY
CREATE TABLE
... TABLESPACE
TABLESPACE
CREATE TABLE
SHOW CREATE TABLE
INFORMATION_SCHEMA.TABLES
ALTER TABLE
COPY
INPLACE
INSTANT
ALGORITHM
ALGORITHM=INSTANT
ALTER TABLE
ALGORITHM=INPLACE
ALGORITHM=INPLACE
ALGORITHM=COPY
ALGORITHM
ALGORITHM=DEFAULT
ALGORITHM
ALTER TABLE
ALTER TABLE
ALTER
TABLE
ALTER TABLE
ALTER TABLE
LOCK=SHARED
LOCK=EXCLUSIVE
COPY
ALTER TABLE
old_alter_table
ALGORITHM=COPY
old_alter_table
DEFAULT
InnoDB
ALTER TABLE
ALTER TABLE
ALTER TABLE
tbl_name
RENAME
TABLE
frm
InnoDB
ALTER
INDEX
DEFAULT
ALTER TABLE
ADD COLUMN
ALGORITHM=INSTANT
ALGORITHM=INSTANT
ALTER TABLE
CHANGE COLUMN
ADD INDEX
INPLACE
ALGORITHM=INPLACE
ALGORITHM=COPY
ALTER TABLE
ALGORITHM=COPY
WITHOUT VALIDATION
ALTER TABLE
ALTER TABLE
IMPORT ... PARTITION ...
TABLESPACE
ALTER TABLE
DROP PARTITION
REBUILD
PARTITION
NDB
ADD
RANGE
ADD
HASH
LINEAR HASH
ADD
REORGANIZE
MyISAM
myisam_sort_buffer_size
ALTER TABLE
LOCK = DEFAULT
ALGORITHM=INSTANT
LOCK
LOCK
LOCK = DEFAULT
ALGORITHM
LOCK = NONE
LOCK = SHARED
ALGORITHM
LOCK = EXCLUSIVE
ALGORITHM
ADD
DROP
col_name
FIRST
col_name
DROP TABLE
CHANGE
ALTER TABLE ... ADD
CHANGE
RENAME COLUMN
CHANGE
MODIFY
CHANGE
FIRST
MODIFY
CHANGE
FIRST
RENAME COLUMN
CHANGE
ALTER
CHANGE
RENAME COLUMN
CHANGE
a
BIGINT
ALTER TABLE t1 CHANGE a b BIGINT NOT NULL;
CHANGE
CHANGE
ALTER TABLE t1 CHANGE b b INT NOT NULL;
MODIFY
修改表T1修改B INT NOT NULL;
CHANGE
CHANGE
b
ALTER TABLE t1 CHANGE b a INT NOT NULL;
RENAME COLUMN
改变重命名表列B到A;
a
c
——交换和巴尔特重命名表列A到B,B列一个重命名;“旋转”,B、C通过cyclealter重命名表列A到B,B到C柱更名,更名列C一;
CHANGE
PRIMARY KEY
col1
INT
ALTER TABLE t1 MODIFY col1 BIGINT;
INT
UNSIGNED
COMMENT
修改表T1修改col1 bigint符号默认1评论我的专栏;
CHANGE
ALTER TABLE
CHANGE
CHANGE
MyISAM
CHANGE
CHANGE
ALTER TABLE
FIRST
CHANGE
ALTER ... SET DEFAULT
NULL
NULL
DROP PRIMARY KEY
InnoDB
UNIQUE INDEX
DROP INDEX
SHOW INDEX FROM
tbl_name
index_type
type_name
index_option
index_option
RENAME INDEX
old_index_name
TO
new_index_name
old_index_name
ALTER TABLE
new_index_name
ALTER TABLE
REPAIR
TABLE
ALTER
TABLE
MyISAM
ALTER TABLE ... ENABLE KEYS
ALTER TABLE ... DISABLE KEYS
INDEX
SELECT
EXPLAIN
ALTER TABLE
ANALYZE
TABLE
ALTER INDEX
FOREIGN KEY
InnoDB
symbol
index_name
CHECK
ALTER TABLE
CREATE TABLE
index_name
ADD CONSTRAINT name
FOREIGN KEY (....) ...
REFERENCES
FOREIGN KEY
InnoDB
ALTER
TABLE
修改表 tbl_name
删除外键 fk_symbol
;
ALTER TABLE
ALTER TABLE ...
ALGORITHM=INPLACE
ALTER TABLE ...
ALGORITHM=COPY
VARCHAR(20)
VARCHAR(30)
VARCHAR(1024)
ALTER TABLE ... DROP
FOREIGN KEY
ALTER TABLE ... ADD
FOREIGN KEY
ALTER TABLE
tbl_name
RENAME
new_tbl_name
tbl_name
tbl_name
CHAR
VARCHAR
TEXT
修改表 tbl_name
转换字符集 charset_name
;
COLLATE
VARCHAR
TEXT
TEXT
TEXT
, each character might require up to three bytes, for a maximum possible length of 3 × 65,535 = 196,605 bytes. That length does not fit in aTEXT
MEDIUMTEXT
VARCHAR
MEDIUMTEXT
CONVERT TO CHARACTER SET
ALTER TABLE t MODIFY latin1_text_col TEXT CHARACTER SET utf8;
ALTER TABLE t MODIFY latin1_varchar_col VARCHAR(M
) CHARACTER SET utf8;
CONVERT TO CHARACTER SET binary
CHAR
VARCHAR
TEXT
BINARY
VARBINARY
BLOB
charset_name
CONVERT TO CHARACTER
SET
character_set_database
CONVERT TO
latin1
ALTER TABLE t1 CHANGE c1 c1 BLOB; ALTER TABLE t1 CHANGE c1 c1 TEXT CHARACTER SET utf8;
BLOB
ALTER TABLEtbl_name
DEFAULT CHARACTER SETcharset_name
;
DEFAULT
foreign_key_checks
foreign_key_checks
foreign_key_checks
foreign_key_checks
ON UPDATE CASCADE
InnoDB
DISCARD TABLESPACE
ORDER BY
ORDER BY
DESC
ORDER BY
InnoDB
ALTER TABLE ... ORDER
BY
partition_options
ALTER TABLE
REMOVE PARTITIONING
REMOVE PARTITIONING
DROP PARTITION
IMPORT
PARTITION
REORGANIZE PARTITION
ANALYZE PARTITION
REPAIR
PARTITION
ALTER TABLE ...
EXCHANGE PARTITION
ALTER
TABLE
partition_options
ALTER TABLE
partition_options
partition_options
CREATE TABLE
CREATE TABLE t1 ( id INT, year_col INT );
HASH
ALTER TABLE t1 PARTITION BY HASH(id) PARTITIONS 8;
ALGORITHM
ALGORITHM=1
ALGORITHM=2
KEY
ALGORITHM=2
[LINEAR] KEY
LINEAR KEY
ALTER TABLE
... PARTITION BY
CREATE TABLE ... PARTITION BY
partition_definition
CREATE TABLE
CREATE TABLE t1 ( id INT, year_col INT ) PARTITION BY RANGE (year_col) ( PARTITION p0 VALUES LESS THAN (1991), PARTITION p1 VALUES LESS THAN (1995), PARTITION p2 VALUES LESS THAN (1999) );
p3
DROP PARTITION
LIST
KEY
partition_names
p0
ALTER TABLE t1 DROP PARTITION p0, p1;
ADD PARTITION
IF
[NOT] EXISTS
DISCARD
PARTITION ... TABLESPACE
IMPORT
PARTITION ... TABLESPACE
InnoDB
.idb
ALTER TABLE t1 DISCARD PARTITION p2, p3 TABLESPACE;
修改表T1进口分区P2、P3表空间;
DISCARD
PARTITION ... TABLESPACE
IMPORT
PARTITION ... TABLESPACE
InnoDB
ALTER TABLE
... REORGANIZE PARTITION
TRUNCATE PARTITION
CREATE TABLE t1 ( id INT, year_col INT ) PARTITION BY RANGE (year_col) ( PARTITION p0 VALUES LESS THAN (1991), PARTITION p1 VALUES LESS THAN (1995), PARTITION p2 VALUES LESS THAN (1999), PARTITION p3 VALUES LESS THAN (2003), PARTITION p4 VALUES LESS THAN (2007) );
p0
修改表T1删除分区P0;
DELETE
DELETE FROM t1 WHERE year_col < 1991;
WHERE
DELETE
p3
修改表T1删除分区P1、P3;
DELETE
DELETE FROM t1 WHERE (year_col >= 1991 AND year_col < 1995) OR (year_col >= 2003 AND year_col < 2007);
ALL
TRUNCATE PARTITION
INFORMATION_SCHEMA.PARTITIONS
SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 't1';
COALESCE PARTITION
KEY
number
CREATE TABLE t2 ( name VARCHAR (30), started DATE ) PARTITION BY HASH( YEAR(started) ) PARTITIONS 6;
t2
修改表T2合并分区2;
number
REORGANIZE
PARTITION
partition_names
partition_definition
partition_names
partition_definitions
VALUES LESS THAN
p0
p2
ALTER TABLE ... REORGANIZE PARTITION
ALTER
TABLE ... EXCHANGE PARTITION
CHECK TABLE
REPAIR TABLE
ANALYZE PARTITION
OPTIMIZE PARTITION
REPAIR
PARTITION
partition_names
partition_names
InnoDB
ALTER TABLE ... REBUILD
PARTITION
ANALYZE PARTITION
OPTIMIZE PARTITION
REMOVE PARTITIONING
ALTER TABLE
ENGINE
ALTER TABLE
NDB
ALTER TABLE
REMOVE PARTITIONING
REMOVE PARTITIONING
ADD PARTITION
COALESCE PARTITION
ANALYZE
PARTITION
REPAIR PARTITION
ALTER TABLE
ADD
PARTITION
TRUNCATE PARTITION
REORGANIZE PARTITION
ANALYZE
PARTITION
OPTIMIZE PARTITION
REMOVE PARTITIONING
ALTER TABLE t1 ANALYZE PARTITION p1, ANALYZE PARTITION p2; ALTER TABLE t1 ANALYZE PARTITION p1, CHECK PARTITION p2;
p1
t1
ALTER TABLE t1 ANALYZE PARTITION p1, p2;
ANALYZE
ALTER TABLE t1 ANALYZE PARTITION p1; ALTER TABLE t1 CHECK PARTITION p2;
REBUILD
ALTER TABLE
CHECK PARTITION
ALTER TABLE
MODIFY
CREATE TABLE t1 (c1 INT); ALTER TABLE t1 ADD COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) STORED;
CREATE TABLE t1 (c1 INT, c2 INT GENERATED ALWAYS AS (c1 + 1) STORED); ALTER TABLE t1 MODIFY COLUMN c2 TINYINT GENERATED ALWAYS AS (c1 + 5) STORED;
CREATE TABLE t1 (c1 INT, c2 INT GENERATED ALWAYS AS (c1 + 1) STORED); ALTER TABLE t1 CHANGE c2 c3 INT GENERATED ALWAYS AS (c1 + 1) STORED; ALTER TABLE t1 DROP COLUMN c3;
CREATE TABLE t1 (c1 INT, c2 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL); ALTER TABLE t1 DROP COLUMN c2; ALTER TABLE t1 ADD COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) STORED;
CREATE TABLE t1 (c1 INT, c2 INT); ALTER TABLE t1 MODIFY COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) STORED;
CREATE TABLE t1 (c1 INT, c2 INT GENERATED ALWAYS AS (c1 + 1) STORED); ALTER TABLE t1 MODIFY COLUMN c2 INT;
ADD COLUMN
ADD COLUMN
ALTER TABLE
ADD COLUMN
InnoDB
VIRTUAL
WITHOUT VALIDATION
WITHOUT VALIDATION
WITH VALIDATION
WITHOUT VALIDATION
ADD
COLUMN
MODIFY COLUMN
ER_WRONG_USAGE
ALTER TABLE
ALTER TABLE
col_name
col_name
DEFAULT(
col_name
)ALTER TABLE
DEFAULT()
t1
创建表T1(一个整数,B查尔(10));
t1
ALTER TABLE t1 RENAME t2;
a
INTEGER
b
CHAR(20)
c
修改表T2修改字段不为空,改变B C字符(20);
TIMESTAMP
ALTER TABLE t2 ADD d TIMESTAMP;
d
a
Alater T2 Add Index(D),Addénéunique(a);
c
修改表T2降C柱;
AUTO_INCREMENT
ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (c);
c
AUTO_INCREMENT
NOT NULL
AUTO_INCREMENT
SET
INSERT_ID=
value
ALTER TABLE
AUTO_INCREMENT=
value
MyISAM
AUTO_INCREMENT
AUTO_INCREMENT
AUTO_INCREMENT
t2
AUTO_INCREMENT
创建表T2(ID int auto_increment主键)SELECT * FROM T1的col1,col2;
t1
col2
t2
AUTO_INCREMENT
创建表T2像T1 T2;修改表添加ID int auto_increment主键;插入T2 SELECT * FROM T1的col1,col2;
t1
AUTO_INCREMENT
删除表T1 T2 T1表重命名;
ALTER TABLESPACEtablespace_name
RENAME TOtablespace_name
[ENGINE [=]engine_name
]
InnoDB
CREATE TABLESPACE
ENGINE
RENAME TO
autocommit
autocommit
RENAME TO
LOCK TABLES
FLUSH TABLES WITH READ
LOCK
ALTER [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] [DEFINER = {user
| CURRENT_USER }] [SQL SECURITY { DEFINER | INVOKER }] VIEWview_name
[(column_list
)] ASselect_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
CREATE
VIEW
CREATE VIEW
DROP
SELECT
ALTER VIEW
SET_USER_ID
SUPER
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS]db_name
[create_specification
] ...create_specification
: [DEFAULT] CHARACTER SET [=]charset_name
| [DEFAULT] COLLATE [=]collation_name
CREATE DATABASE
CREATE
CREATE
SCHEMA
CREATE
DATABASE
IF NOT EXISTS
CREATE DATABASE
LOCK
TABLES
create_specification
COLLATE
CREATE DATABASE
CREATE [DEFINER = {user
| CURRENT_USER }] EVENT [IF NOT EXISTS]event_name
ON SCHEDULEschedule
[ON COMPLETION [NOT] PRESERVE] [ENABLE | DISABLE | DISABLE ON SLAVE] [COMMENT 'string
'] DOevent_body
;schedule
: ATtimestamp
[+ INTERVALinterval
] ... | EVERYinterval
[STARTStimestamp
[+ INTERVALinterval
] ...] [ENDStimestamp
[+ INTERVALinterval
] ...]interval
:quantity
{YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE | WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE | DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}
CREATE EVENT
EVENT
SET_USER_ID
SUPER
CREATE
EVENT
CREATE EVENT
ON SCHEDULE
DO
CREATE
EVENT
CREATE EVENT myevent ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO UPDATE myschema.mytable SET mycol = mycol + 1;
myevent
mycol
event_name
MyEvent
event_name
schema_name
event_name
DEFINER
user
user_name
host_name
CURRENT_USER
CURRENT_USER()
CREATE EVENT
DEFINER = CURRENT_USER
DEFINER
SET_USER_ID
SUPER
user
CURRENT_USER
SET_USER_ID
SUPER
DEFINER
CURRENT_USER()
IF NOT EXISTS
CREATE EVENT
CREATE TABLE
event_name
ON SCHEDULE
event_body
AT
timestamp
timestamp
DATETIME
TIMESTAMP
MySQL的> SELECT NOW();
--------------------- | now() | --------------------- | 2006-02-10 23:59:01 | --------------------- 1行集(0.04秒)MySQL > CREATE EVENT e_totals
-> ON SCHEDULE AT '2006-02-10 23:59:00'
-> DO INSERT INTO test.totals VALUES (NOW());
查询行,0行的影响,1报警(0秒)MySQL > SHOW WARNINGS\G
*************************** 1。行***************************水平:注意代码:1588message:活动执行时间是在过去完成不保存设置。该事件被创建后立即下降。
CREATE EVENT
CURRENT_TIMESTAMP
+
INTERVAL
interval
interval
DATE_ADD()
+ INTERVAL '2:10' MINUTE_SECOND
AT
CURRENT_TIMESTAMP + INTERVAL 3 WEEK + INTERVAL 2 DAY
+ INTERVAL
EVERY
interval
+ INTERVAL
EVERY
+ INTERVAL
+
INTERVAL
EVERY
STARTS
timestamp
interval
EVERY 3 MONTH STARTS CURRENT_TIMESTAMP + INTERVAL 1
WEEK
EVERY 2 WEEK STARTS CURRENT_TIMESTAMP
+ INTERVAL '6:15' HOUR_MINUTE
STARTS
CURRENT_TIMESTAMP
EVERY
ENDS
timestamp
interval
EVERY 12 HOUR
STARTS CURRENT_TIMESTAMP + INTERVAL 30 MINUTE ENDS
CURRENT_TIMESTAMP + INTERVAL 4 WEEK
ENDS
ENDS
STARTS
EVERY
GET_LOCK()
ON SCHEDULE
timestamp
interval
CREATE EVENT
ALTER EVENT
ON SCHEDULE
time_zone
ON
COMPLETION PRESERVE
DISABLE
ALTER EVENT
ENABLE
DISABLE ON SLAVE
COMMENT
comment
DO
e_hourly
site_activity
创建事件e_hourly计划每1小时评论清除会话表的每一个小时,你删除site_activity.sessions;
sql_mode
CREATE EVENT
ALTER EVENT
DO
SELECT
SHOW
SELECT ...
INTO
INSERT INTO ...
SELECT
DO
DO
END
分隔符|创建事件e_daily进度每1天的评论保存会话总数然后清除表每一天的开始插入site_activity.totals(时间、总)选择current_timestamp,计数(*)从site_activity.sessions;删除site_activity.sessions;端|分隔符;
delimiter
delimiter | CREATE EVENT e ON SCHEDULE EVERY 5 SECOND DO BEGIN DECLARE v INTEGER; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; SET v = 0; WHILE v < 5 DO INSERT INTO t1 VALUES (0); UPDATE t2 SET s1 = s1 + 1; SET v = v + 1; END WHILE; END | delimiter ;
CREATE EVENT e_call_myproc ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY DO CALL myproc(5, 27);
SYSTEM_VARIABLES_ADMIN
SUPER
CREATE FUNCTION
CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEXindex_name
[index_type
] ONtbl_name
(key_part
,...) [index_option
] [algorithm_option
|lock_option
] ...key_part
: {col_name
[(length
)] | (expr
)} [ASC | DESC]index_option
: KEY_BLOCK_SIZE [=]value
|index_type
| WITH PARSERparser_name
| COMMENT 'string
' | {VISIBLE | INVISIBLE}index_type
: USING {BTREE | HASH}algorithm_option
: ALGORITHM [=] {DEFAULT | INPLACE | COPY}lock_option
: LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}
CREATE
TABLE
InnoDB
CREATE INDEX
CREATE INDEX
ALTER TABLE
CREATE INDEX
ALTER TABLE
InnoDB
innodb_stats_persistent
ANALYZE
TABLE
InnoDB
(
key_part1
,
key_part2
, ...)col1
col3
key_part
DESC
DESC
ASC
SPATIAL
CREATE INDEX
col_name
(length
)
BLOB
TEXT
BLOB
TEXT
MyISAM
CREATE
TABLE
ALTER TABLE
CREATE INDEX
CHAR
VARCHAR
TEXT
BINARY
VARBINARY
BLOB
InnoDB
COMPACT
DYNAMIC
MyISAM
CREATE INDEX
name
CREATE INDEX part_of_name ON customer (name(10));
name
INSERT
t1
col2
创建表T1(COL1,COL2 varchar varchar(10)(20),指数(col1,col2(10)));
CREATE TABLE t1 (col1 INT, col2 INT, INDEX func_index ((ABS(col1)))); CREATE INDEX idx1 ON t1 ((col1 + col2)); CREATE INDEX idx2 ON t1 ((col1 + col2), (col1 - col2), col1); ALTER TABLE t1 ADD INDEX ((col1 * 40) DESC);
ASC
INDEX ((col1 + col2), (col3 - col4))
INDEX (col1 + col2, col3 - col4)
INDEX ((col1), (col2))
INDEX (col1, col2)
SUBSTRING()
CAST()
CREATE
TABLE ... LIKE
UNIQUE
SPATIAL
InnoDB
UNIQUE NOT NULL
SUBSTRING()
CAST()
SUBSTRING()
SUBSTRING()
SELECT
SUBSTRING()
CREATE TABLE tbl (col1 LONGTEXT, INDEX idx1 ((SUBSTRING(col1, 1, 10))));SELECT * FROM tbl WHERE SUBSTRING(col1, 1, 9) = '123456789';SELECT * FROM tbl WHERE SUBSTRING(col1, 1, 10) = '1234567890';
JSON
CREATE TABLE employees (data JSON, INDEX ((data->>'$.name')));
->>
JSON_UNQUOTE(JSON_EXTRACT(...))
JSON_UNQUOTE()
LONGTEXT
LONGTEXT
JSON
CAST()
CREATE TABLE employees (data JSON, INDEX ((CAST(data->>'$.name' AS CHAR(30)))));
VARCHAR(30)
CAST()
CAST()
SELECT
CAST()
CREATE TABLE employees ( data JSON, INDEX str_index ((CAST(data->>'$.name' AS CHAR(30)))), INDEX int_index ((CAST(data->>'$.salary' AS SIGNED))) ); INSERT INTO employees VALUES ('{ "name": "James", "salary": 10000 }'), ('{ "name": "Mary", "salary": 12000 }'), ('{ "name": "Peter", "salary": 8000 }'); SELECT * FROM employees WHERE data->>'$.name' = 'James'; SELECT * FROM employees WHERE data->>'$.salary' > 9000;
UNIQUE
UNIQUE
NULL
PRIMARY KEY
_rowid
SELECT
_rowid
PRIMARY
KEY
_rowid
_rowid
UNIQUE NOT NULL
FULLTEXT
InnoDB
MyISAM
CHAR
VARCHAR
TEXT
MyISAM
InnoDB
NDB
ARCHIVE
POINT
GEOMETRY
INDEX
PRIMARY KEY
index_option
KEY_BLOCK_SIZE [=]
value
MyISAM
KEY_BLOCK_SIZE
KEY_BLOCK_SIZE
InnoDB
index_type
CREATE TABLE lookup (id INT) ENGINE = MEMORY; CREATE INDEX id_index ON lookup (id) USING BTREE;
index_type
index_type
SPATIAL INDEX
RTREE
RTREE
index_type
tbl_name
index_type
TYPE
type_name
type_name
index_type
BTREE | |||||
BTREE | |||||
BTREE | |||||
FULLTEXT | |||||
SPATIAL |
BTREE | |||||
BTREE | |||||
BTREE | |||||
FULLTEXT | |||||
SPATIAL |
BTREE | |||||
BTREE | |||||
BTREE | |||||
HASH | |||||
HASH | |||||
HASH |
WITH PARSER
parser_name
FULLTEXT
InnoDB
MyISAM
COMMENT
'
string
'
MERGE_THRESHOLD
index_option
CREATE INDEX
CREATE TABLE t1 (id INT);CREATE INDEX id_index ON t1 (id) COMMENT 'MERGE_THRESHOLD=40';
MERGE_THRESHOLD
InnoDB
MERGE_THRESHOLD
CREATE TABLE
ALTER TABLE
VISIBLE
ALGORITHM
ALTER TABLE
CREATE [DEFINER = {user
| CURRENT_USER }] PROCEDUREsp_name
([proc_parameter
[,...]]) [characteristic
...]routine_body
CREATE [DEFINER = {user
| CURRENT_USER }] FUNCTIONsp_name
([func_parameter
[,...]]) RETURNStype
[characteristic
...]routine_body
proc_parameter
: [ IN | OUT | INOUT ]param_name
type
func_parameter
:param_name
type
type
:Any valid MySQL data type
characteristic
: COMMENT 'string
' | LANGUAGE SQL | [NOT] DETERMINISTIC | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA } | SQL SECURITY { DEFINER | INVOKER }routine_body
:Valid SQL routine statement
db_name.sp_name
CREATE FUNCTION
CALL
CREATE PROCEDURE
CREATE FUNCTION
CREATE ROUTINE
SET_USER_ID
SUPER
CREATE
FUNCTION
SUPER
ALTER ROUTINE
EXECUTE
automatic_sp_privileges
DEFINER
IGNORE_SPACE
IGNORE_SPACE
()
IN
INOUT
IN
INOUT
FUNCTION
IN
NULL
OUT
CALL
INOUT
col_name
INOUT
OUT
MySQL的> delimiter //
MySQL的> CREATE PROCEDURE simpleproc (OUT param1 INT)
-> BEGIN
-> SELECT COUNT(*) INTO param1 FROM t;
-> END//
查询好,为受影响的行(0.001秒)MySQL > delimiter ;
MySQL的> CALL simpleproc(@a);
查询好,为受影响的行(0.001秒)MySQL > SELECT @a;
------ | @ | ------ | 3 | ------ 1行集(0秒)
delimiter
//
RETURNS
RETURN
value
RETURN
ENUM
SET
RETURN
ENUM
SET
delimiter
mysql>CREATE FUNCTION hello (s CHAR(20))
mysql>RETURNS CHAR(50) DETERMINISTIC
->RETURN CONCAT('Hello, ',s,'!');
Query OK, 0 rows affected (0.00 sec) mysql>SELECT hello('world');
+----------------+ | hello('world') | +----------------+ | Hello, world! | +----------------+ 1 row in set (0.00 sec)
COLLATE
routine_body
SELECT
INSERT
END
CREATE
COMMIT
SELECT
var_list
SHOW
EXPLAIN
CHECK TABLE
ER_SP_NO_RETSET
ER_SP_BADSELECT
USE
db_name
sql_mode
COMMENT
SHOW CREATE
PROCEDURE
SHOW CREATE
FUNCTION
LANGUAGE
DETERMINISTIC
NOT DETERMINISTIC
DETERMINISTIC
NONDETERMINISTIC
DETERMINISTIC
NOW()
RAND()
NOW()
RAND()
SQL SECURITY
INVOKER
DEFINER
EXECUTE
DEFINER
user
'
user_name
'@'host_name
'CURRENT_USER
CURRENT_USER()
CREATE PROCEDURE
CREATE FUNCTION
DEFINER = CURRENT_USER
DEFINER
SET_USER_ID
SUPER
user
CURRENT_USER
SET_USER_ID
SUPER
DEFINER
DEFINER
SQL
SECURITY DEFINER
CURRENT_USER
mysql.user
CREATE DEFINER = 'admin'@'localhost' PROCEDURE account_count()BEGIN SELECT 'Number of accounts:', COUNT(*) FROM mysql.user;END;
DEFINER
DEFINER
EXECUTE
SELECT
SQL
SECURITY INVOKER
CREATE DEFINER = 'admin'@'localhost' PROCEDURE account_count()SQL SECURITY INVOKERBEGIN SELECT 'Number of accounts:', COUNT(*) FROM mysql.user;END;
DEFINER
EXECUTE
SELECT
DECLARE
SET x = (SELECT 1, 2)
CHARACTER
SET
CHARACTER SET
CHARACTER SET
character_set_database
collation_database
CREATE SERVERserver_name
FOREIGN DATA WRAPPERwrapper_name
OPTIONS (option
[,option
] ...)option
: { HOSTcharacter-literal
| DATABASEcharacter-literal
| USERcharacter-literal
| PASSWORDcharacter-literal
| SOCKETcharacter-literal
| OWNERcharacter-literal
| PORTnumeric-literal
}
FEDERATED
servers
SUPER
server_name
server_name
wrapper_name
option
OWNER
CREATE SERVER
CREATE TABLE
mysql.servers
Host
Username
Port
CREATE SERVER s FOREIGN DATA WRAPPER mysql OPTIONS (USER 'Remote', HOST '198.51.100.106', DATABASE 'test');
FEDERATED
CREATE TABLE t (s1 INT) ENGINE=FEDERATED CONNECTION='s';
CREATE SERVER
CREATE SERVER
CREATE OR REPLACE SPATIAL REFERENCE SYSTEMsrid
srs_attribute
... CREATE SPATIAL REFERENCE SYSTEM [IF NOT EXISTS]srid
srs_attribute
...srs_attribute
: { NAME 'srs_name
' | DEFINITION 'definition
' | ORGANIZATION 'org_name
' IDENTIFIED BYorg_id
| DESCRIPTION 'description
' }srid
,org_id
:32-bit unsigned integer
INFORMATION_SCHEMA
ST_SPATIAL_REFERENCE_SYSTEMS
SUPER
OR REPLACE
CREATE OR REPLACE
MySQL的> CREATE OR REPLACE SPATIAL REFERENCE SYSTEM 4326 ...;
错误3716(sr005):不能修改方案4326。有至少一列取决于它。
SELECT * FROM INFORMATION_SCHEMA.ST_GEOMETRY_COLUMNS WHERE SRS_ID=4326;
CREATE ... IF NOT EXISTS
CREATE SPATIAL REFERENCE
SYSTEM
NAME
NAME
srs_name
org_name
org_id
NAME
srs_name
org_name
CREATE SPATIAL REFERENCE
SYSTEM
CREATE SPATIAL REFERENCE SYSTEM 4120 NAME 'Greek' ORGANIZATION 'EPSG' IDENTIFIED BY 4120 DEFINITION 'GEOGCS["Greek",DATUM["Greek",SPHEROID["Bessel 1841", 6377397.155,299.1528128,AUTHORITY["EPSG","7004"]], AUTHORITY["EPSG","6120"]],PRIMEM["Greenwich",0, AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278, AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST], AUTHORITY["EPSG","4120"]]';
<horz cs>
<authority>
<parameter>
CREATE [TEMPORARY] TABLE [IF NOT EXISTS]tbl_name
(create_definition
,...) [table_options
] [partition_options
] CREATE [TEMPORARY] TABLE [IF NOT EXISTS]tbl_name
[(create_definition
,...)] [table_options
] [partition_options
] [IGNORE | REPLACE] [AS]query_expression
CREATE [TEMPORARY] TABLE [IF NOT EXISTS]tbl_name
{ LIKEold_tbl_name
| (LIKEold_tbl_name
) }create_definition
:col_name
column_definition
| [CONSTRAINT [symbol
]] PRIMARY KEY [index_type
] (key_part
,...) [index_option
] ... | {INDEX|KEY} [index_name
] [index_type
] (key_part
,...) [index_option
] ... | [CONSTRAINT [symbol
]] UNIQUE [INDEX|KEY] [index_name
] [index_type
] (key_part
,...) [index_option
] ... | {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name
] (key_part
,...) [index_option
] ... | [CONSTRAINT [symbol
]] FOREIGN KEY [index_name
] (key_part
,...)reference_definition
| CHECK (expr
)column_definition
:data_type
[NOT NULL | NULL] [DEFAULT {literal
| (expr
)} ] [AUTO_INCREMENT] [UNIQUE [KEY]] [[PRIMARY] KEY] [COMMENT 'string
'] [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}] [reference_definition
] |data_type
[GENERATED ALWAYS] AS (expression
) [VIRTUAL | STORED] [NOT NULL | NULL] [UNIQUE [KEY]] [[PRIMARY] KEY] [COMMENT 'string
']data_type
: (see Chapter 11, Data Types)key_part
: {col_name
[(length
)] | (expr
)} [ASC | DESC]index_type
: USING {BTREE | HASH}index_option
: KEY_BLOCK_SIZE [=]value
|index_type
| WITH PARSERparser_name
| COMMENT 'string
' | {VISIBLE | INVISIBLE}reference_definition
: REFERENCEStbl_name
(key_part
,...) [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE] [ON DELETEreference_option
] [ON UPDATEreference_option
]reference_option
: RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULTtable_options
:table_option
[[,]table_option
] ...table_option
: AUTO_INCREMENT [=]value
| AVG_ROW_LENGTH [=]value
| [DEFAULT] CHARACTER SET [=]charset_name
| CHECKSUM [=] {0 | 1} | [DEFAULT] COLLATE [=]collation_name
| COMMENT [=] 'string
' | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'} | CONNECTION [=] 'connect_string
' | {DATA|INDEX} DIRECTORY [=] 'absolute path to directory
' | DELAY_KEY_WRITE [=] {0 | 1} | ENCRYPTION [=] {'Y' | 'N'} | ENGINE [=]engine_name
| INSERT_METHOD [=] { NO | FIRST | LAST } | KEY_BLOCK_SIZE [=]value
| MAX_ROWS [=]value
| MIN_ROWS [=]value
| PACK_KEYS [=] {0 | 1 | DEFAULT} | PASSWORD [=] 'string
' | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT} | STATS_AUTO_RECALC [=] {DEFAULT|0|1} | STATS_PERSISTENT [=] {DEFAULT|0|1} | STATS_SAMPLE_PAGES [=]value
| TABLESPACEtablespace_name
| UNION [=] (tbl_name
[,tbl_name
]...)partition_options
: PARTITION BY { [LINEAR] HASH(expr
) | [LINEAR] KEY [ALGORITHM={1|2}] (column_list
) | RANGE{(expr
) | COLUMNS(column_list
)} | LIST{(expr
) | COLUMNS(column_list
)} } [PARTITIONSnum
] [SUBPARTITION BY { [LINEAR] HASH(expr
) | [LINEAR] KEY [ALGORITHM={1|2}] (column_list
) } [SUBPARTITIONSnum
] ] [(partition_definition
[,partition_definition
] ...)]partition_definition
: PARTITIONpartition_name
[VALUES {LESS THAN {(expr
|value_list
) | MAXVALUE} | IN (value_list
)}] [[STORAGE] ENGINE [=]engine_name
] [COMMENT [=] 'string
' ] [DATA DIRECTORY [=] ''] [INDEX DIRECTORY [=] '
data_dir
'] [MAX_ROWS [=]
index_dir
max_number_of_rows
] [MIN_ROWS [=]min_number_of_rows
] [TABLESPACE [=] tablespace_name] [(subpartition_definition
[,subpartition_definition
] ...)]subpartition_definition
: SUBPARTITIONlogical_name
[[STORAGE] ENGINE [=]engine_name
] [COMMENT [=] 'string
' ] [DATA DIRECTORY [=] ''] [INDEX DIRECTORY [=] '
data_dir
'] [MAX_ROWS [=]
index_dir
max_number_of_rows
] [MIN_ROWS [=]min_number_of_rows
] [TABLESPACE [=] tablespace_name]query_expression:
SELECT ... (Some valid select or union statement
)
CREATE TABLE
CREATE
InnoDB
CREATE TABLE
CREATE
TABLE
tbl_name
db_name.tbl_name
`mydb.mytbl`
IF NOT EXISTS
CREATE TABLE
TEMPORARY
LIKE
CREATE TABLE ... LIKE
创建表 new_tbl
喜欢 orig_tbl
;
[AS]
query_expression
SELECT
CREATE TABLE
创建表 new_tbl
为SELECT * FROM orig_tbl
;
IGNORE|REPLACE
IGNORE
SELECT
data_type
data_type
AUTO_INCREMENT
BLOB
TEXT
JSON
CHAR
VARCHAR
TEXT
COLLATE
CHARSET
CREATE TABLE t (c CHAR(20) CHARACTER SET utf8 COLLATE utf8_bin);
CHAR
VARCHAR
BINARY
VARBINARY
col_name
length
BLOB
TEXT
length
CHAR
VARCHAR
TEXT
length
BINARY
VARBINARY
BLOB
InnoDB
BLOB
TEXT
创建测试表(blob_col blob,指数(blob_col(10)));
CREATE
TABLE
JSON
NOT NULL | NULL
NULL
NULL
InnoDB
MEMORY
NOT NULL
DEFAULT
DEFAULT
NO_ZERO_DATE
NO_ZERO_IN_DATE
CREATE TABLE
NO_ZERO_IN_DATE
AUTO_INCREMENT
AUTO_INCREMENT
0
value
+1value
1
AUTO_INCREMENT
LAST_INSERT_ID()
mysql_insert_id()
NO_AUTO_VALUE_ON_ZERO
AUTO_INCREMENT
AUTO_INCREMENT
AUTO_INCREMENT
AUTO_INCREMENT
MyISAM
AUTO_INCREMENT
SELECT * FROM tbl_name
哪里 auto_col
是空的
sql_auto_is_null
InnoDB
AUTO_INCREMENT
COMMENT
COMMENT
SHOW
CREATE TABLE
SHOW FULL
COLUMNS
COLUMN_FORMAT
NDB
GENERATED ALWAYS
InnoDB
CONSTRAINT
symbol
CONSTRAINT
symbol
symbol
symbol
symbol
PRIMARY KEY
NOT NULL
PRIMARY KEY
PRIMARY
PRIMARY KEY
UNIQUE
PRIMARY KEY
InnoDB
PRIMARY KEY
UNIQUE
PRIMARY KEY
PRIMARY
KEY(
key_part
, ...)
PRIMARY KEY
_rowid
SELECT
PRIMARY KEY
_2
...
tbl_name
KEY | INDEX
KEY
PRIMARY
KEY
UNIQUE
UNIQUE
NULL
UNIQUE
PRIMARY KEY
_rowid
SELECT
FULLTEXT
FULLTEXT
InnoDB
MyISAM
CHAR
VARCHAR
TEXT
WITH PARSER
index_option
InnoDB
MyISAM
SPATIAL
SPATIAL
MyISAM
FOREIGN KEY
reference_definition
reference_option
InnoDB
CHECK
CHECK
key_part
key_part
DESC
length
REDUNDANT
InnoDB
COMPRESSED
CREATE
TABLE
ALTER
TABLE
CREATE
INDEX
CHAR
VARCHAR
TEXT
BINARY
VARBINARY
BLOB
index_type
index_type
type_name
CREATE TABLE lookup (id INT, INDEX USING BTREE (id)) ENGINE = MEMORY;
USING
index_option
index_option
KEY_BLOCK_SIZE
MyISAM
KEY_BLOCK_SIZE
KEY_BLOCK_SIZE
WITH PARSER
WITH PARSER
InnoDB
MyISAM
MyISAM
ALTER
TABLE
COMMENT
InnoDB
index_option
index_option
reference_definition
InnoDB
InnoDB
ON UPDATE
InnoDB
FOREIGN KEY
CREATE TABLE
InnoDB
MATCH
ON UPDATE
MATCH
InnoDB
NULL
InnoDB
NOT
NULL
UPDATE
UNIQUE
NOT
NULL
REFERENCES
FOREIGN KEY
RESTRICT
SET NULL
SET
DEFAULT
ALTER TABLE
ENGINE
'DEFAULT'
InnoDB | InnoDB |
MyISAM | |
MEMORY | |
CSV | |
ARCHIVE | |
EXAMPLE | |
FEDERATED | |
HEAP | MEMORY |
MERGE | MyISAM
|
NO_ENGINE_SUBSTITUTION
InnoDB
default_storage_engine
AUTO_INCREMENT
AUTO_INCREMENT
MEMORY
ARCHIVE
AUTO_INCREMENT
CREATE TABLE
tbl_name
AUTO_INCREMENT =N
AVG_ROW_LENGTH
MyISAM
AVG_ROW_LENGTH
myisam_data_pointer_size
[DEFAULT] CHARACTER SET
CHARSET
DEFAULT
CHECKSUM
CHECKSUM
TABLE
[DEFAULT] COLLATE
COMMENT
InnoDB
table_option
COMPRESSION
InnoDB
LZ4
COMPRESSION
CONNECTION
FEDERATED
COMMENT
DATA DIRECTORY
InnoDB
DATA DIRECTORY='
directory
.ibd
innodb_file_per_table
InnoDB
MyISAM
DATA DIRECTORY='
directory
INDEX DIRECTORY='
directory
InnoDB
DATA DIRECTORY
FILE
INDEX DIRECTORY
DATA DIRECTORY
--skip-symbolic-links
MyISAM
.MYD
.MYD
INDEX
DIRECTORY
--keep_files_on_create
MyISAM
INDEX
DIRECTORY
.MYI
DATA DIRECTORY
DELAY_KEY_WRITE
delay_key_write
MyISAM
ENCRYPTION
ENCRYPTION
InnoDB
ENCRYPTION
keyring_file
INSERT_METHOD
MERGE
INSERT_METHOD
FIRST
NO
KEY_BLOCK_SIZE
MyISAM
KEY_BLOCK_SIZE
InnoDB
InnoDB
InnoDB
innodb_page_size
innodb_page_size
innodb_page_size
innodb_strict_mode
InnoDB
innodb_strict_mode
innodb_strict_mode
KEY_BLOCK_SIZE
Create_options
SHOW TABLE STATUS
SHOW CREATE TABLE
InnoDB
KEY_BLOCK_SIZE
innodb_page_size
InnoDB
MAX_ROWS
MAX_ROWS
MIN_ROWS
MEMORY
PACK_KEYS
MyISAM
CHAR
VARCHAR
BINARY
VARBINARY
PACK_KEYS
PACK_KEYS=1
storage_size_for_key + pointer_size
NULL
PASSWORD
ROW_FORMAT
CREATE TABLE
Row_format
SHOW TABLE STATUS
SHOW CREATE TABLE
InnoDB
innodb_default_row_format
ROW_FORMAT
ROW_FORMAT=DEFAULT
ROW_FORMAT
ROW_FORMAT=DEFAULT
innodb_default_row_format
InnoDB
BLOB
DYNAMIC
InnoDB
ROW_FORMAT=COMPRESSED
ROW_FORMAT=COMPRESSED
COMPRESSED
REDUNDANT
ROW_FORMAT
innodb_strict_mode
ROW_FORMAT=FIXED
ROW_FORMAT=FIXED
innodb_strict_mode
ROW_FORMAT=DYNAMIC
ROW_FORMAT=FIXED
innodb_strict_mode
InnoDB
MyISAM
DYNAMIC
COMPRESSED
STATS_AUTO_RECALC
InnoDB
innodb_stats_auto_recalc
0
ANALYZE TABLE
STATS_PERSISTENT
InnoDB
innodb_stats_persistent
0
ALTER TABLE
ANALYZE TABLE
STATS_SAMPLE_PAGES
ANALYZE
TABLE
TABLESPACE
TABLESPACE
创建表 tbl_name
... TABLESPACE [=]tablespace_name
tablespace_name
TABLESPACE
CREATE TABLE
ALTER TABLE
mysql> CREATE TABLE t1 ( a INT NOT NULL, PRIMARY KEY (a)) -> ENGINE=InnoDB TABLESPACE ts1 -> PARTITION BY RANGE (a) PARTITIONS 3 ( -> PARTITION P1 VALUES LESS THAN (2), -> PARTITION P2 VALUES LESS THAN (4) TABLESPACE ts2, -> PARTITION P3 VALUES LESS THAN (6) TABLESPACE ts3);
TABLESPACE
innodb_system
创建表 tbl_name
... TABLESPACE [=] innodb_system
TABLESPACE [=] innodb_system
innodb_file_per_table
ROW_FORMAT=DYNAMIC
TABLESPACE [=] innodb_system
innodb_file_per_table
创建表 tbl_name
... TABLESPACE [=] innodb_file_per_table
innodb_file_per_table
TABLESPACE=innodb_file_per_table
InnoDB
innodb_file_per_table
DATA DIRECTORY
CREATE TABLE ... TABLESPACE=innodb_file_per_table
TABLESPACE
TABLESPACE
ALTER TABLE
ALTER TABLE ...
REORGANIZE PARTITION
MyISAM
SELECT
UPDATE
DELETE
MERGE
partition_options
CREATE TABLE
partition_options
PARTITION BY
partition_options
num
num
expr
HASH(
expr
)
expr
CREATE TABLE
CREATE TABLE t1 (col1 INT, col2 CHAR(5)) PARTITION BY HASH(col1); CREATE TABLE t1 (col1 INT, col2 CHAR(5), col3 DATETIME) PARTITION BY HASH ( YEAR(col3) );
VALUES LESS THAN
PARTITION
BY HASH
PARTITION BY HASH
expr
LINEAR
AND
KEY(
column_list
)
HASH
column_list
创建表的TK(col1 int,char(5),col2 col3日期)分区键(COL3)分区4;
LINEAR
&
CREATE TABLE tk (col1 INT, col2 CHAR(5), col3 DATE) PARTITION BY LINEAR KEY(col3) PARTITIONS 5;
ALGORITHM={1|2}
ALGORITHM=1
ALGORITHM=2
KEY
ALGORITHM=2
[LINEAR] KEY
LINEAR
KEY
CREATE TABLE t1 (a INT)
/*!50100 PARTITION BY KEY */ /*!50611 ALGORITHM = 1 */ /*!50100 ()
PARTITIONS 3 */
KEY
KEY
ALGORITHM=1
SHOW CREATE TABLE
ALGORITHM=2
VALUES LESS THAN
PARTITION
BY KEY
RANGE(
expr
)
expr
VALUES LESS THAN
RANGE
PARTITION BY RANGE COLUMNS
CREATE TABLE
创建表T1(year_col int,int some_data)按范围分区(分区year_col)(P0值小于(1991年),分区P1值小于(1995年),分区P2的值小于(1999年),分区P3值小于(2002年),分区P4值小于(2006年),分区P5值小于最大值);
PARTITION ... VALUES LESS THAN ...
VALUES LESS THAN
switch ... case
MAXVALUE
RANGE
COLUMNS(
column_list
)
RANGE
WHERE a = 1 AND b < 10
WHERE a = 1 AND b = 10 AND c
< 10
PARTITION ... VALUES LESS THAN
(
value_list
)column_list
value_list
column_list
BLOB
SET
BIT
VALUES LESS THAN
VALUES LESS THAN
VALUES LESS THAN
NULL
MAXVALUE
创建表的RC(一个int不空,不空的b int)范围列分区(A,B)(分区P0值小于(10,5),分区P1值小于(20,10),分区P2的值小于(50次),分区P3值小于(65次),分区P4值小于(最大值,最大值));
VALUES LESS THAN
1
'1'
LIST(
expr
)
RANGE
VALUES IN
create table Client _公司(id、name varchar(35)城市分区表(partition(ID)在R0值(1,5,9,13,17,21),R1的值的分区(2,6,10,14,18,22),在分区的R2值(3,7,11,15,19,23),分配在R3的值(4,8,12,16,20,24));
VALUES IN
PARTITION BY
LIST
LIST
LIST
COLUMNS
LIST
COLUMNS(
column_list
)
LIST
WHERE a = 5 AND b = 5
WHERE a = 1 AND b = 10 AND c
= 5
PARTITION ... VALUES IN
(
value_list
)
LIST
COLUMNS(
column_list
)value_list
column_list
value_list
MAXVALUE
VALUES IN
PARTITION BY LIST
VALUES IN
COLUMNS
column_list
value_list
CREATE
TABLE
CREATE TABLE lc ( a INT NULL, b INT NULL ) PARTITION BY LIST COLUMNS(a,b) ( PARTITION p0 VALUES IN( (0,0), (NULL,NULL) ), PARTITION p1 VALUES IN( (0,1), (0,2), (0,3), (1,1), (1,2) ), PARTITION p2 VALUES IN( (1,0), (2,0), (2,1), (3,0), (3,1) ), PARTITION p3 VALUES IN( (1,3), (2,2), (2,3), (3,2), (3,3) ) );
PARTITIONS
num
PARTITIONS
num
num
PARTITION
num
PARTITIONS
LIST
SUBPARTITION BY
SUBPARTITION BY
KEY
LIST
SUBPARTITIONS
PARTITIONS
PARTITIONS
0.2E+01
2
partition_definition
partition_definition
PARTITION
partition_name
VALUES
VALUES LESS THAN
[STORAGE] ENGINE
[STORAGE] ENGINE
SUBPARTITION
COMMENT
COMMENT
COMMENT = 'Data for the years previous to 1999'
DATA DIRECTORY
DATA DIRECTORY
data_dir
index_dir
FILE
INDEX DIRECTORY
CREATE TABLE th (id INT, name VARCHAR(30), adate DATE) PARTITION BY LIST(YEAR(adate)) ( PARTITION p1999 VALUES IN (1995, 1999, 2003) DATA DIRECTORY = '/var/appdata/95/data
' INDEX DIRECTORY = '/var/appdata/95/idx
', PARTITION p2000 VALUES IN (1996, 2000, 2004) DATA DIRECTORY = '/var/appdata/96/data
' INDEX DIRECTORY = '/var/appdata/96/idx
', PARTITION p2001 VALUES IN (1997, 2001, 2005) DATA DIRECTORY = '/var/appdata/97/data
' INDEX DIRECTORY = '/var/appdata/97/idx
', PARTITION p2002 VALUES IN (1998, 2002, 2006) DATA DIRECTORY = '/var/appdata/98/data
' INDEX DIRECTORY = '/var/appdata/98/idx
' );
DATA DIRECTORY
CREATE TABLE
table_option
DATA DIRECTORY
NO_DIR_IN_CREATE
MAX_ROWS
max_number_of_rows
min_number_of_rows
TABLESPACE
InnoDB
subpartition_definition
subpartition_definition
name
name
SUBPARTITION
HASH
RANGE
CREATE TABLE t1 ( s1 INT, s2 INT AS (EXP(s1)) STORED ) PARTITION BY LIST (s2) ( PARTITION p1 VALUES IN (1) );
EXP()
EXP()
CREATE TABLE
ALTER
TABLE
InnoDB
MyISAM
DESCRIBE
SHOW TABLE STATUS
SHOW
CREATE TABLE
InnoDB
SHOW
CREATE TABLE
SHOW TABLE
STATUS
KEY_BLOCK_SIZE
InnoDB
InnoDB
innodb_file_per_table
innodb_file_per_table
MyISAM
tbl_name
| |
|
TEMPORARY
TEMPORARY
InnoDB
innodb_strict_mode
CREATE TEMPORARY
TABLE
ROW_FORMAT=COMPRESSED
KEY_BLOCK_SIZE
innodb_strict_mode
ibtmp1
innodb_file_per-table
CREATE TABLE
TEMPORARY
TEMPORARY
CREATE TEMPORARY TABLES
DROP TABLE
INSERT
UPDATE
SELECT
CREATE TEMPORARY TABLES
CREATE TEMPORARY TABLES
CREATE TEMPORY TABLE ... LIKE
InnoDB
TABLESPACE
创建临时表 new_tbl
SELECT * FROM orig_tbl
限制为0;
CREATE TABLE ... LIKE
创建表 new_tbl
喜欢 orig_tbl
;
SELECT
LIKE
CREATE TABLE
LOCK TABLES
CREATE TABLE ...
LIKE
CREATE TABLE
CREATE TABLE ... LIKE
CREATE TABLE ... LIKE
CREATE TABLE ... LIKE
INDEX
DIRECTORY
TEMPORARY
TEMPORARY
CREATE TEMPORARY TABLE ... LIKE
mysql
innodb_system
CREATE TABLE
... LIKE
innodb_file_per_table
CREATE TABLEnew_tbl
SELECT * FROMorig_tbl
LIMIT 0;
SELECT
CREATE TABLE
创建表 new_tbl
[为]选择* orig_tbl
;
SELECT
MySQL的> CREATE TABLE test (a INT NOT NULL AUTO_INCREMENT,
-> PRIMARY KEY (a), KEY(b))
-> ENGINE=MyISAM SELECT b,c FROM test2;
MyISAM
b
ENGINE
CREATE TABLE
SELECT
CREATE TABLE
SELECT
MySQL的> SELECT * FROM foo;
我| | n - 1 | |——MySQL > CREATE TABLE bar (m INT) SELECT n FROM foo;
查询行,1行的影响(0.02秒)记录:1份:0警告:0mysql > SELECT * FROM bar;
------ --- | M | N | ------ --- |空| 1 | ------ --- 1行集(0秒)
foo
foo
CREATE TABLE ...
SELECT
CREATE TABLE
SELECT
SELECT
CREATE TABLE
SELECT
REPLACE
REPLACE
REPLACE
SELECT
CREATE TABLE ... REPLACE SELECT
CREATE TABLE ...
SELECT
SELECT
MySQL的> CREATE TABLE bar (UNIQUE (n)) SELECT n FROM foo;
CREATE TABLE ... SELECT
SELECT
CREATE TABLE ... SELECT
AUTO_INCREMENT
VARCHAR
CHAR
NOT
NULL
COLLATION
DEFAULT
CREATE
TABLE ... SELECT
CREATE TABLE artists_and_works SELECT artist.name, COUNT(work.artist_id) AS number_of_works FROM artist LEFT JOIN work ON artist.id = work.artist_id GROUP BY artist.id;
CREATE TABLE foo (a TINYINT NOT NULL) SELECT b+1 AS a FROM bar;
CREATE TABLE
... SELECT
CREATE TABLE ...
SELECT
FOR UPDATE
SELECT
CREATE
TABLE
new_table
SELECT ... FROM
old_table
...
CREATE TABLE
ALTER TABLE
【约束[ symbol
] [重点]外商 index_name
]( key_part
引用,…) tbl_name
( key_part
[删除,…) reference_option
[更新] reference_option
] reference_option
:限制|级联|空集|没有行动|默认设置
index_name
index_name
CONSTRAINT
symbol
index_name
CONSTRAINT
symbol
index_name
FOREIGN KEY
index_name
FOREIGN KEY
REFERENCES
foreign_key_checks
index_name
InnoDB
CONSTRAINT
symbol
symbol
symbol
symbol
InnoDB
FOREIGN KEY
INSERT
UPDATE
UPDATE
DELETE
ON UPDATE
FOREIGN KEY
CASCADE
ON UPDATE CASCADE
FOREIGN KEY
ON DELETE CASCADE
ON UPDATE
CASCADE
FOREIGN
KEY
SET NULL
ON DELETE SET NULL
SET NULL
NOT
NULL
RESTRICT
NO
ACTION
ON UPDATE
NO ACTION
NO ACTION
RESTRICT
SET DEFAULT
InnoDB
ON UPDATE SET
DEFAULT
ON DELETE
RESTRICT
ON UPDATE CASCADE
ON UPDATE SET NULL
ON
UPDATE SET DEFAULT
InnoDB
parent
CREATE TABLE parent ( id INT NOT NULL, PRIMARY KEY (id) ) ENGINE=INNODB; CREATE TABLE child ( id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE ) ENGINE=INNODB;
product_order
customer
CREATE TABLE product ( category INT NOT NULL, id INT NOT NULL, price DECIMAL, PRIMARY KEY(category, id)) ENGINE=INNODB;CREATE TABLE customer ( id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;CREATE TABLE product_order ( no INT NOT NULL AUTO_INCREMENT, product_category INT NOT NULL, product_id INT NOT NULL, customer_id INT NOT NULL, PRIMARY KEY(no), INDEX (product_category, product_id), INDEX (customer_id), FOREIGN KEY (product_category, product_id) REFERENCES product(category, id) ON UPDATE CASCADE ON DELETE RESTRICT, FOREIGN KEY (customer_id) REFERENCES customer(id)) ENGINE=INNODB;
ALTER TABLE
修改表 tbl_name
[ [添加约束 symbol
] [重点]外商 index_name
]( key_part
引用,…) tbl_name
( key_part
[删除,…) reference_option
[更新] reference_option
]
ALTER TABLE
ALTER TABLE
修改表 tbl_name
删除外键 fk_symbol
;
FOREIGN KEY
fk_symbol
SHOW CREATE TABLE
MySQL的> SHOW CREATE TABLE ibtest11c\G
*************************** 1. row *************************** Table: ibtest11cCreate Table: CREATE TABLE `ibtest11c` ( `A` int(11) NOT NULL auto_increment, `D` int(11) NOT NULL default '0', `B` varchar(200) NOT NULL default '', `C` varchar(175) default NULL, PRIMARY KEY (`A`,`D`,`B`), KEY `B` (`B`,`C`), KEY `C` (`C`), CONSTRAINT `0_38775` FOREIGN KEY (`A`, `D`)REFERENCES `ibtest11a` (`A`, `D`)ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `0_38776` FOREIGN KEY (`B`, `C`)REFERENCES `ibtest11a` (`B`, `C`)ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=INNODB CHARSET=utf8mb41 row in set (0.01 sec)mysql>ALTER TABLE ibtest11c DROP FOREIGN KEY `0_38775`;
ALTER TABLE
ALTER TABLE ...
ALGORITHM=INPLACE
ALTER TABLE ...
ALGORITHM=COPY
ALTER TABLE ...
DROP FOREIGN KEY
ALTER TABLE ...
ADD FOREIGN KEY
FOREIGN KEY ...
REFERENCES ...
"
ANSI_QUOTES
lower_case_table_names
SHOW CREATE
TABLE
显示创建表 tbl_name
;
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
InnoDB
INNODB_FOREIGN
INNODB_FOREIGN_COLS
foreign_key_checks
MySQL的> SET foreign_key_checks = 0;
MySQL的> SOURCE
dump_file_name
;MySQL的> SET foreign_key_checks = 1;
foreign_key_checks
LOAD DATA
ALTER TABLE
foreign_key_checks =
0
ALTER TABLE
DROP TABLE
SET foreign_key_checks =
0
ALTER TABLE
InnoDB
SHOW ENGINE
INNODB STATUS
LOCK
TABLES
LOCK TABLES
READ
LOCK TABLES
WRITE
InnoDB
MATCH
ON UPDATE
MATCH
MATCH SIMPLE
UNIQUE
NULL
UPDATE
UNIQUE
NOT NULL
REFERENCES
FOREIGN KEY
MyISAM
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
INNODB_SYS_FOREIGN
INNODB_SYS_FOREIGN_COLS
InnoDB
SHOW
ENGINE INNODB STATUS
ER_NO_REFERENCED_ROW_2
ER_ROW_IS_REFERENCED_2
ER_NO_REFERENCED_ROW
ER_ROW_IS_REFERENCED
DEFINER
CREATE TABLE
ALTER TABLE
PRIMARY KEY
USING
VARCHAR
TEXT
VARBINARY
BLOB
CHARACTER SET binary
CHAR
BINARY
VARCHAR
VARBINARY
TEXT
BLOB
ENUM
SET
创建表(C1 varchar(10)字符集的文本字符集的二进制二进制,C2、C3型(A,B,C)字符集的二进制);
CREATE TABLE t ( c1 VARBINARY(10), c2 BLOB, c3 ENUM('a','b','c') CHARACTER SET binary );
DESCRIBE
SHOW CREATE TABLE
CREATE TABLE
sidea
sidec
创建表的三角形(思达双,sideB双,sideC双(sqrt(思达*思达sideB * sideB)));插入三角形(思达,sideB)值(1,1),(3,4),(8);
mysql> SELECT * FROM triangle;
+-------+-------+--------------------+
| sidea | sideb | sidec |
+-------+-------+--------------------+
| 1 | 1 | 1.4142135623730951 |
| 3 | 4 | 5 |
| 6 | 8 | 10 |
+-------+-------+--------------------+
triangle
col_name
data_type
[GENERATED ALWAYS] AS (expression
) [VIRTUAL | STORED] [NOT NULL | NULL] [UNIQUE [KEY]] [[PRIMARY] KEY] [COMMENT 'string
']
AS (
expression
)GENERATED ALWAYS
VIRTUAL
VIRTUAL
InnoDB
STORED
VIRTUAL
VIRTUAL
NULL
CONNECTION_ID()
CURRENT_USER()
NOW()
AUTO_INCREMENT
AUTO_INCREMENT
CREATE TABLE
CREATE
TABLE ... LIKE
CREATE
TABLE ... SELECT
SELECT
ON UPDATE CASCADE
ON UPDATE SET NULL
ON UPDATE
SET DEFAULT
InnoDB
NEW.
col_name
col_name
INSERT
REPLACE
UPDATE
DEFAULT
JSON
t1
last_name
选择concat(first_name,' ',last_name)作为full_name从T1;
v1
full_name
创建视图v1 asselect *,concat(first_name,' ',last_name)作为full_name从T1;选择full_name从V1;
full_name
创建表T1(first_name varchar(10),last_name varchar(10),full_name varchar(255)为(concat(first_name,' ',last_name)));选择full_name从T1;
InnoDB
UNIQUE
INSERT
UPDATE
COMPACT
DYNAMIC
JSON
MySQL的> CREATE TABLE jemp (
-> c JSON,
-> g INT GENERATED ALWAYS AS (c->"$.id")),
-> INDEX i (g)
-> );
查询行,0行受影响(0.28秒)MySQL > INSERT INTO jemp (c) VALUES
> ('{"id": "1", "name": "Fred"}'), ('{"id": "2", "name": "Wilma"}'),
> ('{"id": "3", "name": "Barney"}'), ('{"id": "4", "name": "Betty"}');
查询好,四行受影响(0.04秒)记录:四重复:0警告:0mysql > SELECT c->>"$.name" AS name
> FROM jemp WHERE g > 2;
-------- |名字| -------- | Barney | |贝蒂| -------- 2行集(0秒)MySQL > EXPLAIN SELECT c->>"$.name" AS name
> FROM jemp WHERE g > 2\G
*************************** 1。行***************************编号:1 select_type:简单表:jemp分区:null类型:rangepossible_keys:我:我key_len:5编号:零排:2过滤:额外100:用其中1行集,1报警(0秒)MySQL > SHOW WARNINGS\G
*************************** 1。行***************************水平:注意代码:1003message:/ * * /选择选择# json_unquote(json_extract(`测试`。` jemp `。` C `,“美元。名字))作为`名字`从`测试`。` jemp `哪里(`测试`。` jemp ` ` G。` >二)一行在集(0.001秒)
EXPLAIN
SELECT
->>
JSON_UNQUOTE()
SHOW
WARNINGS
mysql>EXPLAIN SELECT c->>"$.name"
>FROM jemp WHERE g > 2 ORDER BY c->"$.name"\G
*************************** 1. row *************************** id: 1 select_type: SIMPLE table: jemp partitions: NULL type: range possible_keys: i key: i key_len: 5 ref: NULL rows: 2 filtered: 100.00 Extra: Using where; Using filesort 1 row in set, 1 warning (0.00 sec) mysql>SHOW WARNINGS\G
*************************** 1. row *************************** Level: Note Code: 1003 Message: /* select#1 */ select json_unquote(json_extract(`test`.`jemp`.`c`,'$.name')) AS `c->>"$.name"` from `test`.`jemp` where (`test`.`jemp`.`g` > 2) order by json_extract(`test`.`jemp`.`c`,'$.name') 1 row in set (0.00 sec)
->
->>
JSON_EXTRACT()
JSON_UNQUOTE()
GEOMETRY
CREATE TABLESPACEtablespace_name
ADD DATAFILE 'file_name
' [FILE_BLOCK_SIZE = value] [ENGINE [=]engine_name
]
InnoDB
CREATE TABLESPACE
InnoDB
CREATE
TABLE
tbl_name
... TABLESPACE [=]
tablespace_name
ALTER TABLE
tbl_name
TABLESPACE [=]
tablespace_name
CREATE TABLESPACE
CREATE
TABLESPACE
NDB
ADD DATAFILE
.ibd
DATADIR
InnoDB
innodb_directories
innodb_directories
file_name
FILE_BLOCK_SIZE
innodb_page_size
InnoDB
ROW_FORMAT=COMPRESSED
FILE_BLOCK_SIZE
FILE_BLOCK_SIZE
innodb_page_size
REDUNDANT
COMPRESSED
FILE_BLOCK_SIZE
innodb_page_size
FILE_BLOCK_SIZE/1024
innodb_page_size=16K
FILE_BLOCK_SIZE=8K
KEY_BLOCK_SIZE
ENGINE
engine_name
ENGINE =
InnoDB
InnoDB
default_storage_engine=InnoDB
tablespace_name
innodb_
TABLESPACE
CREATE TABLE
ALTER TABLE
CREATE TABLE ...
TABLESPACE
innodb_file_per_table
innodb_strict_mode
innodb_strict_mode
innodb_strict_mode
CREATE TABLE ...
TABLESPACE
ALTER TABLE ...
TABLESPACE
innodb_strict_mode
innodb_strict_mode
DROP TABLESPACE
DROP TABLE
BLOB
InnoDB
ALTER TABLE ...
DISCARD TABLESPACE
ALTER TABLE
...IMPORT TABLESPACE
mysql> CREATE TABLESPACE `ts1` ADD DATAFILE 'ts1.ibd' Engine=InnoDB; Query OK, 0 rows affected (0.01 sec) mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=REDUNDANT; Query OK, 0 rows affected (0.00 sec) mysql> CREATE TABLE t2 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=COMPACT; Query OK, 0 rows affected (0.00 sec) mysql> CREATE TABLE t3 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=DYNAMIC; Query OK, 0 rows affected (0.00 sec)
innodb_page_size
KEY_BLOCK_SIZE
mysql> CREATE TABLESPACE `ts2` ADD DATAFILE 'ts2.ibd' FILE_BLOCK_SIZE = 8192 Engine=InnoDB;Query OK, 0 rows affected (0.01 sec)mysql> CREATE TABLE t4 (c1 INT PRIMARY KEY) TABLESPACE ts2 ROW_FORMAT=COMPRESSEDKEY_BLOCK_SIZE=8;Query OK, 0 rows affected (0.00 sec)
CREATE [DEFINER = {user
| CURRENT_USER }] TRIGGERtrigger_name
trigger_time
trigger_event
ONtbl_name
FOR EACH ROW [trigger_order
]trigger_body
trigger_time
: { BEFORE | AFTER }trigger_event
: { INSERT | UPDATE | DELETE }trigger_order
: { FOLLOWS | PRECEDES }other_trigger_name
tbl_name
CREATE
TRIGGER
CREATE TRIGGER
TRIGGER
SET_USER_ID
SUPER
CREATE
TRIGGER
SUPER
DEFINER
trigger_time
AFTER
BEFORE
trigger_event
trigger_event
trigger_event
INSERT
INSERT
LOAD DATA
INSERT
INTO ... ON DUPLICATE KEY UPDATE ...
AFTER INSERT
AFTER
UPDATE
BEFORE UPDATE
trigger_order
PRECEDES
PRECEDES
trigger_body
BEGIN ... END
OLD
OLD.
col_name
col_name
NEW.
col_name
col_name
sql_mode
DEFINER
user
user_name
host_name
CURRENT_USER
CURRENT_USER()
CREATE TRIGGER
DEFINER = CURRENT_USER
DEFINER
SET_USER_ID
SUPER
user
CURRENT_USER
SET_USER_ID
SUPER
DEFINER
DEFINER
CREATE TRIGGER
TRIGGER
DEFINER
CURRENT_USER()
LOCK TABLES
CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] [DEFINER = {user
| CURRENT_USER }] [SQL SECURITY { DEFINER | INVOKER }] VIEWview_name
[(column_list
)] ASselect_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
CREATE VIEW
CREATE OR REPLACE
VIEW
CREATE
VIEW
CREATE OR REPLACE
VIEW
select_statement
SELECT
SELECT
select_statement
SELECT *
ALGORITHM
SQL SECURITY
CREATE VIEW
CREATE VIEW
SELECT
SELECT
SELECT
DROP
CREATE VIEW
SET_USER_ID
SUPER
db_name.view_name
创建视图的测试。V为SELECT * FROM t;
SELECT
SELECT
SELECT
column_list
column_list
SELECT
SELECT
UNION
SELECT
创建视图v_today(今天)作为选择current_date;
mysql>CREATE TABLE t (qty INT, price INT);
mysql>INSERT INTO t VALUES(3, 50);
mysql>CREATE VIEW v AS SELECT qty, price, qty*price AS value FROM t;
mysql>SELECT * FROM v;
+------+-------+-------+ | qty | price | value | +------+-------+-------+ | 3 | 50 | 150 | +------+-------+-------+
SELECT
SELECT
SELECT
CHECK TABLE
TEMPORARY
SELECT
ORDER BY
LIMIT
ALL
SQL_SMALL_RESULT
SELECT
FOR UPDATE
LOCK IN SHARE
MODE
mysql>CREATE VIEW v (mycol) AS SELECT 'abc';
Query OK, 0 rows affected (0.01 sec) mysql>SET sql_mode = '';
Query OK, 0 rows affected (0.00 sec) mysql>SELECT "mycol" FROM v;
+-------+ | mycol | +-------+ | mycol | +-------+ 1 row in set (0.01 sec) mysql>SET sql_mode = 'ANSI_QUOTES';
Query OK, 0 rows affected (0.00 sec) mysql>SELECT "mycol" FROM v;
+-------+ | mycol | +-------+ | abc | +-------+ 1 row in set (0.00 sec)
DEFINER
SQL SECURITY
INVOKER
user
'
user_name
'@'host_name
'CURRENT_USER
CURRENT_USER()
CREATE VIEW
DEFINER = CURRENT_USER
DEFINER
SET_USER_ID
SUPER
user
CURRENT_USER
SET_USER_ID
SUPER
DEFINER
DEFINER
CURRENT_USER
SQL SECURITY INVOKER
CURRENT_USER
SQL
SECURITY DEFINER
CURRENT_USER
DEFINER
CURRENT_USER
SELECT
DEFINER
DEFINER
SQL SECURITY
INVOKER
DEFINER
SQL
SECURITY
f()
CREATE VIEW v AS SELECT * FROM t WHERE t.id = f(t.name);
f()
如果名称为空则称p1();别人叫p2();如果;
f()
p1()
f()
v
DEFINER
SQL SECURITY
DEFINER
SELECT
DEFINER
ALGORITHM
MERGE
UNDEFINED
UPDATE
DELETE
INSERT
DEFAULT
WITH CHECK OPTION
select_statement
WITH CHECK OPTION
CASCADED
CHECK OPTION
CASCADED
WITH
CHECK OPTION
DROP {DATABASE | SCHEMA} [IF EXISTS] db_name
DROP DATABASE
DROP DATABASE
DROP
DROP
SCHEMA
DROP
DATABASE
IF EXISTS
DATABASE()
DROP DATABASE
DROP DATABASE
DROP DATABASE
.BAK
.DAT
.HSH
.MRG
.MYD
.MYI
.cfg
.db
.ibd
.ndb
DROP DATABASE
TEMPORARY
DROP EVENT [IF EXISTS] event_name
event_name
event_name
EVENT
DROP FUNCTION
DROP INDEXindex_name
ONtbl_name
[algorithm_option
|lock_option
] ...algorithm_option
: ALGORITHM [=] {DEFAULT|INPLACE|COPY}lock_option
: LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE}
DROP INDEX
index_name
tbl_name
ALTER TABLE
PRIMARY
DROP INDEX `PRIMARY` ON t;
ALGORITHM
ALTER TABLE
DROP {PROCEDURE | FUNCTION} [IF EXISTS] sp_name
ALTER ROUTINE
EXECUTE
IF EXISTS
SHOW WARNINGS
DROP FUNCTION
DROP SERVER [ IF EXISTS ] server_name
server_name
SUPER
FEDERATED
DROP SERVER
DROP SERVER
DROP SPATIAL REFERENCE SYSTEM [IF EXISTS]srid
srid
:32-bit unsigned integer
SUPER
DROP SPATIAL REFERENCE SYSTEM 4120;
IF EXISTS
mysql> DROP SPATIAL REFERENCE SYSTEM 4326;
ERROR 3716 (SR005): Can't modify SRID 4326. There is at
least one column depending on it.
SELECT * FROM INFORMATION_SCHEMA.ST_GEOMETRY_COLUMNS WHERE SRS_ID=4326;
DROP SPATIAL REFERENCE SYSTEM
DROP [TEMPORARY] TABLE [IF EXISTS]tbl_name
[,tbl_name
] ... [RESTRICT | CASCADE]
DROP TABLE
DROP
DROP TABLE
IF EXISTS
SHOW
WARNINGS
IF EXISTS
TEMPORARY
TEMPORARY
TEMPORARY
TEMPORARY
RESTRICT
DROP TABLE
innodb_force_recovery
DROP TABLESPACEtablespace_name
[ENGINE [=]engine_name
]
InnoDB
CREATE
TABLESPACE
DROP TABLESPACE
tablespace_name
ENGINE
engine_name
ENGINE
InnoDB
tablespace_name
DROP DATABASE
tablespace_name
InnoDB
InnoDB
mysql> CREATE TABLESPACE `ts1` ADD DATAFILE 'ts1.ibd' Engine=InnoDB; Query OK, 0 rows affected (0.01 sec) mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts10 Engine=InnoDB; Query OK, 0 rows affected (0.02 sec) mysql> DROP TABLE t1; Query OK, 0 rows affected (0.01 sec) mysql> DROP TABLESPACE ts1; Query OK, 0 rows affected (0.01 sec)
DROP TRIGGER [IF EXISTS] [schema_name
.]trigger_name
DROP TRIGGER
TRIGGER
IF EXISTS
IF EXISTS
DROP VIEW [IF EXISTS]view_name
[,view_name
] ... [RESTRICT | CASCADE]
DROP VIEW
DROP
DROP VIEW
DROP VIEW
DROP
VIEW
IF EXISTS
RESTRICT
RENAME TABLEtbl_name
TOnew_tbl_name
[,tbl_name2
TOnew_tbl_name2
] ...
RENAME TABLE
ALTER
DROP
CREATE
INSERT
old_table
RENAME TABLE old_table TO new_table;
ALTER TABLE
修改表old_table重命名new_table;
RENAME TABLE
ALTER
TABLE
重命名表old_table1到new_table1,old_table2到new_table2,old_table3到new_table3;
tmp_table
重命名表old_table到tmp_table,new_table到old_table,tmp_table到new_table;
LOCK TABLES
WRITE
锁表old_table1写;重命名表old_table1到new_table1,new_table1到new_table2;
LOCK TABLE old_table1 READ; RENAME TABLE old_table1 TO new_table1, new_table1 TO new_table2;
RENAME TABLE
RENAME TABLE
RENAME TABLE
重命名表 current_db.tbl_name
以 other_db.tbl_name;
RENAME TABLE
ER_TRG_IN_WRONG_SCHEMA
TEMPORARY
ALTER
TABLE
RENAME TABLE
RENAME TABLE
tbl_name
tbl_name
TRUNCATE [TABLE] tbl_name
TRUNCATE TABLE
DROP
TRUNCATE
TABLE
DELETE
DROP TABLE
CREATE TABLE
TRUNCATE
TABLE
InnoDB
TRUNCATE TABLE
DELETE
DELETE
TRUNCATE TABLE
NDB
TRUNCATE TABLE
AUTO_INCREMENT
InnoDB
TRUNCATE TABLE
TRUNCATE TABLE
InnoDB
TRUNCATE TABLE
HANDLER OPEN
TRUNCATE TABLE
DROP TABLE
CREATE TABLE
InnoDB
READ
COMMITTED
READ
UNCOMMITTED
MIXED
InnoDB
innodb_adaptive_hash_index
TRUNCATE
TABLE
DROP TABLE
CREATE TABLE
TRUNCATE TABLE
CALLsp_name
([parameter
[,...]]) CALLsp_name
[()]
CALL
CREATE PROCEDURE
CALL p()
CALL
INOUT
ROW_COUNT()
mysql_affected_rows()
OUT
IN
INOUT
INOUT
CREATE PROCEDURE p (OUT ver_param VARCHAR(25), INOUT incr_param INT)BEGIN # Set value of OUT parameter SELECT VERSION() INTO ver_param; # Increment value of INOUT parameter SET incr_param = incr_param + 1;END;
INOUT
MySQL的> SET @increment = 10;
MySQL的> CALL p(@version, @increment);
MySQL的> SELECT @version, @increment;
———————————————————————————————————————
CALL
PREPARE
EXECUTE
OUT
mysql>SET @increment = 10;
mysql>PREPARE s FROM 'CALL p(?, ?)';
mysql>EXECUTE s USING @version, @increment;
mysql>SELECT @version, @increment;
+--------------------+------------+ | @version | @increment | +--------------------+------------+ | 8.0.3-rc-debug-log | 11 | +--------------------+------------+
CALL
CALL
CALL
CLIENT_MULTI_RESULTS
mysql_real_connect()
CLIENT_MULTI_STATEMENTS
CLIENT_MULTI_RESULTS
CALL
mysql_query()
mysql_real_query()
mysql_next_result()
CALL
INOUT
CALL
mysql_stmt_next_result()
CALL
INOUT
DELETE
DELETE
WITH
DELETE
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROMtbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [WHEREwhere_condition
] [ORDER BY ...] [LIMITrow_count
]
DELETE
tbl_name
ROW_COUNT()
WHERE
where_condition
ORDER BY
DELETE [LOW_PRIORITY] [QUICK] [IGNORE]tbl_name
[.*] [,tbl_name
[.*]] ... FROMtable_references
[WHEREwhere_condition
] DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROMtbl_name
[.*] [,tbl_name
[.*]] ... USINGtable_references
[WHEREwhere_condition
]
DELETE
SELECT
TRUNCATE TABLE
DELETE
DELETE
TRUNCATE TABLE
DELETE
row_count
DELETE
LIMIT
DELETE
t
DELETE
FROM t PARTITION (p0)
ALTER
TABLE t TRUNCATE PARTITION (p0)
PARTITION
DELETE FROM t PARTITION (p0) WHERE c < 5
c < 5
PARTITION
FROM
AUTO_INCREMENT
InnoDB
tbl_name
autocommit
MyISAM
MyISAM
MyISAM
DELETE
LOW_PRIORITY
DELETE
MEMORY
MyISAM
IGNORE
DELETE
LIMIT
timestamp_column
DELETE FROM somelog WHERE user = 'jcole'ORDER BY timestamp_column LIMIT 1;
ORDER BY
InnoDB
DELETE
INSERT INTO t_copy SELECT * FROM t WHERE ... ;
RENAME TABLE
重命名表T t_old,t_copy T;
DROP TABLE t_old;
RENAME TABLE
MyISAM
INSERT
OPTIMIZE TABLE
OPTIMIZE TABLE
QUICK
DELETE QUICK
AUTO_INCREMENT
DELETE QUICK
QUICK
DELETE
OPTIMIZE TABLE
DELETE QUICK
OPTIMIZE TABLE
DELETE
ORDER
BY
DELETE
table_references
FROM
USING
DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3WHERE t1.id=t2.id AND t2.id=t3.id;
DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;
t1
INNER JOIN
DELETE
SELECT
t1
LEFT JOIN
DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;
.*
tbl_name
DELETE
ON DELETE
DELETE t1 FROM test AS t1, test2 WHERE ...
DELETE
table_references
DELETE a1, a2 FROM t1 AS a1 INNER JOIN t2 AS a2 WHERE a1.id=a2.id; DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a1.id=a2.id;
DELETE t1 AS a1, t2 AS a2 FROM t1 INNER JOIN t2 WHERE a1.id=a2.id; DELETE FROM t1 AS a1, t2 AS a2 USING t1 INNER JOIN t2 WHERE a1.id=a2.id;
DOexpr
[,expr
] ...
DO
DO
expr
DO
RELEASE_LOCK()
SELECT
MySQL的> SELECT SLEEP(5);
---------- |睡眠(5)| ---------- | 0 | ---------- 1行集(5.02秒)
DO
MySQL的> DO SLEEP(5);
查询行,0行受影响(4.99秒)
DO
DO id FROM t1
HANDLERtbl_name
OPEN [ [AS]alias
] HANDLERtbl_name
READindex_name
{ = | <= | >= | < | > } (value1
,value2
,...) [ WHEREwhere_condition
] [LIMIT ... ] HANDLERtbl_name
READindex_name
{ FIRST | NEXT | PREV | LAST } [ WHEREwhere_condition
] [LIMIT ... ] HANDLERtbl_name
READ { FIRST | NEXT } [ WHEREwhere_condition
] [LIMIT ... ] HANDLERtbl_name
CLOSE
HANDLER
MyISAM
HANDLER ... OPEN
HANDLER ... CLOSE
HANDLER
mytable
HANDLER ... READ
my_idx
col_b
HANDLER
HANDLER ... READ my_idx = (col_a_val,col_b_val,col_c_val) ...HANDLER ... READ my_idx = (col_a_val,col_b_val) ...HANDLER ... READ my_idx = (col_a_val) ...
HANDLER
`PRIMARY`
处理程序 tbl_name
读小学` `…
HANDLER ... READ
HANDLER ... READ
HANDLER
tbl_name
READ
index_name
InnoDB
LIMIT
LIMIT
SELECT
HANDLER ... CLOSE
HANDLER
SELECT
HANDLER
SELECT
HANDLER
HANDLER
SELECT
HANDLER
HANDLER ...
OPEN
HANDLER ... PREV
FLUSH
TABLES
HANDLER
TRUNCATE TABLE
HANDLER OPEN
FLUSH
TABLES
tbl_name
WITH READ
LOCK
IMPORT TABLE FROMsdi_file
[,sdi_file
] ...
IMPORT TABLE
.sdi
IMPORT TABLE
FILE
CREATE
IMPORT TABLE
.sdi
secure_file_priv
secure_file_priv
MyISAM
managers
hr
export_basedir
export_basedir
import_basedir
import_basedir
/tmp/export
/tmp/mysql-files
secure_file_priv
mysql> FLUSH TABLES hr.employees, hr.managers WITH READ LOCK;
.sdi
.sdi
.sdi
managers
managers_238.sdi
MyISAM
.MYI
shell>cd
shell>export_basedir
/data/hrcp employees_125.sdi /tmp/export
shell>cp managers_238.sdi /tmp/export
shell>cp employees.{MYD,MYI} /tmp/export
shell>cp managers.{MYD,MYI} /tmp/export
mysql> UNLOCK TABLES;
mysql> CREATE SCHEMA hr;
.sdi
secure_file_priv
hr
内核> cd /tmp/export
内核> cp employees_125.sdi /tmp/mysql-files
内核> cp managers_238.sdi /tmp/mysql-files
内核> cp employees.{MYD,MYI}
import_basedir
/data/hr内核> cp managers.{MYD,MYI}
import_basedir
/data/hr
IMPORT
TABLE
mysql>IMPORT TABLE FROM
'/tmp/mysql-files/employees.sdi',
'/tmp/mysql-files/managers.sdi';
.sdi
secure_file_priv
.sdi
sdi_file
.sdi
?
*
IMPORT
TABLE
.sdi
进口表/甲氧苄啶/ MySQL文件/ * SDI”;
.sdi
IMPORT TABLE
LOAD DATA
IMPORT TABLE
REPAIR TABLE
IMPORT TABLE
IMPORT TABLE
MyISAM
CREATE TEMPORARY
TABLE
DATA DIRECTORY
IMPORT TABLE
.sdi
.sdi
.sdi
.sdi
.sdi
IMPORT
TABLE
lower_case_table_names
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [(col_name
[,col_name
] ...)] {VALUES | VALUE} (value_list
) [, (value_list
)] ... [ON DUPLICATE KEY UPDATEassignment_list
] INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] SETassignment_list
[ON DUPLICATE KEY UPDATEassignment_list
] INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [(col_name
[,col_name
] ...)] SELECT ... [ON DUPLICATE KEY UPDATEassignment_list
]value
: {expr
| DEFAULT}value_list
:value
[,value
] ...assignment
:col_name
=value
assignment_list
:assignment
[,assignment
] ...
INSERT
INSERT
... VALUES
INSERT ... SET
INSERT
... SELECT
INSERT
UNIQUE
INSERT ...
SELECT
INSERT ... ON
DUPLICATE KEY UPDATE
DELAYED
INSERT
UPDATE
UPDATE
SELECT
col_name
=expr
PARTITION
INSERT
INSERT
REPLACE
INSERT
REPLACE
INSERT IGNORE
tbl_name
VALUES
SELECT
INSERT ...
VALUES
INSERT ...
SELECT
SELECT
tbl_name
SET
INSERT
VALUES
INSERT
插入 tbl_name
(一)values();
DEFAULT
INSERT
VALUES
DEFAULT
DEFAULT(
col_name
)col_name
expr
INT
FLOAT
DECIMAL(10,6)
YEAR
19.9921
1999
INT
YEAR
FLOAT
DECIMAL
expr
col1
插入 tbl_name
(COL1,COL2)值(15、2×2);
col1
col1
插入 tbl_name
(COL1,COL2)值(COL2 * 2,15);
AUTO_INCREMENT
AUTO_INCREMENT
INSERT
INSERT INTO tbl_name
(a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
INSERT INTO tbl_name
(a,b,c) VALUES(1,2,3,4,5,6,7,8,9);
VALUE
INSERT
ROW_COUNT()
mysql_affected_rows()
INSERT ...
VALUES
INSERT ...
SELECT
唱片 N1
重复: N2
警告: N3
mysql_info()
Records
Duplicates
NULL
INSERT
INSERT INTO ...
SELECT
''
INSERT INTO ...
SELECT
SELECT
INSERT
NOT
NULL
'10.34 a'
CHAR
VARCHAR
TEXT
BLOB
INSERT
INSERT
LAST_INSERT_ID()
mysql_insert_id()
INSERT
INSERT
LOW_PRIORITY
INSERT
INSERT
LOW_PRIORITY
LOW_PRIORITY
MEMORY
LOW_PRIORITY
HIGH_PRIORITY
--low-priority-updates
HIGH_PRIORITY
MEMORY
IGNORE
INSERT
UNIQUE
IGNORE
IGNORE
INSERT
INSERT
IGNORE
IGNORE
mysql_info()
ON DUPLICATE KEY UPDATE
PRIMARY
KEY
UPDATE
mysql_real_connect()
INSERT DELAYED
INSERT
INSERT
MyISAM
InnoDB
INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [(col_name
[,col_name
] ...)] SELECT ... [ON DUPLICATE KEY UPDATEassignment_list
]value
: {expr
| DEFAULT}assignment
:col_name
=value
assignment_list
:assignment
[,assignment
] ...
INSERT ...
SELECT
SELECT
插入tbl_temp2(fld_id)选择从哪里tbl_temp1.fld_order_id tbl_temp1 tbl_temp1.fld_order_id > 100;
INSERT ...
SELECT
IGNORE
INSERT
SELECT
SELECT
t
TEMPORARY
AUTO_INCREMENT
INSERT
... SELECT
SELECT
INSERT
SELECT
PARTITION
SELECT
INSERT
INSERT
... SELECT
SELECT
SELECT
SELECT
ORDER BY
INSERT ...
SELECT ON DUPLICATE KEY UPDATE
INSERT IGNORE ...
SELECT
INSERT ... SELECT
MyISAM
InnoDB
ON DUPLICATE KEY UPDATE
PRIMARY
KEY
UPDATE
UNIQUE
INSERT INTO t1 (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1; UPDATE t1 SET c=c+1 WHERE a=1;
InnoDB
INSERT
b
INSERT
UPDATE
UPDATE t1 SET c=c+1 WHERE a=1 OR b=2 LIMIT 1;
a=1 OR b=2
ON DUPLICATE KEY UPDATE
ON DUPLICATE KEY UPDATE
mysql_real_connect()
AUTO_INCREMENT
INSERT
... ON DUPLICATE KEY UPDATE
LAST_INSERT_ID()
ON DUPLICATE KEY UPDATE
ON DUPLICATE KEY
UPDATE
VALUES(
col_name
)INSERT
INSERT ...
ON DUPLICATE KEY UPDATE
VALUES(
col_name
)col_name
VALUES()
INSERT
INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);
INSERT INTO t1 (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=3; INSERT INTO t1 (a,b,c) VALUES (4,5,6) ON DUPLICATE KEY UPDATE c=9;
INSERT
... SELECT
ON DUPLICATE KEY
UPDATE
DISTINCT
SELECT
UNION
UNION
INSERT INTO t1 (a, b) SELECT c, d FROM t2 UNION SELECT e, f FROM t3ON DUPLICATE KEY UPDATE b = b + c;
UNION
INSERT INTO t1 (a, b)SELECT * FROM (SELECT c, d FROM t2 UNION SELECT e, f FROM t3) AS dtON DUPLICATE KEY UPDATE b = b + c;
GROUP BY
INSERT ...
SELECT
SELECT
INSERT ...
SELECT ON DUPLICATE KEY UPDATE
INSERT ...
SELECT ON DUPLICATE KEY UPDATE
INSERT ...
ON DUPLICATE KEY UPDATE
INSERT ... ON DUPLICATE KEY UPDATE
MyISAM
InnoDB
INSERT DELAYED ...
DELAYED
INSERT
INSERT DELAYED
DELAYED
DELAYED
DELAYED
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name
' [REPLACE | IGNORE] INTO TABLEtbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [CHARACTER SETcharset_name
] [{FIELDS | COLUMNS} [TERMINATED BY 'string
'] [[OPTIONALLY] ENCLOSED BY 'char
'] [ESCAPED BY 'char
'] ] [LINES [STARTING BY 'string
'] [TERMINATED BY 'string
'] ] [IGNOREnumber
{LINES | ROWS}] [(col_name_or_user_var
[,col_name_or_user_var
] ...)] [SETcol_name
={expr
| DEFAULT}, [,col_name
={expr
| DEFAULT}] ...]
LOAD DATA
INFILE
LOAD DATA
INFILE
SELECT ... INTO
OUTFILE
SELECT ... INTO
OUTFILE
LOAD DATA
INFILE
LINES
LINES
LOAD DATA
INFILE
--local
--compress
INSERT
LOAD DATA
INFILE
LOAD DATA
INFILE
character_set_filesystem
LOAD DATA
MyISAM
InnoDB
character_set_database
SET NAMES
character_set_client
binary
LOAD DATA
INFILE
SELECT ... INTO
OUTFILE
--default-character-set
LOAD DATA
INFILE
ucs2
utf16le
LOW_PRIORITY
LOAD DATA
MEMORY
CONCURRENT
LOAD DATA
LOAD
DATA
CONCURRENT
LOCAL
local_infile
LOCAL
LOCAL
LOCAL
LOAD DATA
tmpdir
slave_load_tmpdir
C:\WINDOWS\TEMP
LOAD DATA
LOCAL
LOCAL
LOCAL
myfile.txt
LOAD DATA
db1
LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;
LOCAL
IMPORT TABLE
LOCAL
FILE
LOCAL
secure_file_priv
LOCAL
FILE
LOCAL
LOAD DATA
INFILE
LOAD DATA
LOCAL INFILE
IGNORE
REPLACE
REPLACE
IGNORE
LOCAL
LOCAL
SET foreign_key_checks = 0
LOAD DATA
LOAD DATA
INFILE
REPAIR TABLE
LOAD DATA
INFILE
ALTER
TABLE ... ENABLE KEYS
LOAD DATA
INFILE
SELECT ... INTO
OUTFILE
LINES
LINES
FIELDS
[OPTIONALLY] ENCLOSED BY
FIELDS
FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' STARTING BY ''
'\t'
LOAD DATA
INFILE
\
\n
FIELDS ESCAPED
BY
SELECT ... INTO
OUTFILE
\
LINES TERMINATED BY '\r\n'
\r
LINES STARTING BY
'
prefix_string
'
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test FIELDS TERMINATED BY ',' LINES STARTING BY 'xxx';
xxx"abc",1 something xxx"def",2 "ghi",3
("abc",1)
IGNORE
number
LINES
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;
SELECT
... INTO OUTFILE
LOAD DATA
INFILE
LOAD DATA
INFILE
SELECT ... INTO
OUTFILE
SELECT *为文件数据.txt”字段终止符','从表2;
LOAD DATA INFILE 'data.txt' INTO TABLE table2 FIELDS TERMINATED BY ',';
LOAD DATA
INFILE
LOAD DATA INFILE数据.txt”为表表字段终止符'\t';
LOAD DATA
INFILE
LOAD DATA INFILE数据.txt”为表 tbl_name
字段终止符','封闭'“'线终止“\r\n”忽略1线;
OPTIONALLY
''
FIELDS ESCAPED
BY
LINES STARTING
BY
LINES TERMINATED BY
'\r\n'
%%
创建表的笑话(一个int不空auto_increment主键,笑话文本不为空);LOAD DATA INFILE /甲氧苄啶/笑话.txt”为表笑话字段终止符”系用终止\n \n’%%(开玩笑);
FIELDS [OPTIONALLY] ENCLOSED BY
SELECT ... INTO
OUTFILE
ENCLOSED BY
“1”、“弦”、“100.20”、“2”、“字符串,逗号”,“102.20”“3”,“一个包含“报价”、“102.20”、“4”、“字符串”,引号和逗号“,”102.20“
OPTIONALLY
CHAR
BINARY
TEXT
ENUM
一、“字符串”,100.202,”字符串,用逗号“,”102.203,字符串“报价”,102.204,“字符串”,引号和逗号“,102.20
ENCLOSED BY
ESCAPED BY
LOAD DATA
INFILE
1、“字符串”,100.202,“一个包含,逗号“,102.203,”一个字符串包含一个“引用”,102.204,“字符串”,引号和逗号”,102.20
ENCLOSED BY
OPTIONALLY
ESCAPED BY
ENCLOSED BY
ENCLOSED BY
"The ""BIG"" boss" -> The "BIG" boss The "BIG" boss -> The "BIG" boss The ""BIG"" boss -> The ""BIG"" boss
FIELDS ESCAPED BY
FIELDS ESCAPED BY
NULL
\
FIELDS ESCAPED BY
FIELDS ESCAPED BY
FIELDS ESCAPED BY
FIELDS [OPTIONALLY] ENCLOSED BY
FIELDS TERMINATED
BY
0
FIELDS ESCAPED BY
NULL
LINES TERMINATED BY
FIELDS TERMINATED
BY
FIELDS TERMINATED BY
''
TINYINT
SMALLINT
MEDIUMINT
INT
BIGINT
LINES TERMINATED BY
NULL
NULL
LINES
FIELDS
NULL
\N
ESCAPED BY
FIELDS ENCLOSED BY
NULL
FIELDS ENCLOSED BY
FIELDS ESCAPED BY
NULL
FIELDS
TERMINATED BY
NULL
NULL
LOAD DATA
INFILE
LOAD
DATA INFILE
FIELDS TERMINATED BY '"' ENCLOSED BY '"'
FIELDS ESCAPED BY
LINES TERMINATED BY
LOAD DATA
INFILE
LOAD DATA
INFILE
persondata
Load into table的日期是persondata.txt infile是persondata;
LOAD DATA
INFILE
负荷数据是persondata.txt infile是into table(persondata col_name_or_user_var
【, col_name_or_user_var
]…);
col_name_or_user_var
SET
t1.column2
LOAD DATA INFILE 'file.txt' INTO TABLE t1 (column1, @var1) SET column2 = @var1/100;
SET
LOAD DATA INFILE 'file.txt' INTO TABLE t1 (column1, column2) SET column3 = CURRENT_TIMESTAMP;
LOAD DATA INFILE 'file.txt' INTO TABLE t1 (column1, @dummy, column2, @dummy, column3);
SET
SET
SET
IGNORE
LOAD
DATA
BEFORE INSERT
0
INSERT
UPDATE
sql_mode
TRADITIONAL
LOCAL
sql_mode
TIMESTAMP
\N
TIMESTAMP
LOAD DATA
INFILE
ENUM
SET
INSERT
ENUM
SET
BIT
SET
'
BIT
内核> cat /tmp/bit_test.txt
B B是10 1111111内核> mysql test
MySQL的> LOAD DATA INFILE '/tmp/bit_test.txt'
INTO TABLE bit_test (@var1)
SET b = CAST(CONV(MID(@var1, 3, LENGTH(@var1)-3), 2, 10) AS UNSIGNED);
查询行,2行受影响(0秒)记录:2:0:0删除了警告:0mysql > SELECT BIN(b+0) FROM bit_test;
---------- |仓(B0)| ---------- |十| | 1111111 | ---------- 2行集(0.001秒)
BIT
0b011010
0b
SET b = CAST(CONV(MID(@var1, 3, LENGTH(@var1)-2), 2, 10) AS UNSIGNED)
LOAD DATA
db1.t1
mkfifo /数据库/数据/ DB1 / ls.datchmod 666 /数据库/数据/ DB1 / ls.datfind / LS > /数据库/数据/ DB1 / ls.dat和MySQL E“LOAD DATA INFILE的LS。DAT”为表T1“db1
LOAD DATA
INFILE
记录:1删除:0:0 0跳过警告:
INSERT
LOAD DATA
INFILE
SHOW WARNINGS
max_error_count
mysql_info()
LOAD XML [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name
' [REPLACE | IGNORE] INTO TABLE [db_name
.]tbl_name
[CHARACTER SETcharset_name
] [ROWS IDENTIFIED BY '<tagname
>'] [IGNOREnumber
{LINES | ROWS}] [(field_name_or_user_var
[,field_name_or_user_var
] ...)] [SETcol_name
={expr
| DEFAULT}, [,col_name
={expr
| DEFAULT}] ...]
LOAD XML
file_name
tagname
<
LOAD XML
--xml
--xml
-e
内核> mysql --xml -e 'SELECT * FROM mydb.mytable' > file.xml
LOAD XML
INFILE
<row>
ROWS IDENTIFIED
BY
<row
column1
="value1
"column2
="value2
" .../>
<row
> <column1
>value1
</column1
> <column2
>value2
</column2
> </row
>
name
<field>
<row> <field name='column1
'>value1
</field> <field name='column2
'>value2
</field> </row>
LOAD XML
LOAD DATA
LOW_PRIORITY
LOCAL
REPLACE
CHARACTER SET
SET
(
field_name_or_user_var
,
...)
IGNORE
number
LINESnumber
number
LOAD
DATA
person
使用测试;创建一个表(person_id INT NOT NULL主键名varchar(40)空、varchar(40)零,模型创建时间戳);
person.xml
<list> <person person_id="1" fname="Kapek" lname="Sainnouine"/> <person person_id="2" fname="Sajon" lname="Rondela"/> <person person_id="3"><fname>Likame</fname><lname>?rrtmons</lname></person> <person person_id="4"><fname>Slar</fname><lname>Manlanth</lname></person> <person><field name="person_id">5</field><field name="fname">Stoma</field> <field name="lname">Milu</field></person> <person><field name="person_id">6</field><field name="fname">Nirtam</field> <field name="lname">Skl?d</field></person> <person person_id="7"><fname>Sungam</fname><lname>Dulb?d</lname></person> <person person_id="8" fname="Sraref" lname="Encmelt"/></list>
person.xml
mysql>LOAD XML LOCAL INFILE 'person.xml'
->INTO TABLE person
->ROWS IDENTIFIED BY '<person>';
Query OK, 8 rows affected (0.00 sec) Records: 8 Deleted: 0 Skipped: 0 Warnings: 0
person.xml
错误二(hy000):文件/人。XML没有找到(errcode:2)
ROWS IDENTIFIED BY '<person>'
<person>
person
test.person
SELECT
MySQL的> SELECT * FROM person;
----------- -------- ------------ --------------------- | person_id |名| LName |创造| ----------- -------- ------------ --------------------- | 1 | kapek | sainnouine | 2007-07-13 16:18:47 | | 2 | sajon | rondela | 2007-07-13 16:18:47 | | 3 | likame |?rrtmons | 2007-07-13 16:18:47 | | 4 | SLAR | manlanth | 2007-07-13 16:18:47 | | 5 |气孔|尼鲁| 2007-07-13 16:18:47 | | 6 | nirtam | SKL?D | 2007-07-13 16:18:47 | | 7 | sungam | dulb?D | 2007-07-13 16:18:47 | | 8 | sreraf | encmelt | 2007-07-13 16:18:47 | ----------- -------- ------------ --------------------- 8行集(0秒)
LOAD XML
shell>mysql --xml -e "SELECT * FROM test.person" > person-dump.xml
shell>cat person-dump.xml
<?xml version="1.0"?> <resultset statement="SELECT * FROM test.person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <row> <field name="person_id">1</field> <field name="fname">Kapek</field> <field name="lname">Sainnouine</field> </row> <row> <field name="person_id">2</field> <field name="fname">Sajon</field> <field name="lname">Rondela</field> </row> <row> <field name="person_id">3</field> <field name="fname">Likema</field> <field name="lname">?rrtmons</field> </row> <row> <field name="person_id">4</field> <field name="fname">Slar</field> <field name="lname">Manlanth</field> </row> <row> <field name="person_id">5</field> <field name="fname">Stoma</field> <field name="lname">Nilu</field> </row> <row> <field name="person_id">6</field> <field name="fname">Nirtam</field> <field name="lname">Skl?d</field> </row> <row> <field name="person_id">7</field> <field name="fname">Sungam</field> <field name="lname">Dulb?d</field> </row> <row> <field name="person_id">8</field> <field name="fname">Sreraf</field> <field name="lname">Encmelt</field> </row> </resultset>
--xml
-e
person
MySQL的> USE test;
MySQL的> CREATE TABLE person2 LIKE person;
查询好,为受影响的行(0.001秒)MySQL > LOAD XML LOCAL INFILE 'person-dump.xml'
-> INTO TABLE person2;
查询行,8行受影响(0.01秒)记录:8:0:0删除了警告:0mysql > SELECT * FROM person2;
----------- -------- ------------ --------------------- | person_id |名| LName |创造| ----------- -------- ------------ --------------------- | 1 | kapek | sainnouine | 2007-07-13 16:18:47 | | 2 | sajon | rondela | 2007-07-13 16:18:47 | | 3 |利奇马|?rrtmons | 2007-07-13 16:18:47 | | 4 | SLAR | manlanth | 2007-07-13 16:18:47 | | 5 |气孔|尼鲁| 2007-07-13 16:18:47 | | 6 | nirtam | SKL?D | 2007-07-13 16:18:47 | | 7 | sungam | dulb?D | 2007-07-13 16:18:47 | | 8 | sreraf | encmelt | 2007-07-13 16:18:47 | ----------- -------- ------------ --------------------- 8行集(0秒)
person2
LOAD XML
MySQL的> TRUNCATE person2;
查询行,8行受影响(0.26秒)MySQL > ALTER TABLE person2 DROP COLUMN created;
查询行,0行受影响(0.52秒)记录:0份:0警告:0mysql > SHOW CREATE TABLE person2\G
*************************** 1. row *************************** Table: person2Create Table: CREATE TABLE `person2` ( `person_id` int(11) NOT NULL, `fname` varchar(40) DEFAULT NULL, `lname` varchar(40) DEFAULT NULL, PRIMARY KEY (`person_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf81 row in set (0.00 sec)mysql>LOAD XML LOCAL INFILE 'person-dump.xml'
-> INTO TABLE person2;
查询行,8行受影响(0.01秒)记录:8:0:0删除了警告:0mysql > SELECT * FROM person2;
----------- -------- ------------ | person_id |名| LName | ----------- -------- ------------ | 1 | kapek | sainnouine | | 2 | sajon | rondela | | 3 |利奇马|?rrtmons | | 4 | SLAR | manlanth | | 5 |气孔|尼禄| | 6 | nirtam | SKL?D | | 7 | sungam | dulb?D | | 8 | sreraf | encmelt | ----------- -------- ------------ 8行集(0秒)
LOAD XML
(
field_name_or_user_var
,
...)person
MySQL的> CREATE TABLE individual (
-> individual_id INT NOT NULL PRIMARY KEY,
-> name1 VARCHAR(40) NULL,
-> name2 VARCHAR(40) NULL,
-> made TIMESTAMP
- >);查询行,0行受影响(0.42秒)
mysql> LOAD XML INFILE '../bin/person-dump.xml' INTO TABLE test.individual;
ERROR 1263 (22004): Column set to default value; NULL supplied to NOT NULL column 'individual_id' at row 1
SET
MySQL的> LOAD XML INFILE '../bin/person-dump.xml'
-> INTO TABLE test.individual (@person_id, @fname, @lname, @created)
-> SET individual_id=@person_id, name1=@fname, name2=@lname, made=@created;
查询行,8行受影响(0.05秒)记录:8:0:0删除了警告:0mysql > SELECT * FROM individual;
--------------- -------- ------------ --------------------- | individual_id | name1 name2 | |了| --------------- -------- ------------ --------------------- | 1 | kapek | sainnouine | 2007-07-13 16:18:47 | | 2 | sajon | rondela | 2007-07-13 16:18:47 | | 3 |利奇马|?rrtmons | 2007-07-13 16:18:47 | | 4 | SLAR | manlanth | 2007-07-13 16:18:47 | | 5 |气孔|尼鲁| 2007-07-13 16:18:47 | | 6 | nirtam | SKL?D | 2007-07-13 16:18:47 | | 7 | sungam | dulb?D | 2007-07-13 16:18:47 | | 8 | srraf | encmelt | 2007-07-13 16:18:47 | --------------- -------- ------------ --------------------- 8行集(0秒)
@
ROWS IDENTIFIED BY
'<
tagname
>'
<?xml version="1.0"?> <list> <person person_id="1"> <fname>Robert</fname> <lname>Jones</lname> <address address_id="1" street="Mill Creek Road" zip="45365" city="Sidney"/> <address address_id="2" street="Main Street" zip="28681" city="Taylorsville"/> </person> <person person_id="2"> <fname>Mary</fname> <lname>Smith</lname> <address address_id="3" street="River Road" zip="80239" city="Denver"/> <!-- <address address_id="4" street="North Street" zip="37920" city="Knoxville"/> --> </person> </list>
test.person
mysql<TRUNCATE person;
Query OK, 0 rows affected (0.04 sec)mysql<SHOW CREATE TABLE person\G
*************************** 1. row *************************** Table: personCreate Table: CREATE TABLE `person` ( `person_id` int(11) NOT NULL, `fname` varchar(40) DEFAULT NULL, `lname` varchar(40) DEFAULT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`person_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8mb41 row in set (0.00 sec)
address
CREATE TABLE
创建表的地址(address_id INT NOT NULL主键,person_id int空街varchar(40),无效,邮政国际空、市varchar(40)为空,创建时间戳);
person
LOAD XML
<person>
mysql>LOAD XML LOCAL INFILE 'address.xml'
->INTO TABLE person
->ROWS IDENTIFIED BY '<person>';
Query OK, 2 rows affected (0.00 sec) Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
SELECT
MySQL的> SELECT * FROM person;
----------- -------- ------- --------------------- | person_id |名| LName |创造| ----------- -------- ------- --------------------- | 1 |罗伯特|琼斯| 2007-07-24 17:37:06 | | 2 |玛丽|史米斯| 2007-07-24 17:37:06 | ----------- -------- ------- --------------------- 2行集(0秒)
<address>
<address>
LOAD XML
MySQL的> LOAD XML LOCAL INFILE 'address.xml'
-> INTO TABLE address
-> ROWS IDENTIFIED BY '<address>';
查询行,3行受影响(0秒)记录:3:0:0删除了警告:0
SELECT
MySQL的> SELECT * FROM address;
------------ ----------- ----------------- ------- -------------- --------------------- | address_id | person_id |街|拉链|市|创造| ------------ ----------- ----------------- ------- -------------- --------------------- | 1 | 1 |磨溪路| 45365 |西德尼| 2007-07-24 17:37:37 | | 2 | 1 |大街| 28681 |泰勒斯维尔| 2007-07-24 17:37:37 | | 3 | 2 |河路| 80239 |丹佛| 2007-07-24 17:37:37 | ------------ ----------- ----------------- ------- -------------- --------------------- 3行集(0秒)
<address>
address
<person>
<address>
address
LOAD DATA
LOAD
XML
LOAD XML
LOCAL
--local-infile=0
--local-infile=OFF
LOAD XML
FILE
FILE
LOAD XML
INFILE
LOAD_FILE()
LOAD XML LOCAL
INFILE
--local-infile=OFF
FILE
MyISAM
InnoDB
REPLACE [LOW_PRIORITY | DELAYED] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [(col_name
[,col_name
] ...)] {VALUES | VALUE} (value_list
) [, (value_list
)] ... REPLACE [LOW_PRIORITY | DELAYED] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] SETassignment_list
REPLACE [LOW_PRIORITY | DELAYED] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [(col_name
[,col_name
] ...)] SELECT ...value
: {expr
| DEFAULT}value_list
:value
[,value
] ...assignment
:col_name
=value
assignment_list
:assignment
[,assignment
] ...
REPLACE
INSERT
UNIQUE
REPLACE
DELAYED
DELAYED
DELAYED
REPLACE
INSERT
col_name
=col_name
DEFAULT(
col_name
)col_name
= DEFAULT(col_name
REPLACE
INSERT
DELETE
DEFAULT
REPLACE
INSERT
REPLACE
REPLACE
REPLACE
mysql_affected_rows()
REPLACE
REPLACE
xxx
REPLACE ... SELECT
SELECT
MIXED
REPLACE
CREATE TABLE
创建测试表(ID int unsigned不空auto_increment数据varchar(64),默认为空,非空current_timestamp TS时间戳默认更新current_timestamp,主键(ID));
mysql>REPLACE INTO test VALUES (1, 'Old', '2014-08-20 18:47:00');
Query OK, 1 row affected (0.04 sec) mysql>REPLACE INTO test VALUES (1, 'New', '2014-08-20 18:47:42');
Query OK, 2 rows affected (0.04 sec) mysql>SELECT * FROM test;
+----+------+---------------------+ | id | data | ts | +----+------+---------------------+ | 1 | New | 2014-08-20 18:47:42 | +----+------+---------------------+ 1 row in set (0.00 sec)
CREATE TABLE test2 (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
data VARCHAR(64) DEFAULT NULL,
ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id, ts)
);
test2
test
MySQL的> REPLACE INTO test2 VALUES (1, 'Old', '2014-08-20 18:47:00');
查询行,1行的影响(0.05秒)MySQL > REPLACE INTO test2 VALUES (1, 'New', '2014-08-20 18:47:42');
查询行,1行的影响(0.06秒)MySQL > SELECT * FROM test2;
---- ------ --------------------- | ID |数据| TS | ---- ------ --------------------- | 1 |老| 2014-08-20 18:47:00 | | 1 |新| 2014-08-20 18:47:42 | ---- ------ --------------------- 2行集(0秒)
test2
ts
REPLACE
MyISAM
WHERE
InnoDB
SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]select_expr
[,select_expr
...] [FROMtable_references
[PARTITIONpartition_list
] [WHEREwhere_condition
] [GROUP BY {col_name
|expr
|position
}, ... [WITH ROLLUP]] [HAVINGwhere_condition
] [WINDOWwindow_name
AS (window_spec
) [,window_name
AS (window_spec
)] ...] [ORDER BY {col_name
|expr
|position
} [ASC | DESC], ... [WITH ROLLUP]] [LIMIT {[offset
,]row_count
|row_count
OFFSEToffset
}] [INTO OUTFILE 'file_name
' [CHARACTER SETcharset_name
]export_options
| INTO DUMPFILE 'file_name
' | INTOvar_name
[,var_name
]] [FOR {UPDATE | SHARE} [OFtbl_name
[,tbl_name
] ...] [NOWAIT | SKIP LOCKED] | LOCK IN SHARE MODE]]
SELECT
UNION
SELECT
WITH
SELECT
SELECT
select_expr
select_expr
table_references
SELECT
table_reference
SELECT ... PARTITION
MyISAM
WHERE
where_condition
WHERE
SELECT
mysql> SELECT 1 + 1;
-> 2
DUAL
MySQL的> SELECT 1 + 1 FROM DUAL;
> 2
DUAL
SELECT
FROM DUAL
HAVING
ORDER
BY
select_expr
select_expr
*
SELECT * FROM T1 T2内加入…
tbl_name
.*
选择T1,T2,T1和T2 *从内…
*
tbl_name
选择AVG(评分),T1,T1…
SELECT
select_expr
alias_name
ORDER BY
SELECT CONCAT(last_name,', ',first_name) AS full_name FROM mytable ORDER BY full_name;
AS
select_expr
选择concat(last_name,',',first_name)从mytable为full_name full_name;
AS
select_expr
SELECT columna columnb FROM mytable;
AS
WHERE
FROM
table_references
tbl_name
[[AS]alias
] [index_hint
]
SET
max_seeks_for_key=
value
tbl_name
db_name
tbl_name
col_name
tbl_name
col_name
db_name
tbl_name
col_name
tbl_name
db_name
tbl_name
tbl_name
AS
alias_name
tbl_name alias_name
SELECT t1.name, t2.salary FROM employee AS t1, info AS t2 WHERE t1.name = t2.name;SELECT t1.name, t2.salary FROM employee t1, info t2 WHERE t1.name = t2.name;
ORDER BY
SELECT college, region, seed FROM tournament ORDER BY region, seed; SELECT college, region AS r, seed AS s FROM tournament ORDER BY r, s; SELECT college, region, seed FROM tournament ORDER BY 2, 3;
DESC
ASC
ORDER BY
(SELECT ... ORDER BY a) ORDER BY a DESC;
ASC
GROUP
BY
GROUP BY
选择一个,B、计数(C)是由test_table T组,由B级,T desc;
GROUP BY
DESC
ORDER BY
SELECT
max_sort_length
GROUP BY
GROUP BY
GROUP BY
ORDER
BY
HAVING
HAVING
HAVING
HAVING
SELECT
HAVING
SELECT COUNT(col1) AS col2 FROM t GROUP BY col2 HAVING col2 = 2;
HAVING
GROUP BY
HAVING
SELECTcol_name
FROMtbl_name
HAVINGcol_name
> 0;
SELECTcol_name
FROMtbl_name
WHEREcol_name
> 0;
HAVING
SELECT user, MAX(salary) FROM users GROUP BY user HAVING MAX(salary) > 10;
select_expr
HAVING
select_expr
选择12作为一组,从一个;
a
select_expr
WINDOW
ORDER BY
select_expr
GROUP BY
FROM
select_expr
HAVING
LIMIT
SELECT
LIMIT
LIMIT
SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
SELECT * FROM tbl LIMIT 95,18446744073709551615;
SELECT * FROM tbl LIMIT 5; # Retrieve first 5 rows
LIMIT
row_count
row_count
tbl
SET @a=1;PREPARE STMT FROM 'SELECT * FROM tbl LIMIT ?';EXECUTE STMT USING @a;
tbl
SET @skip=1; SET @numrows=5;PREPARE STMT FROM 'SELECT * FROM tbl LIMIT ?, ?';EXECUTE STMT USING @skip, @numrows;
LIMIT
row_count
OFFSET
offset
LIMIT
(SELECT ... LIMIT 1) LIMIT 2;
SELECT ...
INTO
SELECT
FOR UPDATE
FOR UPDATE
SELECT
CREATE
TABLE
new_table
SELECT ... FROM
old_table
...old_table
new_table
FOR SHARE
FOR SHARE
FOR
SHARE
NOWAIT
OF
tbl_name
LOCK IN SHARE MODE
NOWAIT
FOR SHARE
SKIP LOCKED
FOR SHARE
NOWAIT
SKIP LOCKED
OF
tbl_name
FOR
SHARE
SELECT * FROM T1,T2为更新共享T1、T2;
OF
tbl_name
tbl_name
SELECT
FOR UPDATE
NOWAIT
SELECT
STRAIGHT_JOIN
ALL
ALL
DISTINCTROW
DISTINCT
HIGH_PRIORITY
SELECT
MyISAM
MERGE
STRAIGHT_JOIN
STRAIGHT_JOIN
table_references
STRAIGHT_JOIN
const
system
EXPLAIN
const
system
LEFT
JOIN
SQL_BIG_RESULT
GROUP BY
SQL_BIG_RESULT
SQL_SMALL_RESULT
SQL_BUFFER_RESULT
SELECT
UNION
SQL_CALC_FOUND_ROWS
SELECT
FOUND_ROWS()
SQL_CACHE
SQL_CACHE
SELECT
MyISAM
WHERE
InnoDB
SELECT ...
INTO
SELECT
SELECT ... INTO
var_list
SELECT ... INTO OUTFILE
SELECT ... INTO DUMPFILE
SELECT
INTO
select_expr
INTO
SELECT
SELECT
INTO
No data
LIMIT
1
选择ID、数据为”X,Y从test.t1限1 @;
SELECT ... INTO
OUTFILE '
file_name
'SELECT
FILE
file_name
character_set_filesystem
SELECT ... INTO
OUTFILE
SELECT ... INTO
OUTFILE
mysql -e "SELECT ..." >
file_name
SELECT ... INTO
OUTFILE
LOAD DATA
INFILE
binary
export_options
LINES
LOAD DATA
INFILE
FIELDS
FIELDS ESCAPED BY
FIELDS ESCAPED BY
FIELDS [OPTIONALLY] ENCLOSED BY
FIELDS TERMINATED
BY
NUL
FIELDS TERMINATED BY
ESCAPED BY
NUL
FIELDS ESCAPED BY
NULL
SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM test_table;
INTO DUMPFILE
BLOB
INTO OUTFILE
root
secure_file_priv
SELECT ...
INTO
JOIN
table_references
SELECT
DELETE
UPDATE
table_references:
escaped_table_reference
【, escaped_table_reference
]… escaped_table_reference
: table_reference
| {黄 table_reference
} table_reference
: table_factor
| join_table
table_factor
: tbl_name
[分区( partition_names
[)] [ 13 ] alias
] [ index_hint_list
| ] table_subquery
[砷] alias
[( col_list
|()] table_references
) join_table
: table_reference
[内] |交叉连接 table_factor
【 join_condition
| ] table_reference
straight_join table_factor
| table_reference
straight_join table_factor
打开(放) conditional_expr
| table_reference
{左|权} [外]加入 table_reference
join_condition
| table_reference
自然[内| {左|权} [外] ]加入 table_factor
join_condition
是: conditional_expr
|使用( column_list
) index_hint_list
: index_hint
【, index_hint
]… index_hint
:为{使用{指数|关键} [加入|通过|组} ]命令([ index_list
])|忽略{ } {关键指标| [加入|通过|组} ]命令( index_list
)为{ |力{ } [加入| |关键指标的|组} ]命令( index_list
) index_list
: index_name
【, index_name
]…
PARTITION
table_factor
table_reference
table_reference
SELECT * FROM t1 LEFT JOIN (t2, t3, t4) ON (t2.a = t1.a AND t3.b = t1.b AND t4.c = t1.c)
SELECT * FROM t1 LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) ON (t2.a = t1.a AND t3.b = t1.b AND t4.c = t1.c)
JOIN
INNER JOIN
ON
optimizer_switch
tbl_name
AS
alias_name
tbl_name alias_name
SELECT t1.name, t2.salary FROM employee AS t1 INNER JOIN info AS t2 ON t1.name = t2.name;SELECT t1.name, t2.salary FROM employee t1 INNER JOIN info t2 ON t1.name = t2.name;
table_subquery
SELECT * FROM (SELECT 1, 2, 3) AS t1;
INNER JOIN
INNER JOIN
LEFT JOIN
col_name
conditional_expr
WHERE
WHERE
ON
LEFT JOIN
SELECT left_tbl.* FROM left_tbl LEFT JOIN right_tbl ON left_tbl.id = right_tbl.id WHERE right_tbl.id IS NULL;
left_tbl
right_tbl
right_tbl
USING(
column_list
)b
c2
a LEFT JOIN b USING (c1, c2, c3)
NATURAL [LEFT] JOIN
LEFT JOIN
RIGHT JOIN
LEFT
JOIN
{ OJ ... }
SELECT left_tbl.* FROM { OJ left_tbl LEFT OUTER JOIN right_tbl ON left_tbl.id = right_tbl.id } WHERE right_tbl.id IS NULL;
{ OJ ...
}
RIGHT OUTER JOIN
STRAIGHT_JOIN
SELECT * FROM table1, table2; SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id; SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id; SELECT * FROM table1 LEFT JOIN table2 USING (id); SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id LEFT JOIN table3 ON table2.id = table3.id;
USING
NATURAL
创建表T1(I型、J int);创建表T2(K,int,int);插入T1值(1, 1);插入的T2值(1, 1);选择*从T1自然连接T2;SELECT * FROM T1 T2(J)一起使用;
SELECT
j
+------+------+------+ | j | i | k | +------+------+------+ | 1 | 1 | 1 | +------+------+------+ +------+------+------+ | j | i | k | +------+------+------+ | 1 | 1 | 1 | +------+------+------+
t1.a
a
a = COALESCE(t1.a, t2.a)
COALESCE(x, y) = (CASE WHEN x IS NOT NULL THEN x ELSE y END)
NULL
NULL
t1(a, b)
t1 t2 ---- ---- 1 x 2 z 2 y 3 w
a
mysql> SELECT * FROM t1 NATURAL LEFT JOIN t2;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | x | NULL |
| 2 | y | z |
+------+------+------+
a
mysql> SELECT * FROM t1 NATURAL RIGHT JOIN t2;
+------+------+------+
| a | c | b |
+------+------+------+
| 2 | z | y |
| 3 | w | NULL |
+------+------+------+
JOIN ... ON
MySQL的> SELECT * FROM t1 LEFT JOIN t2 ON (t1.a = t2.a);
------ ------ ------ ------ | A B C A | | | | ------ ------ ------ ------ | | X 1 2 | |零零| | | Y Z 2 | | | ------ ------ ------。
MySQL的> SELECT * FROM t1 RIGHT JOIN t2 ON (t1.a = t2.a);
------ ------ ------ ------ | A B C A | | | | ------ ------ ------ ------ | | | 2 2 Y Z | | | |零零| 3 | W | ------ ------ ------。
USING
USING
a LEFT JOIN b USING (c1, c2, c3) a LEFT JOIN b ON a.c1 = b.c1 AND a.c2 = b.c2 AND a.c3 = b.c3
SELECT *
ON
SELECT *
Coalece(A.C1,B.C1),coalece(A.C2,B.C2),coalece(A.C3,B.C3)
ON
a.c1, a.c2, a.c3, b.c1, b.c2, b.c3
COALESCE(a.c1,
b.c1)
b.c1
NULL
ON
CREATE TABLE t1 (i1 INT); CREATE TABLE t2 (i2 INT); CREATE TABLE t3 (i3 INT); SELECT * FROM t1 JOIN t2 ON (i1 = i3) JOIN t3;
Unknown column 'i3' in
'on clause'
t3
SELECT * FROM t1 JOIN t2 JOIN t3 ON (i1 = i3);
JOIN
t1, t2 JOIN t3
((t1,
t2) JOIN t3)
CREATE TABLE t1 (i1 INT, j1 INT); CREATE TABLE t2 (i2 INT, j2 INT); CREATE TABLE t3 (i3 INT, j3 INT); INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1, 1); INSERT INTO t3 VALUES(1, 1); SELECT * FROM t1, t2 JOIN t3 ON (t1.i1 = t3.i3);
JOIN
t2
t1.i1
ON
t3
SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);
JOIN
SELECT * FROM t1 JOIN t2 JOIN t3 ON (t1.i1 = t3.i3);
INNER
JOIN
LEFT
JOIN
NATURAL
SELECT ... UNION [ALL | DISTINCT] SELECT ... [UNION [ALL | DISTINCT] SELECT ...]
SELECT
SELECT
SELECT
UNION
SELECT
MySQL的> SELECT REPEAT('a',1) UNION SELECT REPEAT('b',10);
--------------- |重复(A,1)| --------------- |一| | bbbbbbbbbb | ---------------
SELECT
UNION
ALL
SELECT
UNION
ALL
UNION
DISTINCT
UNION
ALL
UNION
DISTINCT
UNION
ALL
ORDER BY
SELECT
SELECT
(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)UNION(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);
ORDER BY
SELECT
UNION
LIMIT
SELECT
UNION
LIMIT
SELECT
ORDER BY
UNION
SELECT
LIMIT
(SELECT a FROM t1 WHERE a=10 AND B=1)UNION(SELECT a FROM t2 WHERE a=11 AND B=2)ORDER BY a LIMIT 10;
ORDER BY
tbl_name
col_name
SELECT
ORDER BY
ORDER
BY
Unknown column 'a' in 'order clause'
(选择B T)联盟(选择…)为B;(选择B T)联盟(选择…)的命令;
UNION
SELECT
SELECT
SELECT
(选择1 sort_col,COL1A,col1b,…从T1)联盟(选择2,col2a,col2b,…从T2)为sort_col;
SELECT
(SELECT 1 AS sort_col, col1a, col1b, ... FROM t1) UNION (SELECT 2, col2a, col2b, ... FROM t2) ORDER BY sort_col, col1a;
SELECT
UNION
ER_AGGREGATE_ORDER_FOR_UNION
选择1为foo联盟选择二阶最大(一);
SELECT
SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);
SELECT * FROM t1 ...
(SELECT column1 FROM
t2)
DELETE FROM t1 WHERE s11 > ANY (SELECT COUNT(*) /* no hint */ FROM t2 WHERE NOT EXISTS (SELECT * FROM t3 WHERE ROW(5*t2.s1,77)= (SELECT 50,11*s1 FROM t4 UNION SELECT 50,77 FROM (SELECT * FROM t5) AS t5)));
SELECT
GROUP BY
LIMIT
UNION
SELECT
INSERT
UPDATE
DELETE
SET
DO
DELETE
INSERT
REPLACE
UPDATE
LOAD DATA
INFILE
NULL
创建表T1(S1 S2 int,char(5)不为空);插入T1值(100,“ABCDE”);选择(选择S2从T1);
SELECT
CHAR
CREATE TABLE
NULL
NULL
NOT NULL
LIMIT
LOAD DATA
INFILE
(SELECT column1 FROM
t1)
CREATE TABLE t1 (s1 INT); INSERT INTO t1 VALUES (1); CREATE TABLE t2 (s1 INT); INSERT INTO t2 VALUES (2);
SELECT
选择(选择S1 T1 T2);
2
s1
SELECT UPPER((SELECT s1 FROM t1)) FROM t2;
non_subquery_operand
comparison_operator
(subquery
)
comparison_operator
= > < >= <= <> != <=>
... WHERE 'a' = (SELECT column1 FROM t1)
non_subquery_operand
LIKE (subquery
)
t1
t2
SELECT * FROM t1 WHERE column1 = (SELECT MAX(column2) FROM t2);
t1
SELECT * FROM t1 AS t WHERE 2 = (SELECT COUNT(*) FROM t1 WHERE t1.id = t.id);
operand
comparison_operator
ANY (subquery
)operand
IN (subquery
)operand
comparison_operator
SOME (subquery
)
comparison_operator
= > < >= <= <> !=
ANY
TRUE
ANY
选择在S1 T1 S1 >任何(选择S1 T2);
t1
TRUE
(21,14,7)
t2
FALSE
(20,10)
NULL
(NULL,NULL,NULL)
IN
= ANY
SELECT s1 FROM t1 WHERE s1 = ANY (SELECT s1 FROM t2); SELECT s1 FROM t1 WHERE s1 IN (SELECT s1 FROM t2);
IN
= ANY
IN
= ANY
NOT IN
<> ANY
<> ALL
SOME
SELECT s1 FROM t1 WHERE s1 <> ANY (SELECT s1 FROM t2); SELECT s1 FROM t1 WHERE s1 <> SOME (SELECT s1 FROM t2);
SOME
<> SOME
operand
comparison_operator
ALL (subquery
)
ALL
TRUE
ALL
选择在S1 T1 S1 >所有(选择S1 T2);
t1
TRUE
(-5,0,+5)
t2
t2
12
10
NULL
(0,NULL,1)
TRUE
TRUE
SELECT * FROM t1 WHERE 1 > ALL (SELECT s1 FROM t2);
NULL
SELECT * FROM t1 WHERE 1 > (SELECT s1 FROM t2);
NULL
SELECT * FROM t1 WHERE 1 > ALL (SELECT MAX(s1) FROM t2);
NULL
NOT IN
<> ALL
SELECT s1 FROM t1 WHERE s1 <> ALL (SELECT s1 FROM t2); SELECT s1 FROM t1 WHERE s1 NOT IN (SELECT s1 FROM t2);
= > < >= <= <> != <=>
SELECT * FROM t1 WHERE (col1,col2) = (SELECT col3, col4 FROM t2 WHERE id = 10); SELECT * FROM t1 WHERE ROW(col1,col2) = (SELECT col3, col4 FROM t2 WHERE id = 10);
t2
id = 10
col3
col1
t1
TRUE
t2
col4
col2
FALSE
NULL
(1,2)
SELECT * FROM t1 WHERE ROW(1) = (SELECT column1 FROM t2)
SELECT * FROM t1 WHERE (column1,column2) = (1,1); SELECT * FROM t1 WHERE column1 = 1 AND column2 = 1;
t1
SELECT column1,column2,column3 FROM t1 WHERE (column1,column2,column3) IN (SELECT column1,column2,column3 FROM t2);
EXISTS
subquery
NOT EXISTS
subquery
SELECT column1 FROM t1 WHERE EXISTS (SELECT * FROM t2);
EXISTS
SELECT 5
SELECT
t2
EXISTS
[NOT] EXISTS
SELECT DISTINCT store_type FROM stores WHERE EXISTS (SELECT * FROM cities_stores WHERE cities_stores.store_type = stores.store_type);
SELECT DISTINCT store_type FROM stores WHERE NOT EXISTS (SELECT * FROM cities_stores WHERE cities_stores.store_type = stores.store_type);
SELECT DISTINCT store_type FROM stores s1 WHERE NOT EXISTS ( SELECT * FROM cities WHERE NOT EXISTS ( SELECT * FROM cities_stores WHERE cities_stores.city = cities.city AND cities_stores.store_type = stores.store_type));
NOT
EXISTS
NOT EXISTS
Stores
x
y
SELECT * FROM t1 WHERE column1 = ANY (SELECT column1 FROM t2 WHERE t2.column2 = t1.column2);
t1
t1
t1
column1 = 5
column2 =
6
column1 = 5
column2 = 7
... WHERE column1 =
ANY (SELECT column1 FROM t2)
WHERE
(5,6)
FALSE
SELECT column1 FROM t1 AS x WHERE x.column1 = (SELECT column1 FROM t2 AS x WHERE x.column1 = (SELECT column1 FROM t3 WHERE x.column2 = t3.column1));
x.column2
SELECT column1
FROM t2 AS x ...
t1
HAVING
val
IN (SELECTkey_val
FROMtbl_name
WHEREcorrelated_condition
)
FROM
SELECT
SELECT ... FROM (subquery
) [AS]tbl_name
...
JSON_TABLE()
SELECT * FROM json_table( arg_list
[你]) tbl_name
…
[AS]
tbl_name
tbl_name
选择从( subquery
[你]) tbl_name
( col_list
)…
CREATE TABLE t1 (s1 INT, s2 CHAR(5), s3 FLOAT);
FROM
插入T1值(1,1,1);插入T1值(2,2’,2);选择SB1、SB2、SB3从(选择S1 SB1,SB2 S2,S3 * 2 SB3从T1)为某人在SB1 > 1;
2, '2', 4.0
SELECT AVG(SUM(column1)) FROM t1 GROUP BY column1;
SELECT AVG(sum_column1) FROM (SELECT SUM(column1) AS sum_column1 FROM t1 GROUP BY column1) AS t1;
sum_column1
mysql> SELECT * FROM (SELECT 1, 2, 3, 4) AS dt;
+---+---+---+---+
| 1 | 2 | 3 | 4 |
+---+---+---+---+
| 1 | 2 | 3 | 4 |
+---+---+---+---+
mysql> SELECT * FROM (SELECT 1, 2, 3, 4) AS dt (a, b, c, d);
+---+---+---+---+
| a | b | c | d |
+---+---+---+---+
| 1 | 2 | 3 | 4 |
+---+---+---+---+
SELECT
EXPLAIN
EXPLAIN
SELECT
t2
f1
CREATE DATABASE d1; USE d1; CREATE TABLE t1 (c1 INT); CREATE TABLE t2 (c1 INT); CREATE FUNCTION f1(p1 INT) RETURNS INT BEGIN INSERT INTO t2 VALUES (p1); RETURN p1; END;
EXPLAIN
SELECT
mysql>SELECT * FROM t2;
Empty set (0.02 sec) mysql>EXPLAIN SELECT f1(5)\G
*************************** 1. row *************************** id: 1 select_type: SIMPLE table: NULL partitions: NULL type: NULL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: NULL filtered: NULL Extra: No tables used 1 row in set (0.01 sec) mysql>SELECT * FROM t2;
Empty set (0.01 sec)
SELECT
Extra
SELECT
MySQL的> EXPLAIN SELECT NOW() AS a1, (SELECT f1(5)) AS a2\G
*************************** 1。行*************************** ID:1 select_type:主表:null类型:nullpossible_keys:空键:空key_len:零号:零排:空:空:没有额外的过滤表used1行集,警告(0.001秒)MySQL > SHOW WARNINGS;
------- ------ ------------------------------------------ |水平|代码|消息| ------- ------ ------------------------------------------ |注| 1249 |选择2降低优化| ------- ------ ------------------------------------------ 1排在设定(0秒)MySQL > SELECT * FROM t2;
空集(0.001秒)
SELECT
MySQL的> EXPLAIN SELECT * FROM t1 AS a1, (SELECT f1(5)) AS a2\G
*************************** 1. row *************************** id: 1 select_type: PRIMARY table: <derived2> partitions: NULL type: systempossible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 1 filtered: 100.00 Extra: NULL*************************** 2. row *************************** id: 1 select_type: PRIMARY table: a1 partitions: NULL type: ALLpossible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 1 filtered: 100.00 Extra: NULL*************************** 3. row *************************** id: 2 select_type: DERIVED table: NULL partitions: NULL type: NULLpossible_keys: NULL key: NULL key_len: NULL ref: NULL rows: NULL filtered: NULL Extra: No tables used3 rows in set (0.00 sec)mysql>SELECT * FROM t2;
------ | C1 | ------ |五| ------一行集(0.001秒)
EXPLAIN
SELECT
BENCHMARK()
EXPLAIN SELECT * FROM t1 AS a1, (SELECT BENCHMARK(1000000, MD5(NOW())));
ERROR 1235 (ER_NOT_SUPPORTED_YET) SQLSTATE = 42000 Message = "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"
SELECT * FROM t1 WHERE s1 IN (SELECT s2 FROM t2 ORDER BY s1 LIMIT 1)
ERROR 1241 (ER_OPERAND_COL) SQLSTATE = 21000 Message = "Operand should contain 1 column(s)"
SELECT (SELECT column1, column2 FROM t2) FROM t1;
ERROR 1242 (ER_SUBSELECT_NO_1_ROW) SQLSTATE = 21000 Message = "Subquery returns more than 1 row"
SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);
SELECT column1 FROM t2
SELECT * FROM t1 WHERE column1 = ANY (SELECT column1 FROM t2);
Error 1093 (ER_UPDATE_TABLE_USED) SQLSTATE = HY000 Message = "You can't specify target table 'x' for update in FROM clause"
UPDATE t1 SET column2 = (SELECT MAX(column1) FROM t1);
UPDATE
UPDATE
DELETE
SELECT
FROM
SELECT * FROM t1 WHERE t1.column1 IN (SELECT column1 FROM t2 ORDER BY column1); SELECT * FROM t1 WHERE t1.column1 IN (SELECT DISTINCT column1 FROM t2); SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t2 LIMIT 1);
SELECT DISTINCT column1 FROM t1 WHERE t1.column1 IN ( SELECT column1 FROM t2);
SELECT DISTINCT t1.column1 FROM t1, t2 WHERE t1.column1 = t2.column1;
SELECT * FROM t1 WHERE s1 IN (SELECT s1 FROM t1 UNION ALL SELECT s1 FROM t2);
SELECT * FROM t1 WHERE s1 IN (SELECT s1 FROM t1) OR s1 IN (SELECT s1 FROM t2);
SELECT (SELECT column1 + 5 FROM t1) FROM t2;
SELECT (SELECT column1 FROM t1) + 5 FROM t2;
SELECT * FROM t1 WHERE (column1,column2) IN (SELECT column1,column2 FROM t2);
SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t2 WHERE t2.column1=t1.column1 AND t2.column2=t1.column2);
NOT (a = ANY (...))
a <> ALL (...)
x = ANY (
table containing
(1,2)
)x=1 OR x=2
= ANY
IN
=
SELECT * FROM t1 WHERE t1.col_name
= (SELECT a FROM t2 WHERE b =some_const
);
SELECT * FROM t1 WHERE t1.col_name
IN (SELECT a FROM t2 WHERE b =some_const
);
BENCHMARK()
EXPLAIN
IN
ANY
EXPLAIN
unique_subquery
index_subquery
…………………(选择 indexed_column
从 single_table
…)
MIN()
MAX()
value
{ALL|ANY|SOME} {> | < | >= | <=} (uncorrelated subquery
)
WHERE
5 >所有(选择X T)
WHERE 5 > (SELECT MAX(x) FROM t)
IN()
SELECT * FROM t1 WHERE id IN (SELECT id FROM t2);
SELECT DISTINCT t1.* FROM t1, t2 WHERE t1.id=t2.id;
SELECT * FROM t1 WHERE id NOT IN (SELECT id FROM t2); SELECT * FROM t1 WHERE NOT EXISTS (SELECT id FROM t2 WHERE t1.id=t2.id);
SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id WHERE table2.id IS NULL;
LEFT [OUTER] JOIN
DELETE
UPDATE
UPDATE
UPDATE
WITH
UPDATE
UPDATE [LOW_PRIORITY] [IGNORE]table_reference
SETassignment_list
[WHEREwhere_condition
] [ORDER BY ...] [LIMITrow_count
]value
: {expr
| DEFAULT}assignment
:col_name
=value
assignment_list
:assignment
[,assignment
] ...
UPDATE [LOW_PRIORITY] [IGNORE]table_references
SETassignment_list
[WHEREwhere_condition
]
UPDATE
DEFAULT
WHERE
LIMIT
UPDATE
table_references
LIMIT
PARTITION
where_condition
where_condition
table_references
where_condition
UPDATE
UPDATE
SELECT
UPDATE
LOW_PRIORITY
UPDATE
MEMORY
IGNORE
UPDATE IGNORE
MIXED
UPDATE
UPDATE t1 SET col1 = col1 + 1;
col2
col1
col2
UPDATE t1 SET col1 = col1 + 1, col2 = col1;
UPDATE
NOT
NULL
0
DEFAULT
UPDATE
mysql_info()
UPDATE
LIMIT
row_count
UPDATE
row_count
UPDATE
t
UPDATE t SET id = id + 1;
id
id
UPDATE t SET id = id + 1 ORDER BY id DESC;
UPDATE
LIMIT
UPDATE
table_references
UPDATE items,month SET items.price=month.price WHERE items.id=month.id;
UPDATE
SELECT
UPDATE
ON UPDATE
UPDATE
MyISAM
WHERE
InnoDB
WITH
cte2
WITH
SELECT
WITH
WITH cte1 AS (SELECT a, b FROM table1), cte2 AS (SELECT c, d FROM table2)SELECT b, d FROM cte1 JOIN cte2WHERE cte1.a = cte2.c;
WITH
WITH
with_clause
:[ ]与递归 cte_name
[( col_name
【, col_name
](AS)] subquery
)[, cte_name
[( col_name
【, col_name
](AS)] subquery
)]…
cte_name
WITH
subquery
subquery
AS
RECURSIVE
WITH
WITH cte (col1, col2) AS ( SELECT 1, 2 UNION ALL SELECT 3, 4 ) SELECT col1, col2 FROM cte;
SELECT
subquery
与热膨胀系数为(选择1 col1,col2两作为联盟的所有选择的三、四选择col1,col2)从CTE;
WITH
WITH
WITH
WITH
与cte1(……)的选择与cte2(……)…………………
WITH
与cte1的cte2(……),(……)的选择…………………
WITH
与cte1为(选一)SELECT * FROM(与cte2为(选择)选择*从cte2加入cte1)为DT;
WITH
与cte1的cte1(……),(……)的选择…………………
WITH cte1 AS (...), cte2 AS (...) SELECT ...
WITH
cte1
cte2
TEMPORARY
WITH RECURSIVE cte (n) AS ( SELECT 1 UNION ALL SELECT n + 1 FROM cte WHERE n < 5 ) SELECT * FROM cte;
+------+ | n | +------+ | 1 | | 2 | | 3 | | 4 | | 5 | +------+
WITH
WITH
RECURSIVE
(错误:表“42s02 1146) cte_name
”不存在
UNION [ALL]
UNION
DISTINCT
选择返回初始行并集合allselect…返回行集
SELECT
SELECT
SELECT
SELECT
UNION
DISTINCT
SELECT 1
SELECT n + 1 FROM cte WHERE n < 5
SELECT
1
1+1=2
2
2+1=3
n
WITH RECURSIVE cte AS ( SELECT 1 AS n, 'abc' AS str UNION ALL SELECT n + 1, CONCAT(str, str) FROM cte WHERE n < 3 ) SELECT * FROM cte;
+------+------+ | n | str | +------+------+ | 1 | abc | | 2 | abc | | 3 | abc | +------+------+
str
SELECT
SELECT
ERROR 1406 (22001): Data too long for column 'str' at row 1
CAST()
SELECT
WITH RECURSIVE cte AS ( SELECT 1 AS n, CAST('abc' AS CHAR(20)) AS str UNION ALL SELECT n + 1, CONCAT(str, str) FROM cte WHERE n < 3 ) SELECT * FROM cte;
+------+--------------+ | n | str | +------+--------------+ | 1 | abc | | 2 | abcabc | | 3 | abcabcabcabc | +------+--------------+
WITH RECURSIVE cte AS ( SELECT 1 AS n, 1 AS p, -1 AS q UNION ALL SELECT n + 1, q * 2, p * 2 FROM cte WHERE n < 5 ) SELECT * FROM cte;
p
+------+------+------+ | n | p | q | +------+------+------+ | 1 | 1 | -1 | | 2 | -2 | 2 | | 3 | 4 | -4 | | 4 | -8 | 8 | | 5 | 16 | -16 | +------+------+------+
ORDER BY
DISTINCT
EXPLAIN
SELECT
Extra
EXPLAIN
SELECT
cte_max_recursion_depth
max_execution_time
SELECT
MAX_EXECUTION_TIME
SELECT
WITH RECURSIVE cte (n) AS ( SELECT 1 UNION ALL SELECT n + 1 FROM cte ) SELECT * FROM cte;
cte_max_recursion_depth
SET SESSION cte_max_recursion_depth = 10; -- permit only shallow recursionSET SESSION cte_max_recursion_depth = 1000000; -- permit deeper recursion
cte_max_recursion_depth
cte_max_recursion_depth
SET max_execution_time = 1000; -- impose one second timeout
WITH RECURSIVE cte (n) AS ( SELECT 1 UNION ALL SELECT n + 1 FROM cte ) SELECT /*+ MAX_EXECUTION_TIME(1000) */ * FROM cte;
KILL QUERY
SELECT
WITH RECURSIVE fibonacci (n, fib_n, next_fib_n) AS( SELECT 1, 0, 1 UNION ALL SELECT n + 1, next_fib_n, fib_n + next_fib_n FROM fibonacci WHERE n < 10)SELECT * FROM fibonacci;
+------+-------+------------+ | n | fib_n | next_fib_n | +------+-------+------------+ | 1 | 0 | 1 | | 2 | 1 | 1 | | 3 | 1 | 2 | | 4 | 2 | 3 | | 5 | 3 | 5 | | 6 | 5 | 8 | | 7 | 8 | 13 | | 8 | 13 | 21 | | 9 | 21 | 34 | | 10 | 34 | 55 | +------+-------+------------+
n
fib_n
next_fib_n
fib_n
n
WHERE
SELECT
MySQL的> WITH RECURSIVE fibonacci ...
… SELECT fib_n FROM fibonacci WHERE n = 8;
------- | fib_n | ------- | 13 | -------
mysql> SELECT * FROM sales ORDER BY date, price;
+------------+--------+
| date | price |
+------------+--------+
| 2017-01-03 | 100.00 |
| 2017-01-03 | 200.00 |
| 2017-01-06 | 50.00 |
| 2017-01-08 | 10.00 |
| 2017-01-08 | 20.00 |
| 2017-01-08 | 150.00 |
| 2017-01-10 | 5.00 |
+------------+--------+
mysql>SELECT date, SUM(price) AS sum_price
FROM sales
GROUP BY date
ORDER BY date;
+------------+-----------+ | date | sum_price | +------------+-----------+ | 2017-01-03 | 300.00 | | 2017-01-06 | 50.00 | | 2017-01-08 | 180.00 | | 2017-01-10 | 5.00 | +------------+-----------+
LEFT JOIN
WITH RECURSIVE dates (date) AS ( SELECT MIN(date) FROM sales UNION ALL SELECT date + INTERVAL 1 DAY FROM dates WHERE date + INTERVAL 1 DAY <= (SELECT MAX(date) FROM sales) ) SELECT * FROM dates;
+------------+ | date | +------------+ | 2017-01-03 | | 2017-01-04 | | 2017-01-05 | | 2017-01-06 | | 2017-01-07 | | 2017-01-08 | | 2017-01-09 | | 2017-01-10 | +------------+
LEFT JOIN
WITH RECURSIVE dates (date) AS ( SELECT MIN(date) FROM sales UNION ALL SELECT date + INTERVAL 1 DAY FROM dates WHERE date + INTERVAL 1 DAY <= (SELECT MAX(date) FROM sales) ) SELECT dates.date, COALESCE(SUM(price), 0) AS sum_price FROM dates LEFT JOIN sales ON dates.date = sales.date GROUP BY dates.date ORDER BY dates.date;
+------------+-----------+ | date | sum_price | +------------+-----------+ | 2017-01-03 | 300.00 | | 2017-01-04 | 0.00 | | 2017-01-05 | 0.00 | | 2017-01-06 | 50.00 | | 2017-01-07 | 0.00 | | 2017-01-08 | 180.00 | | 2017-01-09 | 0.00 | | 2017-01-10 | 5.00 | +------------+-----------+
COALESCE()
sum_price
NULL
创建员工信息表(ID为主键,名称为varchar(100)不为空,manager_id int空,指数(manager_id),外键(manager_id)参考员工(ID));插入员工价值(333,“斯米”,null),#斯米是首席执行官(manager_id是空的)(198,“约翰”,333),#约翰ID 198和报告333(Yasmina)(692,“Tarek”,333),(29,“佩德罗”,198),(4610,“莎拉”,29),(72,“彼埃尔”,29),(123,“阿迪力”,692);
mysql> SELECT * FROM employees ORDER BY id;
+------+---------+------------+
| id | name | manager_id |
+------+---------+------------+
| 29 | Pedro | 198 |
| 72 | Pierre | 29 |
| 123 | Adil | 692 |
| 198 | John | 333 |
| 333 | Yasmina | NULL |
| 692 | Tarek | 333 |
| 4610 | Sarah | 29 |
+------+---------+------------+
WITH RECURSIVE employee_paths (id, name, path) AS ( SELECT id, name, CAST(id AS CHAR(200)) FROM employees WHERE manager_id IS NULL UNION ALL SELECT e.id, e.name, CONCAT(ep.path, ',', e.id) FROM employee_paths AS ep JOIN employees AS e ON ep.id = e.manager_id ) SELECT * FROM employee_paths ORDER BY path;
+------+---------+-----------------+ | id | name | path | +------+---------+-----------------+ | 333 | Yasmina | 333 | | 198 | John | 333,198 | | 29 | Pedro | 333,198,29 | | 4610 | Sarah | 333,198,29,4610 | | 72 | Pierre | 333,198,29,72 | | 692 | Tarek | 333,692 | | 123 | Adil | 333,692,123 | +------+---------+-----------------+
WHERE
SELECT
SELECT
MySQL的> WITH RECURSIVE ...
… SELECT * FROM employees_extended
WHERE id IN (692, 4610)
ORDER BY path;
------ ------- --------------------- | ID名称| |路径| ------ ------- --------------------- | 4610 |莎拉| 333198,294610 | | 692 | Tarek | 333692 | ------ ------- ---------------------
WITH cte AS (SELECT 1) SELECT * FROM cte; SELECT * FROM (SELECT 1) AS dt;
CREATE [TEMPORARY]
TABLE
SET autocommit
START TRANSACTION
COMMIT
ROLLBACK
START TRANSACTION [transaction_characteristic
[,transaction_characteristic
] ...]transaction_characteristic
: WITH CONSISTENT SNAPSHOT | READ WRITE | READ ONLY BEGIN [WORK] COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE] ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE] SET autocommit = {0 | 1}
START TRANSACTION
COMMIT
ROLLBACK
SET autocommit
START TRANSACTION
START TRANSACTION;SELECT @A:=SUM(salary) FROM table1 WHERE type=1;UPDATE table2 SET summary=@A WHERE type=1;COMMIT;
START TRANSACTION
ROLLBACK
START TRANSACTION
WITH CONSISTENT SNAPSHOT
InnoDB
SELECT
WITH
CONSISTENT SNAPSHOT
REPEATABLE READ
WITH CONSISTENT SNAPSHOT
READ WRITE
READ ONLY
InnoDB
READ WRITE
TEMPORARY
read_only
CONNECTION_ADMIN
SUPER
START TRANSACTION
SET autocommit=0;
autocommit
InnoDB
NDB
COMMIT
autocommit
autocommit
BEGIN
START TRANSACTION
BEGIN
BEGIN
BEGIN ... END
BEGIN
[WORK]
BEGIN ...
END
START
TRANSACTION
WORK
ROLLBACK
RELEASE
RELEASE
completion_type
AND CHAIN
READ ONLY
NO
RELEASE
completion_type
LOCK TABLES
UNLOCK
TABLES
FLUSH TABLES
WITH READ LOCK
InnoDB
SERIALIZABLE
SET
TRANSACTION ISOLATION LEVEL
SERIALIZABLE
ROLLBACK
ER_WARNING_NOT_COMPLETE_ROLLBACK
COMMIT
ROLLBACK
SET TRANSACTION
SHOW
PROCESSLIST
State
ROLLBACK
BEGIN
ROLLBACK
--replicate-do-db
--replicate-ignore-db
ROLLBACK
COMMIT
ALTER EVENT
ALTER FUNCTION
ALTER PROCEDURE
ALTER SERVER
ALTER TABLE
ALTER VIEW
CREATE DATABASE
CREATE EVENT
CREATE FUNCTION
CREATE INDEX
CREATE PROCEDURE
CREATE ROLE
CREATE SERVER
CREATE SPATIAL REFERENCE
SYSTEM
CREATE TABLE
CREATE TRIGGER
CREATE VIEW
DROP DATABASE
DROP EVENT
DROP FUNCTION
DROP INDEX
DROP PROCEDURE
DROP ROLE
DROP SERVER
DROP SPATIAL REFERENCE SYSTEM
DROP TABLE
DROP TRIGGER
DROP VIEW
INSTALL PLUGIN
RENAME TABLE
TRUNCATE TABLE
UNINSTALL PLUGIN
CREATE TABLE
DROP TABLE
ALTER
TABLE
CREATE
INDEX
CREATE
TEMPORARY TABLE
CREATE TABLE
ROLLBACK
CREATE
TABLE
CREATE TABLE ...
SELECT
mysql
ALTER USER
CREATE USER
DROP USER
GRANT
RENAME USER
REVOKE
SET PASSWORD
BEGIN
LOCK TABLES
SET autocommit = 1
START
TRANSACTION
UNLOCK
TABLES
UNLOCK
TABLES
LOCK
TABLES
UNLOCK
TABLES
FLUSH TABLES
WITH READ LOCK
START
TRANSACTION
ACTIVE
BEGIN
BEGIN ...
END
LOAD DATA
INFILE
LOAD DATA
INFILE
NDB
ANALYZE TABLE
CACHE INDEX
CHECK TABLE
FLUSH
LOAD INDEX INTO
CACHE
OPTIMIZE
TABLE
REPAIR TABLE
RESET
RESET PERSIST
SAVEPOINTidentifier
ROLLBACK [WORK] TO [SAVEPOINT]identifier
RELEASE SAVEPOINTidentifier
InnoDB
SAVEPOINT
ROLLBACK TO
SAVEPOINT
RELEASE
SAVEPOINT
ROLLBACK
SAVEPOINT
identifier
ROLLBACK TO
SAVEPOINT
ROLLBACK TO
SAVEPOINT
错误1305(42000):保存点 identifier
不存在
RELEASE
SAVEPOINT
COMMIT
ROLLBACK
LOCK INSTANCE FOR BACKUP UNLOCK INSTANCE
LOCK INSTANCE FOR BACKUP
LOCK INSTANCE FOR BACKUP
BACKUP_ADMIN
BACKUP_ADMIN
RELOAD
UNLOCK INSTANCE
LOCK INSTANCE FOR BACKUP
REPAIR
TABLE
TRUNCATE TABLE
OPTIMIZE TABLE
InnoDB
LOCK INSTANCE FOR BACKUP
LOCK INSTANCE FOR
BACKUP
FLUSH
TABLES
tbl_name
[,
tbl_name
] ... WITH READ LOCK
备份实例锁;冲洗表 tbl_name
【, tbl_name
]…读锁;解锁解锁情况表;
冲洗表 tbl_name
【, tbl_name
]…读锁;锁解锁备份实例;实例;打开表;
lock_wait_timeout
LOCK TABLEStbl_name
[[AS]alias
]lock_type
[,tbl_name
[[AS]alias
]lock_type
] ...lock_type
: READ [LOCAL] | [LOW_PRIORITY] WRITE UNLOCK TABLES
LOCK TABLES
LOCK TABLES
SELECT
LOCK TABLES
LOCK TABLES
LOCK
TABLES
LOCK
TABLES READ
LOCK TABLES
WRITE
UNLOCK
TABLES
LOCK TABLES
UNLOCK
TABLES
FLUSH TABLES WITH READ LOCK
WRITE
DROP TABLE
TRUNCATE TABLE
DROP
TABLE
TRUNCATE TABLE
TEMPORARY
LOCK
TABLES
LOCK TABLES
LOCK TABLES
LOCK TABLES
READ [LOCAL]
READ
READ
LOCAL
INSERT
READ LOCAL
READ LOCAL
[LOW_PRIORITY] WRITE
WRITE
LOW_PRIORITY
LOW_PRIORITY
LOCK TABLES
LOCK TABLES
LOCK TABLES
MySQL的> LOCK TABLES t1 READ;
MySQL的> SELECT COUNT(*) FROM t1;
---------- |计数(*)| ---------- | 3 | ---------- MySQL > SELECT COUNT(*) FROM t2;
错误1100(hy000):表“T2”未锁锁表
INFORMATION_SCHEMA
LOCK TABLES
mysql>LOCK TABLE t WRITE, t AS t1 READ;
mysql>INSERT INTO t SELECT * FROM t;
ERROR 1100: Table 't' was not locked with LOCK TABLES mysql>INSERT INTO t SELECT * FROM t AS t1;
INSERT
INSERT
mysql>LOCK TABLE t READ;
mysql>SELECT * FROM t AS myalias;
ERROR 1100: Table 'myalias' was not locked with LOCK TABLES
mysql>LOCK TABLE t AS myalias READ;
mysql>SELECT * FROM t;
ERROR 1100: Table 't' was not locked with LOCK TABLES mysql>SELECT * FROM t AS myalias;
WRITE
READ
READ
LOCK TABLES
LOCK TABLES
UNLOCK
TABLES
LOCK
TABLES
START
TRANSACTION
UNLOCK
TABLES
ALTER TABLE
ALTER TABLE
tbl_name
LOCK TABLES
UNLOCK
TABLES
LOCK TABLES
UNLOCK
TABLES
LOCK TABLES
UNLOCK
TABLES
FLUSH TABLES WITH READ锁;开始交易;选择…打开表;
START
TRANSACTION
FLUSH TABLES WITH READ LOCK
LOCK TABLES
UNLOCK
TABLES
START
TRANSACTION
LOCK
TABLES
UNLOCK
TABLES
SET autocommit = 0
START
TRANSACTION
LOCK
TABLES
UNLOCK
TABLES
t2
SET autocommit=0;LOCK TABLES t1 WRITE, t2 READ, ...;... do something with tables t1 and t2 here ...
打开表提交;
LOCK TABLES
InnoDB
UNLOCK
TABLES
autocommit = 1
LOCK
TABLES
autocommit =
1
ROLLBACK
LOCK
TABLES
LOCK
TABLES
LOCK TABLES
t1
LOCK TABLES t1 WRITE, t2 READ;
t1
t1
CREATE TRIGGER t1_a_ins AFTER INSERT ON t1 FOR EACH ROWBEGIN UPDATE t4 SET count = count+1 WHERE id = NEW.id AND EXISTS (SELECT a FROM t3); INSERT INTO t2 VALUES(1, 2);END;
LOCK TABLES
t2
t4
t1
t2
t2
WRITE
t3
t4
KILL
LOCK TABLES
UNLOCK
TABLES
performance_schema
LOCK
TABLES
xxx
LOCK TABLES
CREATE TABLE
CREATE TABLE ...
LIKE
CREATE VIEW
DROP VIEW
mysql
HELP
CONVERT_TZ()
mysql.help_categorymysql.help_keywordmysql.help_relationmysql.help_topicmysql.procmysql.time_zonemysql.time_zone_leap_secondmysql.time_zone_namemysql.time_zone_transitionmysql.time_zone_transition_type
WRITE
LOCK
TABLES
UPDATE
MyISAM
UNLOCK
TABLES
READ
LOCK
TABLES
SELECT
UPDATE
LOCK TABLES
LOCK TABLES trans READ, customer WRITE;SELECT SUM(value) FROM trans WHERE customer_id=some_id
;UPDATE customer SET total_value=sum_from_previous_statement
WHERE customer_id=some_id
打开表;
LOCK TABLES
SELECT
UPDATE
LOCK TABLES
value
=value
new_value
LAST_INSERT_ID()
GET_LOCK()
RELEASE_LOCK()
pthread_mutex_unlock()
SET [GLOBAL | SESSION] TRANSACTIONtransaction_characteristic
[,transaction_characteristic
] ...transaction_characteristic
: ISOLATION LEVELlevel
| READ WRITE | READ ONLYlevel
: REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED | SERIALIZABLE
InnoDB
SET TRANSACTION
SESSION
GLOBAL
SESSION
SESSION
SESSION
CONNECTION_ADMIN
SUPER
SET TRANSACTION
SESSION
MySQL的> START TRANSACTION;
查询行,0行受影响(0.02秒)MySQL > SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
错误:1568(25001)交易特性不能changedwhile交易正在进行中
--transaction-isolation=
level
level
READ-UNCOMMITTED
READ-COMMITTED
REPEATABLE-READ
SERIALIZABLE
REPEATABLE READ
[mysqld] transaction-isolation = REPEATABLE-READ
transaction_isolation
SELECT @@GLOBAL.transaction_isolation, @@transaction_isolation;SET GLOBAL transaction_isolation='REPEATABLE-READ';SET SESSION transaction_isolation='SERIALIZABLE';
--transaction-read-only
transaction_read_only
ON
transaction_isolation
transaction_read_only
SET GLOBAL
TRANSACTION
SET SESSION
TRANSACTION
SET TRANSACTION
READ
ONLY
READ WRITE
TEMPORARY
READ WRITE
START
TRANSACTION
InnoDB
XA
SERIALIZABLE
REPEATABLE READ
XA {START|BEGIN}xid
[JOIN|RESUME] XA ENDxid
[SUSPEND [FOR MIGRATE]] XA PREPARExid
XA COMMITxid
[ONE PHASE] XA ROLLBACKxid
XA RECOVER [CONVERT XID]
XA
START
RESUME
XA
END
XA
xid
xid
xid
xid
xid
: gtrid
【, bqual
【, formatID
] ]
gtrid
bqual
formatID
gtrid
bqual
bqual
formatID
bqual
formatID
gtrid
bqual
gtrid
bqual
X'6162'
b'
nnnn
'
formatID
gtrid
bqual
gtrid
bqual
xid
xid
XA
RECOVER
XA START
xid
xid
xid
gtrid
bqual
xid
XA
START
xid
gtrid
xid
gtrid
bqual
xid
bqual
XA
RECOVER
XA
RECOVER
XA_RECOVER_ADMIN
XA
RECOVER
xid
'def'
mysql> XA RECOVER;
+----------+--------------+--------------+--------+
| formatID | gtrid_length | bqual_length | data |
+----------+--------------+--------------+--------+
| 7 | 3 | 3 | abcdef |
+----------+--------------+--------------+--------+
formatID
formatID
xid
gtrid_length
gtrid
xid
bqual_length
bqual
xid
data
gtrid
bqual
xid
XA
RECOVER
XA
START
IDLE
XA
PREPARE
XA
PREPARE
XA
RECOVER
xid
XA
RECOVER
XA COMMIT ... ONE PHASE
xid
XA
RECOVER
PREPARED
XA
COMMIT
XA
ROLLBACK
mysql>XA START 'xatest';
Query OK, 0 rows affected (0.00 sec) mysql>INSERT INTO mytable (i) VALUES(10);
Query OK, 1 row affected (0.04 sec) mysql>XA END 'xatest';
Query OK, 0 rows affected (0.00 sec) mysql>XA PREPARE 'xatest';
Query OK, 0 rows affected (0.00 sec) mysql>XA COMMIT 'xatest';
Query OK, 0 rows affected (0.00 sec)
XA
START
START
TRANSACTION
ACTIVE
错误1399年(xae07):xaer_rmfail:命令无法执行全局事务处于活动状态
SHOW
PURGE { BINARY | MASTER } LOGS { TO 'log_name
' | BEFOREdatetime_expr
}
PURGE BINARY LOGS
MASTER
--log-bin
PURGE BINARY LOGS TO 'mysql-bin.010'; PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';
BEFORE
datetime_expr
DATETIME
SHOW SLAVE
STATUS
SHOW BINARY LOGS
PURGE BINARY LOGS TO
.index
.index
PURGE BINARY LOGS
binlog_expire_logs_seconds
RESET MASTER [TO binary_log_file_index_number
]
RESET MASTER
RESET MASTER
1
1
gtid_purged
gtid_executed
mysql.gtid_executed
RESET MASTER
FLUSH BINARY
LOGS
PURGE BINARY
LOGS TO
TO
复位大师1234;显示二进制日志;------------------- ----------- | log_name | file_size | ------------------- ----------- | master-bin.001234 | 154 | ------------------- -----------
RESET MASTER
PURGE BINARY LOGS
RESET MASTER
.000001
PURGE BINARY LOGS
RESET MASTER
RESET MASTER
PURGE BINARY
LOGS
RESET MASTER
STOP SLAVE
RESET SLAVE
RESET MASTER
SET sql_log_bin = {0|1}
sql_log_bin
SYSTEM_VARIABLES_ADMIN
SUPER
@@session.sql_log_bin
SHOW SLAVE STATUS
SHOW RELAYLOG EVENTS
CHANGE MASTER TOoption
[,option
] ... [channel_option
]option
: MASTER_BIND = 'interface_name
' | MASTER_HOST = 'host_name
' | MASTER_USER = 'user_name
' | MASTER_PASSWORD = 'password
' | MASTER_PORT =port_num
| MASTER_CONNECT_RETRY =interval
| MASTER_RETRY_COUNT =count
| MASTER_DELAY =interval
| MASTER_HEARTBEAT_PERIOD =interval
| MASTER_LOG_FILE = 'master_log_name
' | MASTER_LOG_POS =master_log_pos
| MASTER_AUTO_POSITION = {0|1} | RELAY_LOG_FILE = 'relay_log_name
' | RELAY_LOG_POS =relay_log_pos
| MASTER_SSL = {0|1} | MASTER_SSL_CA = 'ca_file_name
' | MASTER_SSL_CAPATH = 'ca_directory_name
' | MASTER_SSL_CERT = 'cert_file_name
' | MASTER_SSL_CRL = 'crl_file_name
' | MASTER_SSL_CRLPATH = 'crl_directory_name
' | MASTER_SSL_KEY = 'key_file_name
' | MASTER_SSL_CIPHER = 'cipher_list
' | MASTER_SSL_VERIFY_SERVER_CERT = {0|1} | MASTER_TLS_VERSION = 'protocol_list
' | MASTER_PUBLIC_KEY_PATH = 'key_file_name
' | GET_MASTER_PUBLIC_KEY = {0|1} | IGNORE_SERVER_IDS = (server_id_list
)channel_option
: FOR CHANNELchannel
server_id_list
: [server_id
[,server_id
] ... ]
CHANGE MASTER TO
CHANGE
MASTER TO
REPLICATION_SLAVE_ADMIN
SUPER
CHANGE MASTER TO
slave_parallel_workers
CHANGE MASTER TO
START SLAVE UNTIL
SQL_AFTER_MTS_GAPS
FOR CHANNEL
channel
channel
CHANGE MASTER TO MASTER_HOST=host1, MASTER_PORT=3002 FOR CHANNEL 'channel2'
CHANGE
MASTER TO
channel
MASTER_HOST
MASTER_PASSWORD
MASTER_HOST
MASTER_HOST
MASTER_LOG_FILE
MASTER_LOG_FILE=''
MASTER_LOG_POS=4
MASTER_HOST=''
MASTER_HOST
MASTER_HOST
\n
ER_MASTER_INFO
MASTER_USER
MASTER_USER
MASTER_USER = ''
MASTER_PASSWORD
CHANGE MASTER TO
CHANGE MASTER
TO
MASTER_PASSWORD
SHOW
PROCESSLIST
START SLAVE
SHOW PROCESSLIST
MASTER_SSL_
xxx
MASTER_SSL_
xxx
xxx
MASTER_SSL_
xxx
caching_sha2_password
caching_sha2_password
MASTER_USER
MASTER_PUBLIC_KEY_PATH
GET_MASTER_PUBLIC_KEY=1
MASTER_PUBLIC_KEY_PATH
caching_sha2_password
MASTER_PUBLIC_KEY_PATH
GET_MASTER_PUBLIC_KEY
MASTER_PUBLIC_KEY_PATH
MASTER_CONNECT_RETRY
MASTER_RETRY_COUNT
Master_Retry_Count
SHOW SLAVE STATUS
. The default value is 24 * 3600 = 86400.--master-retry-count
--master-retry-count
MASTER_DELAY
interval
interval
CHANGE MASTER TO
MASTER_BIND
Master_Bind
SHOW SLAVE STATUS
Master_bind
MASTER_HEARTBEAT_PERIOD
interval
interval
Heartbeat
interval
interval
slave_net_timeout
@@global.slave_net_timeout
RESET SLAVE
MASTER_LOG_FILE
RELAY_LOG_FILE
MASTER_LOG_FILE
RELAY_LOG_FILE
MASTER_LOG_FILE
MASTER_AUTO_POSITION = 1
MASTER_LOG_POS
CHANGE MASTER
TO
CHANGE MASTER TO
RELAY_LOG_POS
MASTER_AUTO_POSITION = 1
CHANGE MASTER
TO
gtid_executed
SHOW SLAVE STATUS
UNION(@@global.gtid_executed, Retrieved_gtid_set - last_received_GTID
)
ER_MASTER_HAS_PURGED_REQUIRED_GTIDS
MASTER_LOG_FILE
MASTER_AUTO_POSITION
SHOW
SLAVE STATUS
gtid_mode
CHANGE MASTER TO ... MASTER_AUTO_POSITION = 1
CHANGE MASTER
TO
MASTER_AUTO_POSITION = 0
MASTER_LOG_FILE
RELAY_LOG_FILE
RELAY_LOG_FILE
IGNORE_SERVER_IDS
IGNORE_SERVER_IDS =
(3)
CHANGE MASTER
TO
IGNORE_SERVER_IDS
--replicate-same-server-id
IGNORE_SERVER_IDS
gtid_mode=ON
CHANGE MASTER TO
SHOW SLAVE STATUS
CHANGE MASTER TO
CHANGE MASTER TO IGNORE_SERVER_IDS = ();
RESET SLAVE ALL
SET
GTID_MODE=ON
SHOW_SLAVE_STATUS
gtid_mode=ON
CHANGE MASTER
TO
CHANGE MASTER TO
MASTER_PORT
MASTER_LOG_POS
CHANGE MASTER TO
STOP SLAVE
CHANGE MASTER TO
START SLAVE
CHANGE MASTER TO
CHANGE MASTER TO
RELAY_LOG_POS
CHANGE MASTER TO
RELAY_LOG_FILE
MASTER_DELAY
CHANGE MASTER TO
MASTER_AUTO_POSITION = 1
SHOW SLAVE STATUS
CHANGE MASTER TO
ER_WARN_OPEN_TEMP_TABLES_MUST_BE_ZERO
Slave_open_temp_tables
CHANGE MASTER TO
CHANGE MASTER TO MASTER_LOG_FILE='
log_name
', MASTER_LOG_POS=log_pos
CHANGE MASTER TO
MASTER_HOST='master2.example.com',
MASTER_USER='replication',
MASTER_PASSWORD='password
',
MASTER_PORT=3306,
MASTER_LOG_FILE='master2-bin.001',
MASTER_LOG_POS=4,
MASTER_CONNECT_RETRY=10;
CHANGE MASTER TO
CHANGE MASTER TO RELAY_LOG_FILE='slave-relay-bin.006', RELAY_LOG_POS=4025;
MASTER_HOST | |
MASTER_USER | |
MASTER_PASSWORD | |
MASTER_LOG_FILE | |
RELAY_LOG_FILE | |
MASTER_SSL_CA | |
MASTER_SSL_CAPATH | |
MASTER_SSL_CERT | |
MASTER_SSL_CRL | |
MASTER_SSL_CRLPATH | |
MASTER_SSL_KEY | |
MASTER_SSL_CIPHER | |
MASTER_TLS_VERSION | |
MASTER_PUBLIC_KEY_PATH |
CHANGE REPLICATION FILTERfilter
[,filter
] [, ...] [FOR CHANNELchannel
]filter
: REPLICATE_DO_DB = (db_list
) | REPLICATE_IGNORE_DB = (db_list
) | REPLICATE_DO_TABLE = (tbl_list
) | REPLICATE_IGNORE_TABLE = (tbl_list
) | REPLICATE_WILD_DO_TABLE = (wild_tbl_list
) | REPLICATE_WILD_IGNORE_TABLE = (wild_tbl_list
) | REPLICATE_REWRITE_DB = (db_pair_list
)db_list
:db_name
[,db_name
][, ...]tbl_list
:db_name.table_name
[,db_name.table_name
][, ...]wild_tbl_list
: 'db_pattern.table_pattern
'[, 'db_pattern.table_pattern
'][, ...]db_pair_list
: (db_pair
)[, (db_pair
)][, ...]db_pair
:from_db
,to_db
CHANGE REPLICATION FILTER
--replicate-do-db
--replicate-wild-ignore-table
STOP SLAVE
SQL_THREAD
START SLAVE
SQL_THREAD
CHANGE
REPLICATION FILTER
REPLICATION_SLAVE_ADMIN
SUPER
channel
group_replication_applier
CHANGE REPLICATION
FILTER
REPLICATE_DO_DB
--replicate-do-db
REPLICATE_IGNORE_DB
--replicate-ignore-db
REPLICATE_DO_TABLE
--replicate-do-table
REPLICATE_IGNORE_TABLE
--replicate-ignore-table
REPLICATE_WILD_DO_TABLE
--replicate-wild-do-table
REPLICATE_WILD_IGNORE_TABLE
--replicate-wild-ignore-table
REPLICATE_REWRITE_DB
--replicate-rewrite-db
REPLICATE_DO_DB
CHANGE REPLICATION FILTER
CHANGE REPLICATION FILTER REPLICATE_DO_DB = (d1), REPLICATE_IGNORE_DB = (d2);
--replicate-do-db=d1
--replicate-ignore-db=d2
FOR CHANNEL
channel
CHANGE REPLICATION FILTER REPLICATE_DO_DB = (d1) FOR CHANNEL channel_1;
FOR
CHANNEL
CHANGE REPLICATION
FILTER
REPLICATE_DO_DB
CHANGE REPLICATION FILTER REPLICATE_DO_DB = (db1, db2), REPLICATE_DO_DB = (db3, db4);CHANGE REPLICATION FILTER REPLICATE_DO_DB = (db3, db4);
--replicate-*
REPLICATION_WILD_TABLE
CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE = ('db1.old%'); CHANGE REPLICATION FILTER REPLICATE_WILD_IGNORE_TABLE = ('db1.new%', 'db2.new%');
REPLICATE_REWRITE_DB
db1
CHANGE REPLICATION FILTER REPLICATE_REWRITE_DB = ((db1, db2));
rewrite-db
dbB
dbD
CHANGE REPLICATION FILTER REPLICATE_REWRITE_DB = ((dbA, dbB), (dbC, dbD));
CHANGE REPLICATION FILTER
REPLICATE_IGNORE_DB
CHANGE REPLICATION FILTER REPLICATE_DO_DB = (), REPLICATE_IGNORE_DB = ();
--replicate-*
RESET SLAVE
ALL
SELECT MASTER_POS_WAIT('master_log_file
',master_log_pos
[,timeout
][,channel
])
RESET SLAVE [ALL] [channel_option
]channel_option
: FOR CHANNELchannel
RESET SLAVE
CHANGE MASTER
TO
RESET SLAVE
gtid_purged
STOP SLAVE
RESET SLAVE
STOP SLAVE
RESET SLAVE
RESET SLAVE
STOP
GROUP REPLICATION
FOR CHANNEL
channel
channel
FOR CHANNEL
channel
RESET SLAVE
ALL
channel
RESET SLAVE
START
SLAVE
CHANGE MASTER TO
RESET SLAVE
RESET
SLAVE ALL
RESET SLAVE
master_info_repository=TABLE
mysql.slave_master_info
RESET SLAVE
RESET SLAVE
START SLAVE
master_info_repository=FILE
CHANGE MASTER TO
RESET SLAVE ALL
CHANGE MASTER TO
RESET SLAVE
--replicate-ignore-table
RESET SLAVE
RESET SLAVE
RESET SLAVE
Slave_heartbeat_period
SET GLOBAL sql_slave_skip_counter = N
N
SET GLOBAL
sql_slave_skip_counter
START SLAVE [thread_types
] [until_option
] [connection_options
] [channel_option
]thread_types
: [thread_type
[,thread_type
] ... ]thread_type
: IO_THREAD | SQL_THREADuntil_option
: UNTIL { {SQL_BEFORE_GTIDS | SQL_AFTER_GTIDS} =gtid_set
| MASTER_LOG_FILE = 'log_name
', MASTER_LOG_POS =log_pos
| RELAY_LOG_FILE = 'log_name
', RELAY_LOG_POS =log_pos
| SQL_AFTER_MTS_GAPS }connection_options
: [USER='user_name
'] [PASSWORD='user_pass
'] [DEFAULT_AUTH='plugin_name
'] [PLUGIN_DIR='plugin_dir
']channel_option
: FOR CHANNELchannel
gtid_set
:uuid_set
[,uuid_set
] ... | ''uuid_set
:uuid
:interval
[:interval
]...uuid
:hhhhhhhh
-hhhh
-hhhh
-hhhh
-hhhhhhhhhhhh
h
: [0-9,A-F]interval
:n
[-n
] (n
>= 1)
START SLAVE
thread_type
START SLAVE
REPLICATION_SLAVE_ADMIN
SUPER
START SLAVE
START SLAVE
SHOW
SLAVE STATUS
START SLAVE
gtid_next
FOR CHANNEL
channel
channel
START SLAVE
START SLAVE
PASSWORD
PLUGIN_DIR
USER
PASSWORD
DEFAULT_AUTH
PLUGIN_DIR
SQL_THREAD
PASSWORD
PLUGIN_DIR
START SLAVE ... UNTIL
gtid_set
thread_type
gtid_set
last
gtid_set
gtid_set
gtid_set
SQL_AFTER_GTIDS
IO_THREAD
START SLAVE SQL_THREAD UNTIL
SQL_BEFORE_GTIDS =
3E11FA47-71CA-11E1-9E33-C80AA9429562:11-56
server_uuid
START SLAVE
SQL_THREAD UNTIL SQL_AFTER_GTIDS =
3E11FA47-71CA-11E1-9E33-C80AA9429562:11-56
slave_preserve_commit_order=0
START SLAVE
UNTIL SQL_AFTER_MTS_GAPS
IO_THREAD
START SLAVE
START SLAVE UNTIL
SQL_AFTER_MTS_GAPS
RESET SLAVE
START SLAVE UNTIL SQL_AFTER_MTS_GAPS; SET @@GLOBAL.slave_parallel_workers = 0; START SLAVE SQL_THREAD;
START SLAVE ...
PASSWORD
SHOW
PROCESSLIST
CHANGE MASTER TO
MASTER_PASSWORD
START SLAVE
START SLAVE
SHOW SLAVE STATUS
Slave_SQL_Running=Yes
Slave_IO_Running=Yes
Slave_IO_Running=Yes
IO_THREAD
SQL_THREAD
PASSWORD
PLUGIN_DIR
UNTIL
until_option
RELAY_LOG_POS
SQL_THREAD
UNTIL
START SLAVE UNTIL
SQL_AFTER_GTIDS
IO_THREAD
IO_THREAD
IO_THREAD
UNTIL
SQL_AFTER_MTS_GAPS
UNTIL
SQL_BEFORE_GTIDS
SQL_AFTER_MTS_GAPS
UNTIL
STOP SLAVE
START SLAVE
IO_THREAD
IO_THREAD
SQL_AFTER_GTIDS
IO_THREAD
UNTIL
DROP TABLE
SHOW BINLOG EVENTS
UNTIL
--skip-slave-start
SHOW SLAVE STATUS
SLAVE START
STOP SLAVE [thread_types
]thread_types
: [thread_type
[,thread_type
] ... ]thread_type
: IO_THREAD | SQL_THREADchannel_option
: FOR CHANNELchannel
STOP
SLAVE
REPLICATION_SLAVE_ADMIN
SUPER
STOP SLAVE
START SLAVE
SQL_THREAD
STOP SLAVE
gtid_next
STOP SLAVE
rpl_stop_slave_timeout
STOP SLAVE
CHANGE MASTER TO
CHANGE MASTER
TO
FOR CHANNEL
channel
channel
STOP SLAVE
Slave_open_temp_tables
CHANGE
MASTER TO
ER_WARN_OPEN_TEMP_TABLES_MUST_BE_ZERO
slave_parallel_workers
KILL
STOP SLAVE
KILL QUERY
KILL CONNECTION
START GROUP_REPLICATION
GROUP_REPLICATION_ADMIN
SUPER
super_read_only=ON
super_read_only
STOP GROUP_REPLICATION
GROUP_REPLICATION_ADMIN
SUPER
STOP GROUP_REPLICATION
super_read_only=ON
group_replication_switch_to_single_primary_mode()
选择group_replication_switch_to_single_primary_mode()
SELECT
group_replication_switch_to_single_primary_mode(
member_uuid
);member_uuid
server_uuid
WHERE
VALUES
mysqli
PREPARE
EXECUTE
DEALLOCATE PREPARE
mysql>PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql>SET @a = 3;
mysql>SET @b = 4;
mysql>EXECUTE stmt1 USING @a, @b;
+------------+ | hypotenuse | +------------+ | 5 | +------------+ mysql>DEALLOCATE PREPARE stmt1;
mysql>SET @s = 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql>PREPARE stmt2 FROM @s;
mysql>SET @a = 6;
mysql>SET @b = 8;
mysql>EXECUTE stmt2 USING @a, @b;
+------------+ | hypotenuse | +------------+ | 10 | +------------+ mysql>DEALLOCATE PREPARE stmt2;
mysql>USE test;
mysql>CREATE TABLE t1 (a INT NOT NULL);
mysql>INSERT INTO t1 VALUES (4), (8), (11), (32), (80);
mysql>SET @table = 't1';
mysql>SET @s = CONCAT('SELECT * FROM ', @table);
mysql>PREPARE stmt3 FROM @s;
mysql>EXECUTE stmt3;
+----+ | a | +----+ | 4 | | 8 | | 11 | | 32 | | 80 | +----+ mysql>DEALLOCATE PREPARE stmt3;
max_prepared_stmt_count
ALTER TABLE ALTER USER ANALYZE TABLE CACHE INDEX CALL CHANGE MASTER CHECKSUM {TABLE | TABLES} COMMIT {CREATE | DROP} INDEX {CREATE | RENAME | DROP} DATABASE {CREATE | DROP} TABLE {CREATE | RENAME | DROP} USER {CREATE | DROP} VIEW DELETE DO FLUSH {TABLE | TABLES | TABLES WITH READ LOCK | HOSTS | PRIVILEGES | LOGS | STATUS | MASTER | SLAVE | USER_RESOURCES} GRANT INSERT INSTALL PLUGIN KILL LOAD INDEX INTO CACHE OPTIMIZE TABLE RENAME TABLE REPAIR TABLE REPLACE RESET {MASTER | SLAVE} REVOKE SELECT SET SHOW {WARNINGS | ERRORS} SHOW BINLOG EVENTS SHOW CREATE {PROCEDURE | FUNCTION | EVENT | TABLE | VIEW} SHOW {MASTER | BINARY} LOGS SHOW {MASTER | SLAVE} STATUS SLAVE {START | STOP} TRUNCATE TABLE UNINSTALL PLUGIN UPDATE
SHOW WARNINGS
SHOW ERRORS
warning_count
error_count
LIMIT
CALL
PREPARE
EXECUTE
INOUT
IN
PREPARE
PREPARE
EXECUTE
DEALLOCATE PREPARE
mysql_stmt_prepare()
PREPARE
EXECUTE
DEALLOCATE PREPARE
PREPARE
EXECUTE
;
CALL
CALL
CLIENT_MULTI_RESULTS
mysql_real_connect()
CLIENT_MULTI_STATEMENTS
PREPAREstmt_name
FROMpreparable_stmt
PREPARE
stmt_name
EXECUTE
DEALLOCATE PREPARE
preparable_stmt
?
EXECUTEstmt_name
[USING @var_name
[, @var_name
] ...]
PREPARE
EXECUTE
USING
{DEALLOCATE | DROP} PREPARE stmt_name
PREPARE
DEALLOCATE PREPARE
max_prepared_stmt_count
BEGIN ... END
[begin_label
:] BEGIN [statement_list
] END [end_label
]
BEGIN ... END
END
statement_list
statement_list
BEGIN ... END
;
delimiter
//
BEGIN ...
END
[NOT] ATOMIC
BEGIN [WORK]
BEGIN ...
END
START
TRANSACTION
[begin_label
:] BEGIN [statement_list
] END [end_label
] [begin_label
:] LOOPstatement_list
END LOOP [end_label
] [begin_label
:] REPEATstatement_list
UNTILsearch_condition
END REPEAT [end_label
] [begin_label
:] WHILEsearch_condition
DOstatement_list
END WHILE [end_label
]
BEGIN ... END
LOOP
REPEAT
WHILE
begin_label
begin_label
end_label
end_label
begin_label
end_label
begin_label
ITERATE
LEAVE
CREATE PROCEDURE doiterate(p1 INT)BEGIN label1: LOOP SET p1 = p1 + 1; IF p1 < 10 THEN ITERATE label1; END IF; LEAVE label1; END LOOP label1;END;
DECLARE
DECLARE
BEGIN ... END
DECLARE
DECLARE
SET
SELECT ...
INTO
var_list
FETCH ... INTO
var_list
DEFAULT
var_name
= DEFAULT
DECLAREvar_name
[,var_name
] ...type
[DEFAULTvalue
]
DEFAULT
NULL
BEGIN ...
END
BEGIN ...
END
SELECT ... INTO
local_var
SELECT ...
INTO
CREATE PROCEDURE sp1 (x VARCHAR(5))BEGIN DECLARE xname VARCHAR(5) DEFAULT 'bob'; DECLARE newname VARCHAR(5); DECLARE xid INT; SELECT xname, id INTO newname, xid FROM table1 WHERE xname = xname; SELECT newname;END;
xname
SELECT
xname
sp1()
'bob'
SELECT
CREATE PROCEDURE sp2 (x VARCHAR(5)) BEGIN DECLARE xname VARCHAR(5) DEFAULT 'bob'; DECLARE newname VARCHAR(5); DECLARE xid INT; DECLARE done TINYINT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT xname, id FROM table1; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN cur1; read_loop: LOOP FETCH FROM cur1 INTO newname, xid; IF done THEN LEAVE read_loop; END IF; SELECT newname; END LOOP; CLOSE cur1; END;
IF
CASE
ITERATE
LEAVE
LOOP
WHILE
REPEAT
RETURN
IF
WHILE
CASE
FOR
CASEcase_value
WHENwhen_value
THENstatement_list
[WHENwhen_value
THENstatement_list
] ... [ELSEstatement_list
] END CASE
CASE WHENsearch_condition
THENstatement_list
[WHENsearch_condition
THENstatement_list
] ... [ELSEstatement_list
] END CASE
CASE
CASE
CASE
CASE
END CASE
case_value
when_value
when_value
statement_list
when_value
statement_list
NULL
NULL = NULL
WHEN
search_condition
statement_list
search_condition
statement_list
when_value
search_condition
CASE
statement_list
statement_list
WHEN
BEGIN ...
END
DELIMITER | CREATE PROCEDURE p() BEGIN DECLARE v INT DEFAULT 1; CASE v WHEN 2 THEN SELECT v; WHEN 3 THEN SELECT 0; ELSE BEGIN END; END CASE; END; |
IFsearch_condition
THENstatement_list
[ELSEIFsearch_condition
THENstatement_list
] ... [ELSEstatement_list
] END IF
IF
IF()
IF
IF
ELSE
END IF
search_condition
ELSEIF
statement_list
search_condition
statement_list
statement_list
statement_list
IF ... END IF
DELIMITER //CREATE FUNCTION SimpleCompare(n INT, m INT) RETURNS VARCHAR(20) BEGIN DECLARE s VARCHAR(20); IF n > m THEN SET s = '>'; ELSEIF n = m THEN SET s = '='; ELSE SET s = '<'; END IF; SET s = CONCAT(n, ' ', s, ' ', m); RETURN s; END //DELIMITER ;
IF ... END
IF
IF
IF
DELIMITER // CREATE FUNCTION VerboseCompare (n INT, m INT) RETURNS VARCHAR(50) BEGIN DECLARE s VARCHAR(50); IF n = m THEN SET s = 'equals'; ELSE IF n > m THEN SET s = 'greater'; ELSE SET s = 'less'; END IF; SET s = CONCAT('is ', s, ' than'); END IF; SET s = CONCAT(n, ' ', s, ' ', m, '.'); RETURN s; END // DELIMITER ;
IF
m
LEAVE label
LEAVE
LEAVE
BEGIN ...
END
LOOP
REPEAT
WHILE
[begin_label
:] LOOPstatement_list
END LOOP [end_label
]
LOOP
LEAVE
RETURN
LOOP
CREATE PROCEDURE doiterate(p1 INT) BEGIN label1: LOOP SET p1 = p1 + 1; IF p1 < 10 THEN ITERATE label1; END IF; LEAVE label1; END LOOP label1; SET @x = p1; END;
[begin_label
:] REPEATstatement_list
UNTILsearch_condition
END REPEAT [end_label
]
REPEAT
search_condition
REPEAT
statement_list
REPEAT
mysql>delimiter //
mysql>CREATE PROCEDURE dorepeat(p1 INT)
->BEGIN
->SET @x = 0;
->REPEAT
->SET @x = @x + 1;
->UNTIL @x > p1 END REPEAT;
->END
->//
Query OK, 0 rows affected (0.00 sec) mysql>CALL dorepeat(1000)//
Query OK, 0 rows affected (0.00 sec) mysql>SELECT @x//
+------+ | @x | +------+ | 1001 | +------+ 1 row in set (0.00 sec)
RETURN expr
RETURN
expr
RETURN
LEAVE
[begin_label
:] WHILEsearch_condition
DOstatement_list
END WHILE [end_label
]
WHILE
search_condition
statement_list
WHILE
CREATE PROCEDURE dowhile() BEGIN DECLARE v1 INT DEFAULT 5; WHILE v1 > 0 DO ... SET v1 = v1 - 1; END WHILE; END;
CREATE PROCEDURE curdemo() BEGIN DECLARE done INT DEFAULT FALSE; DECLARE a CHAR(16); DECLARE b, c INT; DECLARE cur1 CURSOR FOR SELECT id,data FROM test.t1; DECLARE cur2 CURSOR FOR SELECT i FROM test.t2; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN cur1; OPEN cur2; read_loop: LOOP FETCH cur1 INTO a, b; FETCH cur2 INTO c; IF done THEN LEAVE read_loop; END IF; IF b < c THEN INSERT INTO test.t3 VALUES (a,b); ELSE INSERT INTO test.t3 VALUES (a,c); END IF; END LOOP; CLOSE cur1; CLOSE cur2; END;
DECLAREcursor_name
CURSOR FORselect_statement
SELECT
FETCH
SELECT
FETCH
SELECT
SHOW
FETCH [[NEXT] FROM]cursor_name
INTOvar_name
[,var_name
] ...
SELECT
SELECT
FETCH
'02000'
SELECT
BEGIN ...
END
DECLARE ...
CONDITION
DECLARE ...
HANDLER
SIGNAL
RESIGNAL
GET DIAGNOSTICS
DECLAREcondition_name
CONDITION FORcondition_value
condition_value
:mysql_error_code
| SQLSTATE [VALUE]sqlstate_value
DECLARE
... CONDITION
DECLARE ...
HANDLER
condition_value
DECLARE ...
CONDITION
mysql_error_code
sqlstate_value
'00'
SIGNAL
RESIGNAL
DECLARE CONTINUE HANDLER FOR 1051 BEGIN -- body of handler END;
DECLARE no_such_table CONDITION FOR 1051; DECLARE CONTINUE HANDLER FOR no_such_table BEGIN -- body of handler END;
DECLARE no_such_table CONDITION FOR SQLSTATE '42S02'; DECLARE CONTINUE HANDLER FOR no_such_table BEGIN -- body of handler END;
DECLAREhandler_action
HANDLER FORcondition_value
[,condition_value
] ...statement
handler_action
: CONTINUE | EXIT | UNDOcondition_value
:mysql_error_code
| SQLSTATE [VALUE]sqlstate_value
|condition_name
| SQLWARNING | NOT FOUND | SQLEXCEPTION
DECLARE ...
HANDLER
statement
statement
var_name
=value
END
handler_action
CONTINUE
EXIT
BEGIN ...
END
UNDO
condition_value
DECLARE ...
HANDLER
mysql_error_code
DECLARE CONTINUE HANDLER FOR 1051 BEGIN -- body of handler END;
sqlstate_value
DECLARE CONTINUE HANDLER FOR SQLSTATE '42S02' BEGIN -- body of handler END;
'00'
condition_name
DECLARE
... CONDITION
SQLWARNING
DECLARE CONTINUE HANDLER FOR SQLWARNING BEGIN -- body of handler END;
NOT FOUND
'02000'
DECLARE CONTINUE HANDLER FOR NOT FOUND BEGIN -- body of handler END;
NOT FOUND
var_list
SQLEXCEPTION
'01'
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN -- body of handler END;
SQLSTATE
'23000'
MySQL的> CREATE TABLE test.t (s1 INT, PRIMARY KEY (s1));
查询好,为受影响的行(0.001秒)MySQL > delimiter //
MySQL的> CREATE PROCEDURE handlerdemo ()
-> BEGIN
-> DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' SET @x2 = 1;
-> SET @x = 1;
-> INSERT INTO test.t VALUES (1);
-> SET @x = 2;
-> INSERT INTO test.t VALUES (1);
-> SET @x = 3;
-> END;
-> //
查询好,为受影响的行(0.001秒)MySQL > CALL handlerdemo()//
查询好,为受影响的行(0.001秒)MySQL > SELECT @x//
------ | @ X | ------ | 3 | ------ 1行集(0秒)
@x
DECLARE ...
HANDLER
INSERT
SELECT @x
CONTINUE
声明继续sqlwarning开始结束处理程序;
ITERATE
LEAVE
REPEAT
CREATE PROCEDURE p () BEGIN DECLARE i INT DEFAULT 3; retry: REPEAT BEGIN DECLARE CONTINUE HANDLER FOR SQLWARNING BEGIN ITERATE retry; # illegal END; IF i < 0 THEN LEAVE retry; # legal END IF; SET i = i - 1; END; UNTIL FALSE END REPEAT; END;
retry
IF
ERROR 1308 (42000): LEAVE with no matching label: retry
EXIT
BEGIN ...
END
宣布退出处理程序sqlwarning开始结束;
DECLARE EXIT HANDLER FOR SQLWARNING
BEGIN
block cleanup statements
END;
CONTINUE
CREATE PROCEDURE p () BEGIN DECLARE i INT DEFAULT 3; DECLARE done INT DEFAULT FALSE; retry: REPEAT BEGIN DECLARE CONTINUE HANDLER FOR SQLWARNING BEGIN SET done = TRUE; END; IF done OR i < 0 THEN LEAVE retry; END IF; SET i = i - 1; END; UNTIL FALSE END REPEAT; END;
GET [CURRENT | STACKED] DIAGNOSTICS {statement_information_item
[,statement_information_item
] ... | CONDITIONcondition_number
condition_information_item
[,condition_information_item
] ... }statement_information_item
:target
=statement_information_item_name
condition_information_item
:target
=condition_information_item_name
statement_information_item_name
: NUMBER | ROW_COUNTcondition_information_item_name
: CLASS_ORIGIN | SUBCLASS_ORIGIN | RETURNED_SQLSTATE | MESSAGE_TEXT | MYSQL_ERRNO | CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | CATALOG_NAME | SCHEMA_NAME | TABLE_NAME | COLUMN_NAME | CURSOR_NAMEcondition_number
,target
: (see following discussion)
GET
DIAGNOSTICS
SHOW
WARNINGS
SHOW ERRORS
GET DIAGNOSTICS
CURRENT
GET DIAGNOSTICS
GET [CURRENT]
DIAGNOSTICS
mysql>DROP TABLE test.no_such_table;
ERROR 1051 (42S02): Unknown table 'test.no_such_table' mysql>GET DIAGNOSTICS CONDITION 1
->@p1 = RETURNED_SQLSTATE, @p2 = MESSAGE_TEXT;
mysql>SELECT @p1, @p2;
+-------+------------------------------------+ | @p1 | @p2 | +-------+------------------------------------+ | 42S02 | Unknown table 'test.no_such_table' | +-------+------------------------------------+
GET STACKED DIAGNOSTICS
Statement information: row count ... other statement information items ... Condition area list: Condition area 1: error code for condition 1 error message for condition 1 ... other condition information items ... Condition area 2: error code for condition 2: error message for condition 2 ... other condition information items ... Condition area 3: error code for condition 3 error message for condition 3 ... other condition information items ...
GET DIAGNOSTICS
GET DIAGNOSTICS
@p2
GET DIAGNOSTICS @p1 = NUMBER, @p2 = ROW_COUNT;
GET
DIAGNOSTICS
@p4
GET DIAGNOSTICS CONDITION 1 @p3 = RETURNED_SQLSTATE, @p4 = MESSAGE_TEXT;
target
=
item_name
statement_information_item_name
condition_information_item_name
target
DECLARE
condition_number
DECLARE
_charset
GET
DIAGNOSTICS
MySQL的> GET DIAGNOSTICS CONDITION 1
-> @p5 = SCHEMA_NAME, @p6 = TABLE_NAME;
MySQL的> SELECT @p5, @p6;
??????@ @ | | P5 P6 |????????????| | |
SQLSTATE
GET DIAGNOSTICS CONDITION 1 @errno = MYSQL_ERRNO;
GET DIAGNOSTICS @cno = NUMBER; GET DIAGNOSTICS CONDITION @cno @errno = MYSQL_ERRNO;
GET
DIAGNOSTICS
GET DIAGNOSTICS
GET DIAGNOSTICS
CREATE PROCEDURE do_insert(value INT)BEGIN -- Declare variables to hold diagnostics area information DECLARE code CHAR(5) DEFAULT '00000'; DECLARE msg TEXT; DECLARE rows INT; DECLARE result TEXT; -- Declare exception handler for failed insert DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN GET DIAGNOSTICS CONDITION 1 code = RETURNED_SQLSTATE, msg = MESSAGE_TEXT; END; -- Perform the insert INSERT INTO t1 (int_col) VALUES(value); -- Check whether the insert was successful IF code = '00000' THEN GET DIAGNOSTICS rows = ROW_COUNT; SET result = CONCAT('insert succeeded, row count = ',rows); ELSE SET result = CONCAT('insert failed, error = ',code,', message = ',msg); END IF; -- Say what happened SELECT result;END;
t1.int_col
NULL
mysql>CALL do_insert(1);
+---------------------------------+ | result | +---------------------------------+ | insert succeeded, row count = 1 | +---------------------------------+ mysql>CALL do_insert(NULL);
+-------------------------------------------------------------------------+ | result | +-------------------------------------------------------------------------+ | insert failed, error = 23000, message = Column 'int_col' cannot be null | +-------------------------------------------------------------------------+
GET
[CURRENT] DIAGNOSTICS
GET STACKED
DIAGNOSTICS
RESIGNAL
GET STACKED
DIAGNOSTICS
p()
NULL
NULL
DROP TABLE IF EXISTS t1; CREATE TABLE t1 (c1 TEXT NOT NULL); DROP PROCEDURE IF EXISTS p; delimiter // CREATE PROCEDURE p () BEGIN -- Declare variables to hold diagnostics area information DECLARE errcount INT; DECLARE errno INT; DECLARE msg TEXT; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN -- Here the current DA is nonempty because no prior statements -- executing within the handler have cleared it GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT; SELECT 'current DA before mapped insert' AS op, errno, msg; GET STACKED DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT; SELECT 'stacked DA before mapped insert' AS op, errno, msg; -- Map attempted NULL insert to empty string insert INSERT INTO t1 (c1) VALUES(''); -- Here the current DA should be empty (if the INSERT succeeded), -- so check whether there are conditions before attempting to -- obtain condition information GET CURRENT DIAGNOSTICS errcount = NUMBER; IF errcount = 0 THEN SELECT 'mapped insert succeeded, current DA is empty' AS op; ELSE GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT; SELECT 'current DA after mapped insert' AS op, errno, msg; END IF ; GET STACKED DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT; SELECT 'stacked DA after mapped insert' AS op, errno, msg; END; INSERT INTO t1 (c1) VALUES('string 1'); INSERT INTO t1 (c1) VALUES(NULL); END; // delimiter ; CALL p(); SELECT * FROM t1;
+---------------------------------+-------+----------------------------+ | op | errno | msg | +---------------------------------+-------+----------------------------+ | current DA before mapped insert | 1048 | Column 'c1' cannot be null | +---------------------------------+-------+----------------------------+ +---------------------------------+-------+----------------------------+ | op | errno | msg | +---------------------------------+-------+----------------------------+ | stacked DA before mapped insert | 1048 | Column 'c1' cannot be null | +---------------------------------+-------+----------------------------+
GET
DIAGNOSTICS
+----------------------------------------------+ | op | +----------------------------------------------+ | mapped insert succeeded, current DA is empty | +----------------------------------------------+ +--------------------------------+-------+----------------------------+ | op | errno | msg | +--------------------------------+-------+----------------------------+ | stacked DA after mapped insert | 1048 | Column 'c1' cannot be null | +--------------------------------+-------+----------------------------+
NULL
---------- | C1 | ---------- |字串1 | | | ----------
GET
DIAGNOSTICS
DECLARE
CREATE PROCEDURE p ()BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN -- Declare variables to hold diagnostics area information DECLARE errcount INT; DECLARE errno INT; DECLARE msg TEXT; GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT; SELECT 'current DA before mapped insert' AS op, errno, msg; GET STACKED DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT; SELECT 'stacked DA before mapped insert' AS op, errno, msg;...
DECLARE
GET DIAGNOSTICS
DECLARE
DECLARE
GET
DIAGNOSTICS
--------------------------------- ------- ------ | OP | errno |味精| --------------------------------- ------- ------ |电流大之前插入空|空|映射| --------------------------------- ------- ------ --------------------------------- ------- ---------------------------- | OP | errno |味精| --------------------------------- ------- ---------------------------- |堆叠的大前插入1048 |映射|列“C1”不能为空| --------------------------------- ------- ----------------------------
RESIGNAL [condition_value
] [SETsignal_information_item
[,signal_information_item
] ...]condition_value
: SQLSTATE [VALUE]sqlstate_value
|condition_name
signal_information_item
:condition_information_item_name
=simple_value_specification
condition_information_item_name
: CLASS_ORIGIN | SUBCLASS_ORIGIN | MESSAGE_TEXT | MYSQL_ERRNO | CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | CATALOG_NAME | SCHEMA_NAME | TABLE_NAME | COLUMN_NAME | CURSOR_NAMEcondition_name
,simple_value_specification
: (see following discussion)
RESIGNAL
RESIGNAL
RESIGNAL
SIGNAL
SIGNAL
RESIGNAL
RESIGNAL
RESIGNAL
RESIGNAL
RESIGNAL
RESIGNAL
GET DIAGNOSTICS
condition_value
signal_information_item
RESIGNAL
SIGNAL
condition_value
RESIGNAL
condition_value
SQLSTATE
MESSAGE_TEXT
max_error_count
RESIGNAL
RESIGNAL
DROP TABLE IF EXISTS xx; delimiter // CREATE PROCEDURE p () BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN SET @error_count = @error_count + 1; IF @a = 0 THEN RESIGNAL; END IF; END; DROP TABLE xx; END// delimiter ; SET @error_count = 0; SET @a = 0; CALL p();
DROP TABLE xx
Da 1 .错误:未知(1051 42s02表“XX”)
EXIT
Da 1 .错误1051(442):UNknown Table ' XX ' da 2。错误1051(442):
BEGIN
DA 1. ERROR 0000 (00000): Successful operation DA 2. ERROR 1051 (42S02): Unknown table 'xx'
@a = 0
RESIGNAL
Da 1 .错误:未知(1051 42s02表“XX”)
@a
DA 1. ERROR 0000 (00000): Successful operation
RESIGNAL
RESIGNAL SETsignal_information_item
[,signal_information_item
] ...;
RESIGNAL
RESIGNAL
DROP TABLE IF EXISTS xx; delimiter // CREATE PROCEDURE p () BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN SET @error_count = @error_count + 1; IF @a = 0 THEN RESIGNAL SET MYSQL_ERRNO = 5; END IF; END; DROP TABLE xx; END// delimiter ; SET @error_count = 0; SET @a = 0; CALL p();
RESIGNAL
Da 1 .错误:未知(1051 42s02表“XX”)
RESIGNAL SET MYSQL_ERRNO = 5
1。错误:未知(5 42s02表“XX”)
RESIGNAL
RESIGNAL
SET
区域 condition_value
配置 signal_information_item
【, signal_information_item
]…];
RESIGNAL
RESIGNAL
DROP TABLE IF EXISTS xx; delimiter // CREATE PROCEDURE p () BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN SET @error_count = @error_count + 1; IF @a = 0 THEN RESIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=5; END IF; END; DROP TABLE xx; END// delimiter ; SET @error_count = 0; SET @a = 0; SET @@max_error_count = 2; CALL p(); SHOW ERRORS;
RESIGNAL
RESIGNAL
DA 1. (condition 2) ERROR 1051 (42S02): Unknown table 'xx' (condition 1) ERROR 5 (45000) Unknown table 'xx'
CALL
p()
SHOW ERRORS
MySQL的> CALL p();
错误5(45000):未知的表xx'mysql > SHOW ERRORS;
------- ------ ---------------------------------- |水平|代码|消息| ------- ------ ---------------------------------- |误差| 1051 |未知表'XX' | |误差| 5 |未知表'XX' | ------- ------ ----------------------------------
RESIGNAL
RESIGNAL
mysql>CREATE PROCEDURE p () RESIGNAL;
Query OK, 0 rows affected (0.00 sec) mysql>CALL p();
ERROR 1645 (0K000): RESIGNAL when handler not active
delimiter // CREATE FUNCTION f () RETURNS INT BEGIN RESIGNAL; RETURN 5; END// CREATE PROCEDURE p () BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION SET @a=f(); SIGNAL SQLSTATE '55555'; END// delimiter ; CALL p();
RESIGNAL
f()
f()
f()
SIGNALcondition_value
[SETsignal_information_item
[,signal_information_item
] ...]condition_value
: SQLSTATE [VALUE]sqlstate_value
|condition_name
signal_information_item
:condition_information_item_name
=simple_value_specification
condition_information_item_name
: CLASS_ORIGIN | SUBCLASS_ORIGIN | MESSAGE_TEXT | MYSQL_ERRNO | CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | CATALOG_NAME | SCHEMA_NAME | TABLE_NAME | COLUMN_NAME | CURSOR_NAMEcondition_name
,simple_value_specification
: (see following discussion)
SIGNAL
SIGNAL
SIGNAL
SIGNAL
GET DIAGNOSTICS
condition_value
SIGNAL
condition_name
DECLARE ...
CONDITION
SQLSTATE
SQLSTATE
SIGNAL
SQLSTATE
SIGNAL
SQLSTATE
SIGNAL
condition_information_item_name
=simple_value_specification
condition_information_item_name
Duplicate condition information
item
simple_value_specification
DECLARE
_charset
condition_information_item_name
pval
CREATE PROCEDURE p (pval INT)BEGIN DECLARE specialty CONDITION FOR SQLSTATE '45000'; IF pval = 0 THEN SIGNAL SQLSTATE '01000'; ELSEIF pval = 1 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'An error occurred'; ELSEIF pval = 2 THEN SIGNAL specialty SET MESSAGE_TEXT = 'An error occurred'; ELSE SIGNAL SQLSTATE '01000' SET MESSAGE_TEXT = 'A warning occurred', MYSQL_ERRNO = 1000; SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'An error occurred', MYSQL_ERRNO = 1001; END IF;END;
pval
SQLSTATE
SHOW WARNINGS
pval
MESSAGE_TEXT
pval
pval
p()
SIGNAL
mysql>SIGNAL SQLSTATE '77777';
mysql>CREATE TRIGGER t_bi BEFORE INSERT ON t
->FOR EACH ROW SIGNAL SQLSTATE '77777';
mysql>CREATE EVENT e ON SCHEDULE EVERY 1 SECOND
->DO SIGNAL SQLSTATE '77777';
SIGNAL
SIGNAL
CREATE PROCEDURE p (divisor INT) BEGIN IF divisor = 0 THEN SIGNAL SQLSTATE '22012'; END IF; END;
SIGNAL
SIGNAL
CREATE PROCEDURE p (divisor INT) BEGIN DECLARE divide_by_zero CONDITION FOR SQLSTATE '22012'; IF divisor = 0 THEN SIGNAL divide_by_zero; END IF; END;
SIGNAL
SIGNAL
SIGNAL/RESIGNAL
can only use a CONDITION defined with SQLSTATE
no_such_table申报条件1051;信号no_such_table;
CREATE PROCEDURE p (divisor INT) BEGIN DECLARE my_error CONDITION FOR SQLSTATE '45000'; IF divisor = 0 THEN BEGIN DECLARE my_error CONDITION FOR SQLSTATE '22012'; SIGNAL my_error; END; END IF; SIGNAL my_error; END;
divisor
SIGNAL
SQLSTATE
divisor
SIGNAL
SQLSTATE
CREATE PROCEDURE p () BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN SIGNAL SQLSTATE VALUE '99999' SET MESSAGE_TEXT = 'An error occurred'; END; DROP TABLE no_such_table; END;
CALL p()
DROP TABLE
SQLSTATE
An error occurred
SIGNAL
RESIGNAL
Item Name Definition --------- ---------- CLASS_ORIGIN VARCHAR(64) SUBCLASS_ORIGIN VARCHAR(64) CONSTRAINT_CATALOG VARCHAR(64) CONSTRAINT_SCHEMA VARCHAR(64) CONSTRAINT_NAME VARCHAR(64) CATALOG_NAME VARCHAR(64) SCHEMA_NAME VARCHAR(64) TABLE_NAME VARCHAR(64) COLUMN_NAME VARCHAR(64) CURSOR_NAME VARCHAR(64) MESSAGE_TEXT VARCHAR(128) MYSQL_ERRNO SMALLINT UNSIGNED
NULL
SIGNAL
SIGNAL
SQLSTATE
Class ='00'
SQLSTATE
SIGNAL
Class ='01'
MESSAGE_TEXT = 'Unhandled user-defined warning condition';MYSQL_ERRNO =ER_SIGNAL_WARN
Class ='02'
MESSAGE_TEXT = 'Unhandled user-defined not found condition';MYSQL_ERRNO =ER_SIGNAL_NOT_FOUND
'02'
MESSAGE_TEXT = 'Unhandled user-defined exception condition';MYSQL_ERRNO =ER_SIGNAL_EXCEPTION
CLASS_ORIGIN = SUBCLASS_ORIGIN = ''; CONSTRAINT_CATALOG = CONSTRAINT_SCHEMA = CONSTRAINT_NAME = ''; CATALOG_NAME = SCHEMA_NAME = TABLE_NAME = COLUMN_NAME = ''; CURSOR_NAME = '';
SIGNAL
SIGNAL
MYSQL_ERRNO
SQLSTATE
mysql_sqlstate()
MYSQL_ERRNO
mysql_errno()
MESSAGE_TEXT
mysql_error()
SHOW
WARNINGS
SHOW
ERRORS
MESSAGE_TEXT
Message
GET DIAGNOSTICS
sql_mode
SIGNAL
SQLSTATE
DECLARE ...
HANDLER
Class ='00'
SQLSTATE
SIGNAL
Class ='01'
warning_count
SHOW
WARNINGS
Class ='02'
NOT FOUND
'02'
SQLEXCEPTION
Class ='40'
mysql>delimiter //
mysql>CREATE FUNCTION f () RETURNS INT
->BEGIN
->SIGNAL SQLSTATE '01234'; -- signal a warning
->RETURN 5;
->END//
mysql>delimiter ;
mysql>CREATE TABLE t (s1 INT);
mysql>INSERT INTO t VALUES (f());
t
SHOW WARNINGS
BEGIN ...
END
H2
stmt1
stmt2
H2
H2
开始——外块宣布退出处理程序…;——处理H1宣布退出处理程序;--处理H2… stmt1
; stmt2
;结束;
H1
stmt1
stmt2
开始-开始-外挡块内声明退出处理程序;--处理H1… stmt1
;结束; stmt2
;结束;
SQLSTATE
SQLEXCEPTION
SQLWARNING
BEGIN ...
END
SQLSTATE
SQLSTATE
SQLEXCEPTION
SQLEXCEPTION
SQLSTATE
SQLEXCEPTION
创建程序p1()开始宣布继续为SQLSTATE”42s02 '选择'激活' SQLSTATE处理处理味精;宣布继续不选择“不处理处理程序被激活的味精;表t;结束测试;
SQLSTATE
t
DROP TABLE
mysql> CALL p1();
+--------------------------------+
| msg |
+--------------------------------+
| SQLSTATE handler was activated |
+--------------------------------+
DROP TABLE
SQLSTATE
创建程序p2()开始——外块宣布继续为SQLSTATE”42s02 '选择'激活' SQLSTATE处理处理味精;开始——块内声明继续不选择“不处理处理程序被激活的味精;跌落台试验。T;--发生在块内端;端;
SQLEXCEPTION
mysql> CALL p2();
+------------------------------------+
| msg |
+------------------------------------+
| SQLEXCEPTION handler was activated |
+------------------------------------+
DROP
TABLE
创建程序p3()开始——外块宣布继续不选择“不处理处理程序被激活的味精;开始——块内声明继续SQLSTATE”42s02 '选择'激活' SQLSTATE处理处理味精;结束;跌落台试验。T;--发生在外blockend;
SQLEXCEPTION
DROP TABLE
MySQL的> CALL p3();
------------------------------------ |味精| ------------------------------------ | SQLException处理程序被激活| ------------------------------------
DROP TABLE
创建程序p4()开始--开始--外块内块宣布继续不选择“不处理处理程序被激活的味精;宣布继续为SQLSTATE”42s02 '选择'激活' SQLSTATE处理处理味精;结束;跌落台试验。T;--发生在外blockend;
DROP TABLE
MySQL的> CALL p4();
错误1051(未知42s02):表“测试。”
GET STACKED
DIAGNOSTICS
Statement information: row count ... other statement information items ... Condition area list: Condition area 1: error code for condition 1 error message for condition 1 ... other condition information items ... Condition area 2: error code for condition 2: error message for condition 2 ... other condition information items ... Condition area 3: error code for condition 3 error message for condition 3 ... other condition information items ...
NULL
NUMBER
ROW_COUNT
ROW_COUNT()
NUMBER
MYSQL_ERRNO
SIGNAL
RESIGNAL
CLASS_ORIGIN
RETURNED_SQLSTATE
'ISO
9075'
'MySQL'
SUBCLASS_ORIGIN
CLASS_ORIGIN
RETURNED_SQLSTATE
SUBCLASS_ORIGIN
SUBCLASS_ORIGIN
RETURNED_SQLSTATE
MESSAGE_TEXT
MYSQL_ERRNO
CONSTRAINT_CATALOG
CONSTRAINT_NAME
CATALOG_NAME
TABLE_NAME
CURSOR_NAME
RETURNED_SQLSTATE
MYSQL_ERRNO
SIGNAL
RESIGNAL
RETURNED_SQLSTATE
SIGNAL
SET
SIGNAL
SIGNAL
ROW_COUNT
SIGNAL
RESIGNAL
GET
DIAGNOSTICS
SHOW WARNINGS
SHOW ERRORS
SHOW
WARNINGS
SHOW
ERRORS
GET
DIAGNOSTICS
GET DIAGNOSTICS
RESIGNAL
SHOW
WARNINGS
DROP TABLE
MySQL的> DROP TABLE IF EXISTS test.no_such_table;
查询行,0行的影响,1报警(0.01秒)MySQL > SHOW WARNINGS;
------- ------ ------------------------------------ |水平|代码|消息| ------- ------ ------------------------------------ |注| 1051 |未知表”测试。no_such_table”| ------- ------ ------------------------------------ 1行集(0秒)
SET
MySQL的> SET @x = @@x;
错误1193(hy000):未知的系统变量的x'mysql > SHOW WARNINGS;
------- ------ ----------------------------- |水平|代码|消息| ------- ------ ----------------------------- |误差| 1193 |未知系统变量“X”| ------- ------ ----------------------------- 1行集(0秒)
SET
GET
DIAGNOSTICS
MySQL的> GET DIAGNOSTICS CONDITION 2 @p = MESSAGE_TEXT;
查询行,0行的影响,1报警(0秒)MySQL > SHOW WARNINGS;
------- ------ ------------------------------ |水平|代码|消息| ------- ------ ------------------------------ |误差| 1193 |未知系统变量'XX' | |误差| 1753年|无效的条件数| ------- ------ ------------------------------ 2行集(0.001秒)
GET DIAGNOSTICS
MySQL的> GET DIAGNOSTICS CONDITION 2 @p = MESSAGE_TEXT;
查询好,为受影响的行(0.001秒)MySQL > SELECT @p;
-------------------------- | @ P | -------------------------- |无效的条件数| -------------------------- 1行集(0.01秒)
RETURN
GET
[CURRENT] DIAGNOSTICS
GET
STACKED DIAGNOSTICS
RESIGNAL
RESIGNAL
RESIGNAL
RESIGNAL
max_error_count
RESIGNAL
warning_count
warning_count
max_error_count
warning_count
max_error_count
error_count
warning_count
max_error_count
sql_notes
warning_count
max_error_count
warning_count
error_count
max_error_count
max_error_count
mysql
read_only
CONNECTION_ADMIN
SUPER
ALTER USER [IF EXISTS]user
[auth_option
] [,user
[auth_option
]] ... [REQUIRE {NONE |tls_option
[[AND]tls_option
] ...}] [WITHresource_option
[resource_option
] ...] [password_option
|lock_option
] ... ALTER USER [IF EXISTS] USER() IDENTIFIED BY 'auth_string
' [REPLACE 'current_auth_string
'] ALTER USER [IF EXISTS]user
DEFAULT ROLE {NONE | ALL |role
[,role
] ...}user
: (see Section 6.2.4, “Specifying Account Names”)auth_option
: { IDENTIFIED BY 'auth_string
' [REPLACE 'current_auth_string
'] | IDENTIFIED WITHauth_plugin
| IDENTIFIED WITHauth_plugin
BY 'auth_string
' [REPLACE 'current_auth_string
'] | IDENTIFIED WITHauth_plugin
AS 'hash_string
' }tls_option
: { SSL | X509 | CIPHER 'cipher
' | ISSUER 'issuer
' | SUBJECT 'subject
' }resource_option
: { MAX_QUERIES_PER_HOURcount
| MAX_UPDATES_PER_HOURcount
| MAX_CONNECTIONS_PER_HOURcount
| MAX_USER_CONNECTIONScount
}password_option
: { PASSWORD EXPIRE [DEFAULT | NEVER | INTERVALN
DAY] | PASSWORD HISTORY {DEFAULT |N
} | PASSWORD REUSE INTERVAL {DEFAULT |N
DAY} | PASSWORD REQUIRE CURRENT [DEFAULT | OPTIONAL] }lock_option
: { ACCOUNT LOCK | ACCOUNT UNLOCK }
ALTER USER
ALTER USER
CREATE USER
UPDATE
CURRENT_USER()
选择current_user();
DEFAULT ROLE
ALTER USER
CREATE USER
UPDATE
read_only
ALTER USER
CONNECTION_ADMIN
SUPER
IF EXISTS
ALTER
USER
ALTER
USER
ALTER
USER
'%'
CURRENT_USER
CURRENT_USER()
USER()
修改用户user()经” auth_string
';
ALTER USER
auth_option
user
auth_option
auth_option
user
ALTER USER 'jeffrey'@'localhost'
IDENTIFIED BY 'new_password
' PASSWORD EXPIRE;
sha256_password
改变用户杰夫瑞'@'本地主机'确定' sha256_password new_password
“密码过期间隔180天;
ALTER USER 'jeffrey'@'localhost' ACCOUNT LOCK; ALTER USER 'jeffrey'@'localhost' ACCOUNT UNLOCK;
ALTER USER 'jeffrey'@'localhost' REQUIRE SSL WITH MAX_CONNECTIONS_PER_HOUR 20;
ALTER USER
'jeffrey'@'localhost' IDENTIFIED BY 'new_password
',
'jeanne'@'localhost'
REQUIRE SSL WITH MAX_USER_CONNECTIONS 2
PASSWORD HISTORY 5;
auth_option
IDENTIFIED BY
jeanne
auth_option
auth_plugin
mysql.user
auth_option
default_authentication_plugin
authentication_string
'
auth_string
'hash_string
'
auth_string
'
'
hash_string
'
REPLACE
'
current_auth_string
'
REPLACE
ALTER USER
auth_option
IDENTIFIED BY
'
auth_string
' [REPLACE
'current_auth_string
']
'
auth_string
'
REPLACE
IDENTIFIED WITH
auth_plugin
auth_plugin
IDENTIFIED WITH
auth_plugin
BY
'auth_string
' [REPLACE
'current_auth_string
']
auth_plugin
auth_string
REPLACE
IDENTIFIED WITH
auth_plugin
AS
'hash_string
'
auth_plugin
hash_string
ALTER USER 'jeffrey'@'localhost'
IDENTIFIED BY 'password
';
ALTER USER 'jeffrey'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'password
';
ALTER USER 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password
' REPLACE 'current_password
';
jeffrey
ALTER USER 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4';
ALTER USER ...
DEFAULT ROLE
SET ROLE
DEFAULT
ALTER USER ...
DEFAULT ROLE
SET DEFAULT ROLE
ALTER USER
SET
DEFAULT ROLE
ALTER USER
SET DEFAULT
ROLE
ALTER USER 'joe'@'10.0.0.1' DEFAULT ROLE administrator, developer;
'%'
DEFAULT ROLE
NONE
ALL
role
[,
role
] ...ALTER USER ...
DEFAULT ROLE
REQUIRE
tls_option
REQUIRE
REQUIRE
ALTER USER
tls_option
NONE
ALTER USER 'jeffrey'@'localhost' REQUIRE NONE;
REQUIRE
NONE
--ssl-mode=REQUIRED
SSL
ALTER USER 'jeffrey'@'localhost' REQUIRE SSL;
REQUIRE
SSL
X509
SSL
改变user’杰弗里@ localhost”需要X509;
REQUIRE X509
--ssl-key
--ssl-cert
--ssl-ca
SUBJECT
X509
ISSUER
'
issuer
'
'
issuer
'
ALTER USER 'jeffrey'@'localhost' REQUIRE ISSUER '/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL/CN=CA/emailAddress=ca@example.com';
ISSUER
--ssl-key
--ssl-cert
--ssl-ca
SUBJECT
'
subject
'
subject
ALTER USER 'jeffrey'@'localhost' REQUIRE SUBJECT '/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL demo client certificate/ CN=client/emailAddress=client@example.com';
'
subject
'
SUBJECT
--ssl-key
--ssl-cert
--ssl-ca
CIPHER
'
cipher
'
ALTER USER 'jeffrey'@'localhost' REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA';
SUBJECT
CIPHER
ALTER USER 'jeffrey'@'localhost' REQUIRE SUBJECT '/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL demo client certificate/ CN=client/emailAddress=client@example.com' AND ISSUER '/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL/CN=CA/emailAddress=ca@example.com' AND CIPHER 'EDH-RSA-DES-CBC3-SHA';
WITH
resource_option
WITH
ALTER USER
resource_option
MAX_QUERIES_PER_HOUR
count
count
count
count
MAX_USER_CONNECTIONS
count
count
count
max_user_connections
max_user_connections
ALTER USER 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 500 MAX_UPDATES_PER_HOUR 100;
ALTER USER
password_option
mysql.user
sha256_password
ALTER USER
password_option
PASSWORD EXPIRE
ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE;
PASSWORD EXPIRE DEFAULT
default_password_lifetime
“杰夫”修改用户的密码默认localhost,呼气;
PASSWORD EXPIRE NEVER
ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;
PASSWORD EXPIRE INTERVAL
N
DAY
N
改变用户的密码是“localhost是Jeffrey expire间隔180天;
ALTER USER
password_option
PASSWORD HISTORY DEFAULT
password_history
改变用户的密码是“localhost是Jeffrey历史违约;
PASSWORD HISTORY
N
N
N
更改用户的密码。“localhost”的历史。
ALTER USER
password_option
PASSWORD REUSE INTERVAL DEFAULT
password_reuse_interval
杰弗里的老用户“localhost密码复用间隔违约;
PASSWORD REUSE INTERVAL
N
DAY
N
杰弗里的老用户“localhost密码复用间隔360天;
ALTER USER
password_option
PASSWORD REQUIRE CURRENT
ALTER USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT;
PASSWORD REQUIRE CURRENT OPTIONAL
ALTER USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT OPTIONAL;
PASSWORD REQUIRE CURRENT DEFAULT
password_require_current
“杰夫”修改用户的密码默认使用localhost的电流;
PASSWORD EXPIRE
PASSWORD REUSE INTERVAL
ALTER USER
CREATE ROLE [IF NOT EXISTS]role
[,role
] ...
CREATE ROLE
CREATE
ROLE
CREATE USER
read_only
CREATE
ROLE
CONNECTION_ADMIN
SUPER
CREATE ROLE
IF NOT EXISTS
CREATE ROLE 'administrator', 'developer'; CREATE ROLE 'webapp'@'localhost';
'%'
CREATE USER [IF NOT EXISTS]user
[auth_option
] [,user
[auth_option
]] ... DEFAULT ROLErole
[,role
] ... [REQUIRE {NONE |tls_option
[[AND]tls_option
] ...}] [WITHresource_option
[resource_option
] ...] [password_option
|lock_option
] ...user
: (see Section 6.2.4, “Specifying Account Names”)auth_option
: { IDENTIFIED BY 'auth_string
' | IDENTIFIED WITHauth_plugin
| IDENTIFIED WITHauth_plugin
BY 'auth_string
' | IDENTIFIED WITHauth_plugin
AS 'hash_string
' }tls_option
: { SSL | X509 | CIPHER 'cipher
' | ISSUER 'issuer
' | SUBJECT 'subject
' }resource_option
: { MAX_QUERIES_PER_HOURcount
| MAX_UPDATES_PER_HOURcount
| MAX_CONNECTIONS_PER_HOURcount
| MAX_USER_CONNECTIONScount
}password_option
: { PASSWORD EXPIRE [DEFAULT | NEVER | INTERVALN
DAY] | PASSWORD HISTORY {DEFAULT |N
} | PASSWORD REUSE INTERVAL {DEFAULT |N
DAY} | PASSWORD REQUIRE CURRENT [DEFAULT | OPTIONAL] }lock_option
: { ACCOUNT LOCK | ACCOUNT UNLOCK }
CREATE USER
CREATE USER
CREATE USER
INSERT
read_only
CREATE USER
CONNECTION_ADMIN
SUPER
CREATE USER
CREATE
USER
CREATE
USER
CREATE USER
default_authentication_plugin
NONE
NONE
PASSWORD EXPIRE DEFAULT
PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
PASSWORD REQUIRE CURRENT DEFAULT
ACCOUNT UNLOCK
NONE
GRANT
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password
';
'%'
user
auth_option
auth_option
user
CREATE USER 'jeffrey'@'localhost'
IDENTIFIED BY 'new_password
' PASSWORD EXPIRE;
sha256_password
创建用户杰夫瑞'@'本地主机'确定' sha256_password new_password
“密码过期间隔180天;
CREATE USER 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password1
', 'jeanne'@'localhost' IDENTIFIED WITH sha256_password BY 'new_password2
' REQUIRE X509 WITH MAX_QUERIES_PER_HOUR 60 PASSWORD HISTORY 5 ACCOUNT LOCK;
auth_option
auth_option
auth_plugin
mysql.user
auth_option
default_authentication_plugin
authentication_string
'
auth_string
'hash_string
'
auth_string
'
'
hash_string
'
CREATE USER
auth_option
IDENTIFIED BY
'
auth_string
'
'
auth_string
'
IDENTIFIED WITH
auth_plugin
auth_plugin
IDENTIFIED WITH
auth_plugin
BY
'auth_string
'
auth_plugin
auth_string
IDENTIFIED WITH
auth_plugin
AS
'hash_string
'
auth_plugin
hash_string
CREATE USER 'jeffrey'@'localhost'
IDENTIFIED BY 'password
';
CREATE USER 'jeffrey'@'localhost'
IDENTIFIED WITH mysql_native_password BY 'password
';
'
password
'
DEFAULT ROLE
SET ROLE
DEFAULT
CREATE USER 'joe'@'10.0.0.1' DEFAULT ROLE administrator, developer;
'%'
DEFAULT ROLE
CREATE USER
REQUIRE
tls_option
REQUIRE
REQUIRE
CREATE USER
tls_option
NONE
CREATE USER 'jeffrey'@'localhost' REQUIRE NONE;
REQUIRE
NONE
--ssl-mode=REQUIRED
NONE
SSL
CREATE USER 'jeffrey'@'localhost' REQUIRE SSL;
REQUIRE
SSL
X509
SSL
2 . create user ' Jeffrey ' @ ' ilamhost require XIV;
REQUIRE X509
--ssl-key
--ssl-cert
--ssl-ca
SUBJECT
X509
ISSUER
'
issuer
'
'
issuer
'
CREATE USER 'jeffrey'@'localhost' REQUIRE ISSUER '/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL/CN=CA/emailAddress=ca@example.com';
ISSUER
--ssl-key
--ssl-cert
--ssl-ca
SUBJECT
'
subject
'
subject
CREATE USER 'jeffrey'@'localhost' REQUIRE SUBJECT '/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL demo client certificate/ CN=client/emailAddress=client@example.com';
'
subject
'
SUBJECT
--ssl-key
--ssl-cert
--ssl-ca
CIPHER
'
cipher
'
CREATE USER 'jeffrey'@'localhost' REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA';
SUBJECT
CIPHER
CREATE USER 'jeffrey'@'localhost' REQUIRE SUBJECT '/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL demo client certificate/ CN=client/emailAddress=client@example.com' AND ISSUER '/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL/CN=CA/emailAddress=ca@example.com' AND CIPHER 'EDH-RSA-DES-CBC3-SHA';
WITH
resource_option
WITH
CREATE USER
resource_option
MAX_QUERIES_PER_HOUR
count
count
count
count
MAX_USER_CONNECTIONS
count
count
count
max_user_connections
max_user_connections
CREATE USER 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 500 MAX_UPDATES_PER_HOUR 100;
CREATE USER
password_option
mysql.user
sha256_password
CREATE USER
password_option
PASSWORD EXPIRE
CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE;
PASSWORD EXPIRE DEFAULT
default_password_lifetime
用户创建的密码是“localhost Jeffrey expire是默认的;
PASSWORD EXPIRE NEVER
CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;
PASSWORD EXPIRE INTERVAL
N
DAY
N
用户创建的密码是“localhost是Jeffrey expire间隔180天;
CREATE USER
password_option
PASSWORD HISTORY DEFAULT
password_history
用户创建的密码是“localhost是Jeffrey历史违约;
PASSWORD HISTORY
N
N
N
用户创建的密码是“localhost是Jeffrey历史6;
CREATE USER
password_option
PASSWORD REUSE INTERVAL DEFAULT
password_reuse_interval
Jeffrey:创建用户密码复用间隔localhost违约;
PASSWORD REUSE INTERVAL
N
DAY
N
创建用户密码(Jeffrey“localhost复用间隔360天;
CREATE USER
password_option
PASSWORD REQUIRE CURRENT
CREATE USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT;
PASSWORD REQUIRE CURRENT OPTIONAL
CREATE USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT OPTIONAL;
PASSWORD REQUIRE CURRENT DEFAULT
password_require_current
用户创建的密码是“localhost是Jeffrey require默认流;
PASSWORD EXPIRE
PASSWORD REUSE INTERVAL
CREATE USER
u1
DROP ROLE [IF EXISTS]role
[,role
] ...
DROP ROLE
DROP
ROLE
CREATE USER
read_only
DROP
ROLE
CONNECTION_ADMIN
SUPER
mandatory_roles
DROP ROLE
IF EXISTS
DROP ROLE 'administrator', 'developer'; DROP ROLE 'webapp'@'localhost';
'%'
DROP USER [IF EXISTS]user
[,user
] ...
DROP USER
mandatory_roles
DROP USER
CREATE USER
DELETE
read_only
DROP USER
CONNECTION_ADMIN
SUPER
DROP USER
IF EXISTS
DROP USER 'jeffrey'@'localhost';
'%'
DROP USER
DROP USER
GRANTpriv_type
[(column_list
)] [,priv_type
[(column_list
)]] ... ON [object_type
]priv_level
TOuser_or_role
[,user_or_role
] ... [WITH GRANT OPTION] GRANT PROXY ONuser_or_role
TOuser_or_role
[,user_or_role
] ... [WITH GRANT OPTION] GRANTrole
[,role
] ... TOuser_or_role
[,user_or_role
] ... [WITH ADMIN OPTION]object_type
: { TABLE | FUNCTION | PROCEDURE }priv_level
: { * | *.* |db_name
.* |db_name.tbl_name
|tbl_name
|db_name
.routine_name
}user_or_role
: {user
|role
}user
: (see Section 6.2.4, “Specifying Account Names”)role
: (see Section 6.2.5, “Specifying Role Names”)
GRANT
GRANT
GRANT
GRANT
GRANT
GRANT OPTION
read_only
GRANT
CONNECTION_ADMIN
SUPER
GRANT
REVOKE
GRANT
GRANT ALL ON db1.* TO 'jeffrey'@'localhost'; GRANT 'role1', 'role2' TO 'user1'@'localhost', 'user2'@'localhost'; GRANT SELECT ON world.* TO 'role3';
'%'
CREATE USER
GRANT
ALTER USER
创建用户杰夫瑞'@'本地主机'确定' password
';授予所有在DB1。*杰夫瑞'@'本地主机';'杰夫瑞格兰特选择db2.invoice '@'本地主机';改变用户杰夫瑞'@'本地主机'与max_queries_per_hour 90;
GRANT
SHOW GRANTS
GRANT
GRANT
mysql.user
GRANT
user_name
host_name
user_name
host_name
'test-user'@'%.com'
_
GRANT
db_name
\_
GRANT
GRANT ... ON
db_name
.tbl_name
user
GRANT
user
user_name
host_name
'
user_name
'@'%.example.com'user_name
'
user_name
'@'198.51.100.%'user_name
'
user_name
'user_name
GRANT
授予所有测试。*“'@'本地主机'…;
'
user_name
'@'localhost'mysql.user
SELECT Host, User FROM mysql.user WHERE User='';
DROP USER ''@'localhost';
priv_type
GRANT
REVOKE
ALL [PRIVILEGES] | GRANT OPTION PROXY |
ALTER | ALTER TABLE |
ALTER ROUTINE | |
CREATE | |
CREATE ROUTINE | |
CREATE TABLESPACE | |
CREATE TEMPORARY TABLES | CREATE
TEMPORARY TABLE |
CREATE USER | CREATE USER DROP USER RENAME USER REVOKE ALL
PRIVILEGES |
CREATE VIEW | |
DELETE | DELETE |
DROP | |
EVENT | |
EXECUTE | |
FILE | |
GRANT OPTION | |
INDEX | |
INSERT | INSERT |
LOCK TABLES | LOCK TABLES SELECT |
PROCESS | SHOW
PROCESSLIST |
PROXY | |
REFERENCES | |
RELOAD | FLUSH |
REPLICATION CLIENT | |
REPLICATION SLAVE | |
SELECT | SELECT |
SHOW DATABASES | SHOW DATABASES |
SHOW VIEW | SHOW CREATE VIEW |
SHUTDOWN | |
SUPER | CHANGE MASTER TO KILL PURGE BINARY LOGS SET
GLOBAL |
TRIGGER | |
UPDATE | UPDATE |
USAGE |
AUDIT_ADMIN | |
BINLOG_ADMIN | |
CONNECTION_ADMIN | |
ENCRYPTION_KEY_ADMIN | InnoDB |
FIREWALL_ADMIN | |
FIREWALL_USER | |
GROUP_REPLICATION_ADMIN | |
REPLICATION_SLAVE_ADMIN | |
ROLE_ADMIN | WITH ADMIN OPTION |
SET_USER_ID | DEFINER |
SYSTEM_VARIABLES_ADMIN | |
VERSION_TOKEN_ADMIN |
TRIGGER
GRANT
ALL
[PRIVILEGES]
PROXY
ALL
[PRIVILEGES]
GRANT OPTION
PROXY
mysql
mysql
lower_case_table_names
REVOKE
GRANT
lower_case_table_names
lower_case_table_names
ON
REVOKE
GRANT ALL
db_name
FILE
ALL
GRANT OPTION
PROXY
object_type
FUNCTION
OR
SELECT
CREATE
ON *.*
授予所有*。*”“”“someuser 'somehost;查询、插入*。*”“”“someuser 'somehost;
CREATE TABLESPACE
CREATE USER
FILE
PROCESS
RELOAD
REPLICATION CLIENT
REPLICATION SLAVE
SHOW DATABASES
SHUTDOWN
SUPER
GRANT OPTION
GRANT OPTION
GRANT OPTION
GRANT ALL
mysql.user
ON
db_name
.*
授予所有操作*”“”“someuser 'somehost;查询、插入操作*”“”“someuser 'somehost;
ON *
CREATE
DROP
EVENT
GRANT OPTION
LOCK TABLES
REFERENCES
mysql.db
ON
db_name.tbl_name
给予所有对mydb.mytbl ' someuser”@ 'somehost”;查询、插入mydb.mytbl ' someuser”@ 'somehost”;
tbl_name
db_name.tbl_name
tbl_name
priv_type
ALTER
CREATE VIEW
CREATE
DELETE
DROP
GRANT OPTION
INDEX
INSERT
REFERENCES
SELECT
SHOW VIEW
TRIGGER
UPDATE
CREATE
TEMPORARY TABLE
mysql.tables_priv
GRANT SELECT (col1), INSERT (col1, col2) ON mydb.mytbl TO 'someuser'@'somehost';
priv_type
column_list
INSERT
REFERENCES
SELECT
UPDATE
mysql.columns_priv
ALTER ROUTINE
CREATE ROUTINE
EXECUTE
GRANT OPTION
CREATE ROUTINE
授予创建常规操作*的someuser”@ 'somehost”;授予执行程序mydb.myproc ' someuser”@ 'somehost”;
priv_type
ALTER
ROUTINE
EXECUTE
GRANT OPTION
CREATE ROUTINE
mysql.procs_priv
PROXY
格兰特在localuser代理“localhost externaluser somehost“@”;
PROXY
GRANT
WITH
GRANT OPTION
PROXY
mysql.proxies_priv
GRANT
GRANT 'role1', 'role2' TO 'user1'@'localhost', 'user2'@'localhost';
GRANT
WITH ADMIN OPTION
GRANT
CREATE USER 'u1', 'u2';CREATE ROLE 'r1', 'r2';GRANT 'u1' TO 'u1'; -- simple loop: u1 => u1GRANT 'r1' TO 'r1'; -- simple loop: r1 => r1GRANT 'r2' TO 'u2';GRANT 'u2' TO 'r2'; -- mixed user/role loop: u2 => r2 => u2
WITH
GRANT OPTION
使用*格兰特。*”“”“someuser 'somehost授予期权;
GRANT
OPTION
GRANT OPTION
GRANT OPTION
INSERT
SELECT
SELECT
INSERT
UPDATE
INSERT
SELECT
UPDATE
ALTER
GRANT
UNDER
DROP USER
DROP USER
REVOKE
INSERT
INSERT
INSERT
INSERT
RENAME USERold_user
TOnew_user
[,old_user
TOnew_user
] ...
RENAME USER
RENAME USER
CREATE USER
UPDATE
read_only
RENAME USER
CONNECTION_ADMIN
SUPER
RENAME USER 'jeffrey'@'localhost' TO 'jeff'@'127.0.0.1';
'%'
RENAME USER
RENAME USER
REVOKEpriv_type
[(column_list
)] [,priv_type
[(column_list
)]] ... ON [object_type
]priv_level
FROMuser_or_role
[,user_or_role
] ... REVOKE ALL [PRIVILEGES], GRANT OPTION FROMuser_or_role
[,user_or_role
] ... REVOKE PROXY ONuser_or_role
FROMuser_or_role
[,user_or_role
] ... REVOKErole
[,role
] ... FROMuser_or_role
[,user_or_role
] ...user_or_role
: {user
|role
}user
: (see Section 6.2.4, “Specifying Account Names”)role
: (see Section 6.2.5, “Specifying Role Names”.
REVOKE
read_only
REVOKE
CONNECTION_ADMIN
SUPER
REVOKE
REVOKE INSERT ON *.* FROM 'jeffrey'@'localhost'; REVOKE 'role1', 'role2' FROM 'user1'@'localhost', 'user2'@'localhost'; REVOKE SELECT ON world.* FROM 'role3';
'%'
priv_type
priv_level
object_type
REVOKE
GRANT OPTION
REVOKE ALL PRIVILEGES, GRANT OPTION FROMuser_or_role
[,user_or_role
] ...
REVOKE ALL PRIVILEGES, GRANT OPTION
REVOKE
CREATE USER
UPDATE
REVOKE
mandatory_roles
SELECT
REVOKE ALL ON *.*
REVOKE
DROP
USER
lower_case_table_names
REVOKE
GRANT
lower_case_table_names
lower_case_table_names
REVOKE
SHOW GRANTS
SET DEFAULT ROLE {NONE | ALL |role
[,role
] ...} TOuser
[,user
] ...
user
SET ROLE
DEFAULT
SET DEFAULT ROLE
ALTER
USER ... DEFAULT ROLE
ALTER USER
SET DEFAULT
ROLE
ALTER USER
SET
DEFAULT ROLE
SET DEFAULT ROLE
CREATE USER
UPDATE
SET DEFAULT ROLE administrator, developer TO 'joe'@'10.0.0.1';
'%'
DEFAULT ROLE
NONE
ALL
role
[,
role
] ...SET
DEFAULT ROLE
SET DEFAULT ROLE
SET ROLE
DEFAULT
SET DEFAULT ROLE
SET ROLE
DEFAULT
SET PASSWORD [FORuser
] = 'auth_string
' [REPLACE 'current_auth_string
']
SET PASSWORD
auth_string
REPLACE
REPLACE
SET PASSWORD ...
= '
auth_string
'ALTER USER
修改用户 user
经” auth_string
';
SET
PASSWORD
SET PASSWORD
FOR
user
SET PASSWORD FOR 'jeffrey'@'localhost' = 'auth_string
';
FOR
user
SET PASSWORD = 'auth_string
';
CURRENT_USER()
选择current_user();
REPLACE
FOR
UPDATE
FOR
read_only
SET PASSWORD
CONNECTION_ADMIN
SUPER
FOR
user
SET PASSWORD FOR 'bob'@'%.example.org' = 'auth_string
';
'%'
SET PASSWORD
SET ROLE { DEFAULT | NONE | ALL | ALL EXCEPTrole
[,role
] ... |role
[,role
] ... }
SET ROLE
mandatory_roles
SET ROLE DEFAULT; SET ROLE 'role1', 'role2'; SET ROLE ALL; SET ROLE ALL EXCEPT 'role1', 'role2';
'%'
DEFAULT
SET DEFAULT ROLE
activate_all_roles_on_login
SET ROLE
DEFAULT
SET ROLE
DEFAULT
NONE
ALL
ALL EXCEPT
role
[,
role
] ...
role
[,
role
] ...
SET DEFAULT ROLE
SET ROLE
DEFAULT
SET DEFAULT ROLE
SET ROLE
DEFAULT
ALTER RESOURCE GROUPgroup_name
[VCPU [=]vcpu_spec
[,vcpu_spec
] ...] [THREAD_PRIORITY [=]N
] [ENABLE|DISABLE [FORCE]]vcpu_spec
: {N
|M
-N
}
ALTER RESOURCE GROUP
RESOURCE_GROUP_ADMIN
group_name
ALTER
RESOURCE GROUP
CREATE RESOURCE
GROUP
FORCE
FORCE
FORCE
USR_default
ALTER
RESOURCE GROUP
ALTER RESOURCE GROUP rg1 VCPU = 0-63;
ALTER RESOURCE GROUP rg2 THREAD_PRIORITY = 5;
ALTER RESOURCE GROUP rg3 DISABLE FORCE;
ALTER RESOURCE GROUP
CREATE RESOURCE GROUPgroup_name
TYPE = {SYSTEM|USER} [VCPU [=]vcpu_spec
[,vcpu_spec
] ...] [THREAD_PRIORITY [=]N
] [ENABLE|DISABLE]vcpu_spec
: {N
|M
-N
}
CREATE RESOURCE GROUP
RESOURCE_GROUP_ADMIN
group_name
TYPE
USER
VCPU
VCPU
VCPU
M
N
M
N
VCPU
VCPU = 0,1,2,3,9,10VCPU = 0-3,9-10VCPU = 9,10,0-3VCPU = 0,10,1,9,3,2
THREAD_PRIORITY
THREAD_PRIORITY
THREAD_PRIORITY
ENABLE
CREATE RESOURCE GROUP rg1 TYPE = USER VCPU = 0 THREAD_PRIORITY = 19;
CREATE RESOURCE GROUP rg2 TYPE = SYSTEM THREAD_PRIORITY = -20 DISABLE;
CREATE RESOURCE GROUP
DROP RESOURCE GROUP group_name
[FORCE]
DROP RESOURCE GROUP
RESOURCE_GROUP_ADMIN
group_name
FORCE
FORCE
FORCE
USR_default
DROP RESOURCE GROUP rg1;
DROP RESOURCE GROUP rg2 FORCE;
DROP RESOURCE GROUP
SET RESOURCE GROUPgroup_name
[FORthread_id
[,thread_id
] ...]
SET RESOURCE GROUP
RESOURCE_GROUP_ADMIN
RESOURCE_GROUP_USER
group_name
thread_id
threads
FOR
FOR
SET RESOURCE GROUP rg1;
SET RESOURCE GROUP rg2 FOR 14, 78, 4;
SET RESOURCE GROUP
SET RESOURCE
GROUP
ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLEtbl_name
[,tbl_name
] ... ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLEtbl_name
UPDATE HISTOGRAM ONcol_name
[,col_name
] ... [WITHN
BUCKETS] ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLEtbl_name
DROP HISTOGRAM ONcol_name
[,col_name
] ...
ANALYZE TABLE
ANALYZE TABLE
MyISAM
ANALYZE TABLE
ANALYZE TABLE
ANALYZE TABLE
innodb_read_only
ANALYZE
TABLE
ANALYZE
TABLE
information_schema_stats_expiry=0
SELECT
INSERT
ANALYZE TABLE
NDB
ANALYZE TABLE
InnoDB
ANALYZE
TABLE
LOCAL
ANALYZE TABLE
Table | |
Op | analyze
|
Msg_type | status
info
warning |
Msg_text |
ANALYZE TABLE
InnoDB
innodb_stats_persistent
ANALYZE
TABLE
SHOW INDEX
INFORMATION_SCHEMA.STATISTICS
ANALYZE TABLE
ANALYZE TABLE
WITH
N
BUCKETSN
ANALYZE TABLE
ANALYZE TABLE t UPDATE HISTOGRAM ON c1, c2, c3 WITH 10 BUCKETS; ANALYZE TABLE t UPDATE HISTOGRAM ON c1, c3 WITH 10 BUCKETS; ANALYZE TABLE t DROP HISTOGRAM ON c2;
c1
c3
c3
c2
c3
TEMPORARY
JSON
UPDATE
HISTOGRAM
histogram_generation_max_mem_size
SYSTEM_VARIABLES_ADMIN
SUPER
memory/sql/histograms
DROP TABLE
DROP DATABASE
RENAME TABLE
ALTER TABLE
ALTER TABLE
... CONVERT TO CHARACTER SET
CHECK TABLEtbl_name
[,tbl_name
] ... [option
] ...option
= { FOR UPGRADE | QUICK | FAST | MEDIUM | EXTENDED | CHANGED }
CHECK TABLE
CHECK TABLE
CHECK TABLE
InnoDB
MyISAM
ARCHIVE
CSV
CHECK TABLE
CHECK TABLE
CHECK TABLE
CHECK TABLE
Table | |
Op | check |
Msg_type | status
info
warning |
Msg_text |
Msg_type
Msg_text
Table is already up to
date
FOR UPGRADE
FOR UPGRADE
TEXT
MyISAM
DECIMAL
YEAR(2)
YEAR(2)
CHECK TABLE
REPAIR TABLE
YEAR(2)
YEAR(4)
TIME
DATETIME
TIMESTAMP
avoid_temporal_upgrade
avoid_temporal_upgrade
avoid_temporal_upgrade
CHECK TABLE
... FOR UPGRADE
QUICK | InnoDB
|
FAST | InnoDB
|
CHANGED | InnoDB
|
MEDIUM | InnoDB
|
EXTENDED | InnoDB
|
CHECK TABLE test_table FAST QUICK;
CHECK TABLE
CHECK TABLE
QUICK
FAST
FAST
MyISAM
EXTENDED
CHECK
TABLE ... EXTENDED
CHECK
TABLE
Found row where the auto_increment column has the
value 0
AUTO_INCREMENT
UPDATE
ALTER TABLE
AUTO_INCREMENT
UPDATE
InnoDB
CHECK TABLE
CHECK TABLE
CHECK TABLE
DB_ROLL_PTR
CHECK TABLE
CHECK TABLE
CHECK TABLE
CHECK TABLE
BLOB
InnoDB
.ibd
.ibd
CHECK TABLE
.ibd
CHECK TABLE
CHECK
TABLE
CHECK
TABLE
InnoDB
CHECK TABLE
QUICK
CHECK
TABLE
CHECK TABLE
SPATIAL
CHECK TABLE
MyISAM
CHECK TABLE
CHECK TABLE
Table is
already up to date
CHECK TABLE
MEDIUM
MyISAM
tbl_name
MyISAM
FAST
CHANGED
CHECKSUM TABLEtbl_name
[,tbl_name
] ... [QUICK | EXTENDED]
CHECKSUM TABLE
SELECT
CHECKSUM TABLE
NULL
CHECKSUM
TABLE
InnoDB
EXTENDED
MyISAM
CHECKSUM=1
MyISAM
CHECKSUM=1
CHECKSUM TABLE
CHECKSUM TABLE
... QUICK
QUICK
QUICK
CHECKSUM
TIME
DATETIME
TIMESTAMP
CHECKSUM TABLE
OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLEtbl_name
[,tbl_name
] ...
OPTIMIZE TABLE
OPTIMIZE TABLE
InnoDB
innodb_file_per_table
FULLTEXT
innodb_optimize_fulltext_only=1
innodb_ft_num_word_optimize
MyISAM
MyISAM
VARCHAR
VARBINARY
BLOB
TEXT
INSERT
OPTIMIZE
TABLE
SELECT
INSERT
OPTIMIZE TABLE
InnoDB
MyISAM
ARCHIVE
OPTIMIZE TABLE
OPTIMIZE
TABLE
--skip-new
OPTIMIZE
TABLE
ALTER
TABLE
OPTIMIZE TABLE
OPTIMIZE
TABLE
LOCAL
OPTIMIZE TABLE
Table | |
Op | optimize |
Msg_type | status
info
warning |
Msg_text |
OPTIMIZE TABLE
.MYI
OPTIMIZE TABLE
root
InnoDB
OPTIMIZE TABLE
ALTER TABLE ...
FORCE
OPTIMIZE
TABLE
mysql> OPTIMIZE TABLE foo; +----------+----------+----------+-------------------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +----------+----------+----------+-------------------------------------------------------------------+ | test.foo | optimize | note | Table does not support optimize, doing recreate + analyze instead | | test.foo | optimize | status | OK | +----------+----------+----------+-------------------------------------------------------------------+
OPTIMIZE TABLE
InnoDB
OPTIMIZE
TABLE
ALTER TABLE ...
FORCE
OPTIMIZE TABLE
old_alter_table
--skip-new
OPTIMIZE TABLE
InnoDB
InnoDB
InnoDB
InnoDB
OPTIMIZE TABLE
OPTIMIZE
TABLE
OPTIMIZE TABLE
REPAIR [NO_WRITE_TO_BINLOG | LOCAL] TABLEtbl_name
[,tbl_name
] ... [QUICK] [EXTENDED] [USE_FRM]
REPAIR TABLE
SELECT
INSERT
REPAIR TABLE
REPAIR TABLE
REPAIR TABLE
CHECK TABLE ... FOR
UPGRADE
REPAIR
TABLE
REPAIR TABLE
REPAIR TABLE
REPAIR TABLE
MyISAM
ARCHIVE
CSV
MyISAM
tbl_name
REPAIR TABLE
ALTER TABLE ... REPAIR
PARTITION
NO_WRITE_TO_BINLOG
REPAIR
TABLE
LOCAL
QUICK
QUICK
REPAIR TABLE
EXTENDED
EXTENDED
USE_FRM
USE_FRM
.MYI
USE_FRM
REPAIR
.MYI
AUTO_INCREMENT
.MYI
USE_FRM
REPAIR TABLE
REPAIR
TABLE
error
Failed
repairing incompatible .FRM file
USE_FRM
REPAIR TABLE
REPAIR TABLE
Table | |
Op | repair |
Msg_type | status
info
warning |
Msg_text |
REPAIR TABLE
status
OK
OK
REPAIR TABLE
REPAIR TABLE
--max-record-length
REPAIR TABLE
.MYI
REPAIR TABLE
root
REPAIR TABLE
TIME
DATETIME
TIMESTAMP
avoid_temporal_upgrade
avoid_temporal_upgrade
REPAIR TABLE
avoid_temporal_upgrade
REPAIR TABLE
REPAIR
TABLE
CREATE [AGGREGATE] FUNCTIONfunction_name
RETURNS {STRING|INTEGER|REAL|DECIMAL} SONAMEshared_library_name
ABS()
CONCAT()
function_name
DECIMAL
DECIMAL
shared_library_name
plugin_dir
INSERT
CREATE FUNCTION
CREATE
FUNCTION
user_defined_functions
CREATE FUNCTION
DROP FUNCTION
--skip-grant-tables
AGGREGATE
COUNT()
mysql.func
mysql.func
DROP FUNCTION
CREATE FUNCTION
DROP FUNCTION
DROP FUNCTION function_name
function_name
DELETE
DROP FUNCTION
DROP FUNCTION
CREATE FUNCTION
DROP FUNCTION
DROP FUNCTION
INSTALL COMPONENTcomponent_name
[,component_name
] ...
INSTALL COMPONENT
INSERT
INSTALL COMPONENT 'file://component1', 'file://component2';
file://
plugin_dir
.dll
mysql.component
--skip-grant-tables
ERROR 3527 (HY000): Cannot satisfy dependency for service 'component_a' required by component 'component_b'.
INSTALL PLUGINplugin_name
SONAME 'shared_library_name
'
INSERT
plugin_name
shared_library_name
libmyplugin.dll
plugin_dir
plugin_dir
pkglibdir
plugin_dir
[mysqld]
plugin_dir=/path/to/plugin/directory
plugin_dir
basedir
INSTALL PLUGIN
INSTALL PLUGIN
mysql.plugin
INSTALL PLUGIN
--skip-grant-tables
INSTALL
PLUGIN
INSTALL PLUGIN
loose
--skip-grant-tables
--plugin-load
UNINSTALL
PLUGIN
SHOW PLUGINS
INFORMATION_SCHEMA.PLUGINS
UNINSTALL PLUGIN
INSTALL PLUGIN
INSTALL PLUGIN
UNINSTALL PLUGIN
UNINSTALL COMPONENTcomponent_name
[,component_name
] ...
UNINSTALL COMPONENT
INSTALL COMPONENT
DELETE
UNINSTALL COMPONENT 'file://component1', 'file://component2';
mysql.component
UNINSTALL PLUGIN plugin_name
DELETE
UNINSTALL PLUGIN
INSTALL PLUGIN
plugin_name
mysql.plugin
UNINSTALL PLUGIN
FULLTEXT
WITH PARSER
CREATE TABLE
DROP TABLE
SET
SET
var_name
=
value
SET CHARACTER SET
SET NAMES
SET DEFAULT ROLE
SET ROLE
SET PASSWORD
SET RESOURCE GROUP
SET
TRANSACTION ISOLATION LEVEL
SETvariable_assignment
[,variable_assignment
] ...variable_assignment
:user_var_name
=expr
|param_name
=expr
|local_var_name
=expr
| [GLOBAL | SESSION | PERSIST | PERSIST_ONLY]system_var_name
=expr
| [@@global. | @@session. | @@persist. | @@persist_only. | @@]system_var_name
=expr
SET
SHOW
VARIABLES
log_filter_dragnet
dragnet.log_error_filter_rules
SET
SET
=
:=
@
var_name
设置” var_name
=expr
;
SET @name = 43; SET @total_tax = (SELECT SUM(tax) FROM taxable_transactions);
expr
SET
CREATE PROCEDURE p() BEGIN DECLARE counter INT DEFAULT 0; WHILE counter < 10 DO -- ... do work ... SET counter = counter + 1; END WHILE; END;
SET
SET
GLOBAL
SET GLOBAL max_connections = 1000; SET @@global.max_connections = 1000;
SYSTEM_VARIABLES_ADMIN
SUPER
PERSIST
SET PERSIST max_connections = 1000; SET @@persist.max_connections = 1000;
SET
SET
GLOBAL
SET
PERSIST
SYSTEM_VARIABLES_ADMIN
SUPER
mysqld-auto.cnf
RESET PERSIST;
persisted_globals_load
mysqld-auto.cnf
SET
PERSIST
currently unknown variable 'var_name
'
was read from the persisted config file
PERSIST_ONLY
PERSIST
SET PERSIST_ONLY back_log = 1000;SET @@persist_only.back_log = 1000;
PERSIST
mysqld-auto.cnf
PERSIST_ONLY
PERSIST_RO_VARIABLES_ADMIN
mysqld-auto.cnf
{“mysql_server”:{“max_connections”:“99”、“transaction_isolation”:“read-committed”、“mysql_server_static_options”:{“innodb_api_enable_mdl”:“0”、“log_slave_updates”:“1”} } }
PERSIST_ONLY
"mysql_server_static_options"
SET
GLOBAL
SESSION
@@
SET SESSION sql_mode = 'TRADITIONAL';SET @@session.sql_mode = 'TRADITIONAL';SET @@sql_mode = 'TRADITIONAL';
SYSTEM_VARIABLES_ADMIN
SUPER
sql_log_bin
mysqld-auto.cnf
LOCAL
SESSION
SET
SET
GLOBAL
SET
PERSIST
SET
PERSIST_ONLY
mysql> SET GLOBAL sql_log_bin = ON;
ERROR 1228 (HY000): Variable 'sql_log_bin' is a SESSION
variable and can't be used with SET GLOBAL
GLOBAL
PERSIST
PERSIST_ONLY
mysql> SET max_connections = 1000;
ERROR 1229 (HY000): Variable 'max_connections' is a
GLOBAL variable and should be set with SET GLOBAL
SET
PERSIST
SET
PERSIST_ONLY
mysql>SET PERSIST port = 3307;
ERROR 1238 (HY000): Variable 'port' is a read only variable mysql>SET PERSIST_ONLY port = 3307;
ERROR 1238 (HY000): Variable 'port' is a non persistent read only variable
SET
SESSION
mysql> SET SESSION max_connections = 1000;
ERROR 1229 (HY000): Variable 'max_connections' is a
GLOBAL variable and should be set with SET GLOBAL
SET
SET @x = 1, SESSION sql_mode = '';
GLOBAL
PERSIST_ONLY
SET GLOBAL sort_buffer_size = 1000000, SESSION sort_buffer_size = 1000000; SET @@global.sort_buffer_size = 1000000, @@local.sort_buffer_size = 1000000; SET GLOBAL max_connections = 1000, sort_buffer_size = 1000000;
SET
SET
GLOBAL
SET
PERSIST
mysqld-auto.cnf
SET
GLOBAL
SET
PERSIST
persisted_variables
SELECT
variables_info
GLOBAL
GLOBAL
max_join_size
SET @@session.max_join_size=DEFAULT;SET @@session.max_join_size=@@global.max_join_size;
DEFAULT
SET
PERSIST
DEFAULT
RESET PERSIST
DEFAULT
@@
SELECT
选择“@global.sql_mode,@ @session.sql_mode,@ @ sql_mode;
@@
var_name
@@session.
var_name
=expr
SET {CHARACTER SET | CHARSET}
{'charset_name
' | DEFAULT}
SET CHARACTER
SET
character_set_client
character_set_results
character_set_connection
character_set_database
charset_name
DEFAULT
ucs2
utf32
SET NAMES {'charset_name
' [COLLATE 'collation_name
'] | DEFAULT}
character_set_client
character_set_connection
character_set_results
character_set_connection
collation_connection
COLLATE
charset_name
charset_name
collation_name
DEFAULT
ucs2
utf32
SET NAMES
SHOW
{掌握} logsshow显示二进制| binlog事件[” log_name
“[从] pos
[限制] [ offset
,] row_count
] [显示字符集 like_or_where
] [显示整理 like_or_where
] [全部]列显示 tbl_name
(from db_name
] [ like_or_where
]显示创建数据库 db_name
显示创建事件 event_name
显示创建函数 func_name
显示创建程序 proc_name
显示创建表 tbl_name
显示创建触发器 trigger_name
显示创建视图 view_name
显示数据库[ like_or_where
]显示引擎 engine_name
{状态|互斥}显示【贮藏】enginesshow错误[限制[ offset
,] row_count
eventsshow ]显示功能代码 func_name
显示功能状态[ like_or_where
]给补助 user
显示指数 tbl_name
(from db_name
]显示主人的statusshow打开的表[ db_name
] [ like_or_where
pluginsshow ]显示程序代码 proc_name
显示程序状态[ like_or_where
]显示privilegesshow [全] [ processlistshow简介 types
[是]查询 n
] [偏移 n
[限制] n
]显示profilesshow relaylog事件[” log_name
“[从] pos
[限制] [ offset
,] row_count
]给奴隶hostsshow奴隶地位[通道 channel
] [会话]显示全球|地位[ like_or_where
] [显示表状态 db_name
] [ like_or_where
] [全部] [显示表 db_name
] [ like_or_where
[从]显示触发器 db_name
] [ like_or_where
[全球]显示|会话变量[ ] like_or_where
[限制] [显示警告 offset
,] row_count
] like_or_where
:喜欢的 pattern
“|哪里 expr
SHOW
LIKE
'
pattern
'pattern
_
SHOW
SHOW
SELECT
INFORMATION_SCHEMA
SHOW
SHOW BINARY LOGS SHOW MASTER LOGS
mysql> SHOW BINARY LOGS;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000015 | 724935 |
| binlog.000016 | 733481 |
+---------------+-----------+
SHOW MASTER
LOGS
SHOW BINARY
LOGS
SUPER
REPLICATION CLIENT
SHOW BINLOG EVENTS [IN 'log_name
'] [FROMpos
] [LIMIT [offset
,]row_count
]
'
log_name
'
LIMIT
SELECT
SHOW BINLOG EVENTS
SHOW
BINLOG EVENTS
SHOW BINLOG EVENTS
Log_name
Pos
Event_type
Server_id
End_log_pos
Pos
Info
SHOW BINLOG EVENTS
SHOW BINLOG EVENTS
SHOW RELAYLOG EVENTS
SHOW CHARACTER SET [LIKE 'pattern
' | WHEREexpr
]
SHOW CHARACTER SET
LIKE
mysql> SHOW CHARACTER SET LIKE 'latin%';
+---------+-----------------------------+-------------------+--------+
| Charset | Description | Default collation | Maxlen |
+---------+-----------------------------+-------------------+--------+
| latin1 | cp1252 West European | latin1_swedish_ci | 1 |
| latin2 | ISO 8859-2 Central European | latin2_general_ci | 1 |
| latin5 | ISO 8859-9 Turkish | latin5_turkish_ci | 1 |
| latin7 | ISO 8859-13 Baltic | latin7_general_ci | 1 |
+---------+-----------------------------+-------------------+--------+
SHOW CHARACTER SET
Charset
Description
Default collation
Maxlen
filename
SHOW CHARACTER
SET
INFORMATION_SCHEMA
CHARACTER_SETS
SHOW COLLATION [LIKE 'pattern
' | WHEREexpr
]
SHOW
COLLATION
LIKE
mysql> SHOW COLLATION WHERE Charset = 'latin1';
+-------------------+---------+----+---------+----------+---------+
| Collation | Charset | Id | Default | Compiled | Sortlen |
+-------------------+---------+----+---------+----------+---------+
| latin1_german1_ci | latin1 | 5 | | Yes | 1 |
| latin1_swedish_ci | latin1 | 8 | Yes | Yes | 1 |
| latin1_danish_ci | latin1 | 15 | | Yes | 1 |
| latin1_german2_ci | latin1 | 31 | | Yes | 2 |
| latin1_bin | latin1 | 47 | | Yes | 1 |
| latin1_general_ci | latin1 | 48 | | Yes | 1 |
| latin1_general_cs | latin1 | 49 | | Yes | 1 |
| latin1_spanish_ci | latin1 | 94 | | Yes | 1 |
+-------------------+---------+----+---------+----------+---------+
SHOW COLLATION
Collation
Charset
Id
Default
Compiled
Sortlen
Default
MySQL的> SHOW COLLATION WHERE `Default` = 'Yes';
--------------------- ---------- ---- --------- ---------- --------- |整理|字符集| ID |默认|编译| sortlen | --------------------- ---------- ---- --------- ---------- --------- | big5_chinese_ci | BIG5 | 1 |是|是| 1 | | dec8_swedish_ci | dec8 | 3 |是|是| 1 | | cp850_general_ci | cp850 | 4 |是|是| 1 | | hp8_english_ci |该| 6 |是|是| 1 | | koi8r_general_ci | koi8r | 7 |是|是| 1 | | latin1_swedish_ci | latin1 | 8 |是|是| 1 |…
INFORMATION_SCHEMA
COLLATIONS
SHOW [EXTENDED] [FULL] {COLUMNS | FIELDS} {FROM | IN}tbl_name
[{FROM | IN}db_name
] [LIKE 'pattern
' | WHEREexpr
]
SHOW COLUMNS
SHOW COLUMNS
MySQL的> SHOW COLUMNS FROM City;
------------- ---------- ------ ----- --------- ---------------- |场|型|空|关键|默认|额外| ------------- ---------- ------ ----- --------- ---------------- | ID | int(11)|没有| PRI |空| auto_increment | |名字| char(35)|没有| | | | |国家| char(3)|没有|多| | | |区| char(20)|没有| | | | |人口| int(11)|没有| | 0 | | ------------- ---------- ------ ----- --------- ----------------
tbl_name
FROM db_name
db_name.tbl_name
从表列的文件;显示列mydb.mytable;
EXTENDED
FULL
LIKE
CREATE TABLE
SHOW COLUMNS
Field
Type
Collation
NULL
Null
YES
NO
Key
Key
Key
PRIMARY KEY
Key
UNIQUE
NULL
Null
Key
Key
PRI
MUL
UNIQUE
NULL
UNIQUE
UNIQUE
Default
NULL
DEFAULT
Extra
Privileges
FULL
Comment
FULL
INFORMATION_SCHEMA
COLUMNS
SHOW EXTENDED
COLUMNS
COLUMNS
db_name
tbl_name
DESCRIBE
SHOW
COLUMNS
SHOW CREATE TABLE
SHOW TABLE STATUS
SHOW INDEX
SHOW CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
CREATE DATABASE
IF NOT
EXISTS
SHOW
CREATE SCHEMA
SHOW CREATE DATABASE
MySQL的> SHOW CREATE DATABASE test\G
*************************** 1。行***************************数据库:testcreate数据库:创建数据库`测试` / *!40100默认字符集utf8mb4 * / MySQL > SHOW CREATE SCHEMA test\G
*************************** 1。行***************************数据库:testcreate数据库:创建数据库`测试` / *!40100默认字符集utf8mb4 */
SHOW CREATE DATABASE
sql_quote_show_create
SHOW CREATE EVENT event_name
CREATE
EVENT
EVENT
mysql> SHOW CREATE EVENT test.e_daily\G
*************************** 1. row ***************************
Event: e_daily
sql_mode:
time_zone: SYSTEM
Create Event: CREATE EVENT `e_daily`
ON SCHEDULE EVERY 1 DAY
STARTS CURRENT_TIMESTAMP + INTERVAL 6 HOUR
ON COMPLETION NOT PRESERVE
ENABLE
COMMENT 'Saves total number of sessions then
clears the table each day'
DO BEGIN
INSERT INTO site_activity.totals (time, total)
SELECT CURRENT_TIMESTAMP, COUNT(*)
FROM site_activity.sessions;
DELETE FROM site_activity.sessions;
END
character_set_client: utf8
collation_connection: utf8_general_ci
Database Collation: utf8mb4_0900_ai_ci
character_set_client
character_set_client
collation_connection
ENABLE
SHOW CREATE PROCEDURE proc_name
SHOW CREATE
FUNCTION
SELECT
MySQL的> SHOW CREATE PROCEDURE test.simpleproc\G
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 1。行* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * _ simpleproc SQL程序:程序:创建模式:创建程序simpleproc ` `(超时参数int)begin select count(*)为参数。从endcharacter吨;_看到_客户端utf8collation _:连接:utf8 _ _数据库通用词:utf8mb4 collation _ 0900 _艾_ cimysql > SHOW CREATE FUNCTION test.hello\G
*************************** 1。行***************************功能:你好sql_mode:创建功能:创建功能`你好`(的char(20))返回char(50)返回concat(你好,',,'!')character_set_client:utf8collation_connection:utf8_general_ci数据库排序规则:utf8mb4_0900_ai_ci
character_set_client
character_set_client
collation_connection
SHOW CREATE TABLE tbl_name
CREATE TABLE
MySQL的> SHOW CREATE TABLE t\G
*************************** 1. row *************************** Table: tCreate Table: CREATE TABLE `t` ( `id` int(11) NOT NULL AUTO_INCREMENT, `s` char(60) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
SHOW CREATE TABLE
sql_quote_show_create
CREATE
TABLE
SHOW CREATE TRIGGER trigger_name
CREATE
TRIGGER
TRIGGER
MySQL的> SHOW CREATE TRIGGER ins_sum\G
*************************** 1. row *************************** Trigger: ins_sum sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTIONSQL Original Statement: CREATE DEFINER=`me`@`localhost` TRIGGER ins_sum BEFORE INSERT ON account FOR EACH ROW SET @sum = @sum + NEW.amount character_set_client: utf8 collation_connection: utf8_general_ci Database Collation: utf8mb4_0900_ai_ci Created: 2013-07-09 10:39:34.96
SHOW CREATE TRIGGER
Trigger
sql_mode
SQL Original Statement
CREATE TRIGGER
character_set_client
character_set_client
collation_connection
collation_connection
Database Collation
Created
INFORMATION_SCHEMA
TRIGGERS
SHOW CREATE USER user
CREATE
USER
SELECT
SELECT
IDENTIFIED
AS
<secret>
'%'
CURRENT_USER
CURRENT_USER()
MySQL的> SHOW CREATE USER 'root'@'localhost'\G
*************************** 1。行***************************创造root@localhost用户:创建用户'根'”'localhost'identified ' mysql_native_password'as * 2470c0c06dee42fd1618bb99005adca2ec9d1e19'require没有到期默认帐户解锁密码
SHOW GRANTS
SHOW CREATE VIEW view_name
CREATE
VIEW
MySQL的> SHOW CREATE VIEW v\G
*************************** 1. row *************************** View: v Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`bob`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select 1 AS `a`,2 AS `b`character_set_client: utf8collation_connection: utf8_general_ci
character_set_client
character_set_client
collation_connection
SHOW CREATE VIEW
SHOW VIEW
SELECT
INFORMATION_SCHEMA
VIEWS
sql_mode
ANSI
sql_mode
ANSI
CONCAT()
MySQL的> SET sql_mode = 'ANSI';
查询好,为受影响的行(0.001秒)MySQL > CREATE VIEW test.v AS SELECT 'a' || 'b' as col1;
查询好,为受影响的行(0.01秒)MySQL > SHOW CREATE VIEW test.v\G
*************************** 1。行***************************观点:V创建视图:创建视图的“V”作为选择concat(A,B)为“2”…一行集(0.001秒)
sql_mode
SELECT
SHOW {DATABASES | SCHEMAS} [LIKE 'pattern
' | WHEREexpr
]
SHOW DATABASES
SHOW
SCHEMAS
SHOW
DATABASES
LIKE
SHOW
DATABASES
--skip-show-database
SHOW DATABASES
SHOW ENGINE engine_name
{STATUS | MUTEX}
SHOW ENGINE
PROCESS
显示引擎InnoDB引擎InnoDB引擎statusshow mutexshow performance_schema状态
SHOW ENGINE INNODB
STATUS
InnoDB
InnoDB
SHOW ENGINE INNODB
MUTEX
InnoDB
SET GLOBAL innodb_monitor_enable='latch';
SET GLOBAL innodb_monitor_reset='latch';
SET GLOBAL innodb_monitor_disable='latch';
SHOW ENGINE INNODB
MUTEX
innodb_monitor_enable='all'
innodb_monitor_disable='all'
SHOW ENGINE INNODB
MUTEX
Type
InnoDB
Name
Name
Status
InnoDB
spins
waits
calls
SHOW ENGINE INNODB MUTEX
SHOW ENGINE INNODB MUTEX
os_waits=0
SHOW ENGINE
INNODB MUTEX
SHOW ENGINE
PERFORMANCE_SCHEMA STATUS
MySQL的> SHOW ENGINE PERFORMANCE_SCHEMA STATUS\G
*************************** 3。行***************************型:performance_schema名称:events_waits_history.sizestatus:76 *************************** 4。行***************************型:performance_schema名称:events_waits_history.countstatus:10000 *************************** 5。行***************************型:performance_schema名称:events_waits_history.memorystatus:760000…*************************** 57。行***************************型:performance_schema名称:performance_schema.memorystatus:26459600…
Name
(pfs_cond_class).size
performance_schema
mutex_instances.count
performance_schema
size
count
tbl_name
.memorycount
memory
SHOW
ENGINE
performance_schema_events_waits_history_long_size
performance_schema_events_waits_history_size
performance_schema_max_thread_instances
SHOW [STORAGE] ENGINES
SHOW ENGINES
MySQL的> SHOW ENGINES\G
*************************** 1。行***************************引擎:档案支持:是的评论:归档存储enginetransactions:没有阿隆索:没有保存点:没有*************************** 2。行***************************引擎:黑洞的支持:是的评论:/dev/null存储引擎(任何你写它消失)交易:没有阿隆索:没有保存点:没有*************************** 3。行***************************引擎:mrg_myisam支持:是的评论:相同的MyISAM tablestransactions收集:没有阿隆索:没有保存点:没有*************************** 4。行***************************引擎:联邦支持:没有评论:联合MySQL存储enginetransactions:空:空:空*************************** XA事务5。行***************************引擎:MyISAM支持:是的评论:MyISAM存储enginetransactions:没有阿隆索:没有保存点:没有*************************** 6。行***************************引擎:performance_schema支持:是的评论:性能schematransactions:没有阿隆索:没有保存点:没有*************************** 7。行***************************引擎:InnoDB支持:默认评论:支持事务,行级锁,外keystransactions:是阿隆索:是保存点:是的*************************** 8。行***************************引擎:内存支持:是的评论:基于哈希的,存储在内存中,用于临时tablestransactions:没有阿隆索:没有保存点:没有*************************** 9。行***************************引擎:CSV支持:是的评论:CSV存储enginetransactions:没有阿隆索:没有保存点:无
SHOW ENGINES
SHOW ENGINES
Engine
Support
YES | |
DEFAULT | YES |
NO | |
DISABLED |
NO
DISABLED
DISABLED
engine_name
MyISAM
Comment
Transactions
XA
Savepoints
INFORMATION_SCHEMA
ENGINES
SHOW ERRORS [LIMIT [offset
,]row_count
] SHOW COUNT(*) ERRORS
SHOW ERRORS
SHOW
WARNINGS
LIMIT
SELECT
SHOW COUNT(*)
ERRORS
error_count
显示计数(*)的错误;选择@ @ error_count;
SHOW ERRORS
error_count
SHOW WARNINGS
warning_count
SHOW ERRORS
max_error_count
error_count
max_error_count
max_error_count
SHOW EVENTS [{FROM | IN}schema_name
] [LIKE 'pattern
' | WHEREexpr
]
EVENT
SHOW EVENTS
MySQL的> SELECT CURRENT_USER(), SCHEMA();
| ---------------- ----------流_ user()()|模式| ---------------- ---------- |乔恩@ ghidora | myschema | ---------------- ---------- 1行集(0秒)在MySQL > SHOW EVENTS\G
*************************** 1。行***************************分贝:myschema名称:e_daily定义者:乔恩@姬度拉时区:系统类型:重复执行:空区间值:10区间范围:二开始:2006-02-09 10:41:23结束:零状态:启用鼻祖:0character_set_client:utf8collation_connection:utf8_general_ci数据库排序规则:utf8mb4_0900_ai_ci
FROM
SHOW EVENTS FROM test;
LIKE
SHOW EVENTS
Db
Name
Time zone
Definer
user_name
host_name
Type
RECURRING
Execute At
DATETIME
NULL
Interval Value
NULL
Interval Field
NULL
Starts
DATETIME
NULL
Ends
DATETIME
NULL
Status
DISABLED
SLAVESIDE_DISABLED
Originator
character_set_client
character_set_client
collation_connection
SLAVE_DISABLED
SHOW EVENTS
SHOW CREATE EVENT
INFORMATION_SCHEMA.EVENTS
SHOW EVENTS
SHOW
EVENTS
INFORMATION_SCHEMA.EVENTS
SHOW FUNCTION STATUS [LIKE 'pattern
' | WHEREexpr
]
SHOW PROCEDURE
STATUS
SHOW GRANTS [FORuser_or_role
[USINGrole
[,role
] ...]]user_or_role
: {user
|role
}
GRANT
SHOW CREATE USER
SHOW GRANTS
SELECT
SHOW
GRANTS
GRANT
mysql> SHOW GRANTS FOR 'jeffrey'@'localhost';
+------------------------------------------------------------------+
| Grants for jeffrey@localhost |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `jeffrey`@`localhost` |
| GRANT SELECT, INSERT, UPDATE ON `db1`.* TO `jeffrey`@`localhost` |
+------------------------------------------------------------------+
'%'
SHOW GRANTS; SHOW GRANTS FOR CURRENT_USER; SHOW GRANTS FOR CURRENT_USER();
SHOW GRANTS FOR CURRENT_USER
SHOW GRANTS
ALL PRIVILEGES
ALL PRIVILEGES
SHOW GRANTS
MySQL的> SHOW GRANTS FOR 'root'@'localhost';
改性|资助换根改性| @本地主机|格兰特select,insert,update,delete,创造,滴,| reload,| shutdown,过程,文件,修改,显示references,索引,数据库,|创建临时表,|超级锁表,execute,斯拉夫| REPLICATION | REPLICATION,客户端,创建秀景,山景,创建例程,例程| |圣坛,创建用户,创建表空间,事件,触发器,| |创建角色,角色由* *到承包承包承包承包与根| @ option | localhost格兰特格兰特| |在线代理是“to”是根是localhost |授予期权与改性
SHOW
GRANTS
GRANT OPTION
SHOW GRANTS
WITH GRANT OPTION
GRANT OPTION
GRANT OPTION
USING
SHOW GRANTS
u1
r2
创建角色的R1,R2的选择;格兰特DB1。*“R1”;格兰特插入,更新,删除DB1。*“R2”;创建用户U1 '@'本地主机'确定' u1pass’;格兰特R1,R2为U1的“@ 'localhost ';
SHOW GRANTS
mysql> SHOW GRANTS FOR 'u1'@'localhost';
+---------------------------------------------+
| Grants for u1@localhost |
+---------------------------------------------+
| GRANT USAGE ON *.* TO `u1`@`localhost` |
| GRANT `r1`@`%`,`r2`@`%` TO `u1`@`localhost` |
+---------------------------------------------+
USING
MySQL的> SHOW GRANTS FOR 'u1'@'localhost' USING 'r1';
--------------------------------------------- |补助U1 @本地| --------------------------------------------- |授予使用*。* ` U1 ` @ ` localhost ` | |格兰特选择` DB1 `。* ` U1 ` @ ` localhost ` | |格兰特` R1 ` @ ` % `,` R2 ` @ ` % `到` U1 `“` localhost ` | --------------------------------------------- MySQL > SHOW GRANTS FOR 'u1'@'localhost' USING 'r2';
------------------------------------------------------------- |赠款是U1的| @本地主机使用在线------------------------------------------------------------- |格兰特*。*”“”“”“|本地U1 |格兰特的INSERT,UPDATE,DELETE,DB1的`在线` ` ` U1。*“localhost”| ` ` ` `格兰特| R1 R2”“%”%“”“,”“localhost”到“U1”>“| ------------------------------------------------------------- MySQL SHOW GRANTS FOR 'u1'@'localhost' USING 'r1', 'r2';
--------------------------------------------------------------------- |赠款是U1的| @本地主机使用在线--------------------------------------------------------------------- |格兰特*。*”“”“”“| U1 |本地查询,插入,更新,删除`在线`逻辑`到` U1。*“localhost”| ` ` ` `格兰特| R1 R2的%“”“”“,”` ` `成`对` | U1 --------------------------------------------------------------------- @本地主机
activate_all_roles_on_login
SET ROLE
SHOW GRANTS
SHOW GRANTS
SHOW GRANTS
mandatory_roles
SHOW GRANTS
SHOW GRANTS FOR
user
SHOW
GRANTS FOR
user
SHOW
GRANTS
SHOW GRANTS FOR
CURRENT_USER
SHOW [EXTENDED] {INDEX | INDEXES | KEYS} {FROM | IN}tbl_name
[{FROM | IN}db_name
] [WHEREexpr
]
SHOW INDEX
mysql> SHOW INDEX FROM City\G
*************************** 1. row ***************************
Table: city
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: ID
Collation: A
Cardinality: 4188
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
Visible: YES
Expression: NULL
*************************** 2. row ***************************
Table: city
Non_unique: 1
Key_name: CountryCode
Seq_in_index: 1
Column_name: CountryCode
Collation: A
Cardinality: 232
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
Visible: YES
Expression: NULL
tbl_name
FROM db_name
db_name
tbl_name
显示从文件索引表;显示指数从mydb.mytable;
EXTENDED
WHERE
SHOW INDEX
Table
Non_unique
Key_name
PRIMARY
Seq_in_index
Column_name
Expression
Collation
A
NULL
Cardinality
ANALYZE
TABLE
Cardinality
Sub_part
NULL
CREATE
TABLE
ALTER
TABLE
CREATE
INDEX
CHAR
VARCHAR
TEXT
BINARY
VARBINARY
BLOB
Packed
NULL
Null
YES
''
Index_type
BTREE
HASH
Comment
disabled
Index_comment
COMMENT
Visible
Expression
Column_name
Column_name
NULL
Column_name
Expression
INFORMATION_SCHEMA
STATISTICS
SHOW
EXTENDED INDEX
STATISTICS
db_name
tbl_name
SHOW MASTER STATUS
SUPER
REPLICATION CLIENT
mysql> SHOW MASTER STATUS\G
*************************** 1. row ***************************
File: master-bin.000002
Position: 1307
Binlog_Do_DB: test
Binlog_Ignore_DB: manual, mysql
Executed_Gtid_Set: 3E11FA47-71CA-11E1-9E33-C80AA9429562:1-5
1 row in set (0.00 sec)
Executed_Gtid_Set
gtid_executed
SHOW SLAVE STATUS
SHOW OPEN TABLES [{FROM | IN}db_name
] [LIKE 'pattern
' | WHEREexpr
]
SHOW OPEN TABLES
FROM
db_name
LIKE
SHOW OPEN TABLES
Database
Table
In_use
LOCK TABLE t1 WRITE
LOCK TABLE t1 WRITE
In_use
HANDLER ...
OPEN
HANDLER ...
CLOSE
Name_locked
SHOW OPEN TABLES
SHOW PLUGINS
SHOW PLUGINS
SHOW PLUGINS
MySQL的> SHOW PLUGINS\G
*************************** 1。行***************************名称:binlog状态:活跃型:存储enginelibrary:nulllicense:GPL *************************** 2。行***************************名称:CSV状态:活跃型:存储enginelibrary:nulllicense:GPL *************************** 3。行***************************名称:内存状态:活跃型:存储enginelibrary:nulllicense:GPL *************************** 4。行***************************名称:MyISAM状态:活跃型:存储enginelibrary:nulllicense:GPL…
SHOW PLUGINS
Name
INSTALL
PLUGIN
UNINSTALL
PLUGIN
Status
INACTIVE
DELETING
Type
INFORMATION_SCHEMA
Library
INSTALL
PLUGIN
UNINSTALL
PLUGIN
plugin_dir
UNINSTALL
PLUGIN
License
INSTALL
PLUGIN
Library
SHOW
PLUGINS
SHOW PRIVILEGES
SHOW PRIVILEGES
MySQL的> SHOW PRIVILEGES\G
*************************** 1。行***************************特权:改变背景:表评论:更改表*************************** 2。行***************************特权:改变常规背景:功能,程序注释:改变或删除存储功能/程序*************************** 3。行***************************特权:创设情境:数据库、表、索引评论:创建新的数据库和表*************************** 4。行***************************特权:创建常规语境:评论:使用数据库创建函数/过程*************************** 5。行***************************特权:创建临时表的数据库上下文:评论:使用创建临时表…
SHOW GRANTS
SHOW PROCEDURE CODE proc_name
SHOW
FUNCTION CODE
SELECT
Pos
mysql>DELIMITER //
mysql>CREATE PROCEDURE p1 ()
->BEGIN
->DECLARE fanta INT DEFAULT 55;
->DROP TABLE t2;
->LOOP
->INSERT INTO t3 VALUES (fanta);
->END LOOP;
->END//
Query OK, 0 rows affected (0.00 sec) mysql>SHOW PROCEDURE CODE p1//
+-----+----------------------------------------+ | Pos | Instruction | +-----+----------------------------------------+ | 0 | set fanta@0 55 | | 1 | stmt 9 "DROP TABLE t2" | | 2 | stmt 5 "INSERT INTO t3 VALUES (fanta)" | | 3 | jump 2 | +-----+----------------------------------------+ 4 rows in set (0.00 sec)
BEGIN
DECLARE
variable_name
DROP
INSERT
GOTO instruction #2
SHOW PROCEDURE STATUS [LIKE 'pattern
' | WHEREexpr
]
SHOW
FUNCTION STATUS
LIKE
mysql> SHOW PROCEDURE STATUS LIKE 'sp1'\G
*************************** 1. row ***************************
Db: test
Name: sp1
Type: PROCEDURE
Definer: testuser@localhost
Modified: 2004-08-03 15:29:37
Created: 2004-08-03 15:29:37
Security_type: DEFINER
Comment:
character_set_client: utf8
collation_connection: utf8_general_ci
Database Collation: utf8mb4_0900_ai_ci
character_set_client
character_set_client
collation_connection
ROUTINES
SHOW [FULL] PROCESSLIST
SHOW PROCESSLIST
PROCESSLIST
PROCESS
Info
performance_schema.threads
threads
INFORMATION_SCHEMA.PROCESSLIST
SHOW PROCESSLIST
threads
INFORMATION_SCHEMA.PROCESSLIST
SHOW PROCESSLIST
threads
SHOW PROCESSLIST
CONNECTION_ADMIN
SUPER
KILL
SHOW
PROCESSLIST
MySQL >显示完整的列表*************************** \ G 1。行*************************** ID:1user:系统userhost:DB:nullcommand:connecttime:1030455state:等待主人送EventInfo:空*************************** 2。行*************************** ID:用户:系统userhost:DB:nullcommand:connecttime:1004state:读了中继日志;等待Slave I/O线程更新itinfo:空***************************三。行*************************** ID:3112user:replikatorhost:阿耳忒弥斯:2204db:nullcommand:Binlog DumpTime:2144state:已发送的所有binlog奴隶;等待binlog是updatedinfo:空*************************** 4。行*************************** ID:3113user:replikatorhost:iconnect2:45781db:nullcommand:Binlog DumpTime:2086state:已发送的所有binlog奴隶;等待binlog是updatedinfo:空***************************五。行*************************** ID:3123user:stefanhost:localhostdb:apolloncommand:querytime:0state:nullinfo:显示全processlist5行集(0秒)
SHOW
PROCESSLIST
ID
INFORMATION_SCHEMA.PROCESSLIST
threads
CONNECTION_ID()
system user
event_scheduler
Host
system user
SHOW PROCESSLIST
host_name
client_port
NULL
COM_
xxx
xxx
State
SHOW PROCESSLIST
NULL
NULL
SELECT
SELECT
SHOW PROFILE [type
[,type
] ... ] [FOR QUERYn
] [LIMITrow_count
[OFFSEToffset
]]type
: ALL | BLOCK IO | CONTEXT SWITCHES | CPU | IPC | MEMORY | PAGE FAULTS | SOURCE | SWAPS
SHOW PROFILE
SHOW PROFILES
profiling
profiling
mysql> SET profiling = 1;
SHOW PROFILES
profiling_history_size
SHOW
PROFILE
SHOW
PROFILES
SHOW PROFILE
n
n
SHOW PROFILE
n
n
SHOW PROFILES
LIMIT
row_count
row_count
OFFSET
offset
offset
SHOW PROFILE
Duration
State
SHOW PROCESSLIST
type
ALL
BLOCK IO
CONTEXT SWITCHES
CPU
IPC
MEMORY
PAGE FAULTS
SOURCE
SWAPS
mysql>SELECT @@profiling;
+-------------+ | @@profiling | +-------------+ | 0 | +-------------+ 1 row in set (0.00 sec) mysql>SET profiling = 1;
Query OK, 0 rows affected (0.00 sec) mysql>DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>CREATE TABLE T1 (id INT);
Query OK, 0 rows affected (0.01 sec) mysql>SHOW PROFILES;
+----------+----------+--------------------------+ | Query_ID | Duration | Query | +----------+----------+--------------------------+ | 0 | 0.000088 | SET PROFILING = 1 | | 1 | 0.000136 | DROP TABLE IF EXISTS t1 | | 2 | 0.011947 | CREATE TABLE t1 (id INT) | +----------+----------+--------------------------+ 3 rows in set (0.00 sec) mysql>SHOW PROFILE;
+----------------------+----------+ | Status | Duration | +----------------------+----------+ | checking permissions | 0.000040 | | creating table | 0.000056 | | After create | 0.011363 | | query end | 0.000375 | | freeing items | 0.000089 | | logging slow query | 0.000019 | | cleaning up | 0.000005 | +----------------------+----------+ 7 rows in set (0.00 sec) mysql>SHOW PROFILE FOR QUERY 1;
+--------------------+----------+ | Status | Duration | +--------------------+----------+ | query end | 0.000107 | | freeing items | 0.000008 | | logging slow query | 0.000015 | | cleaning up | 0.000006 | +--------------------+----------+ 4 rows in set (0.00 sec) mysql>SHOW PROFILE CPU FOR QUERY 2;
+----------------------+----------+----------+------------+ | Status | Duration | CPU_user | CPU_system | +----------------------+----------+----------+------------+ | checking permissions | 0.000040 | 0.000038 | 0.000002 | | creating table | 0.000056 | 0.000028 | 0.000028 | | After create | 0.011363 | 0.000217 | 0.001571 | | query end | 0.000375 | 0.000013 | 0.000028 | | freeing items | 0.000089 | 0.000010 | 0.000014 | | logging slow query | 0.000019 | 0.000009 | 0.000010 | | cleaning up | 0.000005 | 0.000003 | 0.000002 | +----------------------+----------+----------+------------+ 7 rows in set (0.00 sec)
getrusage()
PROFILING
SHOW PROFILE FOR QUERY 2; SELECT STATE, FORMAT(DURATION, 6) AS DURATION FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID = 2 ORDER BY SEQ;
SHOW PROFILES
SHOW PROFILES
SHOW PROFILE
SHOW RELAYLOG EVENTS [IN 'log_name
'] [FROMpos
] [LIMIT [offset
,]row_count
] [channel_option
]channel_option
: FOR CHANNELchannel
'
log_name
'
LIMIT
SELECT
SHOW RELAYLOG EVENTS
FOR CHANNEL
channel
channel
SHOW RELAYLOG EVENTS
channel
SHOW RELAYLOG EVENTS
Log_name
Pos
Event_type
Server_id
End_log_pos
End_log_pos
Info
SHOW RELAYLOG EVENTS
SHOW SLAVE HOSTS
SHOW SLAVE HOSTS
MySQL的> SHOW SLAVE HOSTS
;------------ ----------- ------ ----------- -------------------------------------- | server_id |主机|港口| master_id | slave_uuid | ------------ ----------- ------ ----------- -------------------------------------- | 192168010 | iconnect2 | 3306 | 192168011 | 14cb6624-7f93-11e0-b2c0-c80aa9429562 | | 1921680101 |雅典娜| 3306 | 192168011 | 07af4990-f41f-11df-a566-7ac56fdaf645 | ------------ ----------- ------ ----------- --------------------------------------
Server_id
--server-id=
value
Host
--report-host
User
--report-user
--show-slave-auth-info
Password
--report-password
--show-slave-auth-info
Port
--report-port
--report-port
Master_id
SHOW SLAVE STATUS [FOR CHANNEL channel
]
SUPER
REPLICATION CLIENT
SHOW SLAVE STATUS
STOP SLAVE
STOP SLAVE
\G
MySQL的> SHOW SLAVE STATUS\G
*************************** 1。行*************************** slave_io_state:等待主人送事件master_host:localhost master_user:REPL master_port:13000 connect_retry:60 master_log_file:master-bin.000002 read_master_log_pos:1307 relay_log_file:slave-relay-bin.000003 relay_log_pos:1508年relay_master_log_file:master-bin.000002 slave_io_running:是的slave_sql_running:是的replicate_do_db:replicate_ignore_db:replicate_do_table:replicate_ignore_table:replicate_wild_do_table:replicate_wild_ignore_table:last_errno:0 last_error:skip_counter:0 exec_master_log_pos:::没有until_condition relay_log_space 1307年until_log_file:until_log_pos:0 master_ssl_allowed:没有master_ssl_ca_file:master_ssl_ca_path:master_ssl_cert:master_ssl_cipher:master_ssl_key:seconds_behind_master:0master_ssl_verify_server_cert:没有last_io_errno:0 last_io_error:last_sql_errno:0 last_sql_error:replicate_ignore_server_ids:master_server_id:1 master_uuid:3e11fa47-71ca-11e1-9e33-c80aa9429562 master_info_file:/无功/ mysqld.2/data/master.info sql_delay:0 sql_remaining_delay:空slave_sql_running_state:阅读从中继日志master_retry_count事件:10 master_bind:last_io_error_timestamp:last_sql_error_timestamp:master_ssl_crl:master_ssl_crlpath:retrieved_gtid_set:3e11fa47-71ca-11e1-9e33-c80aa9429562:1-5 executed_gtid_set:3e11fa47-71ca-11e1-9e33-c80aa9429562:1-5 auto_position:1 replicate_rewrite_db:channel_name:master_tls_version:tlsv1.2 master_public_key_path:public_key.pem get_master_public_key:0
SHOW SLAVE STATUS
SHOW SLAVE STATUS
Slave_IO_State
State
SHOW PROCESSLIST
Master_Host
Master_User
Master_Port
Connect_Retry
CHANGE MASTER
TO
Master_Log_File
Read_Master_Log_Pos
Relay_Log_File
Relay_Log_Pos
Relay_Master_Log_File
Slave_IO_Running
Slave_IO_Running
Slave_IO_Running
Slave_IO_Running
Slave_running
Slave_SQL_Running
Replicate_Do_DB
--replicate-do-db
--replicate-ignore-db
CHANGE REPLICATION
FILTER
Replicate_Do_Table
Replicate_Wild_Do_Table
--replicate-do-table
--replicate-ignore-table
--replicate-wild-do-table
--replicate-wild-ignore-table
CHANGE REPLICATION
FILTER
Last_Errno
Last_SQL_Errno
RESET MASTER
RESET SLAVE
SHOW SLAVE STATUS
Slave_SQL_Running
Skip_Counter
sql_slave_skip_counter
Exec_Master_Log_Pos
CHANGE MASTER
TO
Relay_Master_Log_File
Relay_Log_File
START SLAVE
UNTIL SQL_AFTER_MTS_GAPS
Relay_Log_Space
Until_Condition
Until_Log_Pos
UNTIL
START SLAVE
Until_Condition
None
Master
Relay
SQL_BEFORE_GTIDS
SQL_AFTER_GTIDS
SQL_AFTER_MTS_GAPS
Until_Log_File
UNTIL
Master_SSL_Allowed
Master_SSL_CA_Path
Master_SSL_Cipher
Master_SSL_CRL_Path
Master_SSL_Verify_Server_Cert
Master_SSL_Allowed
Yes
No
Ignored
MASTER_SSL_CA
MASTER_SSL_CERT
MASTER_SSL_CRL
MASTER_SSL_KEY
CHANGE MASTER TO
Seconds_Behind_Master
Seconds_Behind_Master
Seconds_Behind_Master
NULL
Seconds_Behind_Master
Seconds_Behind_Master
TIMESTAMP
Seconds_Behind_Master
Exec_Master_Log_Pos
Last_IO_Errno
Last_IO_Error
YYMMDD HH:MM:SS
RESET MASTER
RESET SLAVE
Last_SQL_Errno
Last_SQL_Error
Last_SQL_Error
replication_applier_status_by_coordinator
replication_applier_status_by_worker
replication_applier_status_by_worker
SHOW SLAVE STATUS
YYMMDD HH:MM:SS
RESET MASTER
RESET SLAVE
Last_SQL_Errno
Replicate_Ignore_Server_Ids
IGNORE_SERVER_IDS
CHANGE MASTER TO
Ignored_server_ids
CHANGE MASTER
TO
IGNORE_SERVER_IDS = (2,6,9)
Replicate_Ignore_Server_Ids: 2, 6, 9
ignored_server_ids:3, 2, 6,9
Replicate_Ignore_Server_Ids
--replicate-do-table
SET GTID_MODE=ON
SHOW_SLAVE_STATUS
CHANGE MASTER TO
Master_Server_Id
server_id
Master_UUID
server_uuid
Master_Info_File
master.info
SQL_Delay
SQL_Remaining_Delay
Slave_SQL_Running_State
NULL
Slave_SQL_Running_State
Slave_IO_State
SHOW
PROCESSLIST
Master_Retry_Count
MASTER_RETRY_COUNT
CHANGE MASTER
TO
--master-retry-count
Master_Bind
MASTER_BIND
CHANGE MASTER TO
Last_IO_Error_Timestamp
YYMMDD HH:MM:SS
Last_SQL_Error_Timestamp
YYMMDD HH:MM:SS
Retrieved_Gtid_Set
Gtid_log_event
RESET SLAVE
CHANGE MASTER TO
--relay-log-recovery
relay_log_purge = 1
Executed_Gtid_Set
gtid_executed
SHOW MASTER STATUS
Auto_Position
Replicate_Rewrite_DB
Replicate_Rewrite_DB
CHANGE REPLICATION FILTER REPLICATE_REWRITE_DB=((db1,db2), (db3,db4));
Replicate_Rewrite_DB
2 .复制(DB1,DB2),(DB3,DB4)
Channel_name
Master_TLS_Version
Master_public_key_path
sha256_password
Master_public_key_path
Get_master_public_key
caching_sha2_password
Master_public_key_path
SHOW [GLOBAL | SESSION] STATUS [LIKE 'pattern
' | WHEREexpr
]
SHOW STATUS
SHOW STATUS
LIKE
SHOW STATUS
SESSION
GLOBAL
Bytes_received
SESSION
SESSION
SESSION
SHOW
STATUS
Created_tmp_tables
mysql> SHOW STATUS;
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| Aborted_clients | 0 |
| Aborted_connects | 0 |
| Bytes_received | 155372598 |
| Bytes_sent | 1176560426 |
| Connections | 30023 |
| Created_tmp_disk_tables | 0 |
| Created_tmp_tables | 8340 |
| Created_tmp_files | 60 |
...
| Open_tables | 1 |
| Open_files | 2 |
| Open_streams | 0 |
| Opened_tables | 44600 |
| Questions | 2026873 |
...
| Table_locks_immediate | 1920382 |
| Table_locks_waited | 0 |
| Threads_cached | 0 |
| Threads_created | 30022 |
| Threads_connected | 1 |
| Threads_running | 1 |
| Uptime | 80380 |
+--------------------------+------------+
LIKE
MySQL的> SHOW STATUS LIKE 'Key%';
-------------------- ---------- | variable_name |价值| -------------------- ---------- | key_blocks_used | 14955 | | key_read_requests | 96854827 | | key_reads | 162040 | | key_write_requests | 7589728 | | key_writes | 3813196 | -------------------- ----------
SHOW TABLE STATUS [{FROM | IN}db_name
] [LIKE 'pattern
' | WHEREexpr
]
SHOW TABLE STATUS
SHOW TABLES
db_name
LIKE
SHOW TABLE STATUS
Name
Engine
Version
Row_format
Fixed
Compressed
Compact
Dynamic
Packed
Rows
MyISAM
SELECT COUNT(*)
Rows
INFORMATION_SCHEMA
Avg_row_length
Data_length
MyISAM
InnoDB
InnoDB
Max_data_length
MyISAM
InnoDB
Index_length
MyISAM
InnoDB
InnoDB
Data_free
InnoDB
InnoDB
INFORMATION_SCHEMA.PARTITIONS
SELECT SUM(DATA_FREE) FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'mytable';
Auto_increment
AUTO_INCREMENT
Create_time
Update_time
NULL
InnoDB
MyISAM
Check_time
NULL
Collation
Checksum
Create_options
CREATE
TABLE
CREATE TABLE
InnoDB
KEY_BLOCK_SIZE
ROW_FORMAT
Comment
MEMORY
Max_data_length
SHOW TABLE STATUS
Name
view
SHOW [EXTENDED] [FULL] TABLES [{FROM | IN}db_name
] [LIKE 'pattern
' | WHEREexpr
]
SHOW TABLES
db_name
LIKE
LIKE
lower_case_table_names
EXTENDED
SHOW TABLES
ALTER TABLE
DROP TABLE
FULL
SHOW TABLES
VIEW
SHOW
TABLES
SHOW TRIGGERS [{FROM | IN}db_name
] [LIKE 'pattern
' | WHEREexpr
]
SHOW TRIGGERS
TRIGGER
LIKE
ins_sum
mysql> SHOW TRIGGERS LIKE 'acc%'\G
*************************** 1. row ***************************
Trigger: ins_sum
Event: INSERT
Table: account
Statement: SET @sum = @sum + NEW.amount
Timing: BEFORE
Created: 2013-07-09 10:39:34.96
sql_mode: NO_ENGINE_SUBSTITUTION
Definer: me@localhost
character_set_client: utf8
collation_connection: utf8_general_ci
Database Collation: utf8mb4_0900_ai_ci
SHOW TRIGGERS
Trigger
Event
'UPDATE'
Table
Statement
Timing
'AFTER'
Created
sql_mode
Definer
user_name
host_name
character_set_client
character_set_client
collation_connection
collation_connection
Database Collation
INFORMATION_SCHEMA
TRIGGERS
SHOW [GLOBAL | SESSION] VARIABLES [LIKE 'pattern
' | WHEREexpr
]
SHOW VARIABLES
SHOW VARIABLES
LIKE
SHOW VARIABLES
SESSION
GLOBAL
SESSION
SESSION
SESSION
SHOW VARIABLES
SELECT
选择@ @ global.innodb _ _ _路径文件的日期;
version_comment
SET
mysql> SHOW VARIABLES;
+--------------------------------------------+------------------------------+
| Variable_name | Value |
+--------------------------------------------+------------------------------+
| activate_all_roles_on_login | OFF |
| auto_generate_certs | ON |
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
| autocommit | ON |
| automatic_sp_privileges | ON |
| avoid_temporal_upgrade | OFF |
| back_log | 151 |
| basedir | /usr/ |
| big_tables | OFF |
| bind_address | * |
| binlog_cache_size | 32768 |
| binlog_checksum | CRC32 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_error_action | ABORT_SERVER |
| binlog_expire_logs_seconds | 2592000 |
| binlog_format | ROW |
| binlog_group_commit_sync_delay | 0 |
| binlog_group_commit_sync_no_delay_count | 0 |
| binlog_gtid_simple_recovery | ON |
| binlog_max_flush_queue_time | 0 |
| binlog_order_commits | ON |
| binlog_row_image | FULL |
| binlog_row_metadata | MINIMAL |
| binlog_row_value_options | |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | 32768 |
| binlog_transaction_dependency_history_size | 25000 |
| binlog_transaction_dependency_tracking | COMMIT_ORDER |
| block_encryption_mode | aes-128-ecb |
| bulk_insert_buffer_size | 8388608 |
...
| max_allowed_packet | 67108864 |
| max_binlog_cache_size | 18446744073709547520 |
| max_binlog_size | 1073741824 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| max_connect_errors | 100 |
| max_connections | 151 |
| max_delayed_threads | 20 |
| max_digest_length | 1024 |
| max_error_count | 1024 |
| max_execution_time | 0 |
| max_heap_table_size | 16777216 |
| max_insert_delayed_threads | 20 |
| max_join_size | 18446744073709551615 |
...
| thread_handling | one-thread-per-connection |
| thread_stack | 286720 |
| time_zone | SYSTEM |
| timestamp | 1530906638.765316 |
| tls_version | TLSv1,TLSv1.1,TLSv1.2 |
| tmp_table_size | 16777216 |
| tmpdir | /tmp |
| transaction_alloc_block_size | 8192 |
| transaction_allow_batching | OFF |
| transaction_isolation | REPEATABLE-READ |
| transaction_prealloc_size | 4096 |
| transaction_read_only | OFF |
| transaction_write_set_extraction | XXHASH64 |
| unique_checks | ON |
| updatable_views_with_limit | YES |
| version | 8.0.12 |
| version_comment | MySQL Community Server - GPL |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
| version_compile_zlib | 1.2.11 |
| wait_timeout | 28800 |
| warning_count | 0 |
| windowing_use_high_precision | ON |
+--------------------------------------------+------------------------------+
LIKE
LIKE
显示变量的max_join_size”;显示会话变量如max_join_size”;
%
LIKE
显示变量''%1大小%;显示全局变量是“大小%;
_
SHOW WARNINGS [LIMIT [offset
,]row_count
] SHOW COUNT(*) WARNINGS
SHOW WARNINGS
INSERT
UPDATE
LOAD DATA
INFILE
CREATE TABLE
ALTER TABLE
LIMIT
SELECT
SHOW WARNINGS
EXPLAIN
EXPLAIN
SHOW WARNINGS
SHOW WARNINGS
SHOW COUNT(*)
WARNINGS
warning_count
显示计数(*)警告;选择@ @ warning_count;
SELECT
SHOW
ERRORS
SHOW COUNT(*)
ERRORS
GET
DIAGNOSTICS
INSERT
MySQL的> CREATE TABLE t1 (a TINYINT NOT NULL, b CHAR(4));
查询行,0行受影响(0.05秒)MySQL > INSERT INTO t1 VALUES(10,'mysql'), (NULL,'test'), (300,'xyz');
查询行,3行的影响,3警告(0秒)记录:3份:0警告:3mysql > SHOW WARNINGS\G
*************************** 1。行***************************水平:报警代码:1265message:数据截断柱B在连续1 *************************** 2。行***************************水平:报警代码:1048message:列“一”不能为空*************************** 3。行***************************水平:报警代码:1264message:越界值列'行33行集(0秒)
max_error_count
SHOW
WARNINGS
max_error_count
max_error_count
warning_count
max_error_count
max_error_count
ALTER
TABLE
max_error_count
warning_count
MySQL的> SHOW VARIABLES LIKE 'max_error_count';
----------------- ------- | variable_name |价值| ----------------- ------- | max_error_count | 1024 | ----------------- ------- 1行集(0秒)MySQL > SET max_error_count=1, sql_mode = '';
查询好,为受影响的行(0.001秒)MySQL > ALTER TABLE t1 MODIFY b CHAR;
查询行,3行的影响,3警告(0秒)记录:3份:0警告:3mysql > SHOW WARNINGS;
--------- ------ ---------------------------------------- |水平|代码|消息| --------- ------ ---------------------------------------- |警告| 1263 |数据截断柱B在连续1 | --------- ------ ---------------------------------------- 1行集(0秒)MySQL > SELECT @@warning_count;
Fa@warningásónónónónónónónónón que siónónónónónónónónónónónónónónónónónónónónónónónónónónónónónécón de la?---- elásónónónón en el un 1 row in set(0.01 SEC)
max_error_count
warning_count
sql_notes
warning_count
sql_notes
warning_count
MySQL的> SET sql_notes = 1;
MySQL的> DROP TABLE IF EXISTS test.no_such_table;
查询行,0行的影响,1报警(0秒)MySQL > SHOW WARNINGS;
------- ------ ------------------------------------ |水平|代码|消息| ------- ------ ------------------------------------ |注| 1051 |未知表”测试。no_such_table”| ------- ------ ------------------------------------ 1行集(0秒)MySQL > SET sql_notes = 0;
MySQL的> DROP TABLE IF EXISTS test.no_such_table;
查询好,为受影响的行(0.001秒)MySQL > SHOW WARNINGS;
空集(0.001秒)
mysql_warning_count()
warnings
\W
mysql>\W
Show warnings enabled. mysql>SELECT 1/0;
+------+ | 1/0 | +------+ | NULL | +------+ 1 row in set, 1 warning (0.03 sec) Warning (Code 1365): Division by 0 mysql>\w
Show warnings disabled.
BINLOG 'str
'
BINLOG
'
str
'BINLOG_ADMIN
SUPER
CACHE INDEXtbl_index_list
[,tbl_index_list
] ... [PARTITION (partition_list
| ALL)] INkey_cache_name
tbl_index_list
:tbl_name
[[INDEX|KEY] (index_name
[,index_name
] ...)]partition_list
:partition_name
[,partition_name
][, ...]
CACHE INDEX
LOAD INDEX INTO
CACHE
t1
t3
mysql> CACHE INDEX t1, t2, t3 IN hot_cache;
+---------+--------------------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------+--------------------+----------+----------+
| test.t1 | assign_to_keycache | status | OK |
| test.t2 | assign_to_keycache | status | OK |
| test.t3 | assign_to_keycache | status | OK |
+---------+--------------------+----------+----------+
CACHE INDEX
CACHE
INDEX
MySQL的> SET GLOBAL keycache1.key_buffer_size=128*1024;
mysql> CACHE INDEX t1 IN non_existent_cache;
ERROR 1284 (HY000): Unknown key cache 'non_existent_cache'
MyISAM
CREATE TABLE pt (c1 INT, c2 VARCHAR(50), INDEX i(c1)) ENGINE=MyISAM PARTITION BY HASH(c1) PARTITIONS 4;SET GLOBAL kc_fast.key_buffer_size = 128 * 1024;SET GLOBAL kc_slow.key_buffer_size = 128 * 1024;CACHE INDEX pt PARTITION (p0) IN kc_fast;CACHE INDEX pt PARTITION (p1, p3) IN kc_slow;
p0
i
kc_fast
p0
p1
kc_slow
pt
CACHE INDEX pt PARTITION (ALL) IN kc_all; CACHE INDEX pt IN kc_all;
PARTITION
(ALL)
MyISAM
FLUSH [NO_WRITE_TO_BINLOG | LOCAL] {flush_option
[,flush_option
] ... |tables_option
}flush_option
: { BINARY LOGS | ENGINE LOGS | ERROR LOGS | GENERAL LOGS | HOSTS | LOGS | PRIVILEGES | OPTIMIZER_COSTS | RELAY LOGS [FOR CHANNELchannel
] | SLOW LOGS | STATUS | USER_RESOURCES }tables_option
: { TABLES | TABLEStbl_name
[,tbl_name
] ... | TABLES WITH READ LOCK | TABLEStbl_name
[,tbl_name
] ... WITH READ LOCK | TABLEStbl_name
[,tbl_name
] ... FOR EXPORT }
FLUSH
FLUSH
RELOAD
FLUSH
FLUSH
FLUSH
LOCAL
FLUSH LOGS
FLUSH TABLES WITH READ LOCK
FLUSH
TABLES
tbl_name
... FOR
EXPORT
FLUSH
flush-hosts
flush-privileges
flush-tables
SIGHUP
FLUSH
RESET
FLUSH
RESET
FLUSH
flush_option
FLUSH
TABLES
InnoDB
Host '
host_name
' is
blockedmax_connect_errors
max_connect_errors
max_connect_errors
FLUSH LOGS
mysql
global_grants
GRANT
CREATE USER
CREATE SERVER
INSTALL PLUGIN
REVOKE
DROP USER
DROP SERVER
UNINSTALL PLUGIN
FLUSH PRIVILEGES
FLUSH
RELAY LOGS [FOR CHANNEL
channel
]
FOR CHANNEL
channel
FLUSH
RELAY LOGS FOR CHANNEL
channel
FLUSH USER_RESOURCES
max_user_connections
FLUSH TABLES
FLUSH
FLUSH
TABLE
FLUSH
TABLES
InnoDB
FLUSH TABLES
LOCK TABLES ...
READ
FLUSH
TABLES
tbl_name
... WITH READ
LOCK
FLUSH
TABLES
tbl_name
[,
tbl_name
] ...
FLUSH
TABLES
UNLOCK
TABLES
FLUSH TABLES WITH READ LOCK
LOCK TABLES
UNLOCK
TABLES
UNLOCK
TABLES
LOCK TABLES
UNLOCK
TABLES
FLUSH
TABLES WITH READ LOCK
LOCK TABLES
UNLOCK
TABLES
FLUSH TABLES WITH READ
LOCK
FLUSH TABLES WITH READ LOCK
FLUSH
TABLES
tbl_name
[,
tbl_name
] ... WITH READ
LOCK
LOCK TABLES ...
READ
LOCK TABLES
RELOAD
FLUSH
TEMPORARY)
ER_WRONG_OBJECT
ER_NO_SUCH_TABLE
UNLOCK
TABLES
LOCK TABLES
START
TRANSACTION
FLUSH TABLES
FLUSH TABLES
LOCK TABLES ...
READ
UNLOCK
TABLES
LOCK TABLES
HANDLER
FLUSH
TABLES
tbl_name
[,
tbl_name
] ... FOR
EXPORT
FLUSH TABLES
FOR EXPORT
ER_ILLEGAL_HA
FOR EXPORT
FLUSH
TABLES ... FOR EXPORT
SELECT
LOCK
TABLES
RELOAD
FLUSH
TEMPORARY
ER_WRONG_OBJECT
ER_NO_SUCH_TABLE
InnoDB
.ibd
innodb_file_per_table
FOR EXPORT
.ibd
InnoDB
FULLTEXT
FLUSH
TABLES ...FOR EXPORT
FOR EXPORT
InnoDB
table_name
FOR EXPORT
.ibd
UNLOCK
TABLES
LOCK TABLES
START
TRANSACTION
FLUSH
TABLES ... FOR EXPORT
冲洗表…读lockflush表…对于exportlock表…readlock表…写
FLUSH
TABLES ... FOR EXPORT
FLUSH TABLES WITH READ lockflush表…读lockflush表…出口
KILL [CONNECTION | QUERY] processlist_id
KILL
processlist_id
ID
INFORMATION_SCHEMA.PROCESSLIST
SHOW PROCESSLIST
threads
CONNECTION_ID()
KILL
QUERY
KILL
CONNECTION
KILL
processlist_id
KILL QUERY
PROCESS
CONNECTION_ADMIN
SUPER
KILL
SELECT
GROUP BY
ALTER TABLE
KILL
UPDATE
DELETE
GET_LOCK()
Locked
REPAIR TABLE
OPTIMIZE TABLE
LOAD INDEX INTO CACHEtbl_index_list
[,tbl_index_list
] ...tbl_index_list
:tbl_name
[PARTITION (partition_list
| ALL)] [[INDEX|KEY] (index_name
[,index_name
] ...)] [IGNORE LEAVES]partition_list
:partition_name
[,partition_name
][, ...]
LOAD INDEX INTO
CACHE
CACHE INDEX
LOAD INDEX INTO
CACHE
MyISAM
IGNORE LEAVES
IGNORE LEAVES
t1
mysql> LOAD INDEX INTO CACHE t1, t2 IGNORE LEAVES;
+---------+--------------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------+--------------+----------+----------+
| test.t1 | preload_keys | status | OK |
| test.t2 | preload_keys | status | OK |
+---------+--------------+----------+----------+
t1
LOAD
INDEX INTO CACHE
MyISAM
pt
p3
负荷指数为缓存PT分区(P0);负荷指数为缓存分区(P1,P3)PT;
pt
负荷指数为缓存分区(全部);负载Pt Pt索引缓存;
PARTITION (ALL)
LOAD INDEX INTO
CACHE ... IGNORE LEAVES
Blocksize
RESETreset_option
[,reset_option
] ...reset_option
: { MASTER | SLAVE }
RESET
RELOAD
RESET
RESET
PERSIST
RESET
FLUSH
RESET
RESET
reset_option
RESET MASTER
RESET SLAVE
RESET PERSIST [[IF EXISTS] system_var_name
]
RESET PERSIST
SYSTEM_VARIABLES_ADMIN
SUPER
RESET
IF
EXISTS
RESET PERSIST
mysqld-auto.cnf
RESET PERSIST
system_var_name
mysqld-auto.cnf
RESET PERSIST IF EXISTS
system_var_name
mysqld-auto.cnf
RESET PERSIST
persisted_globals_load
RESET PERSIST
persisted_variables
RESET PERSIST
variables_info
RESTART
SHUTDOWN
RESTART
SET
PERSIST_ONLY
RESTART
RESTART
RESTART
RESTART
RESTART
--gdb
--no-monitor
--gdb
--no-monitor
RESTART
{EXPLAIN | DESCRIBE | DESC}tbl_name
[col_name
|wild
] {EXPLAIN | DESCRIBE | DESC} [explain_type
] {explainable_stmt
| FOR CONNECTIONconnection_id
}explain_type
: { FORMAT =format_name
}format_name
: { TRADITIONAL | JSON }explainable_stmt
: { SELECT statement | DELETE statement | INSERT statement | REPLACE statement | UPDATE statement }
DESCRIBE
EXPLAIN
DESCRIBE
EXPLAIN
DESCRIBE
EXPLAIN
DESCRIBE
MySQL的> DESCRIBE City;
------------ ---------- ------ ----- --------- ---------------- |场|型|空|关键|默认|额外| ------------ ---------- ------ ----- --------- ---------------- | ID | int(11)|没有| PRI |空| auto_increment | |名字| char(35)|没有| | | | |国| char(3)|没有|大学| | | |区| char(20)|是|多| | | |人口| int(11)|没有| | 0 | | ------------ ---------- ------ ----- --------- ----------------
DESCRIBE
SHOW COLUMNS
SHOW COLUMNS
DESCRIBE
col_name
wild
_
DESCRIBE
SHOW CREATE TABLE
SHOW TABLE STATUS
SHOW INDEX
EXPLAIN
EXPLAIN
EXPLAIN
EXPLAIN
connection_id
EXPLAIN
SHOW WARNINGS
EXPLAIN
FORMAT
FORMAT
EXPLAIN
SELECT
EXPLAIN
SHOW VIEW
EXPLAIN
EXPLAIN
SELECT
SELECT
EXPLAIN
ANALYZE
TABLE
EXPLAIN
HELP 'search_string
'
HELP
HELP
%
LIKE
rep
contents
帮助的内容
Data Types
帮助“数据类型”
ASCII()
CREATE TABLE
帮助ascii'help”创建表
HELP
HELP
name
description
example
HELP 'replace'
name: REPLACE description: Syntax: REPLACE(str,from_str,to_str) Returns the string str with all occurrences of the string from_str replaced by the string to_str. REPLACE() performs a case-sensitive match when searching for from_str. example: mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww'); -> 'WwWwWw.mysql.com'
name
is_it_category
N
HELP
HELP 'status'
+-----------------------+----------------+ | name | is_it_category | +-----------------------+----------------+ | SHOW | N | | SHOW ENGINE | N | | SHOW MASTER STATUS | N | | SHOW PROCEDURE STATUS | N | | SHOW SLAVE STATUS | N | | SHOW STATUS | N | | SHOW TABLE STATUS | N | +-----------------------+----------------+
source_category_name
name
is_it_category
N
HELP
HELP 'functions'
+----------------------+-------------------------+----------------+ | source_category_name | name | is_it_category | +----------------------+-------------------------+----------------+ | Functions | CREATE FUNCTION | N | | Functions | DROP FUNCTION | N | | Functions | Bit Functions | Y | | Functions | Comparison operators | Y | | Functions | Control flow functions | Y | | Functions | Date and Time Functions | Y | | Functions | Encryption Functions | Y | | Functions | Information Functions | Y | | Functions | Logical operators | Y | | Functions | Miscellaneous Functions | Y | | Functions | Numeric Functions | Y | | Functions | String Functions | Y | +----------------------+-------------------------+----------------+
USE db_name
USE
db_name
db_name
USE
使用db1;select count(*)从mytable;#选择从db1.mytableuse DB2;select count(*)从mytable;#选择从db2.mytable
USE
db1
db2
USE db1;SELECT author_name,editor_name FROM author,db2.editor WHERE author.editor_id = db2.editor.editor_id;