How to Clean a Hacked WordPress Database

7 Oct 20266 min read
Sefat Hossain, WordPress security specialist
By Sefat Hossain
Share
How to Clean a Hacked WordPress Database

Quick answer

To clean a hacked WordPress database: back it up first, then search wp_options, wp_posts, and wp_users for injected scripts, spam links, and unknown admin accounts. Remove malicious entries, delete rogue users, check for suspicious scheduled tasks, and change all passwords. Always pair database cleaning with a file cleanup — malware usually lives in both.

Key takeaways

  • File-only cleanups miss malware that lives in the database.
  • Common hiding spots are wp_options, post content, and the users table.
  • Back up the database before editing, and never guess — remove only confirmed malicious entries.

When people think about a hacked WordPress site, they picture infected files. But the database is just as common a hiding place — and a file-only cleanup will leave the infection alive. Here's how to clean it safely.

Back up before you touch anything

Export the full database first. A wrong edit can break your site, and you'll want a restore point.

Where malware hides in the database

  • wp_options — injected scripts, redirect code, or malicious settings
  • wp_posts — spam links or hidden content inside posts and pages
  • wp_users / wp_usermeta — rogue admin accounts and elevated privileges

Remove the malicious entries

Search for suspicious code (obfuscated scripts, unfamiliar URLs, base64 strings) and remove only what you've confirmed is malicious. Delete unknown admin users and reset the passwords of the rest.

Check scheduled tasks

Look at WordPress cron events for suspicious jobs that could be re-injecting malware or spam on a schedule.

Pair it with a file cleanup

The database is half the job. Clean the files too, close the entry point, and change all credentials. Then re-scan to confirm nothing reappears.

Free security check

Worried your site is infected?

Get a free security assessment — I'll tell you if your WordPress site is compromised and exactly what it needs. No obligation.

Follow-up questions

People also ask

Yes. Injected JavaScript, spam links, redirect code, and rogue admin users all commonly live in the database, not just in files.

Worried about your own site?