Skip to content Skip to sidebar Skip to footer

Python (1040, 'too Many Connections')

im newbie in Python. I have Item table with 3 attributes ( name, price, image) I want to get html from link and save to table. So i do that from books.models import Book, Author,

Solution 1:

I solved this problem by increasing the maximum number of connections allowed by MySQL in my django app settings.py file. More information in MySQL docs

DATABASES = { 
  'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': '',
    'USER': '',
    'PASSWORD': '',
    'HOST': 'localhost',
    'PORT': '3306',
    'OPTIONS': {
           "init_command": "SET GLOBAL max_connections = 100000", #<-- The fix
    }
  }
}

Solution 2:

http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html

If you get a Too many connections error when you try to connect to the mysqld server, this means that all available connections are in use by other clients.

The number of connections permitted is controlled by the max_connections system variable. Its default value is 100. If you need to support more connections, you should set a larger value for this variable.

This means that you have opened more connections to the database than permitted by the server without closing them. I never see calls to close the connection con in your code.

Solution 3:

you need: cur.close() and con.close().

Every connection should be closed after use it

Solution 4:

My situation is not exactly related to OP, but first result on google for my problem, so...

I was getting the too many connections error in django as well. I have two servers deployed on AWS, one EC2 t2.micro (web server) and one RDS t2.micro (mysql database). The web server is running debian, with apt-get installs for apache2 (2.4.10-10+deb8u3), python (2.7.9), and django (1.7.7-1+deb8u3). I'm using django just for the ORM and website is hosted on apache using mod_wsgi.

mysql:

mysql>show variables like "max_connections";
+-----------------+-------+| Variable_name   |Value|+-----------------+-------+| max_connections |66|+-----------------+-------+1rowinset (0.01 sec)

mysql>SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+| Variable_name           |Value|+-------------------------+------------------------------+| innodb_version          |5.6.23|| protocol_version        |10|| slave_type_conversions  ||| version                 |5.6.23-log                   || version_comment         | MySQL Community Server (GPL) || version_compile_machine | x86_64                       || version_compile_os      | Linux                        |+-------------------------+------------------------------+7rowsinset (0.02 sec)

I had to tune down some settings in the /etc/apache2/sites-enabled/000-default.conf to fix the too many connections error. These four settings were previously not in the config file (default values):

ServerLimit 2
MaxRequestWorkers 10
ThreadsPerChild 5

WSGIDaemonProcess aaa threads=6

<VirtualHost *:80>
    ....

mysql processlist (SELECT count(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE user='www-user') now stays around 21.

Post a Comment for "Python (1040, 'too Many Connections')"