MySQL Shell API  8.0.26
Unified development interface for MySQL Products
Classes | Functions
mysqlx

Encloses the functions and classes available to interact with an X Protocol enabled MySQL Product. More...

Classes

class  Type
 Constants to represent data types con Column objects. More...
 
class  LockContention
 Constants to represent lock contention types. More...
 

Functions

Session get_session (ConnectionData connectionData, str password)
 Creates a Session instance using the provided connection data. More...
 
Expression expr (str expressionStr)
 Creates an Expression object based on a string. More...
 
Date date_value (int year, int month, int day, int hour, int minutes, int seconds, int milliseconds)
 Creates a Date object which represents a date time. More...
 

Detailed Description

Encloses the functions and classes available to interact with an X Protocol enabled MySQL Product.

The objects contained on this module provide a full API to interact with the different MySQL Products implementing the X Protocol.

In the case of a MySQL Server the API will enable doing operations on the different database objects such as schema management operations and both table and collection management and CRUD operations. (CRUD: Create, Read, Update, Delete).

Intention of the module is to provide a full API for development through scripting languages such as JavaScript and Python, this would be normally achieved through a normal session.

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

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

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

Function Documentation

◆ get_session()

Session get_session ( ConnectionData  connectionData,
str  password 
)

Creates a Session instance using the provided connection data.

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

A Session object uses the X Protocol to allow executing operations on the connected MySQL Server.

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...]

Connection Options

The following options are valid for use either in a URI or in a dictionary:

  • ssl-mode: The SSL mode to be used in the connection.
  • ssl-ca: The path to the X509 certificate authority file in PEM format.
  • ssl-capath: The path to the directory that contains the X509 certificate authority files in PEM format.
  • ssl-cert: The path to the SSL public key certificate file in PEM format.
  • ssl-key: The path to the SSL private key file in PEM format.
  • ssl-crl: The path to file that contains certificate revocation lists.
  • ssl-crlpath: The path of directory that contains certificate revocation list files.
  • ssl-cipher: The list of permissible encryption ciphers for connections that use TLS protocols up through TLSv1.2.
  • tls-version: List of protocols permitted for secure connections. TLS versions TLSv1 and TLSv1.1 are now deprecated and will be removed in a future release of MySQL Shell. Use TLSv1.2 or TLSv1.3.
  • tls-ciphers: List of TLS v1.3 ciphers to use.
  • auth-method: Authentication method.
  • get-server-public-key: Request public key from the server required for RSA key pair-based password exchange. Use when connecting to MySQL 8.0 servers with classic MySQL sessions with SSL mode DISABLED.
  • server-public-key-path: The path name to a file containing a client-side copy of the public key required by the server for RSA key pair-based password exchange. Use when connecting to MySQL 8.0 servers with classic MySQL sessions with SSL mode DISABLED.
  • connect-timeout: The connection timeout in milliseconds. If not provided a default timeout of 10 seconds will be used. Specifying a value of 0 disables the connection timeout.
  • compression: Enable compression in client/server protocol.
  • compression-algorithms: Use compression algorithm in server/client protocol.
  • compression-level: Use this compression level in the client/server protocol.
  • connection-attributes: List of connection attributes to be registered at the PERFORMANCE_SCHEMA connection attributes tables.
  • local-infile: Enable/disable LOAD DATA LOCAL INFILE.
  • net-buffer-length: The buffer size for TCP/IP and socket communication.

When these options are defined in a URI, their values must be URL encoded.

Base Connection Options

  • scheme: the protocol to be used on the connection.
  • user: the MySQL user name to be used on the connection.
  • dbUser: alias for user.
  • password: the password to be used on the connection.
  • dbPassword: same as password.
  • host: the hostname or IP address to be used on the connection.
  • port: the port to be used in a TCP connection.
  • socket: the socket file name to be used on a connection through unix sockets.
  • schema: the schema to be selected once the connection is done.
Attention
The dbUser and dbPassword options are will be removed in a future release.

The connection options are case insensitive and can only be defined once.

If an option is defined more than once, an error will be generated.

Detailed description of the connection data format is available at Connection Data

◆ expr()

Expression expr ( str  expressionStr)

Creates an Expression object based on a string.

Parameters
expressionStrThe expression to be represented by the object

An expression object is required in many operations on the X DevAPI.

Some applications of the expression objects include:

  • Creation of documents based on a JSON string
  • Defining calculated fields when inserting data on the database
  • Defining calculated fields when pulling data from the database

◆ date_value()

Date date_value ( int  year,
int  month,
int  day,
int  hour,
int  minutes,
int  seconds,
int  milliseconds 
)

Creates a Date object which represents a date time.

Parameters
yearThe year to be used in the new Date object.
monthThe month to be used in the new Date object.
dayThe month to be used in the new Date object.
hourOptional hour to be used in the new Date object.
minutesOptional minutes to be used in the new Date object.
secondsOptional seconds to be used in the new Date object.
millisecondsOptional milliseconds to be used in the new Date object.

This function creates a Date object containing:

  • A date value.
  • A date and time value.
  • A date and time value with milliseconds.