萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> mysql 1040錯誤提示Too many connections的解決方法

mysql 1040錯誤提示Too many connections的解決方法

最簡單的辦法是因為你的my.ini中設定的並發連接數太少或者系統繁忙導致連接數被占滿 解決方式:打開MYSQL安裝目錄打開MY.INI找到max_connections默認是100 .

實例

WINDOWS解決MYSQL Errno.: 1040錯誤
XXXX info: Can not connect to MySQL server

User: root
Time: 2004-5-20 3:00pm
Script: /XXXX/XXXX.php

Error: Too many connections
Errno.: 1040

An error report has been dispatched to our administrator.

 
上面錯誤觀點提示


1.可能是mysql的max connections設置的問題
2.可能是多次insert,update操作沒有關閉session,需要在spring裡配置transaction支持。

解決:
1.修改tomcat裡的session 的time-out時間減少為20,(不是必改項)
2.對處理量大的對數據庫insert或update的操作提供transaction支持.

=======================================
下面的是解決辦法:

 代碼如下 復制代碼 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"

原因:

因為你的mysql安裝目錄下的my.ini中設定的並發連接數太少或者系統繁忙導致連接數被占滿


解決方式:

打開MYSQL安裝目錄打開MY.INI找到max_connections(在大約第93行)默認是100 一般設置到500~1000比較合適,重啟mysql,這樣1040錯誤就解決啦。
max_connections=1000

一定要重新啟動MYSQL才能生效

 代碼如下 復制代碼

CMD->

net stop mysql

net start mysql

 

關於改變innodb_log_file_size後無法啟動mysql的問題

 

 代碼如下 復制代碼 innodb_buffer_pool_size=768M
innodb_log_file_size=256M
innodb_log_buffer_size=8M
innodb_additional_mem_pool_size=4M
innodb_flush_log_at_trx_commit=0
innodb_thread_concurrency=20

以上是對innodb引擎的初步優化, 發現是更新innodb_log_file_size=256M時候出現了問題,只要加上這個就無法啟動,

 後來才知道原來要STOP服務先,然後再刪除原來的文件………
打開/MySQL Server 5.5/data

刪除ib_logfile0, ib_logfile1........ib_logfilen
再開啟選項,成功啟動。


高手優化的MYSQL my.ini的1000人在線配置。

 代碼如下 復制代碼

#This File was made using the WinMySQLAdmin 1.4 Tool
#2004-2-23 16:28:14
#Uncomment or Add only the keys that you know how works.
#Read the MySQL Manual for instructions
[mysqld]
basedir=D:/mysql
#bind-address=210.5.*.*
datadir=D:/mysql/data
#language=D:/mysql/share/your language directory
#slow query log#=
#tmpdir#=
#port=3306
set-variable = max_connections=1500
skip-locking
#skip-networking
set-variable = key_buffer=384M
set-variable = max_allowed_packet=1M
set-variable = table_cache=512
set-variable = sort_buffer=2M
set-variable = record_buffer=2M
set-variable = thread_cache=8
# Try number of CPU's*2 for thread_concurrency
set-variable = thread_concurrency=8
set-variable = myisam_sort_buffer_size=64M
#set-variable = connect_timeout=5
#set-variable = wait_timeout=5
server-id = 1
[isamchk]
set-variable = key_buffer=128M
set-variable = sort_buffer=128M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[myisamchk]
set-variable = key_buffer=128M
set-variable = sort_buffer=128M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[WinMySQLadmin]
Server=D:/mysql/bin/mysqld-nt.exe

copyright © 萬盛學電腦網 all rights reserved