做者:马楚成 (Ivan Ma) mysql
编译:徐轶韬sql
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 besession
能够使用MySQL Shell。框架
1.做为MySQL Server的管理工具。ide
2.做为运行Javascript或Python或SQL的脚本引擎,以访问MySQL Server。工具
3.做为容许经过MySQL Server访问文档存储(如集合API)的工具。插件
4.做为MySQL InnoDB Cluster管理工具。blog
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'。
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”查询)
使用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!