'How to solve exceeded the 'max_questions' resource in mysql which is in shared hosting?

I have PHP based website running on shared hosting(fatcow). I am facing the issue of

#1226 - User 'testdb' has exceeded the 'max_questions' resource (current value: 75000) .

The website has a lot of complex queries with joins. I can't access or can't do anything on web server. The solution is to fix the problem on my application.

How to solve it?



Solution 1:[1]

Try this from your phpmyadmin console (Select your database and go to SQL section):

SET @MAX_QUESTIONS=0; // This will set unlimited.
FLUSH PRIVILEGES;

Alternatively, you can also do this:

UPDATE user SET max_questions = 0 WHERE user = 'you username or root';
FLUSH PRIVILEGES;

If you get an error on privileges then ask your provider/admin.

Solution 2:[2]

Easy way to fix this issue:

User 'root' has exceeded the 'max_questions' resource (current value: 100)

To Fix issue you have to wait 1 hour before you run any of these commands..because the problem is, the max questions are set to a certain number of request per HOUR. If you try to run these commands before the 1 hour is up, these commands will NOT work. So wait 1 Hour..

after that 1 hour has already passed then run the following in the terminal in exact order:

* mysql -u root -p

* use mysql

* select user, max_questions from user; 

* update user set max_questions = 0 where user = 'root';

* flush privileges;

* select user, max_questions from user; 

(If root max questions says '0' then you've fixed it..Now you're done)

Solution 3:[3]

I had a similar issue on my WordPress site. It was hosted on a shared host. The host limits the connections per user to 75000 every hour. The below code enabled me to keep the website running while I debugged any plugin that could be generating too many queries.

I created 4 users with the same password in the wp-config file. The code below changes the database username every 15 minutes using the PHP switch statement.

<code>

$count = date("i");

switch (true) {
    case $count <= 15:
        $user = 'mainuser';
        break;

    case $count <= 30:
        $user = 'mainuserx';
        break;

    case $count <= 45:
        $user = 'mainusery';
        break;

    default:
        $user = 'mainuserz';
        break;
}

define('DB_USER', "$user");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ronak Patel
Solution 2 Jackie Santana
Solution 3 hawlast