mysqlx.SessionΒΆ

class mysqlx.Session(settings: Dict[str, Any])ΒΆ

Bases: object

Enables interaction with a X Protocol enabled MySQL Product.

The functionality includes:

  • Accessing available schemas.

  • Schema management operations.

  • Retrieval of connection information.

Parameters:

settings (dict) – Connection data used to connect to the database.

close() β†’ NoneΒΆ

Closes the session.

close_connections() β†’ NoneΒΆ

Closes all underliying connections as pooled connections

commit() β†’ NoneΒΆ

Commits all the operations executed after a call to startTransaction().

create_schema(name: str) β†’ SchemaΒΆ

Creates a schema on the database and returns the corresponding object.

Parameters:

name (string) – A string value indicating the schema name.

drop_schema(name: str) β†’ NoneΒΆ

Drops the schema with the specified name.

Parameters:

name (string) – The name of the Schema object to be retrieved.

get_connection() β†’ ConnectionΒΆ

Returns the underlying connection.

Returns:

The connection object.

Return type:

mysqlx.connection.Connection

get_default_schema() β†’ Schema | NoneΒΆ

Retrieves a Schema object from the current session by the schema name configured in the connection settings.

Returns:

The Schema object with the given name at connect

time.

None: In case the default schema was not provided with the

initialization data.

Return type:

mysqlx.Schema

Raises:

mysqlx.ProgrammingError – If the provided default schema does not exists.

get_schema(name: str) β†’ SchemaΒΆ

Retrieves a Schema object from the current session by it’s name.

Parameters:

name (string) – The name of the Schema object to be retrieved.

Returns:

The Schema object with the given name.

Return type:

mysqlx.Schema

get_schemas() β†’ List[str]ΒΆ

Returns the list of schemas in the current session.

Returns:

The list of schemas in the current session.

Return type:

list

New in version 8.0.12.

is_open() β†’ boolΒΆ

Returns True if the session is open.

Returns:

Returns True if the session is open.

Return type:

bool

release_savepoint(name: str) β†’ NoneΒΆ

Release a transaction savepoint with the given name.

Parameters:

name (string) – The savepoint name.

rollback() β†’ NoneΒΆ

Discards all the operations executed after a call to startTransaction().

rollback_to(name: str) β†’ NoneΒΆ

Rollback to a transaction savepoint with the given name.

Parameters:

name (string) – The savepoint name.

set_savepoint(name: str | None = None) β†’ strΒΆ

Creates a transaction savepoint.

If a name is not provided, one will be generated using the uuid.uuid1() function.

Parameters:

name (Optional[string]) – The savepoint name.

Returns:

The savepoint name.

Return type:

string

sql(sql: str) β†’ SqlStatementΒΆ

Creates a mysqlx.SqlStatement object to allow running the SQL statement on the target MySQL Server.

Parameters:

sql (string) – The SQL statement to be executed.

Returns:

SqlStatement object.

Return type:

mysqlx.SqlStatement

start_transaction() β†’ NoneΒΆ

Starts a transaction context on the server.

property use_pure: boolΒΆ

True to use pure Python Protobuf implementation.

Type:

bool