Reputation: 2491
I have connected to a MySQL database from R and ran the "set names utf8" directive.
library(RMySQL)
con<-dbConnect(MySQL(), user='john', password='secret', dbname='awesome', host='myhost')
dbSendQuery(con, "SET NAMES UTF8; ")
This usually does the trick when I want UTF8 data back from my queries. However a quick check shows that not all variables have been set correctly
dbGetQuery(con, "SHOW VARIABLES LIKE 'character_set_%'")
# Variable_name Value
#1 character_set_client latin1
#2 character_set_connection latin1
#3 character_set_database utf8
#4 character_set_filesystem binary
#5 character_set_results latin1
#6 character_set_server latin1
#7 character_set_system utf8
Here it's obvious that the character_set_client variable has not been set. It doesn't help to set it explicitly either. In fact it seems like it completely ignores it.
dbSendQuery(con, "SET character_set_client=utf8; ")
dbGetQuery(con, "SHOW VARIABLES LIKE 'character_set_%'")
# Variable_name Value
#1 character_set_client latin1
#2 character_set_connection latin1
#3 character_set_database utf8
#4 character_set_filesystem binary
#5 character_set_results latin1
#6 character_set_server latin1
#7 character_set_system utf8
How can I set this and make the connection return UTF8 encoded text? The schema is using the utf8 encoding and collation.
Upvotes: 0
Views: 1445
Reputation: 3438
There's a handshake that happens, and the client ends up telling the MySQL to use latin1
. It is possible to disable the handshake, or on initial connection SET NAMES utf8
.
Upvotes: 1