0

I have mysql table which has UTF-8 characters stored in some columns. The table was created with the DEFAULT CHARSET=utf8;

If I manually run the select statement I can see the UTF-8 characters but if I use the golang client and use the DB.Query method then I see that the characters are all garbled !

Also, the insert was done from the golang client as well. How come the insert was fine and the read is making it garbled ? I couldn't see any parameters to set the character set while making the query. What am I missing ?

Crusaderpyro
  • 2,163
  • 5
  • 29
  • 53
  • 2
    Client charset is a part of the connection procedure. Show how you're connecting to the databse. – zerkms Oct 25 '17 at 03:32
  • There are about 5 different "garblings", which one did you get? Possibly the answer is here: https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Oct 27 '17 at 14:47

1 Answers1

0

So when the rows were inserted into the DB, the client charset was latin1. And the golang client by default was using utf8. Inserted all the rows again using utf8 and now the golang utf8 client seems to be reading the characters fine !

For others who come across similar problems:

The following command tells the current configuration

mysql> status

The following command sets the client character set. Run it before insert statements.

mysql> set names utf8

Crusaderpyro
  • 2,163
  • 5
  • 29
  • 53
  • 1
    That's not the exactly correct way of doing it: there should be a connection option to specify a charset. – zerkms Oct 25 '17 at 07:48