Monday, March 22, 2010

troubleshoot mysql database connection pool problems

If you are getting following error messages, then its time to tune your mysql max_connection value

1:User 'mysqldba' has exceeded the 'max_user_connections' resource
2:Too many connections
3:GenericJDBCException: Cannot open connection
4:message from server: "Too many connections"

Now once u got these messages, we need to change value of max_connection variable in mysql database.

There are two ways to do this.

Method 1:Without restarting the mysql DB.
a;login to the mysql db.
b: run the query ----
show variables like "max_connections";
c: this will display the current value to max_connections.
d: Now to change the value of max_connection, run this query
set GLOBAL max_connections=NewValue;

max_connection value is changed , now again run the query
'show variables like "max_connections";'
to check if the value is reflecting.

But this value will be temporary, if you restart the mysql DB, max_connection value will again set to its default value

Method 2: This requires restarting the DB, but this change will be permanent and will not go even after restart of the db

a: For this you need to change the global setting file of mysql ie "my.cnf" file
b: By default, path of my.cnf will be under etc directory. If you dont know the path, run the
following command to get the path of my.cnf file
find / -name my.cnf
c: Once you got the path . open the file in vi editor.
d: You will find [mysqld] inside this file
e: Just add one line below this

max_connections=NewValue
f: restart the db.
g: login to the mysql and run the following query to check the value of max_connection

show variables like "max_connections";

No comments:

Post a Comment