Fix serialized data broken due to editing MySQL database in a text editor?

后端 未结 6 613
青春惊慌失措
青春惊慌失措 2020-12-30 02:25

Background: I downloaded a *.sql backup of my WordPress site\'s database, and replaced all instances of the old database table prefix with a new on

6条回答
  •  执念已碎
    2020-12-30 03:26

    This script (https://interconnectit.com/products/search-and-replace-for-wordpress-databases/) can help to update an sql database with proper URLs everywhere, without encountering serialized data issues, because it will update the "characters count" that could throw your URLs out of sync whenever serialized data occurs.

    The steps would be:

    1. if you already have imported a messed up database (widgets not working, theme options not there, etc), just drop that database using PhpMyAdmin. That is, remove everything on it. Then export and have at hand an un-edited dump of the old database.

    2. Now you have to import the (un-edited) old database into the newly created one. You can do this via an import, or copying over the db from PhpMyAdmin. Notice that so far, we haven't done any search and replace yet; we just have an old database content and structure into a new database with its own user and password. Your site will be probably unaccessible at this point.

    3. Make sure you have your WordPress files freshly uploaded to the proper folder on the server, and edit your wp-config.php to make it connect with the new database.
    4. Upload the script into a "secret" folder - just for security reasons - at the same level than wp-admin, wp-content, and wp-includes. Do not forget to remove it all once the search and replace have taken place, because you risk to offer your DB details open to the whole internet.
    5. Now point your browser to the secret folder, and use the script's fine interface. It is very self-explanatory. Once used, we proceed to completely remove it from the server.

    This should have your database properly updated, without any serialized data issues around: the new URL will be set everywhere, and serialized data characters counts will be accordingly updated.

    Widgets will be passed over, and theme settings as well - two of the typical places that use serialized data in WordPress.

    Done and tested solution!

提交回复
热议问题