How to set encoding for MySQL in RODBC?

I have data with Chinese characters like field names and data, I imported them from xls for 2007 access and exported them to ODBC. Then I use RODBC to read them in R, the field names are fine, but for data, all Chinese characters are displayed as ?.

I read the RODBC manual and said:

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'.

I assume this is a problem, but how can I provide this MySQL command via RODBC? Thank!

+3
source share
2 answers

ODBC RODBC, , SET NAMES 'utf8'; MySQL SQL, , SQL, .

- ( ):

sqlQuery(myChannel, query = "SET NAMES 'utf8';")

myChannel - , odbcConnect().

, RODBC RMySQL? RMySQL R.

Update: , , , - , SET NAMES MySQL ODBC. , ( mysql MySQL GUI), , SET NAMES. MySQL:

A SET NAMES 'x' statement is equivalent to these three statements:

SET character_set_client = x;
SET character_set_results = x;
SET character_set_connection = x;

SQL SET NAMES , .

SET CHARACTER SET, , SET NAMES:


SET CHARACTER SET charset_name

SET CHARACTER SET SET NAMES, character_set_connection collation_connection character_set_database collation_database. SET CHARACTER SET x :

SET character_set_client = x;
SET character_set_results = x;
SET collation_connection = @@collation_database;

collation_connection c haracter_set_connection , ( SET character_set_connection = @@character_set_database). character_set_connection.


SET CHARACTER SET 'utf8'.

, / ? , - UTF8? Q. , MS Access, ODBC. , MySQL? , ODBC , / , , "".

MySQL? MS Access RODBC ?

MySQL, RMySQL .

+2

. , .

  • MySQL UTF-8;

  • DSN ODBC " ".

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

.

+2

Source: https://habr.com/ru/post/1784638/


All Articles