Good day everyone! The situation is as follows: I wrote a script to work with mySQL database, the data in which is stored as utf8, the script works, but when inserting utf8 data that is taken from another table, stumbles about an error 1064 mySQL, I don’t understand the characters' \ xd0 \ xbd \ xd0 \ xb0 '. Here is the script itself:
import MySQLdb class mSQLDatabase: __host = 'localhost' __user = 'root' __passwd = '' __selectedDB = 'Database1' __receivedDB = 'Database2' __selectedconn = None __receivedconn = None def __init__(self): self.__selectedconn = MySQLdb.connect(self.__host,self.__user,self.__passwd,self.__selectedDB,use_unicode=True, charset='utf8') self.__receivedconn = MySQLdb.connect(self.__host,self.__user,self.__passwd,self.__receivedDB,use_unicode=True, charset='utf8') def insert(self, query): print(query) cursor = self.__receivedconn.cursor() cursor.execute(query) self.__receivedconn.commit() def query(self, query): cursor = self.__selectedconn.cursor(MySQLdb.cursors.DictCursor) cursor.execute(query) return cursor.fetchall() #!/usr/bin/env python import DatabaseClass import codecs db = DatabaseClass.mSQLDatabase() db = DatabaseClass.mSQLDatabase() query = db.query("select din from S_Din") myset = set() for row in query: myset.add(row.values()[0]) for name in myset: print(name) db.insert("INSERT INTO `Database2`.`discipline` (`name`) VALUES (%s)" %(name))