How to Record WordPress SQL Database Queries & Restore Them on Another Site (2025 Guide)

Bring your database changes with you, without touching phpMyAdmin manually.

Record WordPress SQL Database Queries scheme

TL;DR

  1. Install WP Staging SQL Recorder.
  2. Click Start Recording in Tools → SQL Recorder.
  3. Perform the changes you want copied.
  4. Click Stop Recording and download the .sql file.
  5. Import that file on the destination site via WP‑CLI or phpMyAdmin.

Purpose: Perfect for staging → production deployments, debugging, or cloning a site while keeping content edits in sync.


Why Record SQL Queries?

  • Granular migrations – Move only the changes you just made, not a full DB dump.
  • Audit trail – See exactly what SQL runs when a plugin or theme saves data.
  • Debugging – Re‑produce tricky bugs on a dev site by replaying the queries.

Prerequisites

  • WordPress 5.8+ (tested up to 6.8.2).
  • Admin access on both the source and target sites.
  • The free WP Staging SQL Recorder plugin (download link below).
  • Basic database import permissions (WP‑CLI or phpMyAdmin).

Step‑by‑Step Guide

1. Install & Activate the Plugin

  1. 🚀 Download wp-sql-recorder.zip from github.
  2. Go to Plugins → Add New → Upload Plugin.
  3. Upload the ZIP, click Install Now, then Activate.

2. Start Recording

  • Navigate to Tools → SQL Recorder.
  • Hit Start Recording.
  • A green banner confirms that recording is active and shows the filename, e.g. wp-sql-20250716-153045.sql.
Start Recording
Stop SQL Recording

3. Perform Your Changes

Anything that triggers INSERT, UPDATE, DELETE, CREATE, or ALTER statements is captured. Examples:

  • Publishing new posts or pages.
  • Installing a theme that creates custom tables.
  • Running a plugin’s data migration wizard.

⚠️ SELECT queries are skipped to keep the dump import‑safe and compact.

4. Stop & Download the File

  1. Return to Tools → SQL Recorder.
  2. Click Stop Recording.
  3. A button appears to Download SQL file.

The file lives temporarily in /wp-content/uploads/sql-recordings/—handy for scripting.

5. Transfer the SQL File to Your Destination Server

# Example via scp
scp wp-sql-20250716-153045.sql user@prod:/var/www/html/

6. Import on the Target Site

wp db import wp-sql-20250716-153045.sql

WP‑CLI automatically uses the credentials in wp-config.php.

B. Using phpMyAdmin / Adminer

  1. Open the site’s database in phpMyAdmin.
  2. Click Import, choose the file, and start.

Prefix mismatch? If your target site uses a different table prefix (wp_wp7_), run a quick search‑and‑replace before importing:

sed -i 's/`wp_/`wp7_/g' wp-sql-*.sql

Automating the Workflow

Need to deploy nightly? Pair WP SQL Recorder with a cron‑driven WP‑CLI script:

wp option update wpsr_recording 1                 # start
sleep 3600                                        # ...one hour of edits
wp option update wpsr_recording 0                 # stop
FILE=$(wp option get wpsr_current_file)
wp db export "$FILE"                              # optional safety copy
rsync -avz "$FILE" prod:/var/www/html/sql/
ssh prod "wp --path=/var/www/html db import sql/$(basename $FILE)"

Troubleshooting

SymptomFix
File won’t downloadEnsure uploads/sql-recordings/ is writable (permissions 755).
Import fails with foreign‑key errorsImport during low traffic or disable FK checks: SET FOREIGN_KEY_CHECKS=0; before the dump.
Nothing is recordedConfirm recording is ON and you performed actions that write to the DB.

Frequently Asked Questions

Does it slow down my site?

Minimal. Each write query is appended to a file with LOCK_EX. On high‑write sites, consider enabling it only during deployment windows.

Can I filter specific tables?

Not yet, but it’s on our roadmap. Star the repo to get updates!

Is the dump compatible with MariaDB?

Yes—queries are captured exactly as MySQL/MariaDB receives them.


Next Steps & Call to Action

  • Download WP SQL Recorder → Plugin Page ›
  • Subscribe to our newsletter for more WordPress dev tips.
  • Share this article! It helps other developers and boosts our content reach.

Did this guide save you time? Tweet us your success story with #WP Staging SQLRecorder.