如何在RODBC中为MySQL设置字符集? [英] How to set charset for MySQL in RODBC?

查看:124
本文介绍了如何在RODBC中为MySQL设置字符集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有汉字的数据作为字段名称和数据,我已经从xls导入了它们以访问2007,并将它们导出到ODBC.然后,我使用RODBC在R中读取它们,字段名称确定,但是对于数据,所有的中文字符都显示为?.

I have a data with chinese characters as field names and data, I have imported them from xls to access 2007 and export them to ODBC. Then I use RODBC to read them in R, the field names is OK, but for the data, all of the chinese characters are shown as ?.

我已阅读 RODBC手册并说:

If it is possible to set the DBMS or ODBC driver to communicate in the character set of the R session then this should be done. For example, MySQL can set the communication character set via SQL, e.g. SET NAMES 'utf8'.

我猜这是问题所在,但是如何通过RODBC将这个命令提供给MySQL?谢谢!

I guess this is the problem, but how can I provide this command to MySQL via RODBC? Thanks!

推荐答案

我刚刚找到了解决方法.不知道我是否可以发布.

I just found the cure. Don't know if I can post.

  1. 将MySQL数据库设置为基于UTF-8;

  1. Set up the MySQL database to be UTF-8 based;

设置ODBC DSN,并且不要设置字符集"选项.

Set up the ODBC DSN and do NOT set the "character set" option.

ch<-odbcConnect("mydb",DBMSencoding="UTF-8");

就是这样.

这篇关于如何在RODBC中为MySQL设置字符集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