Skip to content

Hacked WordPress Database Cleanup

If clean files have not fixed your site, the infection is probably stored in the database. We find injected scripts, spam content, changed settings and rogue accounts across every table and remove them carefully, so your content and settings stay intact.

Backup before every change Clear upfront pricing WhatsApp support No lock-in contract
What's Included

What We Cover

Every engagement includes the items below. If your situation needs something different, we discuss it before we start — no surprises.

Exporting a full database backup and cleaning on a tested working copy first
Searching every table, including plugin and custom tables, for scripts, iframes, encoded strings and spam domains
Removing injected code from post content, revisions, comments and post meta
Restoring changed site address values and removing unknown entries from active plugins
Cleaning widget, theme customiser and header or footer script settings
Editing serialized data with tools that keep it readable, never with a plain text replace
Removing rogue administrators, reversing raised capabilities and revoking unused application passwords
Deleting malicious scheduled tasks stored in WordPress's cron entry
Changing the database user's password and updating the site configuration to match

Who Is This For?

  • Owners whose site still shows spam or pop-ups after the files were replaced
  • Sites where code keeps reappearing in posts after being removed
  • Businesses with unknown administrators or accounts with raised permissions
  • Sites whose address settings were changed so the whole site points elsewhere
  • Developers who need a careful database clean on a site with heavy serialized settings
A padlock resting on a laptop keyboard
On this page

You replaced every WordPress file with a clean copy and the problem is still there. The spam link is still in the footer, the pop-up still appears, the site still sends some visitors elsewhere. When that happens, the infection is very likely sitting in the database, where no amount of file cleaning will reach it.

WordPress keeps almost everything that makes your site yours in its database: posts and pages, menus, widgets, theme settings, plugin settings, users and their permissions. Attackers know that. This page covers how we clean a compromised database without breaking the site, and it forms one part of our hacked website repair and emergency help.

Why attackers like the database

File-based malware is what most scanners and most cleanups focus on. The database gets less attention because it is harder to read: rows of content, settings stored in a compact format, and thousands of entries on a busy site. Code placed there survives a fresh install of WordPress, a theme reinstall and a plugin update, because none of those touch the stored data.

The database is also how many attacks happen in the first place. A plugin flaw that allows SQL injection or stored cross-site scripting lets an attacker write straight into your tables without ever uploading a file. Our explainer on SQL injection and XSS in plain language covers how those flaws work.

What we usually find, table by table

Table names below use the default wp_ prefix. Many sites use a different prefix, and the same tables exist under it.

Posts and pages (wp_posts)

Script tags appended to the end of post content, hidden iframes, invisible blocks of spam links, or whole spam posts saved as drafts or under unusual post types. Revisions matter here: WordPress keeps earlier versions of content, and an infected revision can be restored by accident later. Injected code is often added to every post at once by an automated script, so a single sample tells us what to search for across the table.

Settings (wp_options)

This is where a lot of the damage hides. Changed siteurl or home values can send the whole site to another domain. The active_plugins entry can list a plugin you never installed. Widget settings, theme customiser values and the “header and footer scripts” fields of various plugins can carry code that prints on every page. Malicious scheduled tasks are stored here too, inside WordPress’s cron entry.

Users and permissions (wp_users, wp_usermeta)

An extra administrator is the classic find. Less obvious is an ordinary-looking account whose capabilities in wp_usermeta have been raised to administrator, or a real account with an added application password. If you have already spotted an account you do not recognise, our post on unknown admin users in WordPress explains what to check before deleting it.

Post meta, comments and plugin tables

SEO plugin fields that hold titles and descriptions, page builder data stored as meta, comment content with hidden links, and custom tables created by forms, shops or page builders. Plugin tables are easy to forget because they do not follow WordPress’s usual layout.

Clues that the problem lives in your tables

You do not need to read SQL to suspect the database. A few patterns point there fairly reliably:

  • The same strange script or link appears in many posts, but only in content, not in the theme’s header or footer files.
  • The site address in Settings, General has changed, or the site suddenly loads from a different domain.
  • A widget area shows content you did not add, and the widget itself looks empty or harmless in the editor.
  • Searching the post editor’s code view reveals something the visual editor hides, such as an invisible block at the bottom of a page.
  • A security plugin flags posts or options by ID rather than by file name.

None of these prove the files are clean; they only show that the database is involved too. That distinction shapes the order we work in.

Why careless find-and-replace breaks sites

Much of WordPress’s stored data is serialized: a PHP format that records the length of every piece of text alongside the text itself. If you change a string inside that data and the recorded length no longer matches, PHP cannot read the entry any more. The visible result can be a widget that disappears, theme settings that reset, or a plugin that stops working.

So we never clean the database with a plain text replace in phpMyAdmin or a raw SQL UPDATE across serialized fields. We use tools that understand serialized data, such as WP-CLI’s search-replace, and for anything unusual we read the entry, rebuild it correctly and write it back. We also test each pattern on a copy of the database before applying it to the live one.

