Python 3 使用PyMySQL串連Inception 問題

來源:互聯網
上載者:User

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'
              )

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.