Article 59NBB Bash script to automate some Sql commands

Bash script to automate some Sql commands

by
bmxakias
from LinuxQuestions.org on (#59NBB)
Hello

I am using this command:

Code:mysql -N -e "SELECT TABLE_SCHEMA, TABLE_NAME, ENGINE, ROW_FORMAT FROM INFORMATION_SCHEMA.TABLES WHERE ENGINE = 'InnoDB' AND ROW_FORMAT = 'Compact' AND TABLE_SCHEMA != 'mysql';" | while read d t e r; do echo "ALTER TABLE $d.$t ROW_FORMAT=DYNAMIC;"; doneand i am getting something like:

Code:ALTER TABLE designhdbf.core_voters ROW_FORMAT=DYNAMIC;
ALTER TABLE designhdbf.core_validating ROW_FORMAT=DYNAMIC;
ALTER TABLE designhdbf.feedback_feedback ROW_FORMAT=DYNAMIC;
ALTER TABLE designhdbf.core_sitemap ROW_FORMAT=DYNAMIC;
ALTER TABLE designhdbf.core_seo_meta ROW_FORMAT=DYNAMIC;
If i copy a few of that lines and paste them at once it works but if i copy around 30 of them the last commands may fail....

So i am looking for a way to save them at a file (is that the best way to do it?) that i know how to do it by using > /file.log and then read and run one by one the commands like:

Code:mysql -e "ALTER TABLE designhdbf.core_voters ROW_FORMAT=DYNAMIC;"and then:

Code:mysql -e "ALTER TABLE designhdbf.core_validating ROW_FORMAT=DYNAMIC;"e.t.c

Is it possible to execute the command after only after the previous command finishes?

How can i do that on a bash script?

Thank youlatest?d=yIl2AUoC8zA latest?i=f8jXsMBDBx4:pzu24XsHv54:F7zBnMy latest?i=f8jXsMBDBx4:pzu24XsHv54:V_sGLiP latest?d=qj6IDK7rITs latest?i=f8jXsMBDBx4:pzu24XsHv54:gIN9vFwf8jXsMBDBx4
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments