目录
1.创建用户testuser1和testuser2密码为123456
4.登陆用户名为testuser1的数据库,进行检验是否成功,我们发现可以进行增删改查
5.移除用户testuser1的表中的增删改查,并且查询他的权限
6.登陆用户testuser1的数据库,我们虽然可以查看数据库但是不能对表进行增删改查的操作
一、表的约束删除
1.查看所有表的约束条件
show create table student3\G
2.删除主键
alter table students3 drop primary key;
3.删除唯一键
alter table student3 drop index student3_un_1;
4.删除check键值
alter table students drop check student3_chk_1;
5.删除check键值
alter table student3 drop check student3_chk_2;
6.删除not null键值并删除check键值
alter table students modify stu_gender char(1);
alter table students drop check student3_chk_2;
7.删除键外值
alter table student3 drop constraint student3_fo_1;
alter table student3 drop key student3_fo_1;
8.检查表的约束条件是否存在
show create table student3\G
二、设置数据库密码策略
1.查看数据库密码的策略
show variables like '%validate_password%';
2.修改数据库密码的长度
set global validate_password.lenggnt=3;
3.修改数据库密码的安全等级
set global validate_password.policy=0;
三、增加用户
1.创建用户testuser1和testuser2密码为123456
create user testuser1@'%' identified by '123456',testuser2@'%' identified by '123456';
2.查看用户是否创建成功
select host,user,authentication_string from mysql.user;
3.登陆到testuser1看是都能登陆
四、用户权限的授权与撤销
1.查看testuser1当前的权限
show grants for testuser1;
2.给testuser1赋予增删改查的权限
grant select,insert,update,create,alter,drop on mydb.* to testuser@'%';
3.再次查看testuser1的权限
show grants for testuser1;
4.登陆用户名为testuser1的数据库,进行检验是否成功,我们发现可以进行增删改查
show databases;
use mydb;
create table test(
-> id char(1),
-> name varchar(10)
-> );
5.移除用户testuser1的表中的增删改查,并且查询他的权限
revoke create,drop,alter on mydb.* from testuser1@'%';
show grants for testuser1;
6.登陆用户testuser1的数据库,我们虽然可以查看数据库但是不能对表进行增删改查的操作
show databases;
use mydb;
show tables;
create table test2(
-> id int,
-> name char(1)
-> );
7.给testuser2赋予全部的权限
grant all privileges on *.* to testuser2@'%';