mysql - How do I programmatically rename all tables in a database and prepend/append some text to the names of all of them? -


i have mysql database of tables similar to:

users tests billing 

and looking sql query cycles through tables in database , appends application_ name, resulting in:

application_users application_tests application_billing 

depending on operating system using, have considered writing shell script pipes output of "show tables" command through sed generate script file appropriate alter table commands?

amrith@amrith-vbox:~/so$ more showtables.sql show tables amrith@amrith-vbox:~/so$ mysql -uroot -ppassword -n test < showtables.sql | awk '{ print "alter table " $1 " rename abc_"$1 }' alter table conversations rename abc_conversations alter table foo rename abc_foo alter table messages rename abc_messages alter table t1 rename abc_t1 amrith@amrith-vbox:~/so$ 

you can send output .sql file , execute using mysql?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -