To select a database in MySQL, we use the SQL USE statement. Once a specific database is selected, we can perform different operations such as creating tables, adding data, updating, and deleting information. Every operation we perform after selecting a database will be stored in that particular database.
We have a MySQL server with several databases. How would you write a script to connect and run a query against the 'analytics' database?
If you run SELECT DATABASE(); after connecting, what will it return if you haven't selected a database?
What command would you use to switch from the 'test' database to the 'production' database in a MySQL session?
Our new feature needs to write logs to a dedicated 'logs' database, but the existing codebase always connects to the default schema. How would you modify the connection logic, and what pitfalls would you watch for?
During a deployment we saw errors like 'Unknown database "metrics"' after adding a new DB. Walk me through how you'd debug why the application couldn't see the new database.
We want to run a migration that creates tables in a specific database without affecting others. Which MySQL options or statements would you use, and why?
We are building a multi‑tenant SaaS where each tenant gets its own MySQL database on a shared instance. How would you design the connection handling to reliably select the correct database per request, considering connection pooling and failover?
Our read replica lag is causing occasional 'Database not selected' errors when the app switches databases mid‑transaction. How would you address this at the system level?
If we need to enforce that certain users can only access a specific database, what MySQL privileges and architecture would you put in place to prevent accidental cross‑database queries?
We plan to migrate from a monolithic MySQL instance with many databases to a sharded architecture where each shard hosts a subset of databases. What high‑level strategy would you propose for routing traffic to the correct database, handling schema changes, and minimizing downtime across teams?
Our organization wants to standardize how services specify the target database in connection strings to avoid hard‑coded USE statements. How would you design a cross‑team convention and tooling to enforce this, and what migration path would you suggest?