mysql表操作-約束刪除、用戶填加、授權(quán)和撤權(quán)方式
一、表的約束刪除
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

二、設(shè)置數(shù)據(jù)庫密碼策略
1.查看數(shù)據(jù)庫密碼的策略
show variables like '%validate_password%';

2.修改數(shù)據(jù)庫密碼的長度
set global validate_password.lenggnt=3;

3.修改數(shù)據(jù)庫密碼的安全等級
set global validate_password.policy=0;

三、增加用戶
1.創(chuàng)建用戶testuser1和testuser2密碼為123456
create user testuser1@'%' identified by '123456',testuser2@'%' identified by '123456';

2.查看用戶是否創(chuàng)建成功
select host,user,authentication_string from mysql.user;

3.登陸到testuser1看是都能登陸

四、用戶權(quán)限的授權(quán)與撤銷
1.查看testuser1當前的權(quán)限
show grants for testuser1;

2.給testuser1賦予增刪改查的權(quán)限
grant select,insert,update,create,alter,drop on mydb.* to testuser@'%';

3.再次查看testuser1的權(quán)限
show grants for testuser1;

4.登陸用戶名為testuser1的數(shù)據(jù)庫,進行檢驗是否成功,我們發(fā)現(xiàn)可以進行增刪改查
show databases; use mydb; create table test( -> id char(1), -> name varchar(10) -> );

5.移除用戶testuser1的表中的增刪改查,并且查詢他的權(quán)限
revoke create,drop,alter on mydb.* from testuser1@'%'; show grants for testuser1;

6.登陸用戶testuser1的數(shù)據(jù)庫,我們雖然可以查看數(shù)據(jù)庫但是不能對表進行增刪改查的操作
show databases; use mydb; show tables; create table test2( -> id int, -> name char(1) -> );

7.給testuser2賦予全部的權(quán)限
grant all privileges on *.* to testuser2@'%';

總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
MySQL報錯1118,數(shù)據(jù)類型長度過長問題及解決
在使用MySQL過程中,常見的一個問題是報錯1118,這通常發(fā)生在創(chuàng)建表時,錯誤提示為“Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual2024-10-10

