Search code examples
mysqldatabasesample

What is the best way to see a sample of all your databases and tables in one query?


What is the best way to see a sample of all your databases and tables in one query?

For example: while (show databases) { foreach database_name (select * from table_name limit 2)};

[Test_DB] Test_DB.one

+---------------+--------------+
| ip            | tstamp       |
+---------------+--------------+
| 192.168.10.10 | 01/13/2013   |
| 192.168.10.11 | 01/14/2013   |
+---------------+--------------+

[Test_DB] Test_DB.two

+----------------+--------------+
| mac            | tstamp       |
+----------------+--------------+
| dead.beef.cake | 01/13/2013   |
| dead.beef.cake | 01/14/2013   |
+----------------+--------------+

Solution

  • For a quick list you can do this:

    SELECT TABLE_SCHEMA AS _db, TABLE_NAME AS _table FROM information_schema.tables
    

    You'll have to wrap something around that to do the SELECT * ... LIMIT 2 part.