Security 5 min read

WordPress database security: protecting your data

How to secure the WordPress database: strong credentials, limited privileges, table prefixes, remote access, backups, encryption, SQL injection protection and monitoring.

Usman Muhammad UsmanUpdated October 13, 2026
WordPress database security: protecting your data

The WordPress database holds everything: posts, pages, settings, users, password hashes and, for stores, orders and customer details. If attackers can read or change it, they control the site. Most database attacks happen through vulnerable plugins rather than the database server itself, but there are several layers of protection worth putting in place. Here is how I secure databases on client sites.

What is in the database

WordPress stores content in posts tables, settings in options, users and hashed passwords in users tables and extra data in meta tables. Plugins add their own tables for forms, logs, orders and more. WooCommerce stores orders, customers and addresses.

This makes the database the most valuable target on most sites, and the most important thing to back up.

Strong database credentials

Use a unique database username and a long, random password for every site. Never reuse the database password elsewhere. These credentials are stored in wp-config.php, so protecting that file matters too.

If you suspect the credentials were exposed, change the database password in your hosting panel and update wp-config.php.

Database protection
  • Unique credentialsLong random password
  • One user per siteLimited privileges
  • No remote accessLocal connections only
  • Updated pluginsBlock SQL injection
  • Encrypted backupsOff-site, tested
  • MonitoringNew admins, injected code

Limit database user privileges

Each WordPress site should have its own database user with privileges only on its own database. Avoid using a root or shared user that can access other databases on the server. If one site is compromised, this limits damage to that site.

WordPress needs common privileges such as SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER and DROP for updates. Removing these can break plugin and core updates.

Protect wp-config.php

Set restrictive permissions on wp-config.php, keep it out of public backups and never commit it to public code repositories. Some hosts allow moving it above the web root. Block direct web access to it with server rules.

See WordPress file permissions.

Table prefix

Changing the default wp_ table prefix to something unique makes some automated SQL injection attacks less likely to succeed, because they assume default table names. It is a small layer, not a strong defence.

Set a custom prefix during installation. Changing it on an existing site requires updating tables and some option values, so take a backup and follow a careful process.

Restrict remote access

Databases should not be reachable from the public internet. On most hosting, the database only accepts connections from the local server. If your host allows remote MySQL connections, keep them disabled or restricted to specific IP addresses.

Use phpMyAdmin or Adminer only through your hosting panel, protected by the panel login, and avoid installing standalone database tools in public folders.

Prevent SQL injection

SQL injection happens when user input is inserted into database queries without proper handling, allowing attackers to read or change data. WordPress provides safe methods for queries, and well-coded plugins use them. Vulnerable plugins are the main risk.

Keep plugins updated, remove unused ones and use a firewall that blocks injection attempts. See plugin vulnerabilities and do you need a WAF.

Password hashing

WordPress stores passwords as hashes, not plain text, and recent versions use strong hashing algorithms. Never store passwords or sensitive data in plain text in custom fields or plugin settings.

If you build custom features, store only what you need and avoid saving sensitive information such as full card numbers, which should never be stored.

Backups and encryption

Back up the database daily, or more often for stores, and store copies off-site. Encrypt backups where possible and protect backup storage with strong passwords and 2FA, since backups contain all your data.

Test restores regularly. See a backup strategy that works.

Clean up old data

Delete data you no longer need, such as old form entries, expired customer accounts, logs and leftover tables from removed plugins. Less data means less exposure if something goes wrong and supports data protection obligations.

See optimizing the WordPress database.

Monitor for changes

Watch for signs of database tampering: new administrator users, unexpected changes to site URLs, injected scripts in posts or options and spam links. An activity log and security scanner help detect these changes.

See WordPress activity logs and scanning WordPress for malware.

Hosting matters

Good hosts keep database servers patched, isolated and monitored. Managed WordPress hosts often add protections such as automatic backups and restricted access. Shared hosting with poor isolation increases risk.

See choosing WordPress hosting.

Database access for developers

Developers sometimes need direct database access to debug problems or run migrations. Provide it through your hosting panel, SSH tunnels or temporary database users with limited privileges, and remove access when the work is done. Avoid emailing database exports, which contain customer data and password hashes.

When sharing a copy of the database for development, remove or anonymise personal data such as customer names, emails and addresses. This protects customers and reduces your obligations if a developer’s computer is lost or compromised.

Getting help

Database security checks are part of my WordPress security audit and website protection service.

If your database has been tampered with, follow what to do when your WordPress site is hacked.

Key takeaways

  • Use unique credentials and one database user per site.
  • Keep the database closed to remote connections.
  • Updated plugins and a firewall prevent most SQL injection.
  • Back up, encrypt and monitor the database regularly.

Frequently asked questions

Should I change the wp_ table prefix?

It adds a small layer of protection. Set it at installation; changing later needs care.

Can attackers access my database directly?

Rarely, if remote access is disabled. Most attacks go through vulnerable plugins.

Are WordPress passwords stored safely?

Yes, as hashes. Never store passwords in plain text elsewhere.

What is SQL injection?

An attack that manipulates database queries through unsafe input handling.

How often should I back up the database?

Daily for most sites, more often for stores.

Is phpMyAdmin safe?

When accessed through your hosting panel with strong credentials, yes.

Should I use a separate database for each site?

Yes. Each WordPress site should have its own database and user, so a problem on one site cannot affect the data of another.

Free website audit

Get a free audit of your website

Tell me your URL and I'll send a short, prioritized list of the speed, SEO and security fixes that will make the biggest difference.

  • No obligation, no sales call
  • 5.0 rating on Google and Upwork
  • Reply within one business day
Written by Muhammad UsmanWeb Development Team Lead with 5+ years building WordPress, WooCommerce, Shopify and Wix websites. Experience · Certificates About me

More on Security

All Security articles

Have a project in mind?

Tell me what you're building and I'll reply with next steps and an estimate.