Mysql安全機制

來源:互聯網
上載者:User

標籤:

在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安全機制

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.