Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am running an application PHPlist on my linode server, simultaneously running 12 php scripts which open mysql connection, now when i access phplist it shows lot of times an error shows:

Fatal Error: Sorry, the server is currently too busy, please try again later.

When i am trying to access phpmyadmin, it shows me #1040 error. Output of my php scripts which run through cron jobs shows:

PHP Warning: mysqli_connect(): (HY000/1040): Too many connections

Lamp stack i am using on server with phpmyadmin, on using TOP in terminal it shows mysqld using 100-130% CPU. When i am trying to troubleshoot this problem i got some clues:

Increase max_connection variable : 200 i am using (100 by default) Open table cache: 512 (400 by default)

There are lots of variable for set but specific i can't determine, getting some refernce from: too many connections and http://dev.mysql.com/doc/refman/5.5/en/table-cache.html

but according to my usage how to increase memory and what is the maximum memory difficult for me. On my server i am using php scripts around 12, phplist application for sending emails, and a major database for user registrations.

Kindly help me to do resolve this problem.

share|improve this question
    
@RolandoMySQLDBA: Please Enlighten on this problem to resolve –  shihon Jul 6 '12 at 7:48

2 Answers 2

up vote 7 down vote accepted

First you need to do is run this query:

SELECT user,host FROM mysql.user
WHERE super_priv='Y' AND
CONCAT(user,'@',host) <> 'root@localhost';

This will list all users that have SUPER privilege. Most users that do application-related DB processing do not require this privilege. According to the MySQL Documentation, those with SUPER privilege can do the following:

  • Run CHANGE MASTER TO for controlling replication coordinates
  • KILL or mysqladmin kill to kill threads belonging to other accounts
  • PURGE BINARY LOGS to systemically delete binary logs
  • Make configuration changes using SET GLOBAL to modify global system variables
  • mysqladmin debug command
  • enabling or disabling logging
  • performing updates even if the *read_only* system variable is enabled
  • starting and stopping replication on slave servers
  • specification of any account in the DEFINER attribute of stored programs and views
  • HERE IS THE MOST IMPORTANT ONE FOR YOUR PROBLEM: : Enables you to connect (once) even if the connection limit controlled by the max_connections system variable is reached.

You will need to login as root@localhost and revoke SUPER privilege as follows:

UPDATE mysql.user SET super_priv='N'
WHERE super_priv='Y' AND
CONCAT(user,'@',host) <> 'root@localhost';
FLUSH PRIVILEGES;

Once you do this, whenever all users flood mysql connections, only root@localhost can login. After all, if everybody and his grandmother had SUPER privilege, this would bar root@localhost from ever connecting ahead of everybody else. If max_connections is at 200 and you need to raise it to 300 without having to restart mysqld, you can dynamically increase the max_connections with this command:

mysql> SET GLOBAL max_connections = 300;

That will allow more connections effective immediately, but don't just arbitrarily increase the number on whim. You have to make sure mysql has enough RAM to accommodate the increase.

CAVEAT : If you change max_connections dynamically to 300, please put it in /etc/my.cnf

[mysqld]
max_connections=300

You can run mysqltuner.pl on your MySQL DB Server. If you do not have it, then run the following:

cd
wget mysqltuner.pl
perl mysqltuner.pl

The 3rd line under Performance Metrics has this

-------- Performance Metrics -------------------------------------------------
[--] Up for: 8d 20h 46m 22s (8M q [10.711 qps], 129K conn, TX: 90B, RX: 19B)
[--] Reads / Writes: 4% / 96%
[--] Total buffers: 2.1G global + 5.4M per thread (2000 max threads)
[OK] Maximum possible memory usage: 12.6G (80% of installed RAM)

See the 5.4M per thread? That is multipled by max_connections. In this example, that would be a maximum of about 10.8G of RAM. Therefore, each time you bump up max_connections, you should run mysqltuner.pl and check if you are pressing the OS for too much memory.

In any case, limiting who has SUPER privileges give such users opportunity to mitigate flooding mysqld with DB Connections.

share|improve this answer
    
i get this error while trying perl mysqltuner.pl " Attempted to use login credentials from debian maintenance account, but they failed." –  shihon Jul 10 '12 at 7:28
    
I am trying this on my local ubuntu server, it shows maximum memory usage, but on my vps, it shows failure and i can't login in phpmyadmin but login successfully in mysql terminal –  shihon Jul 10 '12 at 7:41
  1. The global variable max_connections determines the maximum number of concurrent connections to MySQL. Make sure that you have a high value for this variable. You can increase this value to 300 or 400 and try restarting MySQL after this settings.
  2. Design your application such that a MySQL connection is kept open for a very short period of time.
  3. You should also check that client code is not using persistent connections (such as mysql_pconnect()) improperly.

Also execute Flush status; command on MySQl server to reduce this value.

I hope these suggestions helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.