0

I have a database which is poorly documented and I am attempting to understand what is in each of the 50 tables located in the database. I want to just see the first few rows to get an idea of this.

For a single table I could type SELECT * FROM TABLENAME1 LIMIT 10 and it works, but I am loathe to type this 50 times. Is there a way from the command line I can get output for all tables? Could I store this output somewhere?

I found this which uses the sp_MSforeachtable command to accomplish this (sp_MSforeachtable @command1="select count(*) from ?";) but that gave me the following error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sp_MSforeachtable @command1="select count(*) from ?"' at line 1

(I'm using MySQL 5.5 on an Ubuntu 18.04 server).

Brandon
  • 1,722
  • 1
  • 19
  • 32
  • 2
    The question you linked to is for SQL-server, not MySQL. – Barmar Jul 25 '22 at 19:07
  • 2
    There's nothing built-in that does this. You can write a stored procedure that loops over the table names in `INFORMATION_SCHEMA.TABLES` – Barmar Jul 25 '22 at 19:09

1 Answers1

1

You can also use a little sh script like this:

mysql -uroot -pYOURPW -Dbernd -N -e'SHOW TABLES' |
while read t
do
 echo;
 echo $t;
 echo;
 mysql -uroot pYOURPW -Dbernd  -e"SELECT * FROM $t LIMIT 10";
done
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39