Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Character set 'utf8' unsupported in python mysql connector

I'm trying to connect my database to a python project using the MySQL connector.

However, when using the code below,

import mysql.connector

mydb =  mysql.connector.MySQLConnection(
  host="localhost",
  user="veensew",
  password="%T5687j5IiYe"
)

print(mydb)

I encounter the following error:

mysql.connector.errors.ProgrammingError: Character set 'utf8' unsupported

I tried to find out why this is happening and I'm getting the same error always.

MySQL Connector version - 8.0.30

I'd appreciate any help. Thank you in advanced!

like image 297
Veen Avatar asked Dec 21 '25 15:12

Veen


2 Answers

I ran into the same issue. There were apparently some changes in version 8.0.30 to the way utf8_ collations are handled (see MySQL Connector release notes). I installed version 8.0.29 which fixed the issue for me.

pip3 install mysql-connector-python==8.0.29
like image 186
Niklas Avatar answered Dec 23 '25 04:12

Niklas


If you are using a MySQL connector to connect a MariaDB server, you have to switch to the correct connector:

  1. install MariaDB connector:
$ pip3 install mariadb
  1. change your code to add import mariadb and mariadb.connect. After this step your code should be as the following:
import mariadb
    
mydb =  mariadb.connect(
  host="localhost",
  user="veensew",
  password="%T5687j5IiYe"
)

print(mydb)

And voila :)

/!\ Do not downgrade to an older MySQL connector, some other day you will have more problems...

like image 27
Ricain Avatar answered Dec 23 '25 04:12

Ricain