WordPress Security ServicesMalware Removal
Hardening

How to Secure Your WordPress Database: Practical Steps That Matter

Your WordPress database holds everything: posts, settings, user accounts and password hashes. It's also where a lot of modern malware hides. Securing it isn't complicated, but a few common mistakes, like a database backup left in a public folder, can undo everything else.

Sergey By Sergey, WordPress security specialist Updated 2 min read
In this guide
  1. 1. Use strong credentials and one database user per site
  2. 2. Don’t give the WordPress user more rights than it needs
  3. 3. Keep the database private
  4. 4. Never leave backups in public folders
  5. 5. Protect wp-config.php
  6. 6. Watch for malware in the database
  7. 7. Back up regularly, and test a restore

1. Use strong credentials and one database user per site

  • Give the database user a long, random password.
  • Use a separate database and user for each site, so one compromised site can’t read the others.
  • Don’t reuse the database password anywhere else.

2. Don’t give the WordPress user more rights than it needs

WordPress needs to read, write and change tables (for updates). It doesn’t need server-wide rights or access to other databases. On shared hosting your host handles this. On a VPS, don’t connect WordPress as root.

3. Keep the database private

  • Most hosts only allow database connections from the server itself. Keep it that way, and don’t open the database port to the internet.
  • Protect phpMyAdmin and similar tools: use your host’s control panel login, and don’t install standalone database tools in your website folder.
  • Remove tools like Adminer if someone uploaded them for a one-off task and left them behind.

4. Never leave backups in public folders

The most common real-world database leak isn’t a hack. It’s a .sql export or a backup zip left in the website folder or in uploads, where anyone can download it. Store backups off-site, and make sure directory listing is off.

5. Protect wp-config.php

It contains your database credentials. Set strict file permissions (often 640 or 600, depending on your host), and make sure it can’t be downloaded. On Apache, add to your root .htaccess:

<Files "wp-config.php">
  Require all denied
</Files>

6. Watch for malware in the database

Modern malware often stores its code in the database, especially in wp_options, so that it survives a file cleanup. Check now and then for unknown administrators and scripts in posts and options. My database malware page has safe, read-only queries to do it.

7. Back up regularly, and test a restore

Daily off-site backups with several weeks of history, and at least one test restore so you know it works.

From my cleanup work: the database is where cleanups most often fall short. The files get cleaned, but a few kilobytes of encoded code in wp_options stay behind and rewrite the malware on the next page load. Securing the database isn’t just about keeping attackers out. It’s also about knowing what’s inside.

Sergey, WordPress Security Specialist
About the author
Sergey, WordPress Security Specialist

10 years in WordPress security and incident investigation, and more than 200 websites cleaned of malware. Top Rated on Upwork with a 100% Job Success score. More about me

Frequently Asked Questions

Does changing the table prefix from wp_ make my site secure?

It's a small obstacle for some automated attacks, and it doesn't hurt on new sites. But it doesn't fix the vulnerabilities attackers use, and changing it on an existing site can break things. It's not worth the risk on a live site.

Can hackers reach my database directly?

On most hosts the database only accepts connections from the server itself, which is good. Attackers usually reach it through WordPress: a vulnerable plugin, or by reading the credentials in wp-config.php after getting onto the server.

What should I do if my database credentials were exposed?

Change the database password in your hosting panel, update DB_PASSWORD in wp-config.php, and check the database for injected code and unknown admin users.

Need a hand?

Let me clean your WordPress site for you

Send me your site URL and what you're seeing. I'll reply with what I think is going on and the next step.

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

Get My Site Cleaned →