无法与PyMySQL建立远程连接(pymysql.err.InternalError:数据包序列号错误) [英] Cannot make remote connection with PyMySQL (pymysql.err.InternalError: Packet sequence number wrong)

查看:1661
本文介绍了无法与PyMySQL建立远程连接(pymysql.err.InternalError:数据包序列号错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:问题已解决,解决方案发布在下面

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:数据包序列号错误-预期值为80

我在PyCharm中运行MacOS 10.12.5,Python 2.7.10(也已在Terminal上尝试过),和PyMySQL 0.7.11(也尝试过0.7.9)

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)

更新:也在Windows 10,Python 2.7.13上尝试过,结果相同

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

数据库托管在cPanel上。在连接之前,也许还有其他设置需要更改。连接用户具有完全特权。我的IP已添加到主机访问列表中。

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.

其他说明:如端口号或主机IP随机更改,它立即拒绝连接。否则,大约需要30秒才会出现数据包序列错误。

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)


推荐答案

虽然主机使用端口2083,但是在这种情况下,每个数据库都使用默认端口3306。

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

使用3306测试时,访问被拒绝,直到我将拒绝的IP添加到cPanel上的远程MySQL的主机访问列表中为止。

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

这篇关于无法与PyMySQL建立远程连接(pymysql.err.InternalError:数据包序列号错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