Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqldump table names prefix

Tags:

database

mysql

I have two mysql databases that have almost the same structure and representing the data of the same web app but one of them represents the current version and second one was made long time ago.

How can I create the database with both dumps inside but with old_ prefix for tables from the first and new_ prefix for tables from the second database?

Is there any mysqldump options to setup the prefix or other solution?

like image 480
Bogdan Gusiev Avatar asked Oct 20 '25 23:10

Bogdan Gusiev


1 Answers

A "mysqldump file" is just a text file full of SQL statements, so you can make quick modifications like these in a text editor.

1) Dump the two databases individually.

2) Edit the "old" dump file:

  • add the correct use mydatabase; line
  • do a search and replace to add old_ in front of the table names.

3) Then, cat dump1 dump2 > combined_dump

4) mysql < combined_dump

like image 92
Seth Avatar answered Oct 23 '25 13:10

Seth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!