05 / 06

How to list databases on our mysql instance?

Difficulty: 2/10
SHOW DATABASES, information_schema, privilege handling

To display the list of all databases present in a MySQL server, we need to use the SHOW DATABASES statement. It returns the result in a tabular form with one column. The databases in the result set will be sorted in alphabetical order.

Query:

Scenario Questions

0-2 years experience

  1. 1We have a new dev box and need to verify which databases exist on the MySQL server. How would you list them using the command line?
  2. 2If you run `SHOW DATABASES;` and only see `information_schema` and `performance_schema`, what might be the cause?

2-5 years experience

  1. 1Our application needs to display all tenant databases at startup, but some users only have read‑only access. How would you implement a reliable way to list databases while respecting privileges?
  2. 2During a deployment you notice that `SHOW DATABASES;` returns an empty set for a service account that previously could see many schemas. Walk me through how you would debug this issue.

5-8 years experience

  1. 1We are moving to a multi‑region MySQL cluster with hundreds of databases per region. What design considerations would you make for efficiently enumerating databases across nodes without overloading the master?
  2. 2Explain how you would enforce that a service can only see databases that belong to its own tenant, both at the MySQL privilege level and in application code.

8+ years experience

  1. 1Our organization is consolidating dozens of legacy MySQL instances into a single sharded platform. How would you design a service that safely lists databases across all shards while handling version differences and ensuring security compliance?
  2. 2Discuss the long‑term maintenance implications of using `SHOW DATABASES` versus querying `information_schema` in a large, automated provisioning pipeline.

Follow-up Questions

  • What would you see if the user connecting doesn't have the SHOW DATABASES privilege?
  • How would you retrieve the list of databases from a Python script using a MySQL driver?
  • If you needed to hide certain schemas from a user, what MySQL privilege changes would you make?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.