1.1库操作
查看所有库
show databases;
指定使用某个数据库
use 数据库名;
创建数据库
create database [if not exists] 库名 [character set 字符集名];
修改库名
alter database 库名 character set 字符集名;
删除库
drop database [if exists] 库名;
1.2表操作
创建表
create table [if not exists] [数据库名.]数据表名 (字段名1 数据类型 约束,字段名2 数据类型 约束,...);
修改表名
alter table 旧表名 rename [to] 新表名
删除表
drop table [if exists] 表名;
复制表
# 复制表结构create table 表名 like 要复制的表;# 复制表的结构+数据create table 表名select 查询列表from 要复制的表[where筛选条件]
1.3列操作
添加列
alter table 表名 add column 列名 类型 [first|after 列名];
ps:最后的first或after表示添加列到某一列的之前或之后,如果不加默认会添加到最后
修改列名
alter table 表名 change column 旧列名 新列名 数据类型;
修改列的数据类型或约束
alter table 表名 modify column 列名 新类型 [新约束];
删除列
alter table 表名 drop column 列名;
