When you start a session in the SQL Console of Data Management Service (DMS), all SQL statements that you execute in that SQL Console tab run in the same session.
Background information
A session is the connection and interaction between a client and a database server. It includes operations such as establishing a connection and executing SQL statements.
Prerequisites
The database type is RDS for MySQL, PolarDB for MySQL, AnalyticDB for MySQL, OceanBase Database for MySQL, or RDS for PostgreSQL.
The instance supports Flexible Management or Stable Change.
Notes
The system terminates a session or transaction if you close the SQL Console tab, refresh the browser, or if the session is idle for more than 10 minutes. When a session is terminated, it is purged and the database connection is closed. To reconnect, you must create a new session.
Sessions in different SQL Console tabs for the same database are independent of each other.
Procedure
- Log on to the DMS console V5.0.
In the Database Instances list on the left, enter the name of your target database in the search box and click the search icon.
Double-click the name of the target database to open the SQL Console page.
Execute a
SETstatement to start a session.Enter a
SETstatement. For example:set @num = 10;NoteSession variables take effect only when you select Direct Execution. You cannot use session variables if you select Background Execution.
If the control mode of the instance is Stable Change, you cannot directly execute SET statements. You must enable Super SQL Mode. For more information, see Super SQL Mode.
After the
SETstatement, enter other SQL statements and click Execute.
Optional: Execute a
BEGIN;orSTART TRANSACTION;statement to start a transaction. This also starts a session and helps ensure data consistency and integrity.After you start a transaction, execute the following commands to commit or roll back the transaction:
Execute
COMMIT;to commit the transaction.Execute
ROLLBACK;to roll back and revoke the operations that have been executed in the transaction.