R连接mysql乱码,看清是查询语句在r软件里是正常的,穿到mysql就乱码了,郁闷!!!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R连接mysql乱码,看清是查询语句在r软件里是正常的,穿到mysql就乱码了,郁闷!!!相关的知识,希望对你有一定的参考价值。
好烦~各位童鞋我的乱码不是查询后字符编码不对,是我用RODBC连接mysql后sqlquery()方法里的中文到了mysql里就变成乱码了,我的obdc和r软件都设置了utf8,mysql也设了utf8,啊啊啊啊好烦~~~下面是控制台输出
> print(paste("select building_area,unit_price from sheet1_copy where project = '","万泉寺东里","'",sep = ""));
[1] "select building_area,unit_price from sheet1_copy where project = '万泉寺东里'"
> sqlQuery(channel = channel,paste("select building_area,unit_price from sheet1_copy where project = '","万泉寺东里","'",sep = ""));
[1] "42000 1064 [MySQL][ODBC 5.3(w) Driver][mysqld-5.7.11-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''涓囨硥瀵轰笢阅?' at line 1"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'select building_area,unit_price from sheet1_copy where project = '涓囨硥瀵轰笢阅\x8c''"
> sqlQuery(channel = channel,"select building_area,unit_price from sheet1_copy where project = '万泉寺东里'");
[1] "42000 1064 [MySQL][ODBC 5.3(w) Driver][mysqld-5.7.11-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''涓囨硥瀵轰笢阅?' at line 1"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'select building_area,unit_price from sheet1_copy where project = '涓囨硥瀵轰笢阅\x8c''"
> sqlQuery(channel = channel,paste("select building_area,unit_price from sheet1_copy where project = '","万泉寺东里","'",sep = ""));
[1] "42000 1064 [MySQL][ODBC 5.3(w) Driver][mysqld-5.7.11-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''涓囨硥瀵轰笢阅?' at line 1"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'select building_area,unit_price from sheet1_copy where project = '涓囨硥瀵轰笢阅\x8c''"
> sqlQuery(channel = channel,"select building_area,unit_price from sheet1_copy where project = '万泉寺东里'");
[1] "42000 1064 [MySQL][ODBC 5.3(w) Driver][mysqld-5.7.11-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''涓囨硥瀵轰笢阅?' at line 1"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'select building_area,unit_price from sheet1_copy where project = '涓囨硥瀵轰笢阅\x8c''"
>
跪求大神指点啊~~~~~~~~~~~~~~~~~~~~~
我已经说了。。。。odbc,mysql,R,都设置了utf8,你看清楚好么。。。
追答把字符串单独拿出来转码
String s=new String(“内容”,"utf-8");试试
已经好了,我把R客户端重启了,应该是设置了但是没有及时生效,真是日了狗了。还是谢谢你的帮助。
本回答被提问者采纳以上是关于R连接mysql乱码,看清是查询语句在r软件里是正常的,穿到mysql就乱码了,郁闷!!!的主要内容,如果未能解决你的问题,请参考以下文章