1、新建数据库并指定编码(避免乱码问题)
UTF-8:
create database test(数据库名) default character set utf8 collate utf8_general_ci;
GBK:
create database test(数据库名) default character set gbk collate gbk_chinese_ci;
2、查询表结构
Show columns from user(表名);
3、增加字段(布尔类型可用tinyint)
Alter table user(表名) add column username(字段名) int not null default 0 after account(字段名,在哪个字段后面);
4、删除非空约束
Alter table user(表名) modify username(字段名,该字段没有唯一索引) varchar(100)(根据原来的写即可) null;
5、添加自增的设置
已建表,未建字段
alter table table(表名) add id(字段名) int auto_increment primary key;
已建表,已建字段
alter table table(表名) change id(原字段名) newId(新字段名) int auto_increment primary key(PK如已设置不需添加);