MySql

ProxySQL手册_05用户配置

2021-10-19  本文已影响0人  这货不是王马勺

转载来自 骏马金龙 https://www.junmajinlong.com

用户配置概述

用户的配置表为mysql_users
注意:在阅读下面内容之前,请确定你已经理解了ProxySQL中的多层次配置系统
特别是:

将mysql users配置从内存数据库拷贝到runtime

将mysql users配置从内存数据库拷贝到runtime数据结构:

Admin> LOAD MYSQL USERS TO RUNTIME;

等价写法:
LOAD MYSQL USERS TO RUN
LOAD MYSQL USERS FROM MEM
LOAD MYSQL USERS FROM MEMORY

将mysql users配置从内存数据库持久化到磁盘数据库

Admin> SAVE MYSQL USERS TO DISK;

等价写法:
SAVE MYSQL USERS FROM MEM
SAVE MYSQL USERS FROM MEMORY

将mysql users配置从runtime库拷贝到内存数据

Admin> SAVE MYSQL USERS TO MEMORY;

等价写法:
SAVE MYSQL USERS TO MEM
SAVE MYSQL USERS FROM RUN
SAVE MYSQL USERS FROM RUNTIME

将mysql users配置从磁盘数据库拷贝到内存数据库

Admin> LOAD MYSQL USERS TO MEMORY;

等价写法:
LOAD MYSQL USERS TO MEM
LOAD MYSQL USERS FROM DISK

使用加密的密码

ProxySQL支持hash后的密码,详细内容可参见(https://github.com/malongshuai/proxysql/wiki/Password-management)。
下面的示例中全都是明文密码。只是为了做实验测试,在生产环境下应该使用加密的hash密码(https://github.com/malongshuai/proxysql/wiki/Password-management#hashed-passwords-and-authentication)。

创建一个新用户

只需向mysql_users表中插入新行即表示创建新用户。
需要注意,该表中有一些字段带有默认值属性。

Admin> SELECT * FROM mysql_users;
Empty set (0.00 sec)

Admin> INSERT INTO mysql_users(username,password) VALUES ('user1','password1');
Query OK, 1 row affected (0.00 sec)

Admin> SELECT * FROM mysql_users;
+----------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
| username | password  | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections |
+----------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
| user1    | password1 | 1      | 0       | 0                 | NULL           | 0             | 0                      | 0            | 1       | 1        | 10000           |
+----------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
1 row in set (0.00 sec)

创建一个带有自定义属性的用户

下面将创建一个满足如下要求的用户:
使用dbtest1作为默认的schema。
默认连接到后端主机组hostgroup_id=10中的某节点。

Admin> INSERT INTO mysql_users(username,password,default_hostgroup,default_schema) VALUES ('user2','password2',10,'dbtest1');
Query OK, 1 row affected (0.00 sec)

限制用户允许"建立到ProxySQL的连接"的最大数量

一个示例:

Admin> SELECT username,max_connections FROM mysql_users;
+----------+-----------------+
| username | max_connections |
+----------+-----------------+
| user1    | 10000           |
| user2    | 10000           |
+----------+-----------------+
2 rows in set (0.00 sec)

Admin> UPDATE mysql_users SET max_connections=100 WHERE username='user2';
Query OK, 1 row affected (0.01 sec)

Admin> SELECT username,max_connections FROM mysql_users;
+----------+-----------------+
| username | max_connections |
+----------+-----------------+
| user1    | 10000           |
| user2    | 100             |
+----------+-----------------+
2 rows in set (0.00 sec)

用户开启事务后,禁止跨主机组路由该用户的请求

当某用户开始一个事务后,该事务内的请求在基于查询规则进行路由时,可能会路由到不同的主机组中。为了避免这种情况,需要启用transaction_persistent来保证事务持久。(译注:只有在事务结束后,该用户的请求才允许路由到其它主机组种)例如:

Admin> SELECT username, transaction_persistent FROM mysql_users;
+----------+------------------------+
| username | transaction_persistent |
+----------+------------------------+
| user1    | 0                      |
| user2    | 0                      |
+----------+------------------------+
2 rows in set (0.00 sec)

Admin> UPDATE mysql_users SET transaction_persistent=1 WHERE username='user2';
Query OK, 1 row affected (0.00 sec)

Admin> SELECT username, transaction_persistent FROM mysql_users;
+----------+------------------------+
| username | transaction_persistent |
+----------+------------------------+
| user1    | 0                      |
| user2    | 1                      |
+----------+------------------------+
2 rows in set (0.00 sec)
上一篇下一篇

猜你喜欢

热点阅读