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')
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;