mysql 常用操作命令

建库

create database 库名

选择库

use 库名;

显示数据库中的所有表

show tables;

显示数据库中的一个表

show create table 表名;

创建表

create table 表名;

删除表

drop table 表名;

添加列

alter table 表名 add column 列名 not null ;

修改列

alter table 表名 modify column 列名 not null;

添加主键

alter table 表名 add primary key (列名);

删除主键

alter table 表名 drop primary key;

添加索引

alter table 表名 add index 索引名(列名);

删除索引

alter table 表名 drop index 索引名(列名);

添加外键

alter table 表名 add constraint 外键名 foreign key (列名)  references 指向的表名 (列名) on delete cascade on update cascade

删除外键

alter table 表名 drop constraint 外键名

alter table 表名 drop foreign key 外键名

修改引擎

alter table 表名 type=InnoDB;

原文地址:https://www.cnblogs.com/zhaozhilu/p/2759103.html