Cannot make remote connection with PyMySQL (pymysq

2019-01-29 10:15发布

问题:

update: Problem solved, solution posted below

I am new to the process of making remote database connections, but it seems that there tends not to be an obvious solution for this error.

pymysql.err.InternalError: Packet sequence number wrong - got 80 expected 0 arises when attempting to make the following pymysql connection

I'm running MacOS 10.12.5, Python 2.7.10 in PyCharm (also tried with Terminal), and PyMySQL 0.7.11 (also tried 0.7.9)

update: also tried on Windows 10, Python 2.7.13 with the same result

The database is hosted on cPanel. Perhaps there are additional settings to change before I can connect. The connecting user has full privileges. My IP was added to the host "access" list.

other notes: As might be expected, if the port number or host IP is randomly changed, it immediately refuses the connection. Otherwise, it takes about 30 seconds before the 'packet sequence' error to arise.

import pymysql.cursors
import pymysql

connection = pymysql.connect(host = hostIPaddress,
                             port = 2083,
                             user = username,
                             passwd = password,
                             db = dbName,
                             charset = 'utf8mb4', # also tried 'utf8'
                             cursorclass=pymysql.cursors.DictCursor)

回答1:

While the port 2083 is used by the host, each database uses the default port 3306 in this case.

When tested with 3306, access was denied until I added the denied IP to the host "access" list in Remote MySQL on cPanel.