mysql 使用utf8编码_使用RMySQL的UTF8编码

bd96500e110b49cbb3cd949968f18be7.png

I am trying to query data from a mysql database, which contains some strings, of course. For the connection and data retrieval I am using RMySQL in R, which works fine. Apart from one thing: the strings I am retrieving seem not to be in utf8. But I need this, because I have some german "Umlaute" in these strings.

When I ask teh databse, which are its encoding by

dbGetQuery(db, "SHOW VARIABLES LIKE 'character_set_%';")

I get the desired answer:

Variable_name Value

1 character_set_client utf8

2 character_set_connection utf8

3 character_set_database utf8

4 character_set_filesystem binary

5 character_set_results utf8

6 character_set_server utf8

7 character_set_system utf8

8 character_sets_dir C:\\Program Files\\MySQL\\MySQL Server 5.7\\share\\charsets\\

But e.g. I receive

Andreas Wünsche

instead of

Andreas Wünsche

Hope that somebody knows how to deal with it. If additonal information is needed, just ask. I can provide it.

解决方案

I find something a bit tricky but works for me :

you have to manually define the col of your data frame to utf-8 like this :

x

Encoding(x)

x

[1] "Wünsche"

Think you have to do this to all your strings vector

EDIT :

Take a look here

seems to fix the same problem by adding 'set character set "utf8"'inside the dbSendQuery()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值