Truy vấn information_schema.schemata để lấy danh sách database.
Truy vấn cơ bản
mysql> SELECT schema_name FROM information_schema.schemata; +--------------------+ | schema_name | +--------------------+ | information_schema | | gaurav | | mysql | | performance_schema | | query | | query1 | | sys | | tutorials | +--------------------+
Có điều kiện WHERE
mysql> SELECT schema_name FROM information_schema.schemata WHERE schema_name LIKE '%schema' OR schema_name LIKE '%s'; +--------------------+ | schema_name | +--------------------+ | information_schema | | performance_schema | | sys | | tutorials | +--------------------+
Lưu ý: Cách này linh hoạt hơn SHOW DATABASES vì có thể lọc, join, sắp xếp bằng SQL chuẩn.