mysql管理之安全機制

2021-09-20 20:31:28 字數 4132 閱讀 7505

mysql.user表

非常重要

一、使用者字段

二、許可權字段

三、安全字段

四、資源控制字段

mysql.db  mysql.hsot

使用者字段

許可權字段

mysql.tables_priv

mysql.columms_priv

procs_priv

登入和退出mysql

例項:mysql -h 192.168.5.240 -p 3306  -uroot -p123 mysql -e 

『select user,host from user』

-h  主機名

-p 伺服器端口

-u 使用者名稱

-p 密碼

-e 連線

sql語句

\s獲取當前伺服器狀態資訊

quit退出登入

建立使用者

方法一create user語句建立

例項:create user user1@

』localhost

』identified by 

『123456』;

方法二insert語句建立  不常用

例項:insert into mysql.user(user,host,password,ssl_cipher,x509_issuer,x509_subject)

values (

『user2』,

』localhost』,

』password(

『123456』),

』』,』』);

flush privileges;

方法三grant語句建立  

//同時授權,最常用

例項:grant select on 『*

』to user3@ 

『localhost

』identitied by 

『123456』;

flush privileges;

刪除使用者

方法一drop user語句刪除

drop user user1@

』localhost』;

方法二delect語句刪除

delect from mysql.user where user=

』user2

』and host=

』localhsot』;

flush privileges;

修改使用者密碼(root修改自己密碼

)方法一

mysqladmin -u root -p password 

『new password

』//將提示輸入舊密碼

方法二update mysql.user set password=password(

『new password

』) where user=

』root

』and host=

』localhost』;

flush privileges;

方法三set password=password(

『new password』);

flush privileges;

root修改其他使用者密碼

方法一set password for user3@

』localhost

』=password(

『new_password』);

flush privileges;

方法二update mysql.user set password=password(

『new passowrd

』) where user=

』user3

』and host=

』localhost』;

flush privileges;

方法三grant select on 『*

』to user3@

』localhost

』identified by 

『tianyun』;

flush privileges;

普通使用者修改自己密碼

set password=password(

『new passowrd』);

丟失root使用者密碼

vim /etc/my.cnf

skip-grant-tables   //增加這一句表示跳過授權表也就是跳過密碼驗證

儲存退出

service mysqld restart  //重啟

mysq

伺服器

mysql -uroot

update mysql.user set password=password(

『new password

』) where user=

』root

』and host=

』localhost』;

flush privileges;

user(y/n)==>db==>tables_priv==>colums_priv

grant 許可權列表 

on 庫名

.表名 

to  

使用者名稱@'

客戶端主機

'  [identified by '

密碼' with grant option]

1)許可權列表   all   所有許可權(不包括授權許可權)

select update

2)庫名.表名  

*.*  

所有資料庫

資料庫.*  指定資料庫下的所資料物件  最常用

資料庫名稱.表名稱 指定資料庫的指定表

3)客戶端主機

物件列表(為誰賦值了上面的增刪改查的這些許可權

)%   所有主機

192.168.2.%   192.168.2.段的主機

192.168.2.8   指定主機

4)with_option

引數grant option          授權選項

max_queries_per_hour;   定義每小時允許查詢的查詢數

max_updates_per_hour;   定義每小時允許更新的查詢數

max_connections_per_hour; 定義每小時可以建立的連線數

max_user_connections;    定義單個使用者同時可以建立的連線數

例項:把pro這個資料庫下的所有許可權都給了李四

grant all on pro.*  to lisi@localhost;

//db級的

grant all on 

*.*  to

admin1@`%` identified by 

『tianyun

』;   //全域性

grant all on pro.*  to 

admin2@`%` identified by 

『tianyun

』with grant option;  //增加這個使用者的授權許可權

grant all on 

bbs.user to admin4@』% 

』identified by 

『tianyun

』//表級

grant select (col1),insert(col2,col3) on bbs.user to admin@』%

』identified by 

『tianyun

』;  //列級別

檢視許可權:

show grants for 使用者名稱

@客戶端主機名  

\g例項 show grants for admin1@』%

』\g

刪除收回許可權

revoke 許可權列表 

on 物件列表 

from 

使用者列表

revoke all on pro.* from lisi@localhost;

//**所有許可權

revoke 

delete 

on pro.* from lisi@localhost;

//**部分許可權

注意:在日常管理中在刪除使用者之前應該是先刪除該使用者所有許可權,再刪除該使用者,不然以後如果再建立相同的使用者的話許可權就還是存在的,這是不可以的

mysql安全機制 Mysql安全機制

在mysql下mysql庫中有6個許可權表 mysql.user 使用者字段,許可權字段,安全字段,資源控制字段 mysql.db mysql.host 使用者字段,許可權字段 mysql.tables priv,mysql.columms priv,mysql.procs priv 一 使用者管理...

Mysql安全機制

在mysql下mysql庫中有6個許可權表 mysql.user 使用者字段,許可權字段,安全字段,資源控制字段 mysql.db mysql.host 使用者字段,許可權字段 mysql.tables priv,mysql.columms priv,mysql.procs priv 一 使用者管理...

mysql安全管理 MySQL安全管理

資料庫伺服器通常包含關鍵的資料,確保這些資料的安全和完整需要利用訪問控制。一 訪問控制 mysql伺服器的安全基礎 使用者應該對他們需要的資料具有適當的訪問權,既不能多也不能少。訪問控制 你需要給使用者提供他們所需的訪問權,且僅提供他們所需的訪問權。在日常工作中,絕不能使用root,應該建立一系列的...