Is it possible to prepend some text to all tables when exporting a mysql dump.
For example: if the table is named chapters
I want to prepend old_
to it so it becomes old_chapters
Depending on the complexity of your schema, you may be able to accomplish this with a carefully crafted sed
command that finds all of the table references and prepends the table names with "old_".
For example, this command will dump your schema and data and add the old_ prefix to the drop/create table statements as well as the lock/alter table and insert statements:
mysqldump your_schema | sed -e 's/DROP TABLE IF EXISTS `/DROP TABLE IF EXISTS `old_/' -e 's/CREATE TABLE `/CREATE TABLE `old_/' -e 's/INSERT INTO `/INSERT INTO `old_/' -e 's/LOCK TABLES `/LOCK TABLES `old_/' -e 's/ALTER TABLE `/ALTER TABLE `old_/'
However, that command will not add the table prefix for any of the following types of table references: