☰
WEB SECURITY / PRACTICE

Minimum WordPress Database User Privileges

Minimum WordPress Database User Privileges

WordPress should not connect to MySQL as root or through an account that can access all databases. If the website or a plugin is compromised, an attacker could use that account's privileges to read, modify, or delete data belonging to other projects on the server.

A safer approach is to use a separate database user for each website. The user should have access only to the required database, connect from a specific host, and receive only the privileges WordPress needs for everyday operation and table-structure updates.

Why root and access to all databases are dangerous

The root account is intended for MySQL administration, not for running a web application. If the root password ends up in wp-config.php, an error log, a backup, or is stolen through a plugin vulnerability, the entire database server may be at risk.

The same problem occurs when one user has privileges for several websites or can connect from any host through the % wildcard. If one WordPress installation is compromised, the attacker may then be able to access the databases of other projects.

A separate user does not eliminate every risk, but it limits the potential impact of an incident to a specific database. This is one of the basic WordPress and MySQL hardening measures.

  • Do not use root in wp-config.php.
  • Do not use one administrative user for multiple independent websites.
  • Do not give the web application access to all databases through ON *.*.
  • Do not use '%' as the host unless there is a clear need and additional restrictions are in place.

What privileges WordPress needs

For a typical WordPress installation, the SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, and INDEX privileges are usually sufficient for a specific database. The first four are needed to read and modify content, while the others are used to create tables and change their structure during updates to WordPress, themes, or plugins.

The privilege set should match your maintenance process. If the site never performs automatic updates and migrations are handled by a separate administrative user, CREATE, ALTER, DROP, and INDEX can be considered separately. However, excessively restricting privileges on a production site often causes errors during updates.

The web application does not need GRANT, FILE, PROCESS, SUPER, or SHUTDOWN. These privileges extend capabilities beyond the operation of a specific site and should not belong to a user whose password is stored in the WordPress configuration.

  • SELECT — reading data.
  • INSERT, UPDATE, DELETE — creating, modifying, and deleting records.
  • CREATE, ALTER, DROP, INDEX — operations involving table structures and indexes.
  • GRANT, FILE, PROCESS, SUPER, SHUTDOWN — do not grant these to the WordPress user.

How to create a separate MySQL user

Run the commands below under a MySQL administrative account. Replace site_db, wp_app, localhost, and the password with your own values. It is best to use a separate database and username for each website so that access permissions do not become mixed.

The host value must match the way WordPress connects to MySQL. A connection through a Unix socket often uses localhost, while a TCP connection uses 127.0.0.1. These are different MySQL account entries, so an incorrect value can cause an access-denied error.

  • Make sure the site_db database has already been created.
  • Generate a long, unique password that is not used by any other service.
  • Grant permissions on site_db.* or on specific tables, not on all databases on the server.
  • Limit the host to the actual connection source, such as localhost or 127.0.0.1.
CREATE USER 'wp_app'@'localhost' IDENTIFIED BY 'ЗМІНІТЬ_НА_ДОВГИЙ_ПАРОЛЬ';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX
ON `site_db`.* TO 'wp_app'@'localhost';
SHOW GRANTS FOR 'wp_app'@'localhost';

Why you should not use host %

The 'wp_app'@'%' entry allows connections from any host if MySQL network settings permit them. For a local WordPress installation, this broad condition is usually unnecessary. It increases the number of paths through which the password could be exploited.

If the website and database run on different servers, specify the application server's exact IP address or a controlled hostname instead of %. Also restrict access at the firewall level and do not expose the MySQL port to the entire Internet.

  • For a local site, check the difference between localhost and 127.0.0.1.
  • For a remote application, use a specific connection source.
  • Do not treat changing the host value as a replacement for a network firewall.

How to connect the user in wp-config.php

After creating the account, update the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST settings in wp-config.php. DB_HOST must match the host for which the MySQL privileges were granted. If only the password changes, the other parameters can remain unchanged.

The configuration file contains secrets, so it should not be published in a repository, shared in public chats, or left available for download through the web server. Make sure PHP is processed as code and that the file is not delivered to users as plain text.

