Do you need to switch the data between two MySQL databases? Before today I did not think I would every need to, but let’s just say that something happened that needed me to think outside the box. And do it quickly.
That is when the idea came to me. Use the Shell game trick to accomplish this task. And the surprising thing was it was really easy to do. I am going to show you a way to do it without any stress. All queries you are found in this GitHub repo.
First, you need two databases, blog_production and blog_test.
You will also need to population both databases with sample data.
From the queries on GitHub, you will notice that the data in both tables are different. Next, we want to switch the data, and at the same time not lose any of it.
Here is where our shell game ideas comes in.
Create a fix database. Let us call it blog_fix.
Next make blog_production empty, so that we can copy data from blog_production to blog_fix.
Next, we copy the data from test to production – now test is empty. Next we copy the data from blog_fix to blog_test.
Lastly we drop the fix database since we do not need it anymore. Problem solved.
Just save or bookmark this post, because you just might need it someday.
Take care, keep learning and cheers.

Leave a comment