A default schema for a session can be specified using the
schema
attribute in the
URI-like
connection string or key-value pairs when opening a
connection session. The Session
class
getDefaultSchema()
method returns the default schema for
the Session
.
If no default schema has been selected at connection, the
Session
class
setCurrentSchema()
function can be used to set
a current schema.
MySQL Shell JavaScript Code
Press CTRL+C to copyvar mysqlx = require('mysqlx'); // Direct connect with no client-side default schema specified var mySession = mysqlx.getSession('user:password@localhost'); mySession.setCurrentSchema("test");
MySQL Shell Python Code
Press CTRL+C to copyfrom mysqlsh import mysqlx # Direct connect with no client-side default schema specified mySession = mysqlx.get_session('user:password@localhost') mySession.set_current_schema("test")
Node.js JavaScript Code
Press CTRL+C to copy/* Connector/Node.js does not support the setCurrentSchema() method. One can specify the default schema in the URI-like connection string. */
C# Code
Press CTRL+C to copy// Direct connect with no client-side default schema specified var mySession = MySQLX.GetSession("server=localhost;port=33060;user=user;password=password;"); mySession.SetCurrentSchema("test");
Python Code
Press CTRL+C to copy# Connector/Python from mysqlsh import mysqlx # Direct connect with no client-side default schema specified mySession = mysqlx.get_session('user:password@localhost') mySession.set_current_schema("test")
Java Code
Press CTRL+C to copy/* Connector/J does not support the setCurrentSchema() method. One can specify the default schema in the URI-like connection string. */
C++ Code
Press CTRL+C to copy/* Connector/C++ does not support the setCurrentSchema() method. One can specify the default schema in the URI-like connection string. */
Notice that setCurrentSchema()
does not change
the session's default schema, which remains unchanged throughout
the session, or remains null
if not set at
connection. The schema set by
setCurrentSchema()
can be returned by the
getCurrentSchema()
method.
An alternative way to set the current schema is to use the
Session
class
sql() method and the
USE
statement.
db_name