The Lucid Developer

Wednesday, March 19, 2008

Been a while (Mysqldump Replace into vs Insert into)

It has been a while since I have posted. I believe you are going to see more then you have in the past. One reason is that I want to start posting answers to some of my biggest problems I run into here at work with programming. For example today I needed to do a mysqldump to move data from my development environment to my production environment. The problem was I only needed to do an update not a drop and replace. So I did a bunch of research and here is what I found.

If you use the linux command sed you can change all of your insert statements into replace statements like this..

mysqldump -u DATABASE_USER -p DATABASE_NAME |sed -e "s|INSERT INTO|REPLACE INTO|" > OUTPUTFILE.EXT

Labels: , , , , , , ,