Python 3 使用PyMySQL连接Inception 问题


PyMySQL 连接Inception ,在判断版本时会出现value error 问题。原因是pymysql通过‘.’进行分割,但是Inception的版本信息是这样的

./mysql -V

 Ver 14.14 Distrib Inception2.1.50, for Linux (x86_64) using  EditLine wrapper

Oracle mysql的版本是:

mysql  Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using  EditLine wrapper

因此Pymysql获取到的值为Inception2,最后int() 报value error。

可以简单修改pymysql connections.py(只是解决了问题,对具体代码还不是很了解)

    def _request_authentication(self):
        # https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse
        if self.server_version.split('.', 1)[0] == 'Inception2':
            self.client_flag |= CLIENT.MULTI_RESULTS
        elif int(self.server_version.split('.', 1)[0]) >= 5:
            self.client_flag |= CLIENT.MULTI_RESULTS

使用Pymysql connection配置可以是下面这样

 conn = pymysql.connect(host='127.0.0.1',
              user='',
              passwd='',
              db='',
              port=6669,
              autocommit=True,
              cursorclass=pymysql.cursors.DictCursor,
              charset='utf8mb4'
              )

相关内容