ProxySQL官檔翻譯__05_ProxySQL配置之Users配置

05_ProxySQL配置之Users配置

備註:文章編寫時間201904-201905期間,後續官方在github的更新沒有被寫入
~
~mysql

1、用戶配置[Users Configuration]

用戶在mysql_users中配置。git

友情提醒:在閱讀下部分以前,請確保瞭解了ProxySQL使用的多層配置系統。github

特別注意:
1)若是沒有運行LOAD MYSQL USERS TO RUNTIME,那麼mysql_users表中的更改不會生效;
2)若是沒有運行SAVE MYSQL USERS TO DISK 保存配置到的磁盤,那麼mysql_users表中的更改將在重啓/崩潰後丟失。sql

2、將MySQL用戶配置信息從MEMORY層複製到RUNTIME層[Copying mysql users from memory to runtime]

將MySQL用戶配置信息從MEMORY層數據庫加載到RUNTIME層數據結構:數據庫

Admin> LOAD MYSQL USERS TO RUNTIME;

其餘可被接受的別名操做:
Admin> LOAD MYSQL USERS TO RUN;

Admin> LOAD MYSQL USERS FROM MEM;

Admin> LOAD MYSQL USERS FROM MEMORY;

3、將MySQL用戶配置信息從MEMORY層複製到DISK層[Copying mysql users from memory to disk]

將MySQL用戶配置信息從MEMORY層數據庫中保留到DISK層數據庫:數據結構

Admin> SAVE MYSQL USERS TO DISK;

其餘可被接受的別名操做:
Admin> SAVE MYSQL USERS FROM MEM;

Admin> SAVE MYSQL USERS FROM MEMORY;

4、將MySQL用戶配置信息從RUNTIME層複製到MEMORY層[Copying mysql users from runtime to memory]

將MySQL用戶配置信息從RUNTIME層數據結構中保留到MEMORY層數據庫中:frontend

Admin> SAVE MYSQL USERS TO MEMORY;

其餘可被接受的別名操做:
Admin> SAVE MYSQL USERS TO MEM;

Admin> SAVE MYSQL USERS FROM RUN;

Admin> SAVE MYSQL USERS FROM RUNTIME;

5、將MySQL用戶配置信息從DISK層複製到MEMORY層[Copying mysql users from disk to memory]

將MySQL用戶配置信息從DISK層數據庫加載到MEMORY層數據庫:ide

Admin> LOAD MYSQL USERS TO MEMORY;

其餘可被接受的別名操做:
Admin> LOAD MYSQL USERS TO MEM;

Admin> LOAD MYSQL USERS FROM DISK;

6、使用加密密碼[Using encrypted passwords]

ProxySQL支持hash處理後的密碼,詳情參看Password management部分(06_ProxySQL配置之密碼管理)。
在後面的示例中,使用的是明文密碼。雖然這對於測試是可接受的,但它不適合生產。對於生產,應該只能使用hash後的密碼散列。測試

7、建立新用戶[Creating a new user]

爲了建立新用戶,必須在mysql_users表中插入對應的新行。
注意,該表有幾列是有默認值的。加密

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

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

Admin> SELECT * FROM mysql_users\G;
*************************** 1. row ***************************
              username: user01
              password: password01
                active: 1
               use_ssl: 0
     default_hostgroup: 0
        default_schema: NULL
         schema_locked: 0
transaction_persistent: 1
          fast_forward: 0
               backend: 1
              frontend: 1
       max_connections: 10000
               comment: 
1 row in set (0.00 sec)

ERROR: 
No query specified

8、建立不使用默認值的新用戶[create a new user changing several defaults]

在此示例中,將建立一個新用戶:
1)使用dbtest01做爲默認(連入)的數據庫;
2)默認狀況下,將鏈接到主機組10(主機組十)中的主機。

Admin> SELECT username,password,default_hostgroup,default_schema FROM mysql_users;
+----------+------------+-------------------+----------------+
| username | password   | default_hostgroup | default_schema |
+----------+------------+-------------------+----------------+
| user01   | password01 | 0                 | NULL           |
+----------+------------+-------------------+----------------+
1 row in set (0.00 sec)

Admin> INSERT INTO mysql_users(username,password,default_hostgroup,default_schema) VALUES ('user02','password02',10,'dbtest01'); 
Query OK, 1 row affected (0.00 sec)

Admin> SELECT username,password,default_hostgroup,default_schema FROM mysql_users;
+----------+------------+-------------------+----------------+
| username | password   | default_hostgroup | default_schema |
+----------+------------+-------------------+----------------+
| user01   | password01 | 0                 | NULL           |
| user02   | password02 | 10                | dbtest01       |
+----------+------------+-------------------+----------------+
2 rows in set (0.00 sec)

9、爲proxysql建立用戶連最大接數限制[Limiting the number of connections a user can create to proxysql]

示例:

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

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

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

10、禁用跨組執行事務[Disabling routing across hostgroups once a transaction has started for a specific user]

一旦針對特定用戶啓動了事務,就禁用跨主機組的路由

啓動事務後,可能會根據查詢規則將某些查詢發送到其餘主機組。爲了防止這種狀況發生,能夠啓用transaction_persistent(默認啓用)。

示例:

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

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

Admin> SELECT username, transaction_persistent FROM mysql_users;
+----------+------------------------+
| username | transaction_persistent |
+----------+------------------------+
| user01   | 1                      |
| user02   | 1                      |
+----------+------------------------+
2 rows in set (0.00 sec)

完畢!

相關文章
相關標籤/搜索