標籤:
在mysql下mysql庫中有6個許可權表
mysql.user
使用者欄位,許可權欄位,安全欄位,資源控制欄位
mysql.db 、 mysql.host
使用者欄位,許可權欄位
mysql.tables_priv,mysql.columms_priv,mysql.procs_priv
一、使用者管理
(1)建立使用者的三種方法
1.create user [email protected]‘localhost‘ identified by ‘123456‘;2.insert into mysql.user(user,host,password,ssl_cipher,x509_issuer,x509_subject) values(‘user2‘,‘localhost‘,password(‘123456‘),‘‘,‘‘,‘‘);3.grant select on *.* to [email protected]‘localhost‘ identified by ‘123‘ //授select權所有庫和所有表給user3,密碼123
flush privileges
(2)刪除使用者
1.drop user [email protected]‘localhost‘2.delete from mysql.user where user=‘user1‘ and host=‘localhost‘;
(3)root使用者修改自己密碼
1.mysqladmin -uroot -proot password ‘123‘2.update mydql.user set password=password(‘new_password‘) where user=‘root‘ and host=‘localhost‘;3.set password=password(‘new_password‘)
flush privileges //重新整理授權表
(4)root使用者修改其他使用者密碼
1.set password for [email protected]‘localhost‘ =password(‘new_password‘);flush privileges;2.updatae mysql.user set password=password(‘new_password‘) where user=‘user3‘ and host=‘localhost‘;flush privileges;3.grant select on *.* to [email protected]‘localhost‘ identified by ‘pwd‘;flush privileges;
(5)普通使用者修改自己密碼
set password=password(‘new_password‘);
(6)丟失root使用者密碼
vim /etc/my.cnfskip-grant-tables//將這句話的注釋去掉service mysqld restartmysql -uroot //然後就可以跳過許可權表進入mysqlupdate mysql.user set password=password(‘new_password‘) where user=‘user3‘ and host=‘localhost‘;flush privileges;\q //退出mysqlvim /etc/my.cnf#skip-grant-tables //將這句話再重新注釋
二、許可權管理
文法格式:grant 許可權列表 on 庫名.表名 to 使用者名稱@‘用戶端‘ [identified by ‘password‘ with grant option]
其中:with_option參數如下
grant option: 授權選項max_queries_per_hour:定義每小時允許執行的查詢數max_updates_per_hou:定義每小時允許執行的更新數max_connections_per-hour:定義每小時可以建立的串連數max-user_connections:定義單個使用者同是可以建立的串連數
授權樣本
grant all on *.* to [email protected]‘%‘ identified by ‘password‘;grant all on *.* to [email protected]‘%‘ identified by ‘pw‘ with grant option;grant all on *.* bbs.* to [email protected]‘%‘ identified by ‘pw‘;grant all on bbs.user to [email protected]‘%‘ identified by ‘pw‘;grant select(col1),insert(col2,col3) on bbs.user to [email protected]‘%‘ identified by ‘pw‘;flush privileges
查看許可權
show grants for [email protected]‘%‘ \G;
回收許可權 revoke 許可權列表 on 資料庫名 from 使用者名稱@‘用戶端主機‘
1.revoke delete on *.* from [email protected]‘%‘;//回收部分許可權2.revoke all privileges on *.* from [email protected]‘%‘;revoke grant on *.* from [email protected]‘%‘; //回收全部許可權(包括授權)
flush privileges; //重新整理授權
Mysql安全機制