Documentation Home
X DevAPI User Guide for MySQL Shell in JavaScript Mode
Download this Manual
PDF (US Ltr) - 1.2Mb
PDF (A4) - 1.2Mb


2.5 Setting the Current Schema

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.

var mysqlx = require('mysqlx');

// Direct connect with no client-side default schema specified
var mySession = mysqlx.getSession('user:password@localhost');
mySession.setCurrentSchema("test");

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 db_name statement.