R-特殊字符未插入mysql [英] R- Special Characters are not inserting in mysql

查看:105
本文介绍了R-特殊字符未插入mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用R编程将特殊字符插入MySQL?

How to insert the special characters into MySQL using r programming?

我有一个数据框,它将从tsv文件中读取数据.我想将这些值插入到包含2000行的mysql数据库数据框中.但是它仅插入23行.我正在使用RODBC库.

I have a data frame which will read data from a tsv file. I want to insert these values into mysql database data frame contains 2000 rows. But it is inserting only 23 rows. I am using RODBC library.

问题出在数据中的特殊字符.

The problem was the special characters inside the data.

示例数据:

  1. 莫桑比克
  2. 索尼的

错误:

Error in sqlSave(conn, data4, "test.solution8", append = TRUE, verbose = TRUE,  : 
      [RODBC] Failed exec in Update
    HY000 1366 [MySQL][ODBC 5.2(w) Driver][mysqld-5.6.11]Incorrect string value: '\xE7a a m...' for column 'fullcontent' at row 1

推荐答案

您的数据库,程序和连接均具有编码.

Your database, program and the connection each have an encoding.

确保您的连接使用与数据库相同的编码

Make sure your connection uses the same encoding as your database

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

此处的问题中也对此进行了讨论.

This was also discussed in this question here.

这篇关于R-特殊字符未插入mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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