mysql使用者資源限制

2021-07-03 02:37:01 字數 2371 閱讀 6426

mysql資料庫對使用者有限制,比如密碼更新多少次,該使用者最大連線數等

sql/structs.h原始碼定義了結構體

typedef struct  user_conn user_conn;

可以看到,其中儲存了使用者名稱、客戶端host資訊,還有本使用者的更新數、連線數等。與之配套的,是乙個hash結構hash_user_connections,hash_key中包含user和host。因此相同user &host的連線共享同乙個user_conn.

2、資料來源

conn_per_hour, updates, questions是當前連線對應的使用者的實時統計資訊。user_resources為元資料,**於表mysql.user.

如:在localhost用root賬戶登入,update mysql.user set max_updates =2 where user=』root』; flush privileges; (必須flush後才生效)。則此賬號最多只能執行2個更新操作(不侷限於update)。

3、相關問題

hash_user_connections為記憶體結構,因此統計資訊重啟後並不儲存;

如果達到某個統計值達到上限,比如更新數,如何清空?

實際上並沒有提供單獨清空某個統計值的介面。但在執行 flush privileges和flush user_resources時,會將所有的統計值清空。對應被呼叫的函式為 reset_mqh (sql/sql_connect.cc)

void reset_mqh(lex_user *lu, bool get_them= 0)

}else

}mysql_mutex_unlock(&lock_user_conn);

#endif /* no_embedded_access_checks */

}4、是否所有的連線都會設定user_connect?

實際上,由於mysql.user裡面的最後四個字段往往是被設定為預設的0。是否設定user_connect就取決於配置引數max_user_connections。 若為0,則該server的所有連線,都不設定user_connect.。估計是mysql考慮到所有這些值都為0,不需要記錄統計資訊。實現策略的**為:

vim sql/sql_acl.cc

if ((acl_user->user_resource.questions || acl_user->user_resource.updates ||

acl_user->user_resource.conn_per_hour ||

acl_user->user_resource.user_conn ||

global_system_variables.max_user_connections) &&

get_or_create_user_conn(thd,

(opt_old_style_user_limits ? sctx->user : sctx->priv_user),

(opt_old_style_user_limits ? sctx->host_or_ip : sctx->priv_host),

&acl_user->user_resource))

dbug_return(1); // the error is set by get_or_create_user_conn()

sctx->password_expired= acl_user->password_expired;

#endif

}else

sctx->skip_grants();

const user_conn *uc;

if ((uc= thd->get_user_connect()) &&

(uc->user_resources.conn_per_hour || uc->user_resources.user_conn ||

global_system_variables.max_user_connections) &&

check_for_max_user_connections(thd, uc))

dbug_print("info",

("capabilities: %lu  packet_length: %ld  host: '%s'  "

"login user: '%s' priv_user: '%s'  using password: %s "

"access: %lu  db: '%s'",

thd->client_capabilities, thd->max_client_packet_length,

sctx->host_or_ip, sctx->user, sctx->priv_user,

thd->password ? "yes": "no",

sctx->master_access, mpvio.db.str));

mysql資源限制 MySQL 限制使用者使用資源

在mysql 5.7及後續版本中,可以按照賬號來限制每個賬號實際具有的資源限制。語法 grant with option,如 grant select on test.to user1 localhost with max queries per hour3max user connections5...

MySQL之使用者資源限制

膜拜一下,mysql太強悍了。建立新使用者 mysql grant all privileges on to zhaiwx1987 localhost identified by 123456 with grant option 而通過如下語句建立使用者,則暫不授權,所有許可權都未開啟.grant ...

MYSQL中限制資源的使用

今天看到手冊,不小心看到了這裡,自己做了幾個例子。從mysql4.x開始,mysql就增加了以每個使用者為基礎,限制mysql伺服器的資源利用。自己檢視mysql.user 表就會發現裡面最後幾個字段 mysql select version version 5.1.17 beta communit...