MySQL2 prevent from Rails migration - mysql

I am trying to run heroku rake db:seed for my Rails app in Heroku. It has a lot of queries involve. I got this error message:
rake aborted!
Mysql2::Error: User '222ad0ef2670fe' has exceeded the 'max_questions' resource
(current value: 3600)
What does current value 3600 means? (queries/hours?) and how can I change it to, say, 10,000?
Thank you.

The reason for the error is you have reached max number of queries per hour. In this case you can wait an hour if you're in developer mode or upgrade your plan.
View the corresponding FAQ
I'm getting an error message saying that I have exceeded the
'max_questions' resource for my database. What can I do?
The max_questions resource is defined by how many queries you may
issue to your database in an hour. Our free plans start with 3,600
queries per hour and increase to 18,000 upon purchasing a paid plan
with us. Larger plans have larger QPH limits. We recommend that you
upgrade your database with us to lift this limitation off of your
database
.

Since your issue is with heroku you will need to contact their support team. In order to change the max_questions variable you need to have root access to the db. See http://www.mkyong.com/mysql/how-to-modify-the-max_questions-resource-value-in-mysql/ for exactly how to do it.
max_questions is the amount of queries an account on the SQL server can make per hour.
You will also want to check max_updates, max_connections, and max_user_connections to make sure they line up with the expected traffic load for your app.
See http://dev.mysql.com/doc/refman/4.1/en/user-resources.html for more detail

Upgrade your db. I was on Cleardb ignite, perfect for cheapskates, and I would typically max out max_questions after loading a couple thousand rows during a nightly import. I bumped up to 'punch' ($9.99/month) and haven't experienced the issue since.

Related

Does the 'max_user_connections' resource error resolve if I change the server on Heroku

