編寫MySQL Shell插件(REPORT)

做者:馬楚成 (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

  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的管理工具。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」執行

編寫MySQL Shell插件(REPORT)

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」

編寫MySQL Shell插件(REPORT)
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」查詢)

編寫MySQL Shell插件(REPORT)

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

編寫MySQL Shell插件(REPORT)

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」報告。

編寫MySQL Shell插件(REPORT)

With a CONNECTED session, and Running the report can be simply to execute "\show dbsize"

使用CONNECTED會話,而後運行報告,能夠簡單地執行「 \ show dbsize」。

編寫MySQL Shell插件(REPORT)

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)。
編寫MySQL Shell插件(REPORT)

Enjoy Reading!

相關文章
相關標籤/搜索