Fetching UTF-8 text from MySQL in R returns “????”

前端 未结 3 1702
逝去的感伤
逝去的感伤 2020-11-28 09:27

I\'m stuck trying to fetch UTF-8 text in a MySQL database from R. I\'m running R on OS X (tried both via the GUI and command line), where the default locale is en_US.UTF-8,

3条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 09:47

    Thanks to @chooban I found out the connection session was using latin1 instead of utf8. Here are two solutions I found:

    • For RMySQL, after connecting run the query SET NAMES utf8 to change the connection character set.
    • For RODBC, connect using CharSet=utf8 in the DSN string. I was not able to run SET NAMES via ODBC.

    This question pointed me in the right direction.

提交回复
热议问题