I have deployed my Rails (3.2.13) app on heroku (its almost 3 years for deployment). That time I have used unicorn as a server.
I have used ClearDB addon for setting mysql database on Heroku.
Currently I am facing issue where I am getting following error
Mysql2::Error (User 'username' has exceeded the 'max_questions' resource (current value: 54000)):
I referred this answer where he has suggested
Scale up your database by upgrading to a higher ClearDB plan (http://dashboard.heroku.com)
But I am already on the highest clearDB plan
Scale down your application by reducing the number of dynos/workers (heroku ps:scale command)
for this I have already reduced my worker dynos.
But Still facing the issue.
Can any one provide me other solution that would be great.
Should I move from unicorn to puma server?
This seems to be an issue with the number of queries that are executed per hour as opposed to the number of connections as in the answer you've referenced (note the error is has exceeded 'max_questions' as opposed to has excedded 'max_user_connections'.
This answer https://getsatisfaction.com/cleardb/topics/max-question-error-on-heroku and http://w2.cleardb.net/faqs/#multi_7 suggests that cleardb puts a limit on the number of queries that can be executed, which wouldn't be affected by the number of dyno's (assuming the same number of requests/workload will still be coming in), or changing from unicorn to puma.
I would suggest getting in touch with ClearDB support and seeing if they can put you on a plan that removes this restriction.
There is no way to change the MySQL variable MAX_USER_CONNECTIONS on Heroku for free accounts. Changing the number of connections at once requires upgrading the plan.
Please refer to this link

Resque Mysql2::Error: User has exceeded the 'max_user_connections' resource (current value: 10)

I am running Resque on Heroku, and my database is ClearDB. I am getting this error:
"Mysql2::Error: User 'bdb2aedbee2c38' has exceeded the 'max_user_connections' resource (current value: 10): SHOW FULL FIELDS FROM projects"
That error is coming from my Resque admin of my Heroku app.
How can I figure out how many connections Resque is making to ClearDB?
How can I tell ClearDB to either allow more connections, or tell Resque to create less?
Does "current value: 10" refer to how many connections ClearDB is allowing, or is this how many current connections Resque is trying to make?
Thanks!
Your application server dynos or Resque workers are consuming more connections than your database plan provides.
You have two options:
Scale up your database by upgrading to a higher ClearDB plan (http://dashboard.heroku.com)
Scale down your application by reducing the number of dynos/workers (heroku ps:scale command)
The first link when I googled your addons links to the page describing the service and pricing tiers. You are on the free, 10 connection tier.
https://addons.heroku.com/cleardb

Node.js and MySQL "Too many connections" error

I'm using Node.js to run a web-server for my web application. I'm also using the node-mysql module to interface with a MySQL server for all my persistent database needs.
Whenever there is a critical error within my Node.js application that crashes my app's process I get an email sent to me. So, I keep getting this email with an error saying "Too many connections". Here's an example of the error:
Error: Too many connections
at Function.Client._packetToUserObject (/apps/x/node_modules/mysql/lib/client.js:394:11)
at Client._handlePacket (/apps/x/node_modules/mysql/lib/client.js:307:43)
at Parser.EventEmitter.emit (events.js:96:17)
at Parser.write.emitPacket (/apps/x/node_modules/mysql/lib/parser.js:71:14)
at Parser.write (/apps/x/node_modules/mysql/lib/parser.js:576:7)
at Socket.EventEmitter.emit (events.js:96:17)
at TCP.onread (net.js:396:14)
As you can see all it tells me is that the error is coming from the mysql module, but it doesn't tell me where in my application code the issue is occurring.
My application opens a db connection anytime I need to run one or more queries. I immediately close the connection after all my queries and data has been collected. So, I don't understand how I could be exceeding the 151 max_connections limit.
Unless there is a place in my code where I forgot to call db.end() to close the connection, I don't see how my app would leak like this. Even if there was such a mistake, I wouldn't get these emails sent by the dozens. Yesterday, I received almost 100 emails with roughly the same error. How could this be happening? If my application had leaked and allocated connections over time, as soon as the first error occurred the app process would crash and all connections would be lost, preventing the app to crash again. Since I received ~100 emails, this means the app crashed ~100 times, and all within a short period of time. This could only mean that somewhere in my application a lot of connections where established in a short period of time, right?
How could I avoid this problem? This is very discouraging. All help is highly appreciated. Thanks
MySQL has a default MAX_CONNECTIONS = '100' not 151 unless you changed it. Also, in truth you have MAX_CONNECTIONS + 1. The plus 1 allows a root user to logon even after you have maxed out the conenctions in order to figure out what is actually being used. When your connections are maxed out try logging on as root and running the following command from MySQL.
mysql> SHOW FULL PROCESSLIST
Post the output of this command above. Once you actually know what is consuming your resources you can go about fixing it.It could easily be your code that is leaving open connections.
You should take a look at the follwoing documentation: Show Processlist
+1 for question. Investigations showed us that node-mysql opens the connections and doesn't close them. Because of that at one moment be reach the limit of max connections. The question is why node-mysql doesn't close the connections?

Mysql max user connections bug

I'm facing a really weird problem to me.
I'm trying to connect with an user to my mysql 5.5 instance but it keep saying to me that user already exceeded the max_user_connections
ERROR 1226 (42000): User 'xpto' has exceeded the 'max_user_connections' resource (current value: 100)
But,
show processlist
doesn't shows any connection used by that user. I'm pretty sure that user is not using any connection at all.
If i increase the current value to 110 for example i can connect. Then if i lower i can't connect.
EDIT: the global connections usage is 500 and only a few (10/20) are being used.
Any clue?
The server has too many open connections already. A MySQL server can only handle a specific number of open connections before refusing to allow any more, and this limit is shared amongst all users of the server. It's usually set quite high, although it's easily possible for someone to effectively DoS a MySQL server by making lots of connections.
If you got the error message (code 1226) indicates that the entire MySQL server has run out of connection slots - this is the DoS scenario.
Your database must have a user ‘A’ using which you have configured your wordpress blog.
Now the problem is that user ‘A’ has exceeded maximum_questions resource (current value: 40)
Create a new user ‘B’ in your database through your domain control panel and update the same user name you wp-config.php file in
wordpress installation directory.
Now you got the problem fixed in few minutes. It will not disturb the database or the posts you have in your wordpress or phpbb.
Copied from neuronring blog
Are you on MySQL 5, and you've set the user's MAX_USER_CONNECTIONS, and the user recently disconnected?
From MySQL docs:
For the MAX_USER_CONNECTIONS limit, an edge case can occur if the
account currently has open the maximum number of connections permitted
to it: A disconnect followed quickly by a connect can result in an
error (ER_TOO_MANY_USER_CONNECTIONS or ER_USER_LIMIT_REACHED) if the
server has not fully processed the disconnect by the time the connect
occurs. When the server finishes disconnect processing, another
connection will once more be permitted.

mysqlplus is better adapter than ruby mysql?

I want to know if the mysqlplus gem is a better database driver than the common Ruby mysql gem? I used to have some problems in my Rails application, like:
ActiveRecord::StatementInvalid: Mysql::Error: MySQL server has gone away
MySQL server has gone away means either the mysql server has crashed running your query or (more commonly) you sent it a quert that is larger than max_allowed_packet. see http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html
if you want to only check for 'mysql server has gone away' errors then activerecord is more than sufficient. it is a mature codebase, good enough for most usecases.
checkout http://blog.new-bamboo.co.uk/2010/4/11/automatic-reconnection-of-mysql-connections-in-active-record for more details.
mysqlplus is better when you need concurrency, all the cool boys recommend it :-)
but i am not sure if it is production ready.
mysql reaps the connections after a period of inactivity. this is defined in 'wait_timeout'.
Can see this in mysql by:
mysql> show variables like 'wait_timeout'
by default it is 8 hours. you are getting this error as you have established a connection and there have been no queries executed over this connection for this period.
Activerecord has ActiveRecord::Base#verify_active_connections! for this usecase.
if you specify reconnect: true in database.yml it will do this automatically.
The above method is executed when we checkout a connection from the connection-pool, it guards against inactivity.
It will not help you if you are running a long-running query and it exceeds the wait_timeout period, Then you may have to increase the timeout variable in mysql. You may also try setting the patch in:
http://gist.github.com/238999 This will retry the query on such a error, circumstances may have changed, but the patch is not robust as it does not have a retry count.