Forums

exceeded the 'max_user_connections' resource

Hi,

I'm getting this error when I use Flask-SQLAlchemy with binds to manage multiple databases.

User 'lucasamos2' has exceeded the 'max_user_connections' resource (current value: 3)

I have the this in my code and have followed other instructions on the forum to no avail

app.config["SQLALCHEMY_POOL_RECYCLE"] = 280

If I remove the binds the error goes away and I have an old Pythonanywhere account that I quickly cloned my repo into and the problem also occurs on that account. Is this a limitation of the free accounts? Thanks

how are you doing this db binding?

My database connection is established using the following code:

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
username="***",
password="***",
hostname="***.mysql.pythonanywhere-services.com",
databasename="***$***",
)

SQLALCHEMY_BINDS = {
'sensordata2' : 'mysql+mysqlconnector://***@***.mysql.pythonanywhere-services.com/***$***'
}

app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_BINDS"] = SQLALCHEMY_BINDS
app.config["SQLALCHEMY_POOL_RECYCLE"] = 280
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)
migrate = Migrate(app, db)

The table I want to store in the sensordata2 database is created using the following code

class Sensorrecord(db.Model):
__bind_key__ = 'sensordata2'

__tablename__ = "Sensorrecord"

id = db.Column(db.Integer, primary_key=True)
reading = db.Column(db.Float, nullable=False)
unit = db.Column(db.String(64), nullable=False)

Thanks

So the error has stopped now, which is odd as I did check that I didn't have a large number of open connections.

OK, so the error has recurred but I'm pretty sure that it only occurs when I am using flask with binds i.e.

flask db init --multidb

Anyone come across this before? :)

The error is possibly because you have some code that takes up a connection and doesn't close it. Periodically, those connections are cleared down, which is why it then works for you.

Then when that part of your code gets run again 3 times, then you hit your connection limit again, and then need to wait awhile before it gets cleared down.

Thanks, I am using Flask-sqlalchemy which I understand handles the connection management. Maybe when I restart my app they are not getting shut down properly. Thanks for the info :)

I think it might have something to do with using an external database management program at the same time. It might mislead sqlalchemy as to how many connections are currently open

I confirm I was having that error and as soon as I closed an external database management program I had opened, the issue disappeared

It could have been a side effect of your database management program keeping many connections to the database opened. Good to know that it's no longer a problem.

Is there any way to restart MySQL database to reset all connections because of "max_user_connections" error? My website is down and I do not want to wait while Pythonanywhere will clear this for me.

Unless you still have code running that does not close connections, they will time out in 5 minutes.

I am having the same problem. I also waited 5 min for a timeout but still the same.

The problem was solved after using SQLAlchemy's close and dispose functions.