mysql too many connections 이 뜨는데 이거 우찌 해결하냐
ERROR 1040 (HY000): Too many connections
root@-10186:~# mysql -u root -p
Enter password:
ERROR 1040 (HY000): Too many connections
root@-10186:~# ^C
root@-10186:~# ^C
root@-10186:~# ^C
root@-10186:~# mysqladmin -u root -p variables | grep max_connections
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Too many connections'
root@-10186:~#
show status like 'threads_connected';
: 현재 연결되어있는 thread 수 확인
show variables like 'wait_timeout';
: 현재 지정된 wait_timeout 값 확인
show variables like 'max_connections';
: 현재 지정된 max_connections 값 확인
set global max_connections=500;
: max_connections 500으로 설정
set global wait_timeout=60;
: wait_timeout 60으로 설정 (초 단위)
wait_timeout
: 지정된 시간동안 mysql에서 응답이 없을경우 커넥션을 종료
max_connections
: mysql이 허용할 수 있는 클라이언트의 최대 연결 수. 많이 높아도 좋지 않다.
1. 현재 설정 값 확인해 보기
$ mysql -u root -p
mysql> use mysql
mysql> show variables like '%max_connection%';
결과 예) max_connections 151
mysql> show variables like 'wait_timeout';
결과 예) wait_timeout 28800
2. my.cnf 파일 수정
[ 참고 ] 만약 my.cnf 파일이 어디에 있는지 모르면 아래 명령어로 찾아보세요.
$ sudo find / -name my.cnf
[ 파일 수정 방법 ] sudo 로 관리자 권한 사용, vi 에디터를 이용하여 my.cnf 파일 수정.
$ sudo vi /etc/mysql/my.cnf
[mysqld] 을 찾아서 아래 내용을 추가합니다.
max_connections = 1000
interactive_timeout=300
wait_timeout = 300
3. MySQL 재시작 하기
$ sudo /etc/init.d/mysql restart
4. 재시작 후 설정 값 다시 확인해 보기
$ mysql -u root -p
mysql> use mysql
mysql> show variables like '%max_connection%';
결과 예) max_connections 1000
mysql> show variables like 'wait_timeout';
결과 예) wait_timeout 300