USE
Sets the default database for subsequent operations. SQL statements run against this database unless you explicitly qualify a table with a different database name.
PolarDB-X 1.0 allows you to connect to different databases deployed in the same PolarDB-X 1.0 instance. This is similar to cross-database queries on standalone MySQL databases. When you log on to a PolarDB-X 1.0 instance, use DB_NAME to configure the default database. You can execute the USE statement to switch between databases, which helps you manage multiple databases at a time.
Prerequisites
Before you begin, ensure that you have:
A PolarDB-X 1.0 instance with at least one database
The required permissions on the target database — grant permissions in the console (Manage accounts and permissions)
Syntax
USE db_nameSwitch the default database
Run USE with the target database name:
USE NEW_DBAll subsequent statements run against NEW_DB until you switch again.
How it works
The following example shows how the default database changes with each USE call:
USE db1;
SELECT COUNT(*) FROM orders; -- runs against db1.orders
USE db2;
SELECT COUNT(*) FROM orders; -- runs against db2.ordersUsage notes
After switching databases, hints and sequences in your SQL statements take effect on the new default database. This applies when no database is specified in the hints or sequences.