Skip to content

Instantly share code, notes, and snippets.

@bhubr
Created December 28, 2023 20:09
Show Gist options
  • Save bhubr/8e51b334ca26d2d1ea210a895c6ed2bd to your computer and use it in GitHub Desktop.
Save bhubr/8e51b334ca26d2d1ea210a895c6ed2bd to your computer and use it in GitHub Desktop.
Sanitize WordPress SQL dump

Sanitize WordPress SQL dump

You might run into errors while injecting a WP SQL dump into a local db (say your remote db is MySQL 5+ and your local one is MySQL 8).

In this case…

1. make a copy of the dump

cp orig-dump.sql sanitized-dump.sql

2. replace occurrences of DEFAULT '0000-00-00 00:00:00'

perl -pi -e "s/DEFAULT '0000-00-00 00:00:00'/DEFAULT CURRENT_TIMESTAMP/g" sanitized-dump.sql

3. replace occurrences of 0000-00-00 00:00:00 with valid dates

perl -pi -e "s/0000-00-00 00:00:00/2023-12-28 02:00:00/g" sanitized-dump.sql

You should be good to go (tested it on a 273Mb dump).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment