Documentation Home
MySQL Shell 8.0
Related Documentation Download this Manual
PDF (US Ltr) - 491.7Kb
PDF (A4) - 492.2Kb
HTML Download (TGZ) - 98.9Kb
HTML Download (Zip) - 110.6Kb

MySQL Shell 8.0  /  ...  /  Connections in JavaScript and Python

4.2.3 Connections in JavaScript and Python

When a connection is made using the command options or by using any of the MySQL Shell commands, a global session object is created. This session is global because once created, it can be used in any of the MySQL Shell execution modes.

Any global session object is available in JavaScript or Python modes because a variable called session holds a reference to it.

In addition to the global session object, sessions can be established and assigned to a different variable by using the functions available in the mysql and mysqlx JavaScript and Python modules.

For example, the following functions are provided by these modules:

  • mysqlx.getSession(connectionData[, password])

    The returned object can be Session if the object was created or retrieved using a Session instance, and ClassicSession if the object was created or retrieved using a ClassicSession instance.

  • mysql.getClassicSession(connectionData[, password])

    The returned object is a ClassicSession which uses the traditional MySQL protocol and has a limited development API.

connectionData can be either a URI-like string or key-value pairs containing the connection parameters. See Connecting to the Server Using URI-Like Strings or Key-Value Pairs.

Sessions created using either mysql.getClassicSession(connection_data) or mysqlx.getSession(connection_data) use ssl-mode=REQUIRED as the default if no ssl-mode is provided, and neither ssl-ca nor ssl-capath is provided. If no ssl-mode is provided and any of ssl-ca or ssl-capath is provided, created sessions default to ssl-mode=VERIFY_CA.

The following example shows how to create a Session using the X Protocol:

mysql-js> var mysession1=mysqlx.getSession('root@localhost:33060', 'password');
mysql-js> mysession1

The following example shows how to create a ClassicSession, with compression enabled for the connection:

mysql-js> var mysession2=mysql.getClassicSession('root@localhost:3306?compression=true', 'password');
mysql-js> mysession2