In a MySQL database, a table is encoded in utf8, but for some reason the connection is in latin1.
res <- RMySQL::dbSendQuery(con,"show variables like 'character_set_%'")
dbFetch(res)
Variable_name Value
1 character_set_client latin1
2 character_set_connection latin1
3 character_set_database utf8mb4
4 character_set_filesystem binary
5 character_set_results latin1
6 character_set_server latin1
7 character_set_system utf8
8 character_sets_dir /usr/share/mysql/charsets/
This page explain how to set the connection's character set to utf8 using RMySQL.
RMySQL::dbGetQuery(con,"show variables like 'character_set_%'")
RMySQL::dbGetQuery(con,"set names utf8")
But I actually prefer to use the dplyr::tbl
to query the database. Since the connection created by dplyr::src_mysql
only has the possibility to send sql statements that create tables. What is the dplyr way to set the connection setting to use utf8 encoding?
iconv()
but it is a hack and I would rather read character vectors directly in utf8. Especially because the database is already in utf8. – Unscreenedskip-character-set-client
in /etc/mysql/my.cf – Unscreened