WordPress Security ServicesMalware Removal
Database Malware Removal

Remove Malware From Your WordPress Database Without Breaking Your Site

You cleaned the files, the scanner says the site is clean, and the malware is still there. That usually means it's stored in the database. I find injected scripts, spam and hidden admin accounts in your WordPress database and remove them carefully, without corrupting your content or settings.

$95 for one infected WordPress site

Includes a 1-month hassle-free guarantee. Multiple infected sites are priced separately. Guarantee terms

Sergey, WordPress security specialist
Top Rated 100% Job Success 10 years · 200+ sites cleaned
Signs of database malwareSYMPTOMS
  • Malware survives a file cleanup
    Files are clean, but the redirect or spam is still there.
  • Scripts in your page source
    Unknown <script> or <iframe> tags inside post content.
  • Admins you can't see
    Extra administrator accounts hidden from the Users screen.
  • Spam pages in Google
    Thousands of posts or pages you never wrote.

Why malware hides in the database

Most cleanups focus on files: replace WordPress core, reinstall plugins, run a scanner. Attackers know this. Code stored in the database survives all of those steps, and it’s often what puts the file malware back afterwards.

There’s also a practical reason. WordPress prints a lot of database content directly into your pages: post content, widgets, theme settings, and header and footer scripts. A single <script> tag saved in the right place appears on every page of your site without touching a single file.

Where malware hides in the WordPress database

Table What can hide there
wp_posts Scripts, iframes or hidden spam links added to post and page content; thousands of spam posts or pages
wp_options Scripts in widgets, theme settings and “insert header code” plugins; a changed siteurl or home (instant redirect); malicious scheduled tasks in the cron option
wp_users / wp_usermeta Administrator accounts the attacker created, sometimes hidden from the Users screen
wp_postmeta Code stored in page builder data or custom fields
wp_comments Spam links and scripts in comments
Plugin tables Anything a vulnerable plugin lets the attacker write

Your tables may use a different prefix than wp_. You can find it in wp-config.php ($table_prefix) or by running wp db prefix.

How to check your database for malware

These queries only read data, so they’re safe to run in phpMyAdmin’s SQL tab or with wp db query. Replace wp_ with your prefix.

-- Scripts and iframes in posts and pages
SELECT ID, post_title, post_type, post_status FROM wp_posts
WHERE post_content LIKE '%<script%' OR post_content LIKE '%<iframe%';

-- Suspicious code in options (widgets, theme settings, header scripts)
SELECT option_name, LENGTH(option_value) AS size FROM wp_options
WHERE option_value LIKE '%<script%' OR option_value LIKE '%eval(%'
   OR option_value LIKE '%base64_decode%' OR option_value LIKE '%fromCharCode%';

-- Site address (should be your own domain)
SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl', 'home');

-- Every administrator, with registration date
SELECT u.ID, u.user_login, u.user_email, u.user_registered FROM wp_users u
JOIN wp_usermeta m ON m.user_id = u.ID
WHERE m.meta_key = 'wp_capabilities' AND m.meta_value LIKE '%administrator%';

-- Sudden bursts of new posts (spam injections show up as spikes)
SELECT DATE(post_date) AS day, COUNT(*) AS posts FROM wp_posts
GROUP BY day ORDER BY posts DESC LIMIT 10;

Not every match is malware. Your analytics code, a chat widget or an embedded video will show up too. Look for scripts loading from domains you don’t recognize, long strings of encoded characters, or String.fromCharCode and eval, which legitimate content rarely needs.

If you’ve found strange entries in wp_options (huge values, random-looking option names, or anything containing base64 or eval), that’s usually the sign of a hacked wp_options table. It’s one of the most common places to clean an infected database, and one of the easiest to break if you edit it carelessly.

Why you shouldn’t just “find and replace” in phpMyAdmin

WordPress stores many settings as serialized data. That’s a format that records the length of every piece of text, like s:24:"...". If you remove a script from inside a serialized value with a plain SQL REPLACE, the recorded length no longer matches. WordPress then can’t read the value at all, and your widgets, theme settings or page builder layouts quietly disappear.

The safe ways to remove database malware are:

  • Edit the affected post or widget in the WordPress dashboard, where possible.
  • Use wp search-replace, which handles serialized data correctly. Run it with --dry-run first.
  • Delete whole malicious records (spam posts, fake admins) instead of editing inside them.

Always export the database before changing anything: wp db export before-cleanup.sql.

How I clean a WordPress database

  1. Back up the full database before any change.
  2. Search every table, not just posts: options, user capabilities, postmeta, comments, and plugin tables.
  3. Separate legitimate from malicious. Your real tracking codes and embeds stay; the injected code goes.
  4. Remove safely, using serialization-aware tools or by deleting whole malicious records.
  5. Clean the source, too. Database malware is usually put there by a backdoor in the files, so the files get the full cleanup as well.
  6. Rotate the database password and security keys, then verify the site and give you a report.

A typical case: a blog owner cleaned the files twice with a security plugin, but visitors kept seeing a fake “click Allow to continue” page. All the files checked out clean. The database told a different story: the same 300-character script had been appended to the end of over a thousand posts, plus a copy in a text widget. A small backdoor in the uploads folder re-added it whenever it was removed. Removing the script from every post with a dry-run-tested wp search-replace, deleting the widget code and the backdoor, and updating the vulnerable form plugin fixed it in one go, without losing a single post.

Database malware is usually part of a bigger infection

It’s rare for an infection to live only in the database. Something wrote it there, and that something is usually still on the server. If you’d like to tackle it yourself, follow my step-by-step WordPress malware removal guide. If you’d rather have it done properly the first time, see the full malware removal service.

Common Questions

Database Malware FAQ

Can malware really live in the WordPress database?

Yes, and it's common. WordPress stores your content, widgets, theme settings and users in the database, and all of those can hold a script or a spam link. Since most scanners focus on files, database malware often survives a cleanup that looked complete.

Will cleaning the database delete my posts or settings?

No. I back up the database first and only remove the injected code or the malicious records, not the posts, pages or settings around them. Where a legitimate setting was modified, I restore its original value.

Can't I just restore an older database backup?

Only if the backup is from before the infection, and then you lose every order, comment and change since. Infections often start weeks before anyone notices, so the "clean" backup may already be infected. Cleaning the current database is usually safer and keeps your recent data.

Should I change my database password?

Yes, after the cleanup. If the attacker could read wp-config.php, they know your database password. Change it in your hosting panel, then update DB_PASSWORD in wp-config.php so the site keeps working.

Is there a WordPress database malware scanner?

Some security plugins check parts of the database, mostly post content and comments for known bad links. Few look thoroughly at options, widgets, user capabilities or custom tables. A targeted manual check with SQL queries, like the ones on this page, still finds what scanners skip.

Clean it safely

Malware still there after a file cleanup?

Send me your site URL and what you're still seeing. I'll check the database and the places scanners skip.

$95 per infected site · 1-month guarantee · direct contact with the specialist

Request Malware Removal →