TheRobotLearns Platform · ProxySQL: from first install to production

ClickHouse Backend Through the MySQL Protocol

  • about 15 min read

Learning objectives

  • Start ProxySQL with `--clickhouse-server` to expose the ClickHouse MySQL interface on port 6090.
  • Configure the module with clickhouse-hostname, clickhouse-port, clickhouse-mysql_ifaces, and clickhouse-read_only, and identify when invalid or empty assignments leave runtime unchanged.
  • Explain that backend target variable changes affect new connections, not already-established connections.
  • Manage client credentials in `clickhouse_users`, load them into `runtime_clickhouse_users`, and save `disk.clickhouse_users`.
  • List supported ClickHouse integer/floating-point, string/fixed-string, and date/datetime types.

Start the ClickHouse MySQL interface

ClickHouse support activates only when ProxySQL starts with --clickhouse-server. This provides high-performance analytical querying through a MySQL protocol interface. The module is also compile-time gated by PROXYSQLCLICKHOUSE, so the running binary must include it. When the option is present, ProxySQL listens on port 6090 using MySQL protocol. For its backend connection, ProxySQL uses localhost, the username Default, and an empty password; that backend credential pair is currently hardcoded.

ProxySQL accepts SELECT, SET, USE, SHOW, DESC or DESCRIBE, CREATE, ALTER, DROP, and RENAME. It accepts INSERT only as INSERT...SELECT. The syntax INSERT VALUES is rejected. Only TEXT protocol is supported, and prepared statements are not available.

Supported ClickHouse types are listed by category. Integer types include Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, and UInt64. Floating-point types are Float32 and Float64. String types are String and FixedString. Date/time types are Date and DateTime.

Takeaway: Start ProxySQL with --clickhouse-server to get the port 6090 ClickHouse MySQL interface.

Four variables you can adjust

You give clickhouse-port an out-of-range value, run LOAD CLICKHOUSE VARIABLES TO RUNTIME, and the runtime port does not change. The released ClickHouse module has four global variables: clickhouse-mysql_ifaces, clickhouse-hostname, clickhouse-port, and clickhouse-read_only. They are dynamic once the module is running.

clickhouse-mysql_ifaces controls the MySQL-protocol listeners and defaults to 0.0.0.0:6090. An empty interface string is rejected up front. Any non-empty interface string is accepted without general parse or bind validation during LOAD. LOAD CLICKHOUSE VARIABLES TO RUNTIME reconciles the listeners. Reconciliation closes the old listener sockets before parsing and binding the replacements. A malformed address or bind failure can leave the intended listener unavailable. Verify replacement listener access before SAVE CLICKHOUSE VARIABLES TO DISK.

clickhouse-hostname sets the backend host for new connections and defaults to 127.0.0.1. An empty hostname assignment returns success but leaves the current host unchanged. clickhouse-port sets the ClickHouse native-protocol backend port for new connections and accepts integer values from 1 through 65535. clickhouse-read_only accepts case-insensitive true or 1 and false or 0; it enables or disables the module's write-command rejection.

Takeaway: Invalid ports, invalid booleans, empty hostnames, or empty interfaces leave the matching runtime value unchanged.

Move client credentials through layers

The clickhouse_users table stores client authentication credentials. Those credentials are separate from the hardcoded ClickHouse backend credential. It uses username, password, active, and max_connections. active must be 0 or 1 and defaults to 1. max_connections must be non-negative and defaults to 10000. username is the primary key.

INSERT INTO clickhouse_users VALUES ('clicku','clickp',1,100); adds one credential row to the in-memory table. Three layers exist for the table: clickhouse_users in memory, runtime_clickhouse_users as the active configuration, and disk.clickhouse_users for persistent storage. LOAD CLICKHOUSE USERS TO RUNTIME moves rows into the active configuration. SAVE CLICKHOUSE USERS TO DISK writes them to persistent storage.

The user command family includes LOAD CLICKHOUSE USERS TO MEMORY and SAVE CLICKHOUSE USERS FROM RUNTIME. The variable command family includes memory-to-runtime, runtime-to-memory, disk-to-memory, and memory-to-disk forms. Backend target changes made through clickhouse-hostname or clickhouse-port affect new connections. They do not rewrite already-established connections.

Takeaway: Insert into clickhouse_users, LOAD to runtime_clickhouse_users, then SAVE to disk.clickhouse_users to persist the credential.

Persist a ClickHouse client user

INSERT INTO clickhouse_users VALUES ('clicku','clickp',1,100);
LOAD CLICKHOUSE USERS TO RUNTIME;
SAVE CLICKHOUSE USERS TO DISK;

This example adds one client credential row and moves it through the in-memory, runtime, and disk layers; after the three commands run, the row is present in the in-memory, active, and persistent user layers. INSERT INTO clickhouse_users VALUES ('clicku','clickp',1,100); adds a row to the in-memory client credentials table. LOAD CLICKHOUSE USERS TO RUNTIME; moves the row into runtime_clickhouse_users, the active configuration. SAVE CLICKHOUSE USERS TO DISK; writes it to disk.clickhouse_users for persistent storage.

Try it: config_layer_sim

Insert a new client user into clickhouse_users. Run LOAD CLICKHOUSE USERS TO RUNTIME. Run SAVE CLICKHOUSE USERS TO DISK. Name the in-memory table, the active table, and the persistent table that hold that user after those commands.

Sources

Do more with an account

ClickHouse Backend Through the MySQL Protocol — ProxySQL: from first install to production