MySQL database common commands summary 1. first determine whether the database/table exists, and then create a database/table
CREATE DATABASE IF NOT EXISTS database_name;CREATE TABLE IF NOT EXISTS table_name;
2. modify the table name in MySQL. modify the table name in MySQL.
AITER TABLE table_old_name RENAME [TO] table_new_name; RENAME TABLE table_old_name TO table_new_name;
3. add columns for MySQL and add columns for MySQL
ALTER TABLE table_name ADD column_name data_type NOT NULL DEFAULT xxx [AFTER/BEFORE] column_name;ALTER TABLE person ADD age tinyint NOT NULL DEFAULT 16 AFTER name;
4. MySQL deletes a column.
ALTER TABLE table_name DROP [COLUMN] column_name;ALTER TABLE person DROP COLUMN age;
5. modify MySQL columns
Alter table table_name CHANGE [COLUMN] column_old_name column_new_name COLUMN declaration
6. MySQL modifies the column data type and only modifies the column data type.
ALTER TABLE table_name MODIFY [COLUMN] column_name data_type;ALTER TABLE person MODIFY COLUMN age int NOT NULL DEFAULT 16;
7. create an index for MySQL
Alter table table_name ADD index/unique/fulltext [index name] (column name); if no index name is added, the alter table table_name ADD primary key (column name) name is directly used );
8. MySQL deletes an index.
Alter table table_name DROP index name; alter table table_name DROP primary key;
9. View all indexes in MySQL
show index from table_name; show index from table_name/G;
10. MySQL
/GMYSQL statement
/GThe parameter changes the display mode of the output result set.