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
Post a Comment