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ù)庫密碼的長(zhǎng)度
set global validate_password.lenggnt=3;

3.修改數(shù)據(jù)庫密碼的安全等級(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當(dāng)前的權(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ù)庫,進(jìn)行檢驗(yàn)是否成功,我們發(fā)現(xiàn)可以進(jì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ù)庫但是不能對(duì)表進(jìn)行增刪改查的操作
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é)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
SPSS連接mysql數(shù)據(jù)庫的超詳細(xì)操作教程
小編最近在學(xué)習(xí)SPSS,在為數(shù)據(jù)庫建立連接時(shí)真的踩了很多坑,這篇文章主要給大家介紹了關(guān)于SPSS連接mysql數(shù)據(jù)庫的超詳細(xì)操作教程,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
MySQL5.6 GTID模式下同步復(fù)制報(bào)錯(cuò)不能跳過的解決方法
搭建虛擬機(jī)centos6.0, mysql5.6.10主從復(fù)制,死活不同步,搞了一整天找到這篇文章終于OK了,特分享一下,需要的朋友可以參考下2020-04-04
MySQL批量修改表及表內(nèi)字段排序規(guī)則舉例詳解
mysql數(shù)據(jù)庫遷移數(shù)據(jù)目錄至另一臺(tái)服務(wù)器詳細(xì)步驟
Mysql連接本地報(bào)錯(cuò):1130-host?...?is?not?allowed?to?connect?t

