前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >编写MySQL Shell插件(REPORT)

编写MySQL Shell插件(REPORT)

作者头像
MySQLSE
发布2020-09-28 15:46:38
2.2K0
发布2020-09-28 15:46:38
举报

作者:马楚成 (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

1. As admin tool to MySQL Server 2. As Scripting Engine to run Javascript or Python or SQL to access MySQL Server 3. As a tools to allow Document Store access (like collection API) with MySQL Server 4. 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/ folderMySQL 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!

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-04-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 MySQL解决方案工程师 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档