作者:马楚成 (Ivan Ma)
编译:徐轶韬
MySQL Shell is a powerful tool. It allows Javascript, Python and SQL access to MySQL.
MySQL Shell是一个功能强大的工具。它允许Javascript,Python和SQL访问MySQL。
Usage of MySQL Shell can be
- As admin tool to MySQL Server
- As Scripting Engine to run Javascript or Python or SQL to access MySQL Server
- As a tools to allow Document Store access (like collection API) with MySQL Server
- As MySQL InnoDB Cluster admin Tooling
可以使用MySQL Shell。
1.作为MySQL Server的管理工具。
2.作为运行Javascript或Python或SQL的脚本引擎,以访问MySQL Server。
3.作为允许通过MySQL Server访问文档存储(如集合API)的工具。
4.作为MySQL InnoDB Cluster管理工具。
Customization and extensible framework is essential to a tool as such DB administrators can create customized report and extension to do the daily job.
自定义和可扩展框架对于工具至关重要,数据库管理员可以创建自定义的报告和扩展来执行日常工作。
This tutorial is written to provide a short summary how we can create a MySQL Shell Report in Python.
编写本教程的目的是提供一个简短摘要,介绍如何使用Python创建MySQL Shell报告。
What is MySQL Shell Report
MySQL Shell report can be executed thru "\show"
什么是MySQL Shell报表
MySQL Shell报表可以通过“ \ show”执行
There are 3 'report's coming with MySQL Shell - namely 'query', 'thread', 'threads'.
MySQL Shell附带3个“报告”,即'query', 'thread', 'threads'。
Query Report :
Getting the "help" with a report can simply to run "\show query --help"
查询报告:
获取报告“帮助”可以简单地运行“ \ show query --help”
Running a Report with a connected session as such the query is executed and printed on the screen (e.g. Running "SELECT 1" query)
通过连接的会话运行报告,这样查询将被执行并打印在屏幕上(例如,运行“ SELECT 1”查询)
Creating a New Report in Python - DB Size
使用Python创建新报告-数据库大小
MySQL Shell allows customization based on the $HOME/.mysqlsh/plugins/ folder
MySQL Shell允许基于$ HOME / .mysqlsh / plugins /folder进行自定义
When MySQL Shell is launched, it looks for all initialization script (init.py / init.js) within the "plugins" folder.
启动MySQL Shell时,它将在“ plugins”中查找所有初始化脚本(init.py / init.js)。”文件夹。
File : $HOME/.mysqlsh/plugins/ext/dbutil/init.py
Once the file is created under the $HOME/.mysqlsh/plugins/ext/dbutil/init.py, MySQL Shell looks up NEW report and the "\show" shows the added "dbsize" report.
在$ HOME / .mysqlsh / plugins / ext / dbutil / init.py下创建文件后,MySQL Shell将查找新报告,而“ \ show”将显示添加的“ dbsize”报告。
With a CONNECTED session, and Running the report can be simply to execute "\show dbsize"
使用CONNECTED会话,然后运行报告,可以简单地执行“ \ show dbsize”。
There is OPTION "limit" which we put into the Python init.py. To show only 3 lines, we can add option (-l 3) as shown as follows.
我们在Python init.py中放入了OPTION“ limit”。仅显示3行,可以如下所示添加选项(-l 3)。
Enjoy Reading!