简体   繁体   English

以json格式输出数据库大小(来自Centos7的MariaDB)

[英]Output Database size in json format (Mariadb from Centos7)

Anyone knows how can I output this data in a json format Full output using mysql command . 任何人都知道如何以json格式输出此数据,并使用mysql命令完整输出 I don't know how can I get them one by one. 我不知道如何才能一一获得。 Using Bash Script. 使用Bash脚本。 Thanking you ahead of time :) 提前谢谢你:)

Basically, The script needs to compute the size of the databaase per GB per client/dbname. 基本上,脚本需要计算每个客户端/ dbname每GB的数据库大小。 Then sent it as json format. 然后以json格式发送。

SAMPLE OUTPUT: 样品输出:

{
    "client_code": "information_schema",
    "key": "disk_usage",
    "value": "0.000069"
  },
  {
    "client_code": "mysql",
    "key": "disk_usage",
    "value": "0.000611"
  },
  {
    "client_code": "newdb",
    "key": "disk_usage",
    "value": "1GB"
  }
]

You will need to pass the --json to mysql command line query to get the output in JSON format. 您将需要将--json传递给mysql命令行查询,以获取JSON格式的输出。 More on this here 这里更多

select table_schema, sum((data_length+index_length)/1024/1024) AS MB from information_schema.tables group by 1; | mysqlsh --json=pretty --sqlc --uri root@192.168.1.141:3306

EDIT : 编辑:

Although direct JSON outputting without 3rd party apps is not possible yet in MySQL or MariaDB. 尽管在MySQL或MariaDB中尚无法在没有第三方应用程序的情况下直接输出JSON。 That said, found an interesting post to convert the normal atomic table to BLOB table and parse it with column_json() function. 就是说,找到了一篇有趣的文章,将普通原子表转换为BLOB表,并使用column_json()函数对其进行了解析。 You can find it here , If you are using CONNECT to data forge then you might find this article useful. 你可以找到它在这里 ,如果您正在使用连接到数据伪造,那么你可能会发现这个文章有用。

我已经找到了一个解决方案,我要做的是内部连接两个数据库,以便获取值,对于json输出,我使用了一个工具csvtojson。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM