Hi,
I have been ripping my hair out trying to get my Golang API to parse a MySQL database columns through gorm and have gotten nowhere when it comes to the entries that have foreign language values. There doesn’t seem to be any guides on this anywhere online so I’m hoping I can get some help here.
I’ve got a database that has many tables containing Japanese characters. For example, I have this string in one of the rows:
美味しい
However, when doing a SELECT on the database for this entry that has this text value, it keeps coming back as:
美味ã—ã„
I’ve ensured the database is correctly created with utf8mb4 and even have this particular column set with CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
on the table. For my call to gorm.Open
, I’ve set the following parameters at the end to ensure that it’s parsing utf8mb4: ?charset=utf8mb4&parseTime=true
How can I get Golang to support UTF8 properly when the database is properly set?
If it helps, here’s the UTF8 is in the database as expected:
mysql> select alt_text from picture_details where id=136;
+--------------+
| alt_text |
+--------------+
| 美味しい |
+--------------+
1 row in set (0.00 sec)
And yes, I’ve tried to change the text to a manually encoded string of \xe7\xbe\x8e\xe5\x91\xb3\xe3\x81\x97\xe3\x81\x84
just to see if that’d resolve it (it didn’t).
Thanks!