Skip to content

Instantly share code, notes, and snippets.

@luclemo
Last active February 25, 2017 19:25
Show Gist options
  • Save luclemo/e54f35ad2ca918508d04cd8d8c5d0007 to your computer and use it in GitHub Desktop.
Save luclemo/e54f35ad2ca918508d04cd8d8c5d0007 to your computer and use it in GitHub Desktop.
Manually sync MySQL database between local and staging or live site #wordpress

Export the mysql database for your WordPress to an .sql file. Unzip it (if applicable) to a convenient place on your computer.

NOTE: If you're using phpMyAdmin to do this export (recommended), make sure that you do a "custom" export, scroll down to "Object creation options," and check these two boxes:

[x] Add CREATE DATABASE / USE statement
[x] Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT statement

Open your .sql file in your preferred text editor. Make the following four changes.

A) Find the line that starts "CREATE DATABASE IF NOT EXISTS" and change the database name given in that line to match the name of your repo. To keep things simple, I always make my Local and Live Databases named the same as each other, but that may not be desirable to you.

B) Find the line that starts "USE" (probably the very next line) and make the identical change as above.

C) Search for the first occurrence of 'siteurl' (which is part of an insert statement for the table `wp_options`). Here's where you'll find the first occurrence of the URL you'll want to run a "find & replace" on. If you're using Sublime text:
	1) Hit Shift + Command + F and paste in that URL
	2) Set the "where field to be "<current file>"
	3) Put the correct URL of the staging or live site into the "replace" field.
	4) Save and rename this new database as your staging/live version.

D) Import this database into your staging/live using PHPmyadmin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment