MySQL compares Japanese characters in a query as question marks

I have a MySQL database with some varchar fields that may contain latin characters or japanese characters. There are records containing Japanese characters, this is not a problem. However, from my C # code using MySqlConnection , I was not able to get the correct results using Japanese characters in my WHERE clauses. He seems to be comparing Japanese characters as if they are question marks. For example, a query with WHERE series_title LIKE '%未来警%' does not return a value where series_title contains "未来 警", but instead returns all records in which series_title contains "???".

Some information:

  • series_title is varchar(150) with utf8_general_ci sort.
  • ConnectionString for MySqlConnection includes a pair of kv CharSet=utf8_general_ci
  • the database contains Japanese characters and is able to return them to the C # client - these are only problems when Japanese characters are sent to it
+4
source share
2 answers

Try adding charset=utf8 to the connection string:

server=server;uid=my_user;password=pass;database=db;charset=utf8;

EDIT:

Try to execute this sql after connecting:

SET NAMES utf8

+4
source

I would guarantee the preservation of your data using the right encoding . For the Japanese, you can try eucjp and you can find out more than you wanted to know about character encoding here . It looks like you might need a spec . Good luck and let me know how you are doing.

0
source

Source: https://habr.com/ru/post/1469404/


All Articles