$30 off During Our Annual Pro Sale. View Details »

MySQL Day Roma - MySQL Shell and Visual Studio Code Extension

lefred
September 28, 2022

MySQL Day Roma - MySQL Shell and Visual Studio Code Extension

Discover the power of the new MySQL command line client and explore the new Visual Studio Code extension to work with MySQL

lefred

September 28, 2022
Tweet

More Decks by lefred

Other Decks in Technology

Transcript

  1. Frédéric Descamps
    Community Manager
    Oracle MySQL
    MySQL Day Rome - September 2022
    MySQL Shell and
    Visual Studio Code
    Extension
    Best MySQL Companions

    View Slide

  2. Who am I ?
    about.me/lefred
    Copyright @ 2022 Oracle and/or its affiliates.
    2

    View Slide

  3. @lefred
    MySQL Evangelist
    using MySQL since version 3.20
    devops believer
    living in
    Dylan Dog fan
    h ps://lefred.be
    Frédéric Descamps
    Copyright @ 2022 Oracle and/or its affiliates.
    3

    View Slide

  4. What Is MySQL Shell ?
    Copyright @ 2022 Oracle and/or its affiliates.
    4

    View Slide

  5. MySQL Shell
    The MySQL Shell is an interactive Javascript, Python, or SQL interface supporting
    development and administration for the MySQL Server
    You can use the MySQL Shell to perform data queries and updates as well as various
    administration operations.
    Copyright @ 2022 Oracle and/or its affiliates.
    5

    View Slide

  6. MySQL Shell (2)
    The MySQL Shell provides:
    Copyright @ 2022 Oracle and/or its affiliates.
    6

    View Slide

  7. MySQL Shell (2)
    The MySQL Shell provides:
    Both Interactive and Batch operations
    Copyright @ 2022 Oracle and/or its affiliates.
    6

    View Slide

  8. MySQL Shell (2)
    The MySQL Shell provides:
    Both Interactive and Batch operations
    Document and Relational Models
    Copyright @ 2022 Oracle and/or its affiliates.
    6

    View Slide

  9. MySQL Shell (2)
    The MySQL Shell provides:
    Both Interactive and Batch operations
    Document and Relational Models
    CRUD Document and Relational APIs via scripting
    Copyright @ 2022 Oracle and/or its affiliates.
    6

    View Slide

  10. 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 @ 2022 Oracle and/or its affiliates.
    6

    View Slide

  11. 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 @ 2022 Oracle and/or its affiliates.
    6

    View Slide

  12. 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 @ 2022 Oracle and/or its affiliates.
    6

    View Slide

  13. MySQL Shell Overview
    PY
    JS
    SQL
    >
    MySQL 8.0
    Upgrade Checker
    Auto Completion
    &
    Command History
    Output
    Formats
    (table, json, tabs)
    Prompt
    Themes
    Batch
    Execution
    5.7
    8.0
    JS
    Document
    Store
    X dev API
    SQL CLI
    importJSON
    InnoDB
    Cluster
    JS
    JS
    parallel
    importTABLE
    data
    dump & load
    InnoDB
    ReplicaSet
    Copyright @ 2022 Oracle and/or its affiliates.
    7

    View Slide

  14. Some Examples of the different modes
    Copyright @ 2022 Oracle and/or its affiliates.
    8

    View Slide

  15. MySQL Shell in Python Mode
    Copyright @ 2022 Oracle and/or its affiliates.
    9

    View Slide

  16. MySQL Shell in Python Mode
    Copyright @ 2022 Oracle and/or its affiliates.
    10

    View Slide

  17. MySQL Shell in Python Mode
    Copyright @ 2022 Oracle and/or its affiliates.
    11

    View Slide

  18. MySQL Shell in Javascript Mode
    Copyright @ 2022 Oracle and/or its affiliates.
    12

    View Slide

  19. MySQL Shell in SQL Mode
    Copyright @ 2022 Oracle and/or its affiliates.
    13

    View Slide

  20. MySQL Shell Modes
    Copyright @ 2022 Oracle and/or its affiliates.
    14

    View Slide

  21. Configuring your Shell
    Copyright @ 2022 Oracle and/or its affiliates.
    15

    View Slide

  22. A nice prompt
    The default prompt is basic. When installing the MySQL Shell package, 10 examples of
    prompt are also installed (in /usr/share/mysqlsh/prompt on Linux).
    After having started MySQL Shell for the rst time, a new folder (~/.mysqlsh) is created.
    You can copy a prompt le inside that folder and rename it prompt.json:
    $
    $ cp
    cp /usr/share/mysqlsh/prompt/prompt_256pl+aw.json ~/.mysqlsh/prompt.json
    /usr/share/mysqlsh/prompt/prompt_256pl+aw.json ~/.mysqlsh/prompt.json
    Copyright @ 2022 Oracle and/or its affiliates.
    16

    View Slide

  23. A nice prompt (2)
    Having a terminal font supporting specials characters (Powerline and Awesome) is
    recommended.
    Example: h ps://github.com/ztomer/fantasque_awesome_powerline
    Copyright @ 2022 Oracle and/or its affiliates.
    17

    View Slide

  24. Other con guration tips
    I usually enable the history of commands:
    \
    \option
    option --persist history.autoSave 1
    --persist history.autoSave 1
    \
    \option
    option --persist history.maxSize 5000
    --persist history.maxSize 5000
    All the options can be listed using \option -l
    Copyright @ 2022 Oracle and/or its affiliates.
    18

    View Slide

  25. Other con guration tips
    I usually enable the history of commands:
    \
    \option
    option --persist history.autoSave 1
    --persist history.autoSave 1
    \
    \option
    option --persist history.maxSize 5000
    --persist history.maxSize 5000
    All the options can be listed using \option -l
    I also recommend to replace the old mysql client by these aliases:
    alias
    alias mysql
    mysql=
    ="mysqlsh --sql mysql://localhost"
    "mysqlsh --sql mysql://localhost"
    alias
    alias mysqlx
    mysqlx=
    ="mysqlsh --js mysqlx://localhost"
    "mysqlsh --js mysqlx://localhost"
    Copyright @ 2022 Oracle and/or its affiliates.
    18

    View Slide

  26. MySQL Shell Utility
    Copyright @ 2022 Oracle and/or its affiliates.
    19

    View Slide

  27. checkForServerUpgrade()
    dumpInstance()
    dumpSchemas()
    dumpTables()
    exportTable()
    importJson()
    importTable()
    loadDump()
    MySQL Shell Utility
    MySQL Shell includes a toolset called "utility".
    The utility module contains 8 very useful methods:
    Copyright @ 2022 Oracle and/or its affiliates.
    20

    View Slide

  28. MySQL Shell Utility : checkForServerUpgrade()
    MySQL Shell helps the DBA to validate the upgrade to MySQL 8.0.
    With util.checkForServerUpgrade(), MySQL Shell can perform a series of tests on a
    speci ed MySQL sever to check is the upgrade process will succeed or if requires rst some
    changes.
    Will check your MySQL 5.7 or 8.0 installation readiness for upgrade to latest version
    Check for legacy issues
    Run the tool before upgrading!
    Always use latest version of MySQL Shell
    Copyright @ 2022 Oracle and/or its affiliates.
    21

    View Slide

  29. usage of old temporal type
    usage of new reserved keywords
    usage of utf8mb3 charset
    con icting name in mysql schema
    partitions with engine not supporting
    native partitioning
    foreign key constraint names longer than
    64 characters
    usage of obsolete MAXDB SQL mode ag
    usage of orther obsolete SQL mode ags
    ENUM/SET column de nitions containing
    elements longer than 255 characters
    usage of partitioned tables in shared
    tablespaces
    MySQL Shell Upgrade Checker Utility
    Upgrade Checker performs the following checks:
    Copyright @ 2022 Oracle and/or its affiliates.
    22

    View Slide

  30. circular directory references in tablespace
    data le paths
    usage of removed functions
    usage of removed GROUP BY ASC/DESC
    syntax
    removed system variables for error
    logging to the system log con guration
    removed system variables
    system variables with new default values
    schema inconsistencies resulting from le
    removal or corruption
    table names containing 'FTS'
    issues reported by check table x for
    upgrade command
    MySQL Shell Upgrade Checker Utility (2)
    Copyright @ 2022 Oracle and/or its affiliates.
    23

    View Slide

  31. MySQL Upgrade Checker: how to use it?
    From the system shell:
    $ mysqlsh -- util checkForServerUpgrade user@localhost:3306 --target-version
    $ mysqlsh -- util checkForServerUpgrade user@localhost:3306 --target-version=
    =8.0
    8.0.30
    .30 \
    \
    --output-format
    --output-format=
    =JSON --con g-path
    JSON --con g-path=
    =/etc/mysql/my.cnf
    /etc/mysql/my.cnf
    Interactively from MySQL Shell:
    mysqlsh
    mysqlsh>
    > util
    util.
    .checkForServerUpgrade
    checkForServerUpgrade(
    ('[email protected]:3306'
    '[email protected]:3306',
    , {
    {"password"
    "password":
    :"password"
    "password",
    ,
    "targetVersion"
    "targetVersion":
    :"8.0.30"
    "8.0.30",
    , "con gPath"
    "con gPath":
    :"/etc/my.cnf"
    "/etc/my.cnf"}
    })
    )
    mysqlsh
    mysqlsh>
    > util
    util.
    .checkForServerUpgrade
    checkForServerUpgrade(
    ()
    )
    Copyright @ 2022 Oracle and/or its affiliates.
    24

    View Slide

  32. MySQL Upgrade Checker - output example
    16) System variables with new default values
    Warning: Following system variables that are not de ned in your
    con guration le will have new default values. Please review if you rely on
    their current values and if so de ne them before performing upgrade.
    More information:
    https://mysqlserverteam.com/new-defaults-in-mysql-8-0/
    back_log - default value will change
    character_set_server - default value will change from latin1 to utf8mb4
    collation_server - default value will change from latin1_swedish_ci to
    utf8mb4_0900_ai_ci
    event_scheduler - default value will change from OFF to ON
    explicit_defaults_for_timestamp - default value will change from OFF to ON
    innodb_autoinc_lock_mode - default value will change from 1 (consecutive) to
    2 (interleaved)
    innodb_ ush_method - default value will change from NULL to fsync (Unix),
    unbuffered (Windows)
    innodb_ ush_neighbors - default value will change from 1 (enable) to 0
    (disable)
    innodb_max_dirty_pages_pct - default value will change from 75 (%) 90 (%)
    innodb_max_dirty_pages_pct_lwm - default value will change from_0 (%) to 10
    (%)
    innodb_undo_log_truncate - default value will change from OFF to ON
    ...
    Copyright @ 2022 Oracle and/or its affiliates.
    25

    View Slide

  33. MySQL Upgrade Checker - output example (2)
    17) Zero Date, Datetime, and Timestamp values
    Warning: By default zero date/datetime/timestamp values are no longer allowed
    in MySQL, as of 5.7.8 NO_ZERO_IN_DATE and NO_ZERO_DATE are included in
    SQL_MODE by default. These modes should be used with strict mode as they will
    be merged with strict mode in a future release. If you do not include these
    modes in your SQL_MODE setting, you are able to insert
    date/datetime/timestamp values that contain zeros. It is strongly advised to
    replace zero values with valid ones, as they may not work correctly in the
    future.
    More information:
    https://lefred.be/content/mysql-8-0-and-wrong-dates/
    sbtest_tpcc.orders2.o_entry_d - column has zero default value: 0000-00-00 00:00:00
    Copyright @ 2022 Oracle and/or its affiliates.
    26

    View Slide

  34. MySQL Shell Utility : dump%() and loadDump()
    Another aspect of the DBAs daily tasks is to deal with logical dumps, for backup, for
    migrations, to reset data in dev environments ...
    Copyright @ 2022 Oracle and/or its affiliates.
    27

    View Slide

  35. MySQL Shell Utility : dump%() and loadDump()
    Another aspect of the DBAs daily tasks is to deal with logical dumps, for backup, for
    migrations, to reset data in dev environments ...
    MySQL Shell provides and amazing tool that relegates all its competitors far behind !
    Copyright @ 2022 Oracle and/or its affiliates.
    27

    View Slide

  36. MySQL Shell Utility : dump%() and loadDump()
    Another aspect of the DBAs daily tasks is to deal with logical dumps, for backup, for
    migrations, to reset data in dev environments ...
    MySQL Shell provides and amazing tool that relegates all its competitors far behind !
    Bye bye mysqldump, mysqlpump, mydumper, ...
    Copyright @ 2022 Oracle and/or its affiliates.
    27

    View Slide

  37. MySQL Shell Utility : dump%() and loadDump()
    Another aspect of the DBAs daily tasks is to deal with logical dumps, for backup, for
    migrations, to reset data in dev environments ...
    MySQL Shell provides and amazing tool that relegates all its competitors far behind !
    Bye bye mysqldump, mysqlpump, mydumper, ...
    Welcome MySQL Shell Load & Dump !!
    Copyright @ 2022 Oracle and/or its affiliates.
    27

    View Slide

  38. Logical Dump
    3 types of dumps are available and are accessible via those methods:
    dumpInstance()
    dumpSchemas()
    dumpTables()
    Copyright @ 2022 Oracle and/or its affiliates.
    28

    View Slide

  39. dump to remote storage (like Object Store)
    progress state tracking
    check for compatibility with MDS
    resume and reset capability
    add rate limitation
    use compression
    on the y changes:
    create invisible PKs
    force InnoDB
    ignore missing PKs
    skip invalid accounts
    strip de ners
    strip restricted grants
    strip tablespaces
    Logical Dump (2)
    Dumps are taken in parallel but has many other bene ts like :
    Copyright @ 2022 Oracle and/or its affiliates.
    29

    View Slide

  40. MySQL Shell Dump
    Copyright @ 2022 Oracle and/or its affiliates.
    30

    View Slide

  41. run analyze tables after load (can be
    limited to those having histograms)
    the character set can be overridden
    invisible PKs creation
    defer the creation of secondary indexes
    (can also be limited to FT)
    just load the scheme's de nition or the
    data
    resume and reset capability
    show progress
    skip binary logs
    update or override GTIDs
    Logical Load
    The generated dumps can also be loaded in parallel and many parameters are supported to
    provide the best experience. Let's see some of them:
    Copyright @ 2022 Oracle and/or its affiliates.
    31

    View Slide

  42. Logical Load (2)
    Take a look

    at this output:
    Copyright @ 2022 Oracle and/or its affiliates.
    32

    View Slide

  43. Logical Load (2)
    Take a look

    at this output:
    Copyright @ 2022 Oracle and/or its affiliates.
    32

    View Slide

  44. Logical Load (2)
    Take a look

    at this output:
    MySQL Shell is also the easiest and fastest way to migrate to MySQL Database Service on
    OCI
    CLOUD
    Copyright @ 2022 Oracle and/or its affiliates.
    32

    View Slide

  45. MySQL Shell Load
    Copyright @ 2022 Oracle and/or its affiliates.
    33

    View Slide

  46. MySQL Shell Utility: importJson()
    If you plan to use MySQL as a Document Store, you can import JSON documents very
    easily.
    Copyright @ 2022 Oracle and/or its affiliates.
    34

    View Slide

  47. MySQL Shell Utility: importJson()
    If you plan to use MySQL as a Document Store, you can import JSON documents very
    easily.
    Task : migrate a collection of more than 25k documents from MongoDB to MySQL
    Copyright @ 2022 Oracle and/or its affiliates.
    34

    View Slide

  48. MySQL Shell Utility: importJson()
    If you plan to use MySQL as a Document Store, you can import JSON documents very
    easily.
    Task : migrate a collection of more than 25k documents from MongoDB to MySQL
    Copyright @ 2022 Oracle and/or its affiliates.
    34

    View Slide

  49. MySQL Shell Utility: importJson()
    If you plan to use MySQL as a Document Store, you can import JSON documents very
    easily.
    Task : migrate a collection of more than 25k documents from MongoDB to MySQL
    Copyright @ 2022 Oracle and/or its affiliates.
    34

    View Slide

  50. MySQL Shell : Document Store
    Now the documents can be used in MySQL Document Store with CRUD operations:
    Copyright @ 2022 Oracle and/or its affiliates.
    35

    View Slide

  51. MySQL Shell Utility: debug
    The debugging and diagnostics utility util.debug.collectDiagnostics() enables you to
    collect diagnostic data on your MySQL server.
    The diagnostic report is generated as a zip le.
    This information could be shared with MySQL Support Team for example.
    Copyright @ 2022 Oracle and/or its affiliates.
    36

    View Slide

  52. MySQL Shell Utility: debug (2)
    Copyright @ 2022 Oracle and/or its affiliates.
    37

    View Slide

  53. MySQL Shell Utility: exportTable() & importTable()
    This method exports a MySQL relational table into a data le.
    Then it can use the le to import a table's content too.
    Multliple dialects are supported:
    default linesTerminatedBy: [LF], eldsTerminatedBy: [TAB], lesEnclosedBy: [empty], eldsOptionallyEnclosed: false
    csv linesTerminatedBy: [CR][LF], eldsTerminatedBy: [,], lesEnclosedBy: ["], eldsOptionallyEnclosed: true
    csv-unix linesTerminatedBy: [LF], eldsTerminatedBy: [,], lesEnclosedBy: ["], eldsOptionallyEnclosed: false
    tsv linesTerminatedBy: [LF], eldsTerminatedBy: [TAB], lesEnclosedBy: ["], eldsOptionallyEnclosed: true
    OCI Object Storage or AWS S3 can also be used.
    Copyright @ 2022 Oracle and/or its affiliates.
    38

    View Slide

  54. MySQL Shell Utility: exportTable() & importTable()
    Copyright @ 2022 Oracle and/or its affiliates.
    39

    View Slide

  55. Admin API
    Copyright @ 2022 Oracle and/or its affiliates.
    40

    View Slide

  56. MySQL Shell Admin API
    The AdminAPI is an API that enables con guring and managing InnoDB Clusters, InnoDB
    ReplicaSets and InnoDB ClusterSets among other things.
    The AdminAPI is available via the dba global object of MySQL Shell
    Copyright @ 2022 Oracle and/or its affiliates.
    41

    View Slide

  57. MySQL Shell Admin API
    The AdminAPI is an API that enables con guring and managing InnoDB Clusters, InnoDB
    ReplicaSets and InnoDB ClusterSets among other things.
    The AdminAPI is available via the dba global object of MySQL Shell
    This provides a very easy and secure way to deploy MySQL Architectures for the DBA.
    It includes con guration, checks and even data provisioning !
    Copyright @ 2022 Oracle and/or its affiliates.
    41

    View Slide

  58. MySQL Shell Admin API (2)
    As like most of the MySQL Shell capabilities all the Admin API calls can be done
    interactively or directly from the command line or a script.
    This allows automation with a con guration management tool for example.
    Copyright @ 2022 Oracle and/or its affiliates.
    42

    View Slide

  59. The new MySQL Operator for K8s also uses MySQL Shell in the
    backend.
    MySQL Shell Admin API (2)
    As like most of the MySQL Shell capabilities all the Admin API calls can be done
    interactively or directly from the command line or a script.
    This allows automation with a con guration management tool for example.
    Copyright @ 2022 Oracle and/or its affiliates.
    42

    View Slide

  60. MySQL Shell Admin API - examples
    Copyright @ 2022 Oracle and/or its affiliates.
    43

    View Slide

  61. MySQL InnoDB Cluster MySQL InnoDB ReplicaSet
    js
    js>
    > \
    \c admin@mysql1
    c admin@mysql1
    js
    js>
    > cluster
    cluster =
    = dba.createCluster
    dba.createCluster(
    ('cluster'
    'cluster')
    )
    js
    js>
    > \
    \c admin@mysql1
    c admin@mysql1
    js
    js>
    > rs
    rs =
    = dba.createReplicaSet
    dba.createReplicaSet(
    ('replicaset'
    'replicaset')
    )
    MySQL Shell Admin API - examples
    Copyright @ 2022 Oracle and/or its affiliates.
    43

    View Slide

  62. MySQL InnoDB Cluster MySQL InnoDB ReplicaSet
    js
    js>
    > \
    \c admin@mysql1
    c admin@mysql1
    js
    js>
    > cluster
    cluster =
    = dba.createCluster
    dba.createCluster(
    ('cluster'
    'cluster')
    )
    js
    js>
    > \
    \c admin@mysql1
    c admin@mysql1
    js
    js>
    > rs
    rs =
    = dba.createReplicaSet
    dba.createReplicaSet(
    ('replicaset'
    'replicaset')
    )
    Con gure server to add later
    js
    js>
    > dba.con gureInstance
    dba.con gureInstance(
    ('admin@mysql2'
    'admin@mysql2')
    ) js
    js>
    > dba.con gureReplicaSetInstance
    dba.con gureReplicaSetInstance(
    ('admin@mysql2'
    'admin@mysql2')
    )
    MySQL Shell Admin API - examples
    Copyright @ 2022 Oracle and/or its affiliates.
    43

    View Slide

  63. MySQL InnoDB Cluster MySQL InnoDB ReplicaSet
    js
    js>
    > \
    \c admin@mysql1
    c admin@mysql1
    js
    js>
    > cluster
    cluster =
    = dba.createCluster
    dba.createCluster(
    ('cluster'
    'cluster')
    )
    js
    js>
    > \
    \c admin@mysql1
    c admin@mysql1
    js
    js>
    > rs
    rs =
    = dba.createReplicaSet
    dba.createReplicaSet(
    ('replicaset'
    'replicaset')
    )
    Con gure server to add later
    js
    js>
    > dba.con gureInstance
    dba.con gureInstance(
    ('admin@mysql2'
    'admin@mysql2')
    ) js
    js>
    > dba.con gureReplicaSetInstance
    dba.con gureReplicaSetInstance(
    ('admin@mysql2'
    'admin@mysql2')
    )
    Add server to the Cluster
    js
    js>
    > cluster.addInstance
    cluster.addInstance(
    ('admin@mysql2'
    'admin@mysql2')
    ) js
    js>
    > rs.addInstance
    rs.addInstance(
    ('admin@mysql2'
    'admin@mysql2')
    )
    MySQL Shell Admin API - examples
    Copyright @ 2022 Oracle and/or its affiliates.
    43

    View Slide

  64. Bootstrap MySQL Router
    $
    $ sudo
    sudo mysqlrouter
    mysqlrouter --user
    --user=
    =mysqlrouter
    mysqlrouter --bootstrap
    --bootstrap
    $
    $ sudo
    sudo systemctl start mysqlrouter
    systemctl start mysqlrouter
    $
    $ sudo
    sudo mysqlrouter
    mysqlrouter --user
    --user=
    =mysqlrouter
    mysqlrouter --bootstrap
    --bootstrap
    $
    $ sudo
    sudo systemctl start mysqlrouter
    systemctl start mysqlrouter
    MySQL Shell Admin API - examples
    Copyright @ 2022 Oracle and/or its affiliates.
    44

    View Slide

  65. MySQL Shell Admin API (3)
    The Admin API also provides all the required methods to manage your MySQL Architecture
    Copyright @ 2022 Oracle and/or its affiliates.
    45

    View Slide

  66. MySQL Shell Admin API (3)
    The Admin API also provides all the required methods to manage your MySQL Architecture
    Copyright @ 2022 Oracle and/or its affiliates.
    45

    View Slide

  67. Extending MySQL Shell
    Copyright @ 2022 Oracle and/or its affiliates.
    46

    View Slide

  68. Extending MySQL Shell
    As a DBA or a developer, you have two di erents ways to extend the capabilities of MySQL
    Shell:
    using the Reporting Framework
    creating your own modules
    Copyright @ 2022 Oracle and/or its affiliates.
    47

    View Slide

  69. Extending MySQL Shell
    As a DBA or a developer, you have two di erents ways to extend the capabilities of MySQL
    Shell:
    using the Reporting Framework
    creating your own modules
    The UDR (User De ned Reports) can be called via the \show and the \watch commands:
    Copyright @ 2022 Oracle and/or its affiliates.
    47

    View Slide

  70. Extending MySQL Shell - UDR
    Copyright @ 2022 Oracle and/or its affiliates.
    48

    View Slide

  71. Extending MySQL Shell - UDR (2)
    You can nd examples of extra User De ned Reports on
    h ps://github.com/lefred/mysql-shell-udr
    Copyright @ 2022 Oracle and/or its affiliates.
    49

    View Slide

  72. Extending MySQL Shell - Plugins
    For repetitive or complex tasks, it's also possible to extend MySQL Shell with plugins.
    Copyright @ 2022 Oracle and/or its affiliates.
    50

    View Slide

  73. Extending MySQL Shell - Plugins
    For repetitive or complex tasks, it's also possible to extend MySQL Shell with plugins.
    Some words on MySQL Shell Plugins:
    can be wri en in Python or JavaScript
    are loaded when starting MySQL Shell
    can use any local modules too
    Copyright @ 2022 Oracle and/or its affiliates.
    50

    View Slide

  74. Extending MySQL Shell - Plugins
    For repetitive or complex tasks, it's also possible to extend MySQL Shell with plugins.
    Some words on MySQL Shell Plugins:
    can be wri en in Python or JavaScript
    are loaded when starting MySQL Shell
    can use any local modules too
    You can nd multiple plugins to test and extend on:
    h ps://github.com/lefred/mysqlshell-plugins
    Copyright @ 2022 Oracle and/or its affiliates.
    50

    View Slide

  75. Users & Privileges - plugins examples
    Dumping all users and grants:
    Copyright @ 2022 Oracle and/or its affiliates.
    51

    View Slide

  76. Users & Privileges - plugins examples
    Copy users from a server to another:
    Copyright @ 2022 Oracle and/or its affiliates.
    52

    View Slide

  77. Users & Privileges - plugins examples
    Create a user wizard
    Copyright @ 2022 Oracle and/or its affiliates.
    53

    View Slide

  78. Users & Privileges - plugins examples
    Create a user wizard
    Copyright @ 2022 Oracle and/or its affiliates.
    53

    View Slide

  79. Users & Privileges - plugins examples
    Authentication methods and passwords to expire:
    Copyright @ 2022 Oracle and/or its affiliates.
    54

    View Slide

  80. Poor's man Collect and Trending
    Copyright @ 2022 Oracle and/or its affiliates.
    55

    View Slide

  81. Poor's man Collect and Trending
    When you have a performance problem with MySQL, the best way to diagnose the issue is
    to use trending information.
    I've extended MySQL Shell with speci c plugins that use third party libraries to collect and
    plot useful information.
    Copyright @ 2022 Oracle and/or its affiliates.
    56

    View Slide

  82. Poor's man Collect and Trending (2)
    Copyright @ 2022 Oracle and/or its affiliates.
    57

    View Slide

  83. Poor's man Collect and Trending (3)
    Copyright @ 2022 Oracle and/or its affiliates.
    58

    View Slide

  84. Poor's man Collect and Trending (4)
    More Information:
    h ps://lefred.be/content/poormans-mysql-monitoring-trending/
    h ps://lefred.be/content/a-graph-a-day-keeps-the-doctor-away-mysql-checkpoint-age/
    h ps://lefred.be/content/a-graph-a-day-keeps-the-doctor-away-mysql-history-list-length/
    h ps://lefred.be/content/a-graph-a-day-keeps-the-doctor-away-full-table-scans/
    h ps://lefred.be/content/dynamic-innodb-redo-log/
    Copyright @ 2022 Oracle and/or its affiliates.
    59

    View Slide

  85. MySQL Shell for Visual Studio Code
    Copyright @ 2022 Oracle and/or its affiliates.
    60

    View Slide

  86. MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    61

    View Slide

  87. Visual Studio Code is the most
    popular IDE with developers
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    61

    View Slide

  88. MySQL Shell for VS Code
    We want to o er a single interface to the developers and and the operators/DBAs.
    Copyright @ 2022 Oracle and/or its affiliates.
    62

    View Slide

  89. MySQL Shell for VS Code
    We want to o er a single interface to the developers and and the operators/DBAs.
    A place where MySQL Workbench and MySQL Shell can merge.
    Copyright @ 2022 Oracle and/or its affiliates.
    62

    View Slide

  90. MySQL Shell for VS Code - Installation
    The installation is very simple using Visual Studio Code's Marketplace:
    Copyright @ 2022 Oracle and/or its affiliates.
    63

    View Slide

  91. MySQL Shell for VS Code - Installation
    Or just use CTRL-P in Visual Studio code and paste the following command:
    ext install Oracle.mysql-shell-for-vs-code
    Copyright @ 2022 Oracle and/or its affiliates.
    64

    View Slide

  92. MySQL Shell for VS Code - Requirements
    The list of requirements is pre y short:
    Visual Studio Code >= 1.63.0
    Windows 64bit or 32bit OR Linux 64 bit OR macOSX 10.11+
    Copyright @ 2022 Oracle and/or its affiliates.
    65

    View Slide

  93. MySQL Shell for VS Code - Installation: certi cates
    The rst time the extension is installed, the setup wizard is started to generate certi cates.
    Those certi cates are installed on your local user account in order to securely access
    MySQL Shell.
    Copyright @ 2022 Oracle and/or its affiliates.
    66

    View Slide

  94. MySQL Shell for VS Code - Installation: certi cates
    You need to install them or the extension won't work properly:
    Copyright @ 2022 Oracle and/or its affiliates.
    67

    View Slide

  95. MySQL Shell for VS Code - Linux
    This is a demo on Linux:
    Copyright @ 2022 Oracle and/or its affiliates.
    68

    View Slide

  96. MySQL Shell for VS Code - under the hood
    The certi cates, log le and some data are stored in the ~/.mysqlsh-gui directory:
    Copyright @ 2022 Oracle and/or its affiliates.
    69

    View Slide

  97. MySQL Shell for VS Code - features
    Copyright @ 2022 Oracle and/or its affiliates.
    70

    View Slide

  98. Activity Bar's Icon &
    View Container.
    The view container
    appears as an icon in the
    activity bar after you install
    the MySQL Shell for VS
    Code extension.
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    71

    View Slide

  99. Database Editor
    Connections View
    This is where you can
    create and manage
    connections to MySQL
    servers and MySQL
    HeatWave
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    72

    View Slide

  100. OCI and MySQL
    HeatWave View
    Con gure the Oracle Cloud
    Instrastructure pro le and
    access your resources.
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    73

    View Slide

  101. MySQL Shell
    Sessions View
    This is the place where you
    can create and manage
    MySQL Shell sessions.
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    74

    View Slide

  102. MySQL Shell Tasks
    View
    Here you can see all
    ongoing tasks for MySQL
    Shell.
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    75

    View Slide

  103. SQL Notebook
    SQL Notebook is an
    embedded, console-type
    editor, which combines
    elements of a classic
    terminal and a visual
    editor.
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    76

    View Slide

  104. MySQL Shell
    Console
    MySQL Shell GUI Console
    provides the full power of
    the MySQL Shell inside a
    notebook- interface-styled
    editor
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    77

    View Slide

  105. VScode ouput,
    debug, terminal...
    This is the standard panel of VS code with
    an embedded terminal, the debug console
    and the output.
    MySQL Shell and MySQL Shell Tasks have
    their own output that can be selected. This
    is very useful when debuging the
    extension.
    MySQL Shell for VS Code
    Copyright @ 2022 Oracle and/or its affiliates.
    78

    View Slide

  106. This editor supports 3 languages:
    SQL
    JavaScript
    TypeScript
    2 protocols are supported:
    classic MySQL protocol (3306)
    X Protocol (mysqlx) (33060)
    MySQL Shell for VS Code - SQL Notebook
    The SQL Notebook editor is the default editor each time you establish a connection to
    MySQL (or SQLite).
    Copyright @ 2022 Oracle and/or its affiliates.
    79

    View Slide

  107. MySQL Shell for VS Code - SQL Notebook
    The SQL Notebook editor combines the best of the GUI editors and the command line
    clients.
    You can see it like a endless document where each commands (called prompt) is followed by
    a result area (output) that is linked to it.
    If you have multiple statements, the output area will contains multiple tabs:
    Copyright @ 2022 Oracle and/or its affiliates.
    80

    View Slide

  108. MySQL Shell for VS Code - SQL Notebook
    The commands can be modi ed ad in nitum: you can croll up and down in the document
    and change all statements any time.
    The editor provides command completion:
    Copyright @ 2022 Oracle and/or its affiliates.
    81

    View Slide

  109. MySQL Shell for VS Code - SQL Notebook
    We have also added a graphs capabilities (work in progress) in TypeScript. Currently
    PieGraph() is available:
    Copyright @ 2022 Oracle and/or its affiliates.
    82

    View Slide

  110. MySQL Shell for VS Code - SQL Notebook (cool)
    MySQL Shell is integrated to VS code also when you edit other les:
    Copyright @ 2022 Oracle and/or its affiliates.
    83

    View Slide

  111. You can select any SQL
    statement in your code and
    execute it the SQL
    Notebook
    MySQL Shell for VS Code - SQL Notebook (cool)
    Copyright @ 2022 Oracle and/or its affiliates.
    84

    View Slide

  112. MySQL Shell for VS Code - SQL Notebook (cool)
    It gets executed in a new block (prompt + output):
    Copyright @ 2022 Oracle and/or its affiliates.
    85

    View Slide

  113. MySQL Shell for VS Code - SQL Notebook (cool)
    You can modify your query and test it. When ready send it back modi ed to the code:
    Copyright @ 2022 Oracle and/or its affiliates.
    86

    View Slide

  114. MySQL Shell for VS Code - SQL Notebook (cool)
    Done ! This is a very cool feature for developers !
    Copyright @ 2022 Oracle and/or its affiliates.
    87

    View Slide

  115. It supports 3 languages:
    SQL
    JavaScript
    Python
    2 protocols are supported:
    classic MySQL protocol (3306)
    X Protocol (mysqlx) (33060)
    MySQL Shell for VS Code - MySQL Shell Console
    The MySQL Shell Consoles view allows you to have dedicated area for working with
    multiple MySQL Shell sessions.
    This is exacly like the usual temrinal MySQL Shell but in VS code:
    Copyright @ 2022 Oracle and/or its affiliates.
    88

    View Slide

  116. MySQL Shell for VS Code - MySQL Shell Console
    The AdminAPI is available when using MySQL Shell Console session. Same for the utilities:
    Copyright @ 2022 Oracle and/or its affiliates.
    89

    View Slide

  117. You also have the possibility to connect to
    your MySQL HeatWave instances using the
    Bastion Service that the extension will deploy
    and con gure for you !
    MySQL Shell for VS Code - OCI
    If you are using OCI, MySQL Shell for VS Code is your best companion.
    It uses by default all con guration pro les de ned in ~/.oci/con g le.
    You have the possibility to see all your MySQL HeatWave instances but also other resources
    like compute instances.
    Copyright @ 2022 Oracle and/or its affiliates.
    90

    View Slide

  118. MySQL Shell for VS Code - OCI
    If no bastion host is present, a new one will be created:
    Copyright @ 2022 Oracle and/or its affiliates.
    91

    View Slide

  119. MySQL Shell for VS Code - OCI
    Copyright @ 2022 Oracle and/or its affiliates.
    92

    View Slide

  120. MySQL Shell for VS Code - OCI
    MySQL Shell Dump & Load utility is integrated and optimized for OCI MySQL HeatWave
    service:
    Copyright @ 2022 Oracle and/or its affiliates.
    93

    View Slide

  121. MySQL Shell for VS Code - OCI
    Copyright @ 2022 Oracle and/or its affiliates.
    94

    View Slide

  122. MySQL Shell for VS Code - OCI
    Copyright @ 2022 Oracle and/or its affiliates.
    95

    View Slide

  123. MySQL Shell for VS Code - OCI
    Copyright @ 2022 Oracle and/or its affiliates.
    96

    View Slide

  124. MySQL Shell for VS Code - se ings
    You have the possibility to modify some se ings for the extension (numbers of records in
    paging, capitalize the SQL commands, ...)
    Copyright @ 2022 Oracle and/or its affiliates.
    97

    View Slide

  125. Share your

    to MySQL
    #mysql
    Join our slack channel!
    bit.ly/mysql-slack
    Copyright @ 2022 Oracle and/or its affiliates.
    98

    View Slide

  126. Questions ?
    Copyright @ 2022 Oracle and/or its affiliates.
    99

    View Slide