当前位置: 代码网 > it编程>数据库>Mysql > mysql表操作-约束删除、用户填加、授权和撤权方式

mysql表操作-约束删除、用户填加、授权和撤权方式

2024年09月14日 Mysql 我要评论
一、表的约束删除1.查看所有表的约束条件show create table student3\g2.删除主键alter table students3 drop primary key;3.删除唯一键

一、表的约束删除

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@'%';

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com