Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MySQL Shell : the best DBA tool ?

1,085 views

Published on

Presentation about how to extend MySQL Shell for DBA daily tasks and Innotop like processlist overview.
This presentation was delivered during the pre-FOSDEM MySQL Day on Feb 1st 2019

  • Be the first to comment

MySQL Shell : the best DBA tool ?

  1. 1. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 1/53 1 / 53
  2. 2. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 2/53 2 / 532 / 532 / 53
  3. 3. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 3/53 MyMySQLSQL ShellShell:: the best DBA tool ? How to use theHow to use the MyMySQLSQL ShellShell as a framework for DBAsas a framework for DBAs             Frédéric Descamps - MySQL Community Manager - Oracle 3 / 53
  4. 4. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 4/53   Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purpose only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied up in making purchasing decisions. The development, release and timing of any features or functionality described for Oracle´s product remains at the sole discretion of Oracle. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 4 / 53
  5. 5. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 5/53 about me - http://about.me/lefred Who am I ?Who am I ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 5 / 53
  6. 6. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 6/53 Frédéric Descamps @lefred MySQL Evangelist Hacking MySQL since 3.23 devops believer living in Belgium 🇧🇪 http://lefred.be   Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 6 / 53
  7. 7. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 7/53 a new tool MyMySQLSQL ShellShell Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 7 / 53
  8. 8. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 8/53 MySQL Shell The MySQL Shell is an interactive Javascript, Python, or SQL interface supporting development and administration for the MySQL Server and is a component of the MySQL Server. You can use the MySQL Shell to perform data queries and updates as well as various administration operations. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 8 / 53
  9. 9. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell.… 9/53 MySQL Shell (2) The MySQL Shell provides: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 9 / 53
  10. 10. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 10/53 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 10 / 53
  11. 11. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 11/53 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 11 / 53
  12. 12. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 12/53 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models CRUD Document and Relational APIs via scripting Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 12 / 53
  13. 13. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 13/53 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models CRUD Document and Relational APIs via scripting Traditional Table, JSON, Tab Separated output results formats Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 13 / 53
  14. 14. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 14/53 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models CRUD Document and Relational APIs via scripting Traditional Table, JSON, Tab Separated output results formats MySQL Standard and X Protocols Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 14 / 53
  15. 15. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 15/53 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models CRUD Document and Relational APIs via scripting Traditional Table, JSON, Tab Separated output results formats MySQL Standard and X Protocols and more... Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 15 / 53
  16. 16. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 16/53 MySQL Shell and Python When using the python mode in the Shell, it's possible to use system modules (local). Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 16 / 53
  17. 17. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 17/53 MySQL Shell and Python (2) Of course this can be any type of modules: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 17 / 53
  18. 18. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 18/53 MySQL Shell and Python (2) Of course this can be any type of modules: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 18 / 53
  19. 19. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 19/53 we want more ! ExtendingExtending MyMySQLSQL ShellShell Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 19 / 53
  20. 20. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 20/53 Extending MySQL Shell It's then possible to create your own modules to extend MySQL Shell. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 20 / 53
  21. 21. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 21/53 Extending MySQL Shell It's then possible to create your own modules to extend MySQL Shell. For calling some long statements or group of operations or sometimes to replace a missing functionality. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 21 / 53
  22. 22. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 22/53 Extending MySQL Shell It's then possible to create your own modules to extend MySQL Shell. For calling some long statements or group of operations or sometimes to replace a missing functionality. Recently, somebody pointed out that since the new DD it was not anymore possible to delete all routines for a specific schema. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 22 / 53
  23. 23. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 23/53 Extending MySQL Shell It's then possible to create your own modules to extend MySQL Shell. For calling some long statements or group of operations or sometimes to replace a missing functionality. Recently, somebody pointed out that since the new DD it was not anymore possible to delete all routines for a specific schema. Jesper explained recently how the MySQL Shell could help here see https://mysql.wisborg.dk/2018/12/02/mysql-8-drop-several-stored-events- procedures-or-functions/ Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 23 / 53
  24. 24. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 24/53 Extending MySQL Shell Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 24 / 53
  25. 25. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 25/53 Extending MySQL Shell Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 25 / 53
  26. 26. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 26/53 Extending MySQL Shell Or for example, retrieve the expiration period of passwords (see https://lefred.be/content/mysql-when-will-the-password-of-my-users-expire/): Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 26 / 53
  27. 27. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 27/53 Extending MySQL Shell Another example, retrieve the tables potentially fragmented (see https://lefred.be/content/overview-of-fragmented-mysql-innodb-tables/): Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 27 / 53
  28. 28. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 28/53 Extending MySQL Shell Recently somebody complained about the complexity of knowing what are the default values of columns when expressions are used (https://forums.mysql.com/read.php? 101,670682,670682): Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 28 / 53
  29. 29. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 29/53 Contribute to MySQL Shell DBA Toolkit ? Get the code from https://github.com/lefred/mysql-shell-mydba and Pull Requests are welcome ! Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 29 / 53
  30. 30. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 30/53 we want even more ! InnoInnotoptop Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 30 / 53
  31. 31. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 31/53 Innotop As maintainer of Innotop, after doing so delayed maintenance, I started a poll on Twitter: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 31 / 53
  32. 32. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 32/53 Innotop (2) So Innotop is not dead... but it's very complex to maintain... Perl ! Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 32 / 53
  33. 33. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 33/53 Innotop (2) So Innotop is not dead... but it's very complex to maintain... Perl ! This is maybe the reason there is less and less contributors... Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 33 / 53
  34. 34. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 34/53 Innotop (2) So Innotop is not dead... but it's very complex to maintain... Perl ! This is maybe the reason there is less and less contributors... ... so and MySQL Shell then ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 34 / 53
  35. 35. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 35/53 Innotop in MySQL Shell Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 35 / 53
  36. 36. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 36/53 Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 00:05 36 / 53
  37. 37. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 37/53 Innotop in MySQL Shell How to use it ?How to use it ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 37 / 53
  38. 38. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 38/53 How to use this module in MySQL Shell ? The module is available on github: https://github.com/lefred/mysql-shell-innotop Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 38 / 53
  39. 39. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 39/53 How to use this module in MySQL Shell ? The module is available on github: https://github.com/lefred/mysql-shell-innotop $ mysqlsh --py root@localhost importimport sys sys.path.append('/home/fred/workspace/mysql-shell-innotop') importimport innotop Py> innotop.session_processlist.run() Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 39 / 53
  40. 40. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 40/53 How to use this module in MySQL Shell ? The module is available on github: https://github.com/lefred/mysql-shell-innotop $ mysqlsh --py root@localhost importimport sys sys.path.append('/home/fred/workspace/mysql-shell-innotop') importimport innotop Py> innotop.session_processlist.run() Add in ~/.mysqlsh/mysqlshrc.py: importimport sys sys.path.append('/home/fred/workspace/mysql-shell-innotop') importimport innotop Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 40 / 53
  41. 41. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 41/53 does it work everywhere ? LimitationsLimitations Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 41 / 53
  42. 42. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 42/53 Limitations requires ncurses Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 42 / 53
  43. 43. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 43/53 Limitations requires ncurses works almost exclusively on Gnu/Linux Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 43 / 53
  44. 44. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 44/53 I want to contribute ! How to write your own extension ?How to write your own extension ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 44 / 53
  45. 45. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 45/53 Creating you own extension All extensions are a single file located in the modulesmodules folder: [fred@imac2 mysql-shell-innotop] $ ls modules/*py modules/common.py modules/global_by_ le_by_bytes.py modules/help.py modules/__init__.py modules/session_processlist.py modules/thread_info.py Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 45 / 53
  46. 46. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 46/53 Skeleton of an extension Every extension starts the same way and requires some mandatory modules: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 46 / 53
  47. 47. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 47/53 Skeleton of an extension Every extension starts the same way and requires some mandatory modules: importimport __builtin__ importimport curses fromfrom datetime importimport datetime fromfrom time importimport sleep importimport innotop Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 47 / 53
  48. 48. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 48/53 Skeleton of an extension Every extension starts the same way and requires some mandatory modules: importimport __builtin__ importimport curses fromfrom datetime importimport datetime fromfrom time importimport sleep importimport innotop Then you need to specify the shortcuts that calls the functions: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 48 / 53
  49. 49. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 49/53 Skeleton of an extension Every extension starts the same way and requires some mandatory modules: importimport __builtin__ importimport curses fromfrom datetime importimport datetime fromfrom time importimport sleep importimport innotop Then you need to specify the shortcuts that calls the functions: innotop.shortcut['h']={'return': 'help', 'stdscr': FalseFalse} Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 49 / 53
  50. 50. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 50/53 Skeleton of an extension Every extension starts the same way and requires some mandatory modules: importimport __builtin__ importimport curses fromfrom datetime importimport datetime fromfrom time importimport sleep importimport innotop Then you need to specify the shortcuts that calls the functions: innotop.shortcut['h']={'return': 'help', 'stdscr': FalseFalse} return:return: name of the module (help.py) stdscr:stdscr: use the same screen (and pass it to the function) Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 50 / 53
  51. 51. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 51/53 Skeleton of an extension - run() defdef runrun(session, delay=1, back=False): stdscr, info = innotop.common.setup(curses, session) keep_running = TrueTrue whilewhile keep_running: time = datetime.now() y,x = innotop.common.topbar(curses, stdscr, info) <your code> # Wait until delay seconds have passed while listening for the q key whilewhile (datetime.now() - time).total_seconds() < delay: c = stdscr.getch() ifif c == ord("q"): keep_running = FalseFalse breakbreak ifif notnot back: # Reset the cures behavior and nish curses.nocbreak() stdscr.keypad(FalseFalse) curses.echo() curses.endwin Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 51 / 53
  52. 52. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 52/53 Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 52 / 53
  53. 53. 1/18/2019 pre FOSDEM MySQL Day - MySQL Shell : the best DBA tool ? file:///home/fred/ownCloud/Presentations/ORACLE/FOSDEM2019/MySQL%20Day%20-%20MySQL%20Shell/MySQL%20Day%20-%20MySQL%20Shell… 53/53 Thank you ! Any Questions ? share your 💕 for MySQL on social media using @mysql #MySQL8isGreat #MySQLDay #MySQLShell Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 53 / 53

×