After changing the password, test the site on staging or during a short, controlled maintenance window. Separately test administrator login, page viewing, media uploads, form operation, and scheduled tasks if they are used.

  • Update the password in the wp-config.php file used by the current installation.
  • Do not unnecessarily leave the old password in backups or environment variables.
  • After testing, open several pages and review the PHP and WordPress error logs.
  • If the connection fails, first check DB_HOST, the database name, the user's host, and the password.
define( 'DB_NAME', 'site_db' );
define( 'DB_USER', 'wp_app' );
define( 'DB_PASSWORD', 'ЗМІНІТЬ_НА_ТОЙ_САМИЙ_ПАРОЛЬ' );
define( 'DB_HOST', 'localhost' );

How to check actual privileges and access to other databases

You should check not only the SQL commands you intended to run, but also the account's actual state. Unnecessary privileges may remain after an earlier configuration, a database import, or using the same user for another project.

The SHOW GRANTS command displays the permissions of a specific account. The result for a web user should not contain ON *.* and should not include WITH GRANT OPTION. Also check whether another entry exists with the same username but a different host, such as '%' or a specific external IP address.

It is best to test access to another database while logged in as the WordPress user itself. The expected result is an access-denied error. Do not perform this test against production data using commands that could modify or delete tables.

  • Run SHOW GRANTS for the user and check the scope specified after ON.
  • Make sure there is no GRANT OPTION or administrative privilege.
  • Check the user's entries for all hosts in the MySQL account table.
  • Make sure the web user has no privileges on other websites' databases.
  • After testing, do not leave temporary administrative accounts enabled unnecessarily.
SHOW GRANTS FOR 'wp_app'@'localhost';

-- Перелік записів користувача перевіряє адміністратор MySQL
SELECT User, Host
FROM mysql.user
WHERE User = 'wp_app';

Common mistakes and a secure maintenance model

The most common mistake is granting permissions on *.* “to make sure everything works.” This solves a connection problem at the cost of losing isolation between websites. Another mistake is removing CREATE or ALTER without checking the update process, then ending up with an incomplete WordPress or plugin update.

Use a separate account for backups, migrations, and one-time operations. It may have broader privileges, but it should not be stored in wp-config.php or used by the web server. After the migration is complete, the account can be disabled or deleted.

If the web user's password becomes known to an unauthorized party, change it in MySQL and wp-config.php, review the logs, active WordPress accounts, and suspicious file changes. Changing the password alone does not replace an investigation of possible compromise.

  • Do not mix application, migration, and backup accounts.
  • Do not remove privileges blindly on production without testing on staging.
  • After making changes, test updates, backups, and restoration.
  • Review privileges regularly after installing new components or moving the site.

Frequently asked questions

Does WordPress need the GRANT privilege?

No. The web application does not need to grant MySQL permissions by itself. GRANT OPTION and administrative privileges should remain with a separate account used for maintenance.

Can one user be used for multiple websites?

Technically, yes, but this is unsafe from an isolation perspective. It is better to create a separate user for each website and grant access only to that site's database.

Which should be used in DB_HOST: localhost or 127.0.0.1?

The value must match the actual connection method. localhost often uses a Unix socket, while 127.0.0.1 uses TCP. In MySQL, these may correspond to different user entries, so check the server configuration.

Is restricting the user to one database enough without a firewall?

No. SQL privilege restrictions protect access to data but do not replace network rules. If the database is remote, its port should be allowed only for the application server or another required source.

Can CREATE, ALTER, and DROP be removed after WordPress is installed?

Only if you understand the consequences and handle updates and migrations through a separate process. These privileges may be required for regular WordPress and plugin updates that change the database structure, so test the restriction on staging first.

Conclusion

A secure WordPress configuration begins with isolating database access: use a separate user, a specific database, a specific host, and the minimum required privileges. Do not use root, ON *.*, or host % unless they are justified by the architecture.

After configuring the account, check SHOW GRANTS, access to other databases, site operation, and the backup process. Keep the administrative account only for controlled migrations and service operations.

← All web security materials