Write MySQL Shell plug-in (REPORT)

Author: Jingle Ma (Ivan Ma)

Compiler: Xu Yitao

MySQL Shell is a powerful tool. It allows Javascript, Python and SQL access to MySQL.
MySQL Shell is a powerful tool. It allows Javascript, Python and SQL to access 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

You can use MySQL Shell.

1. As a management tool for MySQL Server.

2. As a script engine running Javascript or Python or SQL to access MySQL Server.

3. As a tool that allows access to document storage (such as collection API) through MySQL Server.

4. As a MySQL InnoDB Cluster management tool.

Customization and extensible framework is essential to a tool as such DB administrators can create customized report and extension to do the daily job.

Custom and extensible frameworks are essential for tools, and database administrators can create custom reports and extensions to perform daily work.

This tutorial is written to provide a short summary how we can create a MySQL Shell Report in Python.
The purpose of this tutorial is to provide a short summary on how we can create a MySQL Shell Report in Python .

What is MySQL Shell Report
MySQL Shell report can be executed thru "\show"

What is MySQL Shell report
MySQL Shell report can be executed by "\show"

Write MySQL Shell plug-in (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"

Query report:
Get the report "help" by simply running "\ show query --help"

Write MySQL Shell plug-in (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)

Run the report through the connected session so that the query will be executed and printed on the screen (for example, run the "SELECT 1" query)

Write MySQL Shell plug-in (REPORT)

Creating a New Report in Python - DB Size

Use Python to create a new report-database size

Customization based Shell android.permission ON the MySQL The $ HOME / .mysqlsh / plugins / folder
the MySQL Shell allows based $ HOME / .mysqlsh / plugins / folder customize

When MySQL Shell is launched, it looks for all initialization script (init.py / init.js) within the "plugins" folder. When MySQL Shell is launched, it looks for all initialization
scripts (init.py / init .js). "folder.

File : $HOME/.mysqlsh/plugins/ext/dbutil/init.py

Write MySQL Shell plug-in (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.

After creating the file under $HOME/.mysqlsh/plugins/ext/dbutil/init.py, MySQL Shell will look for the new report, and "\show" will show the added "dbsize" report.

Write MySQL Shell plug-in (REPORT)

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

Use the CONNECTED session, and then run the report, you can simply execute "\show dbsize".

Write MySQL Shell plug-in (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.

We put OPTION "limit" in Python init.py. Only 3 lines are displayed, and options can be added as shown below (-l 3).
Write MySQL Shell plug-in (REPORT)

Enjoy Reading!

Guess you like

Origin blog.51cto.com/15080016/2642082