TheRobotLearns Platform · ProxySQL: from first install to production

Config File Bootstrap, Variables, and Grammar

  • about 15 min read

Learning objectives

  • Describe the configuration file's role as static text primarily used during initial bootstrap and for a small set of always-parsed variables.
  • Identify the startup conditions that cause the file to be used, including initial startup or reload startup, and recognize the source recommendation to use the disk database for complex configuration.
  • Recognize the libconfig grammar elements ProxySQL config files use, including scalar values, arrays, lists, groups, and their syntax.
  • Distinguish general variables such as `datadir`, `errorlog`, `pidfile`, `restart_on_missing_heartbeats`, `execute_on_exit_failure`, `uuid`, `web_interface_plugin`, `sqlite3_plugin`, `cluster_sync_interfaces`, and `set_thread_name` from module variables configured in `admin_variables`, `mysql_variables`, and `pgsql_variables`.
  • Explain how prefixes are omitted in module sections and added by Admin when loading variables into `global_variables`.

Why the File Loads Once

You edit proxysql.cnf and restart ProxySQL, but the settings you changed do not apply. ProxySQL prioritises the disk database during startup. If that database exists, it ignores the config file unless you start with --initial or --reload.

The config file is static text used mainly for initial bootstrap. Initial bootstrap is the first setup of a fresh ProxySQL installation. The majority of the settings it contains are read and parsed only during initial bootstrap, an initial startup, or a reload startup. A small set of general variables is always parsed when the file is present.

The disk database is a persistent SQLite3 database. ProxySQL populates the Memory layer from it during standard startup. ProxySQL recommends the disk database for complex configuration. A text file is more error-prone for nested values. Several Admin table fields, such as servers_defaults in mysql_hostgroup_attributes, are JSON. A config file has no input validation, while the disk database adds validation and constraints.

For example, datadir remains parsed even when the disk database is present. It defines where the database file, logs, and other files are stored.

Takeaway: Bootstrap with proxysql.cnf, then configure complex values through DISK.

Reading the File Grammar

You write admin_variables= followed by braces, and the parser treats it as a group. ProxySQL parses the config file with libconfig grammar. That grammar is copied at the end of proxysql.cfg in the proxysql package.

A setting names a variable, uses : or =, then a value, then ;, ,, or nothing. A value may be a scalar value, an array, a list, or a group. Scalar values include boolean, integer, integer64, hex, hex64, float, and string. String values use double quotes. An array uses square brackets around scalar values. A list uses parentheses around values. A group uses braces around settings.

This config block stores admin module settings in a group. It shows two string settings.

admin_variables=
{
    admin_credentials="admin:admin;radmin;radmin"
    mysql_ifaces="0.0.0.0:6032"
}

When loaded into global_variables, Admin stores their names with the admin- prefix. admin_credentials becomes admin_admin_credentials, and mysql_ifaces becomes admin-mysql_ifaces.

Takeaway: In config files, groups use braces, arrays use brackets, lists use parentheses, and scalar values carry libconfig types.

Module Prefixes in global_variables

You put threads=4 in a mysql_variables section, but global_variables stores the value as mysql-threads. Specific modules require their variables to be configured in a section called module_variables. admin_variables is for Admin variables, mysql_variables is for MySQL variables, and pgsql_variables is for PostgreSQL variables. Within each section, the variable prefix must not be specified. You write threads, not mysql-threads. The Admin module adds the prefix relative to the section when loading into global_variables.

The general variables are a small set always parsed from the file. The module sections are separate from that set, so they are read only when ProxySQL parses the config file: during initial bootstrap, an initial startup, or a reload startup.

For example, this mysql_variables group defines MySQL settings without prefixes:

mysql_variables=
{
    threads=4
    max_connections=2048
    default_query_delay=0
    default_query_timeout=36000000
}

When loaded into global_variables, threads=4 becomes mysql-threads, and max_connections=2048 becomes mysql-max_connections. Admin adds mysql- to every variable in that section.

Takeaway: Write unprefixed names inside module sections; Admin stores them in global_variables with admin-, mysql-, or pgsql- prefixes.

Check prefixed module variables

SELECT *
FROM global_variables
WHERE variable_name IN (
  'admin-mysql_ifaces',
  'mysql-threads',
  'mysql-max_connections',
  'pgsql-threads'
);

The SELECT reads rows from global_variables through the Admin interface. The WHERE variable_name IN (...) filter keeps only names that carry a module prefix. You will see admin-mysql_ifaces with 0.0.0.0:6032, mysql-threads with 4, mysql-max_connections with 2048, and pgsql-threads with 4. Those values come from config sections where mysql_ifaces, threads, and max_connections were written without module prefixes.

Try it: config_layer_sim

You are creating proxysql.cnf for a fresh ProxySQL instance. Add this section to the file:

mysql_variables=
{
    threads=4
}

Start ProxySQL with --initial. Connect to Admin and run:

SELECT * FROM global_variables WHERE variable_name IN ('mysql-threads');

You should see a row named mysql-threads with value 4. The prefix was added when Admin loaded the mysql_variables setting into global_variables.

Sources

Do more with an account

Config File Bootstrap, Variables, and Grammar — ProxySQL: from first install to production