How to fix MySQL “Operation not permitted” error

Updated 2 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 (10 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 issue, you just need to switch to persistent MySQL connections.

Before you start

  • You will need access to your website’s PHP files via hPanel File Manager or FTP. Check how to here
  • This issue currently affects websites hosted on Hostinger’s India servers.
  • The fix applies to websites using PHP with either mysqli or PDO to connect to MySQL.

How to fix it

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]);

Save the file and reload your website.

Conclusion

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.

 

Notes:

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