INFORMATION_SCHEMA provides access to database metadata. Metadata is data about the data, such as the name of a database or table, the data type of a column, or access privileges. Other terms sometimes used for this information are data dictionary and system catalog. INFORMATION_SCHEMA is the information database — the place that stores information about all the other databases that the MySQL server maintains. Inside INFORMATION_SCHEMA there are several read-only tables. They are actually views, not base tables, so there are no files associated with them.
How to retrieve all database names from INFORMATION_SCHEMA:
SELECT schema_name FROM INFORMATION_SCHEMA.schemata
After we get the database name, we can get all tables from that database:
SELECT table_name FROM INFORMATION_SCHEMA.tables where table_schema = 'the_database_name'
After we get all the table names from the database, we can retrieve all column names with their data types:
SELECT column_name, column_type FROM INFORMATION_SCHEMA.columns where table_schema = 'the_database_name' AND table_name = 'the_table_name'
Okay, that’s the basics of how to get some database information from the Information_Schema. There is still a lot of other information you can get from Information_Schema.
So if your website is vulnerable to SQL injection, an attacker can easily get your database schema using this technique. Please keep your system up to date and back up regularly.
