Users Configuration

Users are configured in table mysql_users.

Note: Before proceeding reading the following section, please make sure you understand the multi-layer configuration system used by ProxySQL.Specifically:

  • changes in mysql_users table do not take effect without running LOAD MYSQL USERS TO RUNTIME
  • changes in mysql_users table are lost after a restart/crash if not saved to disk running SAVE MYSQL USERS TO DISK
    All changes in mysql_users table do not take effect immediately, neither are persistent.Changes to mysql_users are to be considered as editing a config file without saving it or reloading the service.

Copying mysql users from memory to runtime

loads MySQL users from the in-memory database to the runtime data structures

  1. Admin> LOAD MYSQL USERS TO RUNTIME;

Other alias accepted:

  • LOAD MYSQL USERS TO RUN
  • LOAD MYSQL USERS FROM MEM
  • LOAD MYSQL USERS FROM MEMORY

Copying mysql users from memory to disk

persists the MySQL users from the in-memory database to the on-disk database

  1. Admin> SAVE MYSQL USERS TO DISK;

Other alias accepted:

  • SAVE MYSQL USERS FROM MEM
  • SAVE MYSQL USERS FROM MEMORY

Copying mysql users from runtime to memory

persists the MySQL users from the runtime data structures to the in-memory database

  1. Admin> SAVE MYSQL USERS TO MEMORY;

Other alias accepted:

  • SAVE MYSQL USERS TO MEM
  • SAVE MYSQL USERS FROM RUN
  • SAVE MYSQL USERS FROM RUNTIME

Copying mysql users from disk to memory

loads MySQL users from the on-disk database to the in-memory database

  1. Admin> LOAD MYSQL USERS TO MEMORY;

Other alias accepted:

  • LOAD MYSQL USERS TO MEM
  • LOAD MYSQL USERS FROM DISK

Using encrypted passwords

ProxySQL supports hashed passwords, and a detailed description is available hereIn the examples below passwords are in clear text. Although this is acceptable for testing, it is not suitable for production. For production you should only use hashed passwords

Creating a new user

In order to create a new user, it must be defined inserting a new row in mysql_users table.Note that the table has several column with defaults.

  1. Admin> SELECT * FROM mysql_users;
  2. Empty set (0.00 sec)
  3.  
  4. Admin> INSERT INTO mysql_users(username,password) VALUES ('user1','password1');
  5. Query OK, 1 row affected (0.00 sec)
  6.  
  7. Admin> SELECT * FROM mysql_users;
  8. +----------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
  9. | username | password | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections |
  10. +----------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
  11. | user1 | password1 | 1 | 0 | 0 | NULL | 0 | 0 | 0 | 1 | 1 | 10000 |
  12. +----------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
  13. 1 row in set (0.00 sec)

create a new user changing several defaults

In this example we will create a new user that:

  • uses dbtest1 as default schema
  • by default will be connected to a host in hostgroup 10
  1. Admin> INSERT INTO mysql_users(username,password,default_hostgroup,default_schema) VALUES ('user2','password2',10,'dbtest1');
  2. Query OK, 1 row affected (0.00 sec)

Limiting the number of connections a user can create to proxysql

An example:

  1. Admin> SELECT username,max_connections FROM mysql_users;
  2. +----------+-----------------+
  3. | username | max_connections |
  4. +----------+-----------------+
  5. | user1 | 10000 |
  6. | user2 | 10000 |
  7. +----------+-----------------+
  8. 2 rows in set (0.00 sec)
  9.  
  10. Admin> UPDATE mysql_users SET max_connections=100 WHERE username='user2';
  11. Query OK, 1 row affected (0.01 sec)
  12.  
  13. Admin> SELECT username,max_connections FROM mysql_users;
  14. +----------+-----------------+
  15. | username | max_connections |
  16. +----------+-----------------+
  17. | user1 | 10000 |
  18. | user2 | 100 |
  19. +----------+-----------------+
  20. 2 rows in set (0.00 sec)

Disabling routing across hostgroups once a transaction has started for a specific user

Once a transaction is started, it is possible that some queries are sent to a different hostgroup based on query rules.To prevent this to happen, it is possible to enable transaction_persistent. An example:

  1. Admin> SELECT username, transaction_persistent FROM mysql_users;
  2. +----------+------------------------+
  3. | username | transaction_persistent |
  4. +----------+------------------------+
  5. | user1 | 0 |
  6. | user2 | 0 |
  7. +----------+------------------------+
  8. 2 rows in set (0.00 sec)
  9.  
  10. Admin> UPDATE mysql_users SET transaction_persistent=1 WHERE username='user2';
  11. Query OK, 1 row affected (0.00 sec)
  12.  
  13. Admin> SELECT username, transaction_persistent FROM mysql_users;
  14. +----------+------------------------+
  15. | username | transaction_persistent |
  16. +----------+------------------------+
  17. | user1 | 0 |
  18. | user2 | 1 |
  19. +----------+------------------------+
  20. 2 rows in set (0.00 sec)

原文: https://github.com/sysown/proxysql/wiki/Users-configuration