MySQL ERROR 2003 (HY000): Can't connect to MySQL server on 편집하기

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
4번째 줄: 4번째 줄:
==문제상황==
==문제상황==
*[[MySQL에 원격 접속 허용]]하였으나 접속 안됨
*[[MySQL에 원격 접속 허용]]하였으나 접속 안됨
<syntaxhighlight lang='console'>
<source lang='console'>
[root@zetawiki ~]# mysql -h135.79.246.80 -uroot -pP@ssw0rd
[root@zetawiki ~]# mysql -h135.79.246.80 -uroot -pP@ssw0rd
ERROR 2003 (HY000): Can't connect to MySQL server on '135.79.246.80' (111)
ERROR 2003 (HY000): Can't connect to MySQL server on '135.79.246.80' (111)
</syntaxhighlight>
</source>


==클라이언트측 확인==
==클라이언트측 확인==
<syntaxhighlight lang='console'>
<source lang='console'>
[root@zetawiki ~]# nmap 135.79.246.80 -p 3306 -Pn
[root@zetawiki ~]# nmap 135.79.246.80 -p 3306 -Pn


20번째 줄: 20번째 줄:


Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds
Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds
</syntaxhighlight>
</source>
<syntaxhighlight lang='console'>
<source lang='console'>
[root@zetawiki ~]# nc -z 135.79.246.80 3306
[root@zetawiki ~]# nc -z 135.79.246.80 3306
[root@zetawiki ~]# telnet 135.79.246.80 3306
[root@zetawiki ~]# telnet 135.79.246.80 3306
Trying 135.79.246.80...
Trying 135.79.246.80...
telnet: connect to address 135.79.246.80: Connection refused
telnet: connect to address 135.79.246.80: Connection refused
</syntaxhighlight>
</source>
:→ 방화벽에 막히지는 않았으나 서버가 거부
:→ 방화벽에 막히지는 않았으나 서버가 거부


==서버측 확인==
==서버측 확인==
<syntaxhighlight lang='console'>
<source lang='console'>
root@jmnote02:~# netstat -antp | grep mysql
root@jmnote02:~# netstat -antp | grep mysql
tcp        0      0 127.0.0.1:3306          0.0.0.0:*              LISTEN      2593/mysqld   
tcp        0      0 127.0.0.1:3306          0.0.0.0:*              LISTEN      2593/mysqld   
</syntaxhighlight>
</source>
:→ 3306 포트가 로컬호스트(127.0.0.1)에 대해서만 열려 있음
:→ 3306 포트가 로컬호스트(127.0.0.1)에 대해서만 열려 있음
<syntaxhighlight lang='console'>
<source lang='console'>
root@jmnote02:~# grep ^bind-address /etc/mysql/my.cnf  
root@jmnote02:~# grep ^bind-address /etc/mysql/my.cnf  
bind-address = 127.0.0.1
bind-address = 127.0.0.1
</syntaxhighlight>
</source>


==my.cnf 수정==
==my.cnf 수정==
*[[my.cnf]]를 열어 bind-address를 주석처리한다.
*[[my.cnf]]를 열어 bind-address를 주석처리한다.
<syntaxhighlight lang='bash'>
<source lang='bash'>
vi /etc/mysql/my.cnf  
vi /etc/mysql/my.cnf  
</syntaxhighlight>
</source>
;변경 전
;변경 전
<syntaxhighlight lang='aconf'>
<source lang='aconf'>
# Instead of skip-networking the default is now to listen only on
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
bind-address            = 127.0.0.1
</syntaxhighlight>
</source>
;변경 후
;변경 후
<syntaxhighlight lang='aconf'>
<source lang='aconf'>
# Instead of skip-networking the default is now to listen only on
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# localhost which is more compatible and is not less secure.
#bind-address            = 127.0.0.1
#bind-address            = 127.0.0.1
</syntaxhighlight>
</source>


==MySQL 재시작 및 확인==
==MySQL 재시작 및 확인==
<syntaxhighlight lang='console'>
<source lang='console'>
root@jmnote02:~# service mysql restart
root@jmnote02:~# service mysql restart
mysql stop/waiting
mysql stop/waiting
mysql start/running, process 3432
mysql start/running, process 3432
</syntaxhighlight>
</source>
<syntaxhighlight lang='console'>
<source lang='console'>
root@jmnote02:~# netstat -antp | grep mysql
root@jmnote02:~# netstat -antp | grep mysql
tcp        0      0 0.0.0.0:3306            0.0.0.0:*              LISTEN      3432/mysqld
tcp        0      0 0.0.0.0:3306            0.0.0.0:*              LISTEN      3432/mysqld
</syntaxhighlight>
</source>
:→ 이제 모든 IP에서 접속 가능
:→ 이제 모든 IP에서 접속 가능


==클라이언트측 확인 2==
==클라이언트측 확인 2==
<syntaxhighlight lang='console'>
<source lang='console'>
[root@zetawiki ~]# nc -z 135.79.246.80 3306
[root@zetawiki ~]# nc -z 135.79.246.80 3306
Connection to 135.79.246.80 3306 port [tcp/mysql] succeeded!
Connection to 135.79.246.80 3306 port [tcp/mysql] succeeded!
</syntaxhighlight>
</source>
<syntaxhighlight lang='console'>
<source lang='console'>
[root@zetawiki ~]# mysql -h135.79.246.80 -uroot -pP@ssw0rd
[root@zetawiki ~]# mysql -h135.79.246.80 -uroot -pP@ssw0rd
Welcome to the MySQL monitor.  Commands end with ; or \g.
Welcome to the MySQL monitor.  Commands end with ; or \g.
90번째 줄: 90번째 줄:


mysql>
mysql>
</syntaxhighlight>
</source>


==기타 다른 원인?==
==기타 다른 원인?==
96번째 줄: 96번째 줄:
:예: 다른 곳으로 3306 포트 접근이 막힌 경우
:예: 다른 곳으로 3306 포트 접근이 막힌 경우
*클라이언트측과 MySQL 버전이 서로 상이하면 막힘
*클라이언트측과 MySQL 버전이 서로 상이하면 막힘
:본적이 없는데 어떤 버전이 그런가요? --[[사용자:Jmnote|Jmnote]] ([[사용자토론:Jmnote|토론]]) 2016년 8월 19일 (금) 16:23 (KST)
:본적이 없는데 어떤 버전이 그런가요? --[[사용자:Jmnote|Jmnote]] ([[사용자토론:Jmnote|토론]]) 2016년 8월 19일 (금) 16:23 (KST)


==같이 보기==
==같이 보기==

제타위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 제타위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)

이 문서에서 사용한 틀: