Data Source rejected establishment of connection, message from server: "Too many connections"

Source: Internet
Author: User
Tags finally block

Cause of Error:

Too many connections, too many logged-in users, too few MySQL connections configured, or some connections not shutting down, resulting in too many connections.

Solution to the problem:

Modify the MySQL my.ini configuration file, the Internet says: MySQL installation directory My.ini set in the number of concurrent connections is too small or the system is busy resulting in a full number of connections.

And the project is actually deployed on the Linux system, need to find MY.CNF configuration file, general in Etc/my.cnf, find this file, add the following line:

set-variable=max_connections=1000
set-variable=max_user_connections=500

set-variable=wait_timeout=200

Then restart MySQL to take effect.

net stop MySQL

net start MySQL

Max_connections: To set the maximum number of connections

Max_user_connections: Set maximum number of connections per user 500

Wait_timeout: Indicates that the idle connection will be closed after 200 seconds, but the connection to the work is not affected.

After restarting MySQL, use the following command to see if the changes were successful

# mysqladmin-uroot-p variables

Password:

You can see the following entry indicating the success of the modification

| max_connections | 1000

| max_user_connections | 500

| Wait_timeout | 200

Workaround Two:

Another possibility is that too many connections are open in the code, but forgetting to close in the finally block causes exceptions to be thrown when processing big data. There is no exception to this code.

try{    Conn=good.getconnection ();    stmt = Conn.createstatement (resultset.type_scroll_insensitive, resultset.concur_updatable);String sql1="INSERT into cat_garbage values ('" +rs.getint ("id") +"', '" +rs.getint ("CID") +"', '" +rs.getstring ("Name") +"', '" +rs.getstring ("keyword") +"‘)"; Stmt.executeupdate (SQL1); }  catch (sqlexception| classnotfoundexception| IOException e) {   E.printstacktrace ();  }  finally   {   if (stmt!= null)     Stmt.close ();    if (conn!= null)     Conn.close ();  } 
to remember to close resources such as rs,stmt,conn at any time, learn to use Finally, and in finally, these statements are bound to execute

Data Source rejected establishment of connection, message from server: "Too many connections"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.