mysql許可權操作 Mysql許可權操作

2021-10-18 22:35:53 字數 2755 閱讀 2084

1、建立新使用者

通過root使用者登入之後建立

>> create user testuser@"%" identified by "testuser"   // 建立新使用者,使用者名稱testuser, 密碼為testuser,  可以遠端連線但沒有任何許可權

>> grant all privileges on *.* to user1@localhost identified by "123456" ;  //  建立新使用者,使用者名為user1,密碼為123456 ;

>> grant all privileges on *.* to user1@localhost identified by "123456" ;  //  設定使用者user1,可以在本地訪問mysql

>> grant all privileges on *.* to user1@"%" identified by "123456" ;   //  設定使用者user1,可以在遠端訪問mysql

>> flush privileges ;  //  mysql 新設定使用者或更改密碼後需用flush privileges重新整理mysql的系統許可權相關表,否則會出現拒絕訪問,還有一種方法,就是重新啟動mysql伺服器,來使新設定生效

2、設定使用者訪問資料庫許可權

>> grant all privileges on test_db.* to testuser@localhost identified by "123456" ;  //  設定使用者testuser,只能訪問資料庫test_db,其他資料庫均不能訪問 ;

>> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  設定使用者testuser,可以訪問mysql上的所有資料庫 ;

>> grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" ;  //  設定使用者testuser,只能訪問資料庫test_db的表user_infor,資料庫中的其他表均不能訪問 ;

3、設定使用者操作許可權

>> grant all privileges on *.* to testuser@localhost identified by "123456" with grant option ;  //設定使用者testuser,擁有所有的操作許可權,也就是管理員 ;

>> grant select on *.* to testuser@localhost identified by "123456" with grant option ;  //設定使用者testuser,只擁有【查詢】操作許可權 ;

>> grant select,insert on *.* to testuser@localhost identified by "123456"  ;  //設定使用者testuser,只擁有【查詢\插入】操作許可權 ;

>> grant select,insert,update,delete on *.* to testuser@localhost identified by "123456"  ;  //設定使用者testuser,只擁有【查詢\插入】操作許可權 ;

>> revoke select,insert on what from testuser  //取消使用者testuser的【查詢\插入】操作許可權 ;

4、設定使用者遠端訪問許可權

>> grant all privileges on *.* to testuser@「192.168.1.100」 identified by "123456" ;  //設定使用者testuser,只能在客戶端ip為192.168.1.100上才能遠端訪問mysql ;

5、刪除使用者許可權

>> revoke all privileges on customazition.* from customer@"%"     #revoke 用法和grant類似

>> grant all privileges on *.* to customer@"%"   需要用  revoke all privileges on *.* from customer@"%"  來刪除許可權

>> grant all privileges on customization.* to customer@"%"   需要用  revoke all privileges on customization.* from customer@"%"  來刪除許可權

>> revoke all privileges on *.* from customer@"%" 無法刪除 grant all privileges on customization.* to customer@"%" 建立的許可權

6、關於root使用者的訪問設定

設定所有使用者可以遠端訪問mysql,修改my.cnf配置檔案,將bind-address = 127.0.0.1前面加「#」注釋掉,這樣就可以允許其他機器遠端訪問本機mysql了;

>> grant all privileges on *.* to root@"%" identified by "123456" ;   //  設定使用者root,可以在遠端訪問mysql

>> select host,user from user;   //查詢mysql中所有使用者許可權

關閉root使用者遠端訪問許可權

>> delete from user where user="root" and host="%" ;  //禁止root使用者在遠端機器上訪問mysql

>> flush privileges ;  //修改許可權之後,重新整理mysql的系統許可權相關表方可生效

輸入mysql無許可權 mysql 操作使用者許可權

使用可以對mysql資料庫使用者表有操作許可權的使用者名稱登陸mysql insert into user host,user,password values name password 如果work使用者沒有登陸許可權,則 killall mysqld share mysql mysql.serv...

設定mysql使用者的許可權 mysql使用者許可權設定

關於mysql的使用者管理,筆記 1 建立新使用者 通過root使用者登入之後建立 grant all privileges on to testuser localhost identified by 123456 建立新使用者,使用者名為testuser,密碼為123456 grant all ...

mysql訪問許可權有哪些 MySQL訪問許可權系統

mysql許可權系統的主要功能是驗證從給定主機連線的使用者,並將該使用者與資料庫上的許可權 如select,insert,update和delete 相關聯。附加功能包括維護,授予mysql特定功能 如load data infile 和管理性操作的許可權。mysql許可權系統具有如下限制 不具備使...