Database Names

How to extract database names from MySQL

Database Names

Extracting database names is often a crucial step in SQL injection attacks, as it helps to identify potential targets for further exploitation.

InformationQuery
Tablesinformation_schema.schemata, mysql.db
Columnsschema_name, db
Current DBdatabase(), schema()

Examples

-- Get current database name
SELECT database();

-- List all databases on the server
SELECT schema_name FROM information_schema.schemata;

-- Alternative method (requires privileges)
SELECT DISTINCT(db) FROM mysql.db;

The information_schema database is available from MySQL version 5 and higher, and provides metadata about all databases on the server. Access to the mysql.db table typically requires elevated privileges.

Back to Knowledge Base