2017-05-11 1 views
0

파이썬 3.5를 통해 DB를 연결하는 동안이 문제에 대해 도움을받을 수있는 사람이 누구입니까? 오류 수신 후.Python 3 pymysql 데이터베이스 액세스 - 다음 오류가 발생하는 데이터베이스에 연결

import pymysql 

# Open database connection 
db = pymysql.connect("localhost","testuser","test123","TESTDB",) 

# prepare a cursor object using cursor() method 
cursor = db.cursor() 

# execute SQL query using execute() method. 
cursor.execute("SELECT VERSION()") 

# Fetch a single row using fetchone() method. 
data = cursor.fetchone() 

print ("Database version : %s " % data) 

# disconnect from server 
db.close() 

오류 :

RESTART: C:/Program Files (x86)/Python35-32/db_connect.py Traceback (most recent call last): File "C:\Program Files (x86)\Python35-32\lib\site-packages\pymysql-0.7.11-py3.5.egg\pymysql\connections.py", line 916, in connect **kwargs) File "C:\Program Files (x86)\Python35-32\lib\socket.py", line 712, in create_connection raise err File "C:\Program Files (x86)\Python35-32\lib\socket.py", line 703, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

위의 예외 처리하는 동안 또 다른 예외가 발생했습니다 :

Traceback (most recent call last): File "C:/Program Files (x86)/Python35-32/db_connect.py", line 4, in db = pymysql.connect("localhost","testuser","test123","TESTDB",) File "C:\Program Files (x86)\Python35-32\lib\site-packages\pymysql-0.7.11-py3.5.egg\pymysql__init__.py", line 90, in Connect return Connection(*args, **kwargs) File "C:\Program Files (x86)\Python35-32\lib\site-packages\pymysql-0.7.11-py3.5.egg\pymysql\connections.py", line 706, in __ init __ self.connect() File "C:\Program Files (x86)\Python35-32\lib\site-packages\pymysql-0.7.11-py3.5.egg\pymysql\connections.py", line 963, in connect raise exc pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([WinError 10061] No connection could be made because the target machine actively refused it)")

답변

0

당신이 MySQL이 가지고있는 help

The error (2003) Can't connect to MySQL server on 'server' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, and that the network port you specified is the one configured on the server.

검사에서 실행 중이고 해당 포트에서 연결을 시도하십시오 (기본값 3306)

관련 문제