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: , , , , , , ,

5 Comments:

  • Thank you. This was very helpful when I couldn't figure out why --replace was documented in mysqldump but didn't seem to be implemented.

    By Anonymous Anonymous, at 4:07 PM  

  • You are welcome. It is so hard to find this anywhere. I had to share it.

    By Blogger Lucid Developer, at 2:39 PM  

  • Man, you just saved my life. This thing was driving me nuts. I donĀ“t why they deprecate the option replace in mysqldump options.

    By Blogger Unknown, at 2:28 PM  

  • time saver command. i liked it.

    By Anonymous sree, at 10:56 AM  

  • When i try to execute this command it is overwritting but i want to update/add without losing existing database

    Please advice the correct update/add/insert command

    Elavarasan

    By Anonymous Anonymous, at 10:11 PM  

Post a Comment

<< Home