Search code examples
mysqlsql-serverwordpresslocalhostmamp

How come doing a find/replace on sql dump and importing it gives error #2006?


I have the sql dump for a wordpress install that lives on a domain. I need to make some changes to the site so I have set up a localhost using MAMP.

If I import the sql dump "as-is" it imports without a problem. However I need to change all the URL's in the sql dump to point to localhost instead.

When I use Aptana to do a replace all on the sql file from http://example.com to http://localhost/example and try to import the modified file to mysql I get the error "#2006 - MySQL server has gone away"

What is the problem here? I have temporarily fixed by overriding my hosts file for example.com to point to my localhost but this is not a long term viable option.

I am aware this error usually occurs for files that are too large or the server not responding but I am always able to import the non-modified version of the sql. Also there are 9538 replaces being done so I cannot go through 1 by 1 to find the culprit.

Thank you


Solution

  • (Just realized that it doesn't relate DIRECTLY to your problem, but you still need this info if you are doing Search and Replace in your MySQL dump).

    Data in the WP database is serialized. You can't just search and replace.

    You can't just change the data without re-serializing it.

    There are scripts and services that allow you to do a proper Search and Replace.

    I usually use this tool (git repository here), and it works perfectly. There are also a couple plugins that work, and just discovered this service from a theme creation company that does the same thing.

    Good luck and happy wordpressing.