MySQL安全 使用者語句和函式

2021-09-29 05:24:39 字數 2388 閱讀 3192

使用者訪問許可權資訊儲存在一組規則的myisam表中,稱之為授權表。這些表位於mysql資料庫中,分別是:

其他表提供了使用者訪問和安全的細調(fine-tuning)。可以直接使用標準的sql語句在這些表中操縱資料,後面接著flush privileges語句來更新伺服器快取。不過更推薦專門的sql語句來管理使用者並設定訪問權

與安全和使用者有關的語句列表

create user、drop user、flush、grant、rename user、reset、revoke、se password、show grants、show privileges

與函式有關的語句列表

aes_decrypt()、aes_encrypt()、current_user()、decode()、des_decrypt()、des_encrypt()、encode()、encrypt()、md5()、old_password()、password()、session_user()、sha()、sha1()、system_user()、user()

create user

create user 'user'[@'host'] [identified by [password] 'password'][, ...]
host使用localhost或者127.0.0.1可以本地訪問mysql,使用萬用字元%允許客戶端指定使用者從任意主機連線。

使用者密碼位於identified by子句之後,並在引號中用存文字給出。不必使用password()對密碼加密;密碼加密工作會自動完成。如果打算把密碼設定成雜湊值,使用identified by password子句,如果沒有指定password子句,密碼為空。後續使用set password語句來設定密碼。

使用逗號分隔的列表指定多個使用者賬戶。

drop user

drop user 'user'@'host'
從mysql5.0.2版本開始,這條語句將刪除使用者賬戶和來自所有授權表的特權。

一些使用者可能不止有乙個賬戶(使用者和主機的組合)。為了確保這一點,應該檢查mysql.user表:

select user,host from mysql.user where user like 'sss';
5.0.2版本之前,drop user並不刪除具有全域性許可權的使用者。為了撤銷使用者賬戶的許可權,在使用drop user之前,使用revoke語句

revoke  all on *.* from ''@'';

drop user 'use'@'host'

all選項用以確保刪除所有許可權。*.* 涵蓋了所有資料庫中的所有表。

在mysdql4.1.1版本之前,必須使用如下語句而不是drop user語句:

delete from mysql.user where user='' and host = '';

flush privileges;

必須使用flush privileges才能令前面的delete 語句失效。而在drop user語句之後,這個語句並非必須的。

flush語法

flush [local|no_write_to_binlog] option[,…]

選項:des_key_file,hosts,logs,master,privilege,query_cache,status,table,tables,tables without read lock,user_resources

使用flush語句可以清楚並且過載mysql的臨時快取。想要執行flush命令,必須擁有reload許可權。為了防止該語句攜入二進位制日誌檔案,可以使用no_write_to_binlog標記或者其別名local。

從5.1版本開始,flush不能用在儲存函式和觸發器中,但是可以用在儲存過程之中。

grant 語法

grant

priv_type [(column_list)]

[, priv_type [(column_list)]] ...

on [object_type] priv_level

to user [auth_option] [, user [auth_option]] ...

[require ]

[with ...]

grant proxy on user

to user [, user] ...

[with grant option]

object_type:

priv_level:

user:

(see section 6.2.4, 「specifying account names」)

auth_option:

tls_option:

resource_option:

MySQL 使用者 授權 安全

1 建立乙個使用者,並設定此使用者的密碼 刪除乙個使用者 2 授權 grant 在on 子句中,授予的許可權可以限定為資料庫 表 函式和過程。表示所有的資料庫或表或過程。上例中使用了 all 關鍵字,為該使用者授予了所有的基本許可權。為了令該使用者可以使用grant語句的權力,需要指定 with g...

mysql 語句 mysql對使用者操作的語句

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 登入mysql mysql u root p 密碼 建立使用者 mysql insert into mysql.user host,user,password values...

mysql使用者相關配置語句

mysql配置允許內網機器連線 grant all privileges on to myusername 192.168.1.identified by mypassword with grant option flush privileges 192.168.1.指允許該網段的全部機器 修改使用...