ProxySQL Admin Interface Is Not Your Typical MySQL Server!
ProxySQL implemented some of the commands to make it easy and familiar for MySQL users to navigate the ProxySQL interface.
Join the DZone community and get the full member experience.
Join For FreeIn this blog post, I’ll look at how ProxySQL Admin behaves in some unusual and unexpected ways from a MySQL perspective.
ProxySQL allows you to connect to its admin interface using the MySQL protocol and familiar tools, like the MySQL command line client, to manage its configuration as a set of configuration tables. This ability may trick you into thinking that you’re working with a stripped-down MySQL server — and expect it to behave like MySQL.
It would be a mistake to think this! In fact, ProxySQL embeds the SQLite database to store its configuration. As such, it behaves much closer to SQLite!
Below, I’ll show you a few things that confused me at first. All of these are as of ProxySQL 1.3.6 (in case behavior changes in the future).
Fake Support for “Use” Command
mysql> show databases;
+-----+---------+-------------------------------+
| seq | name | file |
+-----+---------+-------------------------------+
| 0 | main | |
| 2 | disk | /var/lib/proxysql/proxysql.db |
| 3 | stats | |
| 4 | monitor | |
+-----+---------+-------------------------------+
4 rows in set (0.00 sec)
mysql> select database();
+------------+
| DATABASE() |
+------------+
| admin |
+------------+
1 row in set (0.00 sec)
mysql> use stats;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select database();
+------------+
| DATABASE() |
+------------+
| admin |
+------------+
1 row in set (0.00 sec)
mysql> use funkydatabase;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
Here, we can see that:
- There is a concept of multiple databases in the ProxySQL admin interface.
- The ProxySQL admin interface supports the
select database();
function, which is always the same value independent of the database you tried to set. Typically, it will beadmin
orstats
depending on what user you use to connect to the database. - You can use the
use
command to change the database, but it does not really change the database. This is a required command because if you don’t support it, many MySQL clients will not connect.
Invisible Tables
mysql> show tables;
+--------------------------------------+
| tables |
+--------------------------------------+
| global_variables |
| mysql_collations |
| mysql_query_rules |
| mysql_replication_hostgroups |
| mysql_servers |
| mysql_users |
| runtime_global_variables |
| runtime_mysql_query_rules |
| runtime_mysql_replication_hostgroups |
| runtime_mysql_servers |
| runtime_mysql_users |
| runtime_scheduler |
| scheduler |
+--------------------------------------+
13 rows in set (0.00 sec)
mysql> show tables from stats;
+--------------------------------+
| tables |
+--------------------------------+
| global_variables |
| stats_mysql_commands_counters |
| stats_mysql_connection_pool |
| stats_mysql_global |
| stats_mysql_processlist |
| stats_mysql_query_digest |
| stats_mysql_query_digest_reset |
| stats_mysql_query_rules |
+--------------------------------+
8 rows in set (0.00 sec)
mysql> select count(*) from stats_mysql_commands_counters;
+----------+
| count(*) |
+----------+
| 52 |
+----------+
1 row in set (0.00 sec)
We can query a list of tables in our default database (which can’t change), and we also get lists of tables in the stats
database with very familiar MySQL syntax. But we can also query the stats
table directly without specifying the stats
database, even if it is not shown in show tables
for our current database.
Again, this is SQLite behavior!
Strange Create Table Syntax
mysql> show create table scheduler G
*************************** 1. row ***************************
table: scheduler
Create Table: CREATE TABLE scheduler (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
interval_ms INTEGER CHECK (interval_ms>=100 AND interval_ms<=100000000) NOT NULL,
filename VARCHAR NOT NULL,
arg1 VARCHAR,
arg2 VARCHAR,
arg3 VARCHAR,
arg4 VARCHAR,
arg5 VARCHAR,
comment VARCHAR NOT NULL DEFAULT '')
1 row in set (0.00 sec)
If we look into the ProxySQL Admin interface table structure, we see it is not quite MySQL. It uses CHECK
constraints and doesn’t specify the length for VARCHAR
. This is because it is SQLite table definition.
“SHOW” Command Nuances
The ProxySQL Admin interface supports SHOW PROCESSLIST
and even SHOW FULL PROCESSLIST
commands, but not all the commands match the MySQL server output:
mysql> show processlist;
+-----------+---------------+--------+-----------+---------+---------+--------+
| SessionID | user | db | hostgroup | command | time_ms | info |
+-----------+---------------+--------+-----------+---------+---------+--------+
| 129 | proxysql_user | sbtest | 10 | Query | 14 | COMMIT |
| 130 | proxysql_user | sbtest | 10 | Query | 16 | COMMIT |
| 131 | proxysql_user | sbtest | 10 | Query | 9 | COMMIT |
| 133 | proxysql_user | sbtest | 10 | Query | 0 | COMMIT |
| 134 | proxysql_user | sbtest | 10 | Query | 5 | COMMIT |
….
| 191 | proxysql_user | sbtest | 10 | Query | 4 | COMMIT |
| 192 | proxysql_user | sbtest | 10 | Query | 1 | COMMIT |
+-----------+---------------+--------+-----------+---------+---------+--------+
62 rows in set (0.01 sec)
SHOW VARIABLES
works, as does SHOW GLOBAL VARIABLES
, but not SHOW SESSION VARIABLES
.
SHOW STATUS
doesn’t work as expected:
mysql> show status;
ERROR 1045 (#2800): near "show": syntax error
As you can see, while some typical MySQL commands and constructs work, others don’t. This is by design: ProxySQL implemented some of the commands to make it easy and familiar for MySQL users to navigate the ProxySQL interface. But don’t get fooled! It is not MySQL and doesn’t always behave as you would expect.
Published at DZone with permission of Peter Zaitsev, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
-
Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC
-
How Agile Works at Tesla [Video]
-
Top Six React Development Tools
Comments