mysql> SELECT * FROM information_schema.GLOBAL_VARIABLES WHERE variable_name = 'version';
+---------------+-----------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+---------------+-----------------+
| VERSION | 5.6.22-71.0-log |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'version';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| version | 5.6.22-71.0-log |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql> SELECT @@version;
+-----------------+
| @@version |
+-----------------+
| 5.6.22-71.0-log |
+-----------------+
1 row in set (0.00 sec)
In a Stored Procedure, you can do something like
IF (@@version < "5.7") THEN
SELECT user, host FROM mysql.user;
ELSE
SELECT user, host, account_locked FROM mysql.user;
ENDIF;
It gets messier if you also need to handle MariaDB, with its "10.x.y". And, if Percona has any differences, you need to dig deeper into the "version".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…