X DevAPI 用户指南 / 第 2 章连接和会话概念 /
2.5 设置当前模式
在打开连接会话时,可以使用类似 URI 的连接字符串或键值对schema
中的属性
指定会话的默认模式
。类方法返回.
Session
getDefaultSchema()
Session
如果在连接时没有选择默认模式,则
Session
类
setCurrentSchema()
函数可用于设置当前模式。
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")
请注意,setCurrentSchema()
这不会更改会话的默认架构,该架构在整个会话期间保持不变,或者null
如果未在连接时设置则保持不变。设置的模式
setCurrentSchema()
可以通过该
getCurrentSchema()
方法返回。