Mysql DDL操作执行的三种方式 1,INPLACE,在进行DDL操作时,不影响表的读&写,可以正常执行表上的DML操作,避免与COPY方法相关的磁盘I/O和CPU周期,从而最小化数据库的总体负载。 最小化负载有助于在DDL操作期间保持
CREATE INDEX name ON table (col_list);(ALTER TABLE tbl_name ADD INDEX name (col_list);)
DROP INDEX name ON table;(ALTER TABLE tbl_name DROP INDEX name;)
ALTER TABLE tbl_name RENAME INDEX old_index_name TO new_index_name, ALGoRITHM=INPLACE, LOCK=NONE;
CREATE FULLTEXT INDEX name ON table(column);
CREATE TABLE geom (g GEOMETRY NOT NULL);ALTER TABLE geom ADD SPATIAL INDEX(g), ALGORITHM=INPLACE, LOCK=SHARED;
ALTER TABLE tbl_name DROP INDEX i1, ADD INDEX i1(key_part,...) USING BTREE, ALGORITHM=INPLACE;
主键操作
ALTER TABLE tbl_name ADD PRIMARY KEY (column)
ALTER TABLE tbl_name DROP PRIMARY KEY
ALTER TABLE tbl_name DROP PRIMARY KEY, ADD PRIMARY KEY (column)
ALTER TABLE tbl_name ADD COLUMN column_name column_definition,
ALTER TABLE tbl_name DROP COLUMN column_name
ALTER TABLE tbl CHANGE old_col_name new_col_name data_type
ALTER TABLE tbl_name MODIFY COLUMN col_name column_definition FIRST
ALTER TABLE tbl_name CHANGE c1 c1 BIGINT
ALTER TABLE tbl_name CHANGE COLUMN c1 c1 VARCHAR(255)
ALTER TABLE tbl_name ALTER COLUMN col SET DEFAULT literal
ALTER TABLE tbl ALTER COLUMN col DROP DEFAULT
ALTER TABLE table AUTO_INCREMENT=next_value
ALTER TABLE tbl_name MODIFY COLUMN column_name data_type NULL
ALTER TABLE tbl_name MODIFY COLUMN column_name data_type NOT NULL
ALTER TABLE t1 MODIFY COLUMN c1 ENUM("a", "b", "c", "d")
衍生列(generated column)操作
ALTER TABLE t1 ADD COLUMN (c2 INT GENERATED ALWAYS AS (c1 + 1) STORED)
ALTER TABLE t1 MODIFY COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) STORED FIRST
ALTER TABLE t1 DROP COLUMN c2, ALGORITHM=INPLACE, LOCK=NONE;
ALTER TABLE t1 ADD COLUMN (c2 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL)
ALTER TABLE t1 MODIFY COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL FIRST
ALTER TABLE t1 DROP COLUMN c2, ALGORITHM=INPLACE
外键操作ALTER TABLE tbl1 ADD CONSTRaiNT fk_name FOREIGN KEY index (col1)REFERENCES tbl2(col2) referential_actions;
ALTER TABLE tbl DROP FOREIGN KEY fk_name;
表操作ALTER TABLE tbl_name ROW_FORMAT = row_format
ALTER TABLE tbl_name KEY_BLOCK_SIZE = value
ALTER TABLE tbl_name STATS_PERSISTENT=0, STATS_SAMPLE_PAGES=20, STATS_AUTO_RECALC=1, ALGORITHM=INPLACE, LOCK=NONE;
ALTER TABLE tbl_name CHARACTER SET = charset_name, ALGORITHM=INPLACE, LOCK=NONE;
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name, ALGORITHM=COPY;
OPTIMIZE TABLE tbl_name;
ALTER TABLE tbl_name FORCE, ALGORITHM=INPLACE, LOCK=NONE;
ALTER TABLE tbl_name ENGINE=InnoDB, ALGORITHM=INPLACE, LOCK=NONE;
ALTER TABLE old_tbl_name RENAME TO new_tbl_name, ALGORITHM=INPLACE, LOCK=NONE;
表空间操作
ALTER TABLE tbl_name ENCRYPTION="Y", ALGORITHM=COPY;
参考: https://dev.mysql.com/doc/refman/5.7/en/innodb-online-ddl-operations.html Https://dbaplus.cn/news-11-2552-1.html
--结束END--
本文标题: MySQL Online DDL与DML并发阻塞关系总结
本文链接: https://lsjlt.com/news/1887.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0