0

I have my mariadb where I have some text on russian language(which I add by INSERT INTO test VALUES(1, "Абвг Деёжзий", "2138712894-213123", true)) And I have my python code:

import MySQLdb
connection=MySQLdb.connect(user="t", password="t", host="127.0.0.1", database="project")
cursor = connection.cursor()
cursor.execute("SELECT * FROM test;")
for a,b,c,d in cursor:
    print(a,b,c,d)

And as the output I have this:

1 ???? ??????? 2138712894-213123 1

(Where ???? ??????? is one string with space on russian) I tried SET CHARACTER SET utf8 and SET NAMES utf8 but I didn't have the right output. What should I do to get the text.

3 Answers3

1

You should be able to use the charset option in the connect function..

connection=MySQLdb.connect(
   user="t"
 , password="t"
 , host="127.0.0.1"
 , database="project"
 , charset="utf8"
)
Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34
0

Kindly try SET NAMES utf8

It works with MYSQL and should work with MariaDB as well. For the MariaDB KnowledgeBase

Sets the character_set_client, character_set_connection, character_set_results and, implicitly, the collation_connection session system variables to the specified character set and collation.

This determines which character set the client will use to send statements to the server, and the server will use for sending results back to the client.

Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53
0

Notes on Python: http://mysql.rjweb.org/doc.php/charcoll#python

Most notable: Start the source code with

# -*- coding: utf-8 -*-

If that does not suffice, follow the tips in Trouble with UTF-8 characters; what I see is not what I stored for "question marks".

If you need even more debugging, note that the hex encoding for Абвг in utf8 (or utf8mb4) is D090 D0B1 D0B2 D0B3.

Rick James
  • 135,179
  • 13
  • 127
  • 222