MySQL Shell API 9.2.0
Unified development interface for MySQL Products
Classes | Functions

Encloses the functions and classes available to interact with a MySQL Server using the traditional MySQL Protocol. More...

Classes

class  Type
 Constants to represent data types on Column objects. More...
 

Functions

ClassicSession get_classic_session (ConnectionData connectionData, str password)
 Opens a classic MySQL protocol session to a MySQL server. More...
 
ClassicSession get_session (ConnectionData connectionData, str password)
 Opens a classic MySQL protocol session to a MySQL server. More...
 
list split_script (str script)
 Split a SQL script into individual statements. More...
 
dict parse_statement_ast (str statements)
 Parse MySQL statements and return its AST representation. More...
 
str quote_identifier (str s)
 Quote a string as a MySQL identifier, escaping characters when needed. More...
 
str unquote_identifier (str s)
 Unquote a MySQL identifier. More...
 

Detailed Description

Encloses the functions and classes available to interact with a MySQL Server using the traditional MySQL Protocol.

Use this module to create a session using the traditional MySQL Protocol, for example for MySQL Servers where the X Protocol is not available.

Note that the API interface on this module is very limited, even you can load schemas, tables and views as objects there are no operations available on them.

The purpose of this module is to allow SQL Execution on MySQL Servers where the X Protocol is not enabled.

To use the properties and functions available on this module you first need to import it.

mysql-py> from mysqlsh import mysql
// Then you can use the module functions and properties
// for example to create a session
mysql-py> mySession = mysql.get_classic_session('admin@localhost')

When running the shell in interactive mode, this module is automatically imported.

Function Documentation

◆ get_classic_session()

ClassicSession get_classic_session ( ConnectionData  connectionData,
str  password 
)

Opens a classic MySQL protocol session to a MySQL server.

Parameters
connectionDataThe connection data for the session
passwordOptional password for the session
Returns
A ClassicSession

A ClassicSession object uses the traditional MySQL Protocol to allow executing operations on the connected MySQL Server.

Connection Data

The connection data may be specified in the following formats:

  • A URI string
  • A dictionary with the connection options

A basic URI string has the following format:

[scheme://][user[:password]@]<host[:port]|socket>[/schema][?option=value&option=value...]

For additional information about MySQL connection data, see Connection Data.

◆ get_session()

ClassicSession get_session ( ConnectionData  connectionData,
str  password 
)

Opens a classic MySQL protocol session to a MySQL server.

Parameters
connectionDataThe connection data for the session
passwordOptional password for the session
Returns
A ClassicSession

A ClassicSession object uses the traditional MySQL Protocol to allow executing operations on the connected MySQL Server.

Connection Data

The connection data may be specified in the following formats:

  • A URI string
  • A dictionary with the connection options

A basic URI string has the following format:

[scheme://][user[:password]@]<host[:port]|socket>[/schema][?option=value&option=value...]

For additional information about MySQL connection data, see Connection Data.

◆ split_script()

list split_script ( str  script)

Split a SQL script into individual statements.

Parameters
scriptA SQL script as a string containing multiple statements
Returns
A list of statements

The default statement delimiter is `;` but it can be changed with the DELIMITER keyword, which must be followed by the delimiter character(s) and a newline.

◆ parse_statement_ast()

dict parse_statement_ast ( str  statements)

Parse MySQL statements and return its AST representation.

Parameters
statementsSQL statements to be parsed
Returns
AST encoded as a JSON structure

◆ quote_identifier()

str quote_identifier ( str  s)

Quote a string as a MySQL identifier, escaping characters when needed.

Parameters
sthe identifier name to be quoted
Returns
Quoted identifier

◆ unquote_identifier()

str unquote_identifier ( str  s)

Unquote a MySQL identifier.

Parameters
sString to unquote
Returns
Unquoted string.

An exception is thrown if the input string is not quoted with backticks.