创建数据表 create
create table tb (列名1 数据类型,列名2 数据类型,...);
复制数据表 like
仅表格式,不含数据
create table tb_new like tb_old;
删除数据表 drop / trunctae
drop table if exists tb;
(快速删除,在事务之外)
trunctae table tb;
查看 show
查看所有数据表
show tables [from 库名];
查看表结构
show columns from tb;/ desc tb;
查看表创建语句
show create table tb;
查看指定表情况
desc tb;
查看表内索引
show indexes from tb\G;
查看表在电脑中的位置
show variables like '%datadir%';
索引
创建索引原则:数据量超过1万,经常被查询,字符较少
创建表时创建索引(可建多个索引)
create table tb(...,index[索引名](col));
添加索引
create index 索引名 on tb(col);
alter table tb add index[索引名](col);
查看索引
show index from tb;
删除索引
drop index 索引名 on tb;
修改 alter
修改表名称
alter table 旧表名 rename 新表名;/ rename table 旧表名 to 新表名;
修改表编码方式
alter table tb character set gbk/utf8;
添加列
alter table tb add col 数据类型 [first/after 列名];
删除列
alter table tb drop col_1, drop col_2, add...;
修改列定义
alter table tb modify col 数据类型 [first/after 列名];
修改列定义和列名称
alter table tb change 旧列名 新列名 数据类型 [first/after 列名];
