Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Impossible to use utf8mb3 #1126

Closed
Closed
@mixmind

Description

@mixmind

Describe the bug
I have old db that should be migrated to new mariadb server, after data migration I failed to connect to it because of collate that db was created.

Traceback (most recent call last):
  File "/root/test.py", line 23, in <module>
    mysqlconnect()
  File "/root/test.py", line 6, in mysqlconnect
    conn = pymysql.connect(
  File "/opt/venv/lib/python3.9/site-packages/pymysql/connections.py", line 310, in __init__
    self.encoding = charset_by_name(self.charset).encoding
AttributeError: 'NoneType' object has no attribute 'encoding'

To Reproduce
Complete steps to reproduce the behavior:
Create a database with the required charset, and use this code to connect to it:

Schema:

CREATE DATABASE db /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci */;

Code:

  
def mysqlconnect():
    # To connect MySQL database
    conn = pymysql.connect(
        host='localhost',
        user='root', 
        db='db',
        charset="utf8mb3"
        )
      
    cur = conn.cursor()
    cur.execute("select @@version")
    output = cur.fetchall()
    print(output)
      
    # To close the connection
    conn.close()
  
# Driver Code
if __name__ == "__main__" :
    mysqlconnect()

Expected behavior
I can connect to db as usual.

Environment

  • OS: Linux ubuntu 22
  • Server and version: 10.6.12-MariaDB-0ubuntu0.22.04.1-log
  • PyMySQL version: PyMySQL==1.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions