mysql> set @query = 'select
'> now(),
'> @@max_connections as "Max Connections",
'> count(host) as "Current Connections"
'> from information_schema.processlist; ';
Query OK, 0 rows affected (0.00 sec)
mysql> prepare stmt from @query;
Query OK, 0 rows affected (0.01 sec)
Statement prepared
mysql> execute stmt;
+---------------------+-----------------+---------------------+
| now() | Max Connections | Current Connections |
+---------------------+-----------------+---------------------+
| 2021-08-16 18:22:03 | 512 | 1 |
+---------------------+-----------------+---------------------+
1 row in set (0.01 sec)
Then you can execute stmt
as many times as you want in the same session (prepared statements have a scope of the current session).
See https://dev.mysql.com/doc/refman/8.0/en/sql-prepared-statements.html for more information.