DDL语句
create 创建
alter 修改
drop 删除
创建表格式 create table 表名(
字段名1 数据类型 约束条件,
字段名2 数据类型 约束条件,
...);
例如:create table student(
id int(20),
name char(40),
age int);
添加,修改,删除表字段 格式:
删除字段 alter table 表名 drop 字段;
例如:
alter table student drop age;
查看表结构 show columns from 表名;
例如:
show columns from student;
添加字段 alter table 表名 add 字段 数据类型 约束条件;
例如:
alter table student add age int not null;
修改字段 alter table 表名 modify字段名 数据类型 约束条件;
例如:
alter table student modify age int null;
删除表 drop table 表名;
例如:
drop table student;
DML语句
insert 添加
update 修改
delete 删除
添加数据 insert into 表名 values (字段值,字段值,字段值...);
例如:
insert into student values (1,’张三’,18);
添加多行数据 insert into 表名 values (字段值,字段值,字段值...),(字段值,字段值,字段值...),(字段值,字段值,字段值...);
修改数据 update 表名 set 字段=新值 where 条件
例如:
update student set id=2 where name=’张三’;
删除数据 delete from student where 条件
例如:
delete from student where id=1
DCL语句
授权
grant 权限
.表 to '用户' @'IP' identified by '密码';
取消授权 revoke 权限 on 库.表 from '用户' @'IP';
查看某个的用户权限 use mysql;
select * from user where user='用户名称'\G;
查看所有用户权限 select * from user;