proxysql_tools.proxysql package

Submodules

proxysql_tools.proxysql.proxysql module

ProxySQL classes

class proxysql_tools.proxysql.proxysql.ProxySQL(host='localhost', port=3306, user='root', password=None, socket=None)[source]

Bases: object

ProxySQL describes a single ProxySQL instance.

Parameters:
  • host – ProxySQL hostname.
  • port – Port on which ProxySQL listens to admin connections.
  • user – ProxySQL admin user.
  • password – Password for ProxySQL admin.
  • socket – Socket to connect to ProxySQL admin interface.
add_user(user)[source]

Add MySQL user

Parameters:user (ProxySQLMySQLUser) – user for add
backend_registered(backend)[source]

Check if backend is registered.

Parameters:backend – ProxySQLMySQLBackend instance
Returns:True if registered, False otherwise
Return type:bool
delete_user(username)[source]

Delete MySQL user

Parameters:username (str) – username of user
deregister_backend(backend)[source]

Deregister a Galera node from ProxySQL

Parameters:backend (ProxySQLMySQLBackend) – Galera node.
execute(query, *args)[source]

Execute query in ProxySQL.

Parameters:query (str) – Query to execute.
Returns:Query result or None if the query is not supposed to return result
Return type:dict
find_backends(hostgroup_id=None, status=None)[source]

Find backends from mysql_servers. If hostgroup_id or status is given it will filter out backends based on that criteria.

Parameters:
  • hostgroup_id (int) – writer hostgroup_id
  • status (BackendStatus) – Look only for backends in this status
Returns:

Writer MySQL backend or None if doesn’t exist

Return type:

ProxySQLMySQLBackendSet

Raise:

ProxySQLBackendNotFound

get_user(username)[source]

Get user by username

Parameters:username – Username
Returns:User information
Return type:ProxySQLMySQLUser
Raise:ProxySQLUserNotFound
get_users()[source]

Get mysql users

Returns:List of users or empty list
Return type:list(ProxySQLMySQLUser)
ping()[source]

Check health of ProxySQL.

Returns:True if ProxySQL healthy and False otherwise.
Return type:bool
register_backend(backend)[source]

Register Galera node in ProxySQL

Parameters:backend (ProxySQLMySQLBackend) – Galera node.
reload_runtime()[source]

Reload the ProxySQL runtime configuration.

reload_servers()[source]

Loads MySQL servers from the in-memory database to the runtime data structures.

reload_users()[source]

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

reload_variables()[source]

Loads MySQL variables from the in-memory database to the runtime data structures.

save_runtime()[source]

Saves ProxySQL configuration to disk.

save_servers()[source]

Persists the MySQL servers from the runtime data structures to the in-memory database.

save_users()[source]

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

save_variables()[source]

Persists the MySQL variables from the in-memory database to the on-disk database.

update_backend(backend)[source]

Updates backend in ProxySQL table mysql_servers. Currently synonym of register_backend().

class proxysql_tools.proxysql.proxysql.ProxySQLMySQLUser(username='root', password=None, active=True, use_ssl=False, default_hostgroup=0, default_schema='information_schema', schema_locked=False, transaction_persistent=False, fast_forward=False, backend=True, frontend=True, max_connections=10000)[source]

Bases: object

ProxySQLMySQLUser describes record in ProxySQL table mysql_users.

CREATE TABLE mysql_users (
    username VARCHAR NOT NULL,
    password VARCHAR,
    active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
    use_ssl INT CHECK (use_ssl IN (0,1)) NOT NULL DEFAULT 0,
    default_hostgroup INT NOT NULL DEFAULT 0,
    default_schema VARCHAR,
    schema_locked INT CHECK (schema_locked IN (0,1)) NOT NULL DEFAULT 0,
    transaction_persistent INT CHECK (transaction_persistent IN (0,1))
        NOT NULL DEFAULT 0,
    fast_forward INT CHECK (fast_forward IN (0,1)) NOT NULL DEFAULT 0,
    backend INT CHECK (backend IN (0,1)) NOT NULL DEFAULT 1,
    frontend INT CHECK (frontend IN (0,1)) NOT NULL DEFAULT 1,
    max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000,
    PRIMARY KEY (username, backend),
    UNIQUE (username, frontend))
Parameters:
  • username – MySQL username to connect to ProxySQL or Galera node.
  • password – MySQL password.
  • active (bool) – Users with active = 0 will be tracked in the database, but will be never loaded in the in-memory data structures.
  • use_ssl (bool) – Use SSL to connect to MySQL or not
  • default_hostgroup – If there is no matching rule for the queries sent by the users, the traffic it generates is sent to the specified hostgroup.
  • default_schema – The schema to which the connection should change by default.
  • schema_locked (bool) – not supported yet.
  • transaction_persistent (bool) – if this is set for the user with which the MySQL client is connecting to ProxySQL (thus a “frontend” user - see below), transactions started within a hostgroup will remain within that hostgroup regardless of any other rules.
  • fast_forward (bool) – If set, it bypasses the query processing layer (rewriting, caching) and passes the query directly to the backend server.
  • frontend (bool) – If True, this (username, password) pair is used for authenticating to the ProxySQL instance.
  • backend – If True, this (username, password) pair is used for authenticating to the mysqld servers against any hostgroup.
  • max_connections – Maximum number of connection this user can create to MySQL node.

Module contents