Using INFORMATION_SCHEMA instead of shell scripting

November 25, 2008
Author
Peter Zaitsev
Share this Post:

INFORMATION_SCHEMA, in particular by favorite TABLES table is not only helpful to understand tables you have on the system, but I have also found it to be very helpful as a scripting language for variety of database administration tasks. It can be more straightforward compared to using shell or Perl when the operation is database specific.

For example if you would like to MySQLDump only Innodb table in one file per database you can do the following:

As you can see we’re just getting the set of commands to run. How to make it easily runable ? Well just use INTO OUTFILE to create very simple shell script:

In other case I needed to restore Innodb tables from mysqldump because of corrupted Innodb tablespace – to do this I had to clean all .frm files which correspond to innodb tables (as well as ibdata1 and innodb log files). With shell you could so it by looking for .frm files which do not have corresponding .MYI files…. but this will also get all MEMORY tables which we want to leave in tact. Using similar approach we can do:

Do not get me wrong, this is far from replacement for shell in all cases but it is rather handy for some niche tasks, in particular which involve unix commands driven by MySQL meta data.

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved