mysql表操作-約束刪除、用戶填加、授權和撤權方式
一、表的約束刪除
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ù)據(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看是都能登陸
四、用戶權限的授權與撤銷
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的數(shù)據(jù)庫,進行檢驗是否成功,我們發(fā)現(xiàn)可以進行增刪改查
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的數(shù)據(jù)庫,我們雖然可以查看數(shù)據(jù)庫但是不能對表進行增刪改查的操作
show databases; use mydb; show tables; create table test2( -> id int, -> name char(1) -> );
7.給testuser2賦予全部的權限
grant all privileges on *.* to testuser2@'%';
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
SPSS連接mysql數(shù)據(jù)庫的超詳細操作教程
小編最近在學習SPSS,在為數(shù)據(jù)庫建立連接時真的踩了很多坑,這篇文章主要給大家介紹了關于SPSS連接mysql數(shù)據(jù)庫的超詳細操作教程,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2023-02-02MySQL5.6 GTID模式下同步復制報錯不能跳過的解決方法
搭建虛擬機centos6.0, mysql5.6.10主從復制,死活不同步,搞了一整天找到這篇文章終于OK了,特分享一下,需要的朋友可以參考下2020-04-04MySQL批量修改表及表內(nèi)字段排序規(guī)則舉例詳解
在MySQL中字段排序規(guī)則(也稱為字符集和排序規(guī)則)用于確定如何比較和排序字符串,下面這篇文章主要給大家介紹了關于MySQL批量修改表及表內(nèi)字段排序規(guī)則的相關資料,需要的朋友可以參考下2024-05-05mysql數(shù)據(jù)庫遷移數(shù)據(jù)目錄至另一臺服務器詳細步驟
MySQL數(shù)據(jù)庫轉(zhuǎn)移到新服務器是指將現(xiàn)有的MySQL數(shù)據(jù)庫遷移至一個新的服務器環(huán)境中,下面這篇文章主要給大家介紹了關于mysql數(shù)據(jù)庫遷移數(shù)據(jù)目錄至另一臺服務器的詳細步驟,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-07-07Mysql連接本地報錯:1130-host?...?is?not?allowed?to?connect?t
這篇文章主要給大家介紹了關于Mysql連接本地報錯:1130-host?...?is?not?allowed?to?connect?to?this?MySQL?server的解決方法,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2023-03-03