需求描述:
今天在查mysq關於連接數的問題,想要通過一個show variables命令同時查出來多個值.在此記錄下.
操作過程:
1.通過show variables語句的like可以匹配多個值或者某個值
mysql> show variables like 'max_connections'; #這里默認的就是對Variable_name進行匹配,這里是准確匹配. +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 151 | +-----------------+-------+ 1 row in set (0.01 sec) mysql> show variables like 'socket'; +---------------+-----------------+ | Variable_name | Value | +---------------+-----------------+ | socket | /tmp/mysql.sock | +---------------+-----------------+ 1 row in set (0.00 sec)
2.通過%通配符進行匹配
mysql> show variables like '%connec%'; #通過百分號(%)這個通配符進行匹配,可以匹配多項. +-----------------------------------------------+-------------------+ | Variable_name | Value | +-----------------------------------------------+-------------------+ | character_set_connection | latin1 | | collation_connection | latin1_swedish_ci | | connect_timeout | 10 | | disconnect_on_expired_password | ON | | init_connect | | | max_connect_errors | 100 | | max_connections | 151 | | max_user_connections | 0 | | performance_schema_session_connect_attrs_size | 512 | +-----------------------------------------------+-------------------+ 9 rows in set (0.00 sec)
mysql> show variables like 'innodb_thread%'; #%通配符在結束處.
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| innodb_thread_concurrency | 0 |
| innodb_thread_sleep_delay | 10000 |
+---------------------------+-------+
2 rows in set (0.00 sec)
mysql> show variables like '%version'; #%通配符在開始處.
+------------------+---------------+
| Variable_name | Value |
+------------------+---------------+
| innodb_version | 5.7.21 |
| protocol_version | 10 |
| tls_version | TLSv1,TLSv1.1 |
| version | 5.7.21-log |
+------------------+---------------+
4 rows in set (0.00 sec)
3.使用where子句進行匹配查詢
mysql> show variables where variable_name = 'version'; +---------------+------------+ | Variable_name | Value | +---------------+------------+ | version | 5.7.21-log | +---------------+------------+ 1 row in set (0.01 sec) mysql> show variables where variable_name in ('version','innodb_version'); +----------------+------------+ | Variable_name | Value | +----------------+------------+ | innodb_version | 5.7.21 | | version | 5.7.21-log | +----------------+------------+ 2 rows in set (0.00 sec) mysql> show variables where value like '5.7%'; +----------------+------------+ | Variable_name | Value | +----------------+------------+ | innodb_version | 5.7.21 | | version | 5.7.21-log | +----------------+------------+ 2 rows in set (0.00 sec) mysql> show variables where variable_name = 'version' and value = '5.7'; Empty set (0.00 sec) mysql> show variables where variable_name = 'version' and value like '5.7%'; +---------------+------------+ | Variable_name | Value | +---------------+------------+ | version | 5.7.21-log | +---------------+------------+ 1 row in set (0.00 sec)
備注:使用where子句的方式就和在SQL語句中使用where的方式是一樣的.
4.使用_(下划線)匹配單個字符及將下划線當做普通字符使用
mysql> show variables like 'versio_\_c%'; #第一個是通配符,匹配一個字符,第二個下划線當做普通字符使用,所以在前面加上了轉義字符\,將其轉義為普通字符. +-------------------------+------------------------------+ | Variable_name | Value | +-------------------------+------------------------------+ | version_comment | MySQL Community Server (GPL) | | version_compile_machine | x86_64 | | version_compile_os | linux-glibc2.12 | +-------------------------+------------------------------+ 3 rows in set (0.00 sec)
show variables語法:
SHOW [GLOBAL | SESSION] VARIABLES [LIKE 'pattern' | WHERE expr]
小結:
- show variables主要是用來查看系統變量的值.
- 執行SHOW VARIABLES命令不需要任何權限,只要求能夠連接到服務器就可以.
- 使用like語句表示用variable_name進行匹配.
- %百分號通配符可以用在匹配模式中的任何位置
文檔創建時間:2018年7月17日11:33:27