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
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.
What is MySQL Shell Report
MySQL Shell report can be executed thru "\show"
There are 3 'report's coming with MySQL Shell - namely 'query', 'thread', 'threads'.
Query Report :
Getting the "help" with a report can simply to run "\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)
Creating a New Report in Python - DB Size
MySQL Shell allows customization based on the $HOME/.mysqlsh/plugins/ folder
When MySQL Shell is launched, it looks for all initialization script (init.py / init.js) within the "plugins" folder.
File : $HOME/.mysqlsh/plugins/ext/dbutil/init.py
# The function definition is given as follows - show_dbsize ( 3 arguments ) def show_dbsize(session, args, options): query = "SELECT table_schema AS 'Database', ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)', count(table_name) as '# of tables' FROM information_schema.TABLES GROUP BY table_schema" if (options.has_key('limit')): query += ' limit ' + str(options['limit']) result = session.run_sql(query); report = [] if (result.has_data()): report = [result.get_column_names()] for row in result.fetch_all(): report.append(list(row)) return {"report": report} # Register the show_dbsize function as a MySQL Shell report shell.register_report("dbsize", "list", show_dbsize, { "brief":"To list the tables without Primary Key.", 'details': ['You need the SELECT privilege on INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.STATISTICS.'], 'options': [ { 'name': 'limit', 'brief': 'The maximum number of rows to return.', 'shortcut': 'l', 'type': 'integer' } ], 'argc': '0' } ) |
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.
With a CONNECTED session, and Running the report can be simply to execute "\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.
Enjoy Reading!
I am happy to find this post Very useful for me, as it contains lot of information. I Always prefer to read The Quality and glad I found this thing in you post. Thanks read
ReplyDeletethe for u post
ReplyDeletegive a us more information
PHP Training in Chennai | Certification | Online Training Course | Machine Learning Training in Chennai | Certification | Online Training Course | iOT Training in Chennai | Certification | Online Training Course | Blockchain Training in Chennai | Certification | Online Training Course | Open Stack Training in Chennai |
Certification | Online Training Course
Great collection and thanks for sharing this info with us. Waiting for more like this.
ReplyDeleteDevOps certification in Chennai
DevOps Training in Chennai
DevOps course in Chennai
DevOps certification
DevOps Training
Best DevOps Training in Chennai
DevOps Training institute in Chennai
DevOps course
DevOps Training in Velachery
Thanks for sharing excellent information. Your article inspire us to start blogging
ReplyDeleteXerox machine dealers in Chennai
Xerox machine sales in Chennai
Xerox machine service in Chennai
Xerox machine rental in Chennai
Xerox machine AMC in Chennai
Thanks for sharing the valuable information.
ReplyDeletePython Training in Hyderabad
Python Training
Python Online Training
Python Online Training in Hyderabad
Python Institute in Hyderabad
Python Course in Hyderabad
wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. keep it up.
ReplyDeletepython training in bangalore
python training in hyderabad
python online training
python training
python flask training
python flask online training
python training in coimbatore
python training in bangalore
python training in hyderabad
python online training
python training
python flask training
python flask online training
python training in coimbatore
python training in bangalore
python training in hyderabad
python online training
python training
python flask training
python flask online training
python training in coimbatore
very interesting, good job and thanks for sharing such a good blog. Seo Services Delhi
ReplyDeleteNice article, You made my day by sharing an amazing article. I would like to be here again.
ReplyDeleteSEO Training in Pune
SEO Training in Mumbai
SEO Training in Delhi
SEO Training in Bangalore
SEO Training in Hyderabad
I read this post your post so nice and very informative post thanks for sharing this post. Youtube Mp3 Converter
ReplyDeleteVery good content.Thanks for sharing.
ReplyDeletepython Online Training
This comment has been removed by the author.
ReplyDeleteThe content you write is very helpful python course
ReplyDeleteThis is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
ReplyDeleteReactjs Training in Chennai |
Best Reactjs Training Institute in Chennai |
Reactjs course in Chennai
Aivivu đại lý vé máy bay, tham khảo
ReplyDeletevé máy bay đi Mỹ giá rẻ 2021
gia ve tu my ve vietnam
lịch bay từ canada về việt nam
thời gian bay từ nhật về vn
dat ve may bay tu han quoc ve viet nam
Vé máy bay từ Đài Loan về Việt Nam
các khách sạn cách ly ở hà nội
vé máy bay chuyên gia nước ngoài
Nice post.Bibliography maker
ReplyDeleteI go to your blog frequently and counsel it to the complete of folks who desired to feature-on happening their understanding subsequent to ease. The style of writing is exquisite and plus the content material is summit-notch. thanks for that perception you provide the readers! Windows 7 Ultimate Product Key
ReplyDeletei'm incapable of reading articles online particularly frequently, however Im happy I did nowadays. it is selected adroitly written, and your points are adeptly-expressed. I demand you harmoniously, entertain, dont ever lower writing. Reimage Plus Licence Key
ReplyDeleteI appreciated your work this is superb.
ReplyDeleteAbode Acrobat Torrent
Driver Booster License Key 2022
Bandicut Crack
Globalmapper Crack
SQL is a widely used language and is supported by most relational database management systems (RDBMSs). Some of the popular RDBMSs that support SQL include MySQL, PostgreSQL, Oracle, and Microsoft SQL Server
ReplyDeletecheck, SQL Classes in Pune