본문 바로가기
MySql

MySQL Python MySQLdb 연결을위한 SSH 터널

by 베이스 공부 2020. 11. 10.
반응형

다음을 사용하여 SSH 터널을 만들어 보았습니다.

ssh -L 3306:localhost:22 <hostip>

그런 다음 내 Python 스크립트를 실행하여 localhost를 통해 연결

conn = MySQLdb.connect(host'localhost', port=3306, user='bob', passwd='na', db='test')

그러나 다음과 같은 오류가 발생합니다.

(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")

바인드 문제뿐만 아니라 올바른 호스트에 연결되었는지 어떻게 확인할 수 있습니까?

 

해결 방법

 


UNIX 소켓 및 명명 된 파이프는 그렇지 않습니다. work over a network, so if you specify a host other than localhost, TCP will be used, and you can specify an odd port if you need to (the default port 3306) :

db = _mysql.connect (host = "outhouse", port = 3307, passwd = "moonpie", db = "thangs")

정말 그래야만했다면 connect to the local host with TCP by specifying the full host name, or 127.0.0.1 .

 

참조 페이지 https://stackoverflow.com/questions/3577555

 

 

반응형

댓글