Mysql-Mysql2 :: Error:不正确的字符串值: [英] Mysql - Mysql2::Error: Incorrect string value:

查看:248
本文介绍了Mysql-Mysql2 :: Error:不正确的字符串值:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我制造了一个刮板,正在拉一些物品.问题是某些外语,它使mysql db崩溃了.这是我得到的错误.知道我能做什么吗?谢谢!

So I built a scraper and am pulling in some objects. The issue is some are foreign languages and it is tripping the mysql db up a bit. This is the error I got. Any idea what I can do with this? Thanks!

Mysql2 :: Error:不正确的字符串值:'\ xC5 \ x8Dga,...'为列 第1行的说明":INSERT INTO sammiches(countrycreated_atdescriptionimagenameupdated_at)值 (日本","2013-05-03 01:17:06",用油炸面包塞满的热狗面包 面条,上面常撒上咸菜,例如benishōga, 蛋黄酱'','/wiki/File:Yakisoba_sandwich_by_kaex0r.jpg', 'Yakisoba-pan','2013-05-03

Mysql2::Error: Incorrect string value: '\xC5\x8Dga, ...' for column 'description' at row 1: INSERT INTO sammiches (country, created_at, description, image, name, updated_at) VALUES ('Japan', '2013-05-03 01:17:06', 'A hot dog bun stuffed with fried noodles, frequently topped with pickles, such as beni shōga, with mayonnaise', '/wiki/File:Yakisoba_sandwich_by_kaex0r.jpg', 'Yakisoba-pan', '2013-05-03

推荐答案

如果您要插入的字符串具有无效的UTF-8字节序列,也可以触发此操作.例如,在ruby中,您可以使用

This can also be triggered if the string you're trying to insert has invalid UTF-8 byte sequences. For example, in ruby you can remove any invalid characters using

string_with_invalid_sequences.encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '')

String#scrub 可以在ruby 2.1及更高版本中使用

String#scrub can be used in ruby 2.1 onwards

string_with_invalid_sequences.scrub

这篇关于Mysql-Mysql2 :: Error:不正确的字符串值:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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