如何执行 MySQL 查询并避免在输出中出现查询或别名?我尝试将“”(空字符串)作为别名,但没有得到预期的结果,因为我最终得到了一个空行。
编辑:添加了一些代码
SELECT
CONCAT("{\"counters\":{",
-- Total memory used calculation
"\"mysql.total_memory\":",
((@@read_buffer_size + @@sort_buffer_size) * @@max_connections + @@key_buffer_size),",",
-- other monitored server status variables
GROUP_CONCAT(
CONCAT("\"mysql.",LCASE(VARIABLE_NAME),"\":",VARIABLE_VALUE)
)
,"}}")
FROM INFORMATION_SCHEMA.GLOBAL_STATUS
WHERE VARIABLE_NAME = "SLOW_QUERIES"
OR VARIABLE_NAME="Qcache_lowmem_prunes"
OR VARIABLE_NAME="SELECT_FULL_JOIN"
OR VARIABLE_NAME="SELECT_RANGE_CHECK"
OR VARIABLE_NAME="SELECT_SCAN"
OR VARIABLE_NAME="SELECT_RANGE";
我想要一个 json 格式作为输出。我需要这个作为另一个软件的输入。该软件不接受空行以及其他内容(压缩的 json 格式)。
编辑2:添加输出
CONCAT("{\"counters\":{",
"\"mysql.total_memory\":",
((@@read_buffer_size + @@sort_buffer_size) * @@max_connections + @@key_buffer_size),",",
GROUP_CONCAT(
CONCAT("\"mysql.",LCASE(VARIABLE_NAME),"\":",VARIABLE_VALUE)
)
,"}}")
{"counters":{"mysql.total_memory":39108608,"mysql.qcache_lowmem_prunes":0,"mysql.select_full_join":0,"mysql.select_range":0,"mysql.select_range_check":0,"mysql.select_scan":84,"mysql.slow_queries":0}}
我想删除“CONCAT(...)”部分,只将结果作为输出。