2

I have the following query in MySQL workbench:

SELECT japanese
FROM my_table
where japanese = 'する' COLLATE  utf8mb4_ja_0900_as_cs;

When I try to pass the same query through the mysql.connector it blows up:

sql_query = 'SELECT japanese FROM my_table WHERE japanese = %s COLLATE  utf8mb4_ja_0900_as_cs LIMIT 1'

my_variable = (word_to_search,)
mycursor1.execute(sql_query,my_variable)
sql_excecuted = mycursor1.fetchall()

And I get the following error message:

mysql.connector.errors.ProgrammingError: 1253 (42000): COLLATION 'utf8mb4_ja_0900_as_cs' is not valid for CHARACTER SET 'utf8'

In the documentation it says to update your connector settings, and I tried this:

mydb = mysql.connector.connect(host = "localhost", user = 'root',pwrd='123',database ='app')
mydb.set_charset_collation('utf8mb4_ja_0900_as_cs')

And get this error message:

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

I'm feeling I'm in a catch-22 situation, there have been other issues with this program that have driven me to use the utf-8 character set. At the end of the day I'm reading a .txt file and creating an html document and am open to any character set that will allow the Japanese fonts to display correctly AND that I can search the db properly with.

Can someone help me understand the correct character set to use in this situation please?

Thank you!

2
  • mydb.set_charset_collation('utf8mb4_bin') ? Commented Jul 27, 2019 at 13:25
  • 1
    @LukaszSzozda - You've been a saint to me this morning, thank you! Here's the error message I get: mysql.connector.errors.ProgrammingError: Character set 'utf8mb4_bin' unsupported. Commented Jul 27, 2019 at 13:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.