How we clean a hacked database

Back up and copy

Before any change, we export the full database and keep it. A second copy becomes our working database, where search patterns are tried and checked. Nothing is run against the live site until it has been tested there.

Map the infection

We search every table, not just the WordPress ones, for script tags, iframes, encoded strings, suspicious domains, hidden styling around links and known malware markers. The aim is a list of every affected row and what was injected, which also tells us whether one attack or several are involved.

Remove the injected content

Injected code is removed from posts, options, meta and plugin tables, with serialized entries handled correctly. Spam posts and spam revisions are deleted. Settings such as the site address are put back to their real values.

Fix accounts

Rogue administrators are removed after we have recorded their details, raised capabilities are put back, application passwords you do not use are revoked and passwords are reset for remaining administrators. The database user’s own password is also changed at the hosting level, and the site’s configuration updated to match.

Check from the outside

We load pages as a new visitor, on mobile and desktop, and from a search result, because some injected scripts only show in those conditions. If the database was carrying a redirect, the checks follow what our redirect hack removal page describes.

The database is rarely the whole story

Database injections usually come with file-based access too. An attacker who could write to your tables may also have left a script on the server that writes them again. That is why a database cleanup on its own is not a complete job. We pair it with the file search set out on our WordPress backdoor removal page, and where the injected content is mostly search spam, with the work on our SEO spam cleanup page.

What you can safely do now

  • Export a database backup from your hosting panel and keep it somewhere off the server, even though it is infected. It is a record of the state of things.
  • Do not run find-and-replace queries on the live database yourself, even if a forum post suggests one.
  • Do not delete unknown user accounts yet. Note their username, email and creation date first.
  • If posts you edit keep getting code added back, stop editing for now. Something is still writing to the database.
  • Change your hosting panel and WordPress administrator passwords from a device you trust.

Cleaning is not the same as optimising

Some owners ask whether a database “clean-up” plugin will remove the infection. Those plugins remove old revisions, expired temporary data and leftover tables, which is useful for speed and size, as our post on WordPress database optimisation explains. They are not designed to find injected code, and some will happily keep it.

If you think your database has been tampered with, start a WhatsApp message to us with the word HACKED and include your domain and what you are seeing. We will look, give you an honest view of what is going on and when we can start, back up before touching anything, and keep you updated on WhatsApp. The database work fits within the full cleanup described on our WordPress malware removal service page.

Common Problems

Problems We Fix

If what is happening to your website is on this list, we have fixed it before. If it is not, tell us anyway — the list is the common ones, not the only ones.

Clean files, same symptoms

Malware stored in tables survives a fresh install of WordPress, themes and plugins.

Every post was touched

Automated injections add the same code to hundreds of posts and revisions at once.

Settings carry the code

Widgets, theme options and script fields can print malware on every page.

A find-and-replace broke the site

Changing serialized data without fixing its stored lengths makes settings unreadable.

An ordinary account became admin

Raised capabilities in user meta are easy to miss in the Users screen.

How It Works

Our Process

A straightforward process so you always know what is happening and what comes next.

  1. Step 1 of 6

    Export the live database and build a working copy for testing every change

  2. Step 2 of 6

    Map each affected row across all tables and identify the injection patterns

  3. Step 3 of 6

    Remove injected content and spam posts, rebuilding serialized entries correctly

  4. Step 4 of 6

    Restore site address and plugin settings, and clear malicious scheduled tasks

  5. Step 5 of 6

    Fix accounts, reset admin passwords and change the database user's password

  6. Step 6 of 6

    Load pages as a new visitor on mobile, desktop and from search to confirm nothing remains

FAQ

Hacked Database Cleanup — Common Questions

Questions people ask about hacked database cleanup.

A strong clue is that symptoms remain after core, theme and plugin files are replaced with clean copies. We confirm it by searching the tables directly.

It is risky. A plain text replace across serialized settings can break widgets, theme options and plugins, so test on a copy if you try it.

No. Optimisation tools remove old revisions and temporary data; they are not built to find injected code.

No. We remove only the injected material and rogue entries, test every change on a copy first, and keep a full backup of the original.

Something is still writing to the database, usually a backdoor on the server or a scheduled task. Our backdoor removal work looks for exactly that.

Plugin flaws such as SQL injection or stored cross-site scripting let attackers write directly into tables, and a stolen admin login lets them do it through the dashboard.

Still have a question? We are happy to help.

Ask Us Directly

We do not guarantee sales, leads, or Google rankings. We help improve the technical setup, user experience, reliability, and clarity of your website so your marketing has a stronger base.

Ready to Get Started?

Your Website Deserves Proper Care

Get a free, no-pressure website health check. We'll tell you exactly what needs attention and what it will cost — before you commit to anything.

No hidden fees Backup before every change Clear communication in Hindi or English India-based team