一、授权
用户授权,我们涉及到了三个对象
1、用户名root 2、密码 3、主机localhost
创建名字为qq的用户
create user qq@localhost;
创建名字为anan用户并添加密码
create user anan@localhost identified by “123”;
创建用户允许远程端登录
create user anan@10.10.10.100 identified by “123”;允许10.10.10.100以anan登录mysql
create user anan@“10.10.10.%” identified by “123”; 允许10.10.10.0到10.10.10.255以anan登录mysql
create user anan@10.10.10.1_ identified by “123”;允许10.10.10.100到10.10.10.105以anan登录mysql
删除用户
drop user anan@10.10.10.100
删除用户要带上主机地址,避免有同名字不同主机地址的用户出现错删。
二、授权分类
常规权限分五种
select 查询权限
insert 插入权限
update 更新权限
create 创建权限
grant select on aa.bb to anan@localhost 将aa数据库的bb表的查询权限授权给
以localhost登录的anan用户。
grant insert on aa.bb to anan@localhost 将aa数据库的bb表的插入权限授权给
以localhost登录的anan用户。
grant delete on aa.bb to anan@localhost将aa数据库的bb表的删除权限授权给
以localhost登录的anan用户。
grant update on aa.bb to anan@localhost将aa数据库的bb表的更新权限授权给
以localhost登录的anan用户。
grant select(id,name) on aa.bb to anan@localhost 将bian数据库的bb表的id和name
字段的查询权限授权给localhost登录的anan用户
grant select,insert,update,delete on aa.bb to anan@localhost 将aa数据库的bb表的
增删改查的权限授权给以localhost登录的anan用户
**
三、 主外键关系
**
主键primary key:是一个表里的唯一标识,假如一个表没有主键,查询是遍历查询,如果有主键,会以
平衡树数据格式去找。
外键foreign key:就是以表唯一字段为内容的关联字段,约束;定义的时候创建外键
当前表要作为外键的字段 references 要对应的表(对应表的字段)定义好的表添加外键,外键字段必须先存在。
四、关联查询
1、inner join内关联查询
取左右两表的交集
2、left join左关联查询
取左表的所有和左右两表的交集
3、right join右关联查询
取右表的所有和左右两表的交集
五、模糊查询
like向
select * from student where name like “李%”
查询所有 表student中, 名字中姓李的人;当"%李%"这样查询的话 名字中间带“李”字的人也会被搜出