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

前端 未结 3 1694
逝去的感伤
逝去的感伤 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:58

    This worked for me. Here is a full example:

    con = dbConnect(drv = MySQL(), user = user, password = password,
                    dbname = dbname, host=host)
    
    dbSendQuery(con, "SET NAMES utf8mb4;")
    dbSendQuery(con, "SET CHARACTER SET utf8mb4;")
    dbSendQuery(con, "SET character_set_connection=utf8mb4;")
    
    
    dbGetQuery(con, "SELECT * FROM WHATEVER")
    

提交回复
热议问题