PDF (美國信紙) - 1.4Mb
PDF (A4) - 1.4Mb
可以使用在開啟連線工作階段時,在類似 URI 的連線字串或鍵值對中的 schema 屬性,為工作階段指定預設的 schema。Session 類別的 getDefaultSchema() 方法會傳回 Session 的預設 schema。
如果連線時沒有選取預設的 schema,可以使用 Session 類別的 setCurrentSchema() 函式來設定目前的 schema。
MySQL Shell JavaScript 程式碼
var 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 程式碼
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")
Node.js JavaScript 程式碼
/*
Connector/Node.js does not support the setCurrentSchema() method.
One can specify the default schema in the URI-like connection string.
*/
C# 程式碼
// 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 程式碼
# 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 程式碼
/*
Connector/J does not support the setCurrentSchema() method.
One can specify the default schema in the URI-like connection string.
*/
C++ 程式碼
/*
Connector/C++ does not support the setCurrentSchema() method.
One can specify the default schema in the URI-like connection string.
*/
請注意,setCurrentSchema() 不會變更工作階段的預設 schema,預設 schema 在整個工作階段中維持不變,或者如果在連線時未設定,則保持 null。可以使用 getCurrentSchema() 方法傳回 setCurrentSchema() 設定的 schema。
設定目前 schema 的另一種方法是使用 Session 類別的 sql() 方法和 USE 陳述式。db_name