MySQL 5 - 如何检查最大数量和更改最大连接数?

时间:2017-09-03 22:29:46

标签: java mysql spring

使用的是在后端使用MySQL5的传统Spring 4应用程序。

使用原始Spring JDBC调用时,一堆DAO会抛出以下异常:

DAO::org.springframework.jdbc.CannotGetJdbcConnectionException: 
Could not get JDBC Connection; nested exception is

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:

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

在使用Google搜索网页后,我得到了很多不同的解决方案选择,所以我只想问这里。

尝试使用以下方法进行故障排除:

当我在数据库中发出以下命令时:

    show status like 'Conn%';

收率:

Connection_errors_accept            0
Connection_errors_internal          0
Connection_errors_max_connections   395711
Connection_errors_peer_address      2
Connection_errors_select            0
Connection_errors_tcpwrap           0
Connections                         423604612

另一个SQL调用:

show status like '%onn%';

收率:

Aborted_connects                    6857
Connection_errors_accept            0
Connection_errors_internal          0
Connection_errors_max_connections   395711
Connection_errors_peer_address      2
Connection_errors_select            0
Connection_errors_tcpwrap           0
Connections                         423605165
Max_used_connections                1001
Performance_schema_session_connect_attrs_lost   0
Ssl_client_connects                 0
Ssl_connect_renegotiates            0
Ssl_finished_connects               0
Threads_connected                   12

问题(S):

  1. MySQL可以设置的最大连接数是多少,而不会造成任何破坏或进一步的性能问题?

  2. 检查了这样的最大连接数:

    显示“max_connections”;

  3. 等变量

    收率:

    max_connections 1000
    

    互联网上的很多文章都说我需要在数据库服务器下的my.cnf文件中授予/编辑max_connectionsmax_user_connections。另外,请阅读我可以这样的事情:

    mysql> SET GLOBAL max_connections = 3000;
    

    对此问题采取的最佳做法是什么?

    是否只是简单地以root身份授予/编辑数据库服务器下my.cnf文件中的max_connections和max_user_connections?或者,需要更多步骤吗?

0 个答案:

没有答案