mysql json_set多维,mysqlimport问题“设置@@ character_set_database = binary”;防止加载json值...

I have been using mysqlimport without problems for a long time, now as mysql 5.7 added json data type support, I'm trying to use mysqlimport with rows containing json data.

Here is an example of a row in csv file that will be imported using mysqlimport:

column_A_value,column_B_value,[{"x":20,"y":"some name"}]

Notice that the last column type is json. Now when using mysqlimport as the following:

mysqlimport -u user -ppass -h localhost --columns='col_A,col_B,col_C' --local --fields-terminated-by=',' some_db /path/to/products.txt

I got the following error: Cannot create a JSON value from a string with CHARACTER SET 'binary'., when using table: products

However using the generated LOAD DATA IN FILE instead of mysqlimport worked without problems! I opened mysql log and checked the generated LOAD DATA IN FILE command when running mysqlimport, then copied and pasted it, and it worked without problems! I ran something like:

LOAD DATA LOCAL INFILE '/path/to/products.txt'

INTO TABLE products

And it worked! The only difference is that in the log, when running mysqlimport this line was generated also

Query /*!40101 set @@character_set_database=binary */

Then LOAD DATA IN FILE command was generated, so that line is the source of the problem.

So anyway I tried setting character set to utf8,

mysqlimport -u user -ppass -h localhost --columns='col_A,col_B,col_C' --local --fields-terminated-by=',' --default-character-set=utf8 some_db /path/to/products.txt

but in vain, same error happened.

So any clue how to solve this character set issue please ?

解决方案

Check your character set configuration:

show variables like ‘%char%';

Not responding to --default-character-set might still be a bug of mysqlimport:

https://bugs.mysql.com/bug.php?id=29712

Possible Solutions:

Try SET NAMES utf8; before the import

Try using mysql with --default-character-set=utf8 instead of mysqlimport

Alter your my.cnf:

[mysqld]

init-connect='SET NAMES utf8'

character-set-server=utf8

collation-server=utf8_general_ci

default-character-set=utf8

[client]

default-character-set=utf8

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值