MySQL安全機制 DDL DCL

2022-05-07 15:57:24 字數 4202 閱讀 2869

一、mysql使用者管理

1. 修改使用者密碼

===root修改自己密碼===

方法一:

# mysqladmin -uroot -p'123' password 'new_password' //123為舊密碼

方法二:

mysql > update mysql.user set authentication_string=password(『new_password』)

where user=』root』 and host=』localhost』;

mysql > flush privileges;

方法三:

mysql > set password=password(『new_password』);

===root修改其他使用者密碼===

方法一:

mysql > set password for user3@』localhost』=password(『new_password』);

方法二:

mysql > update mysql.user set authentication_string=password(『new_password』)

where user=』user3』 and host=』localhost』;

mysql > flush privileges;

===普通使用者修改自己密碼===

mysql > set password=password(『new_password』);

===丟失root使用者密碼===

進入mysql的配置檔案,在[mysqld]欄位中新增skip-grant-tables,及取消mysql的root密碼,儲存並退出,重啟mysql生效。

# vim /etc/my.cnf

[mysqld]

skip-grant-tables

# service mysqld restart

# mysql -uroot

mysql> update mysql.user set authentication_string=password(『new_password』)

where user=』root』 and host=』localhost』;

mysql> flush privileges;

2. 登入和退出mysql

示例:

mysql -h192.168.5.240 -p 3306 -u root -p123 mysql -e 『select user,host from user』

-h 指定主機名 【預設為localhost】

-p mysql伺服器端口 【預設3306】

-u 指定使用者名稱 【預設root】

-p 指定登入密碼 【預設為空密碼】

此處mysql為指定登入的資料庫

-e 接sql語句

3. 建立使用者

方法一:create user語句建立

create user user1@』localhost』 identified by 『123456』;

方法二: grant語句建立

grant all on *.* to 'user3'@』localhost』 identified by 『123456』;

flush privileges;

4. 刪除使用者

方法一:drop user語句刪除

drop user 'user1'@』localhost』;

方法二:delete語句刪除

delete from mysql.user where user=』user2』 and host=』localhost』;

flush privileges;

二、mysql許可權管理 

1、許可權應用的順序:

user (y|n) ==> db ==> tables_priv ==> columns_priv 

2、語法格式:

grant 許可權列表 on 庫名.表名 to '使用者名稱'@'客戶端主機' [identified by '密碼' with option引數];

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

select,update

==資料庫.表名        *.*               所有庫下的所有表        global level

web.* web          庫下的所有表           database level

web.stu_info web       庫下的stu_info表         table level

select (col1), insert (col1,col2) on mydb.mytbl        column level

==客戶端主機         %              所有主機

192.168.2.%             192.168.2.0網段的所有主機

192.168.2.168           指定主機

localhost            指定主機

3、with_option引數

grant option:                      授權選項

max_queries_per_hour:    定義每小時允許執行的查詢數

max_updates_per_hour:    定義每小時允許執行的更新數

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

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

4、grant示例:

grant all on *.* to admin1@'

%' identified by '

(dulingyu)';

grant all on *.* to admin2@'

%' identified by '

(dulingyu)

'with grant option;

grant all on bbs.* to admin3@'

%' identified by '

(dulingyu)';

grant all on bbs.* to admin3@'

192.168.122.220

' identified by '

(dulingyu)';

grant all on bbs.user to admin4@'%

' identified by '

(dulingyu)';

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

' identified by '

(dulingyu)

';

5、**許可權revoke

檢視許可權

show grants\g;

show grants for admin1@'%'\g;

**許可權revoke

語法:revoke 許可權列表 on 資料庫名 from 使用者名稱@『客戶端主機』

示例:revoke delete on *.* from admin1@』%』; //**部分許可權

revoke all privileges on *.* from admin2@』%』; //**所有許可權

revoke all privileges,grant option on *.* from 'admin2'@'%';

刪除使用者:

5.6          revoke all privilege              drop user

5.7                              drop user

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.user表 非常重要 一 使用者字段 二 許可權字段 三 安全字段 四 資源控制字段 mysql.db mysql.hsot 使用者字段 許可權字段 mysql.tables priv mysql.columms priv procs priv 登入和退出mysql 例項 mysql h...