5.2. Database Enumeration

 

Every database management system (DBMS) contains specific data that can be useful for us during database hacking. Let's explore how to obtain this information using MySQL and PostgreSQL as examples.

 

Database Version

MySQL:

SELECT version(); or SELECT @@version;

Display of MySQL version

PostgreSQL:

SELECT version();

Display of PostgreSQL version

 

 

Current User

By "user," we mean the account currently being used to log into the database. This should not be confused with the user account of the operating system itself.

MySQL:

SELECT current_user();

Diplay of MySQL session user

PostgreSQL:

SELECT current_user;

How to get PostgreSQL session user

 

 

List of Available Databases

MySQL:

SELECT table_schema FROM information_schema.tables GROUP BY table_schema;

List of available databses in MySQL

PostgreSQL:

SELECT datname FROM pg_database;

List of available databases in PostgreSQL

 

 

List of Tables in a Specific Database

In MySQL, you can display the tables in any database by knowing the database's name, which you obtained in the previous step.

MySQL:

SELECT table_name FROM information_schema.tables WHERE table_schema='database_name';

List of tables in a specific database of MySQL

In PostgreSQL, you can only display tables in the current schema. Tables created by a user are marked with the "public" schema.

PostgreSQL:

SELECT table_name FROM information_schema.tables WHERE table_schema='public';

List of tables in a specific database in PostgreSQL

 

 

List of Columns and their data types

MySQL:

SELECT column_name, data_type FROM information_schema.columns WHERE table_schema='database_name' AND table_name='table_name';

List of table columns in MySQL

PostgreSQL:

SELECT column_name, data_type FROM information_schema.columns WHERE table_name='table_name';

List of table columns in PostgreSQL