How to fix MySQL “Operation not permitted” error

Updated 4 days ago

If your website is showing a database connection error such as:

  • PHP Fatal error: Uncaught mysqli_sql_exception: Operation not permitted
  • Connection failed: Operation not permitted
  • ERROR: Could not connect. Operation not permitted
  • SQLSTATE[HY000] [2002] Operation not permitted

This means your website is likely opening a new MySQL connection on every page request, instead of reusing an existing one. Hostinger enforces a per-account MySQL connection rate limit (20 new connections per second) to ensure fair resource usage across all customers. Websites that open a fresh connection on every request can exceed this limit during traffic bursts, causing the error above.

To resolve the error on a custom PHP website, switch to persistent MySQL connections. WordPress doesn’t support persistent connections, so on a WordPress website, reduce the number of requests that open a database connection instead.

Before you start

  • You will need access to your website’s PHP files via Hostinger dashboard File Manager or FTP.
  • The fix applies to websites using PHP with either mysqli or PDO to connect to MySQL. It doesn’t apply to WordPress websites.

Switch a custom PHP website to persistent MySQL connections

You need to locate the file in your website’s code that handles the database connection. This is typically named “config.php”, “db.php”, “connect.php”, “database.php”, or similar.

Option 1 – If your site uses mysqli

Find the line that looks like this:

mysqli_connect("localhost", $user, $pass, $db);

Change “localhost” to “p:localhost”:

mysqli_connect("p:localhost", $user, $pass, $db);

The “p:” prefix tells PHP to use a persistent connection, keeping it open across requests instead of creating a new one each time.

Option 2 – If your site uses PDO

Find the line that looks like this:

new PDO("mysql:host=localhost;dbname=$db", $user, $pass);

Add “[PDO::ATTR_PERSISTENT => true]” as a fourth argument:

new PDO("mysql:host=localhost;dbname=$db", $user, $pass, [PDO::ATTR_PERSISTENT => true]);

Click Deploy in the top-right corner to make the changes live, then reload your website.

After making this change, your website will reuse the existing MySQL connection instead of opening a new one on every request. This keeps your connection count within Hostinger’s rate limits and resolves the “Operation not permitted” error. Your database credentials and all other settings remain unchanged.

Fix the MySQL “Operation not permitted” error on a WordPress website

WordPress doesn’t support persistent MySQL connections. Adding p: to DB_HOST in wp-config.php doesn’t work, because WordPress reads the text after the colon as a port. To keep a WordPress website under the limit of 20 new MySQL connections per second, reduce the number of requests that reach PHP and MySQL:

  • Turn on page caching in the LiteSpeed Cache plugin. Cached pages load without opening a database connection.
  • Turn on a content delivery network (CDN), such as Hostinger CDN, so more visits are served from cache.
  • Replace WP-Cron with a server cron job. Add define('DISABLE_WP_CRON', true); to wp-config.php, then create a cron job in Hostinger dashboard that runs wp-cron.php every 5 minutes.
  • Deactivate plugins that run frequent background tasks or heavy database queries, one at a time, and check whether the error stops.

If your website needs more than 20 new MySQL connections per second during normal traffic, move it to a VPS plan, where this limit doesn’t apply.

NOTES

  • This fix does not require any changes to your database credentials or database name.
  • If you use Joomla or a framework with its own database layer, the connection file location may differ. Check its documentation for how to enable persistent database connections.
  • If the error persists after applying the fix, contact Hostinger support for further assistance.

Other common database issues

If you’re running into a different database-related problem, see: