<i id='9Z0Zl'><tr id='9Z0Zl'><dt id='9Z0Zl'><q id='9Z0Zl'><span id='9Z0Zl'><b id='9Z0Zl'><form id='9Z0Zl'><ins id='9Z0Zl'></ins><ul id='9Z0Zl'></ul><sub id='9Z0Zl'></sub></form><legend id='9Z0Zl'></legend><bdo id='9Z0Zl'><pre id='9Z0Zl'><center id='9Z0Zl'></center></pre></bdo></b><th id='9Z0Zl'></th></span></q></dt></tr></i><div id='9Z0Zl'><tfoot id='9Z0Zl'></tfoot><dl id='9Z0Zl'><fieldset id='9Z0Zl'></fieldset></dl></div>

<tfoot id='9Z0Zl'></tfoot>

  1. <legend id='9Z0Zl'><style id='9Z0Zl'><dir id='9Z0Zl'><q id='9Z0Zl'></q></dir></style></legend>

      <small id='9Z0Zl'></small><noframes id='9Z0Zl'>

      • <bdo id='9Z0Zl'></bdo><ul id='9Z0Zl'></ul>

      如何修复“不正确的字符串值"错误?

      时间:2023-08-18
    1. <small id='14FF5'></small><noframes id='14FF5'>

    2. <i id='14FF5'><tr id='14FF5'><dt id='14FF5'><q id='14FF5'><span id='14FF5'><b id='14FF5'><form id='14FF5'><ins id='14FF5'></ins><ul id='14FF5'></ul><sub id='14FF5'></sub></form><legend id='14FF5'></legend><bdo id='14FF5'><pre id='14FF5'><center id='14FF5'></center></pre></bdo></b><th id='14FF5'></th></span></q></dt></tr></i><div id='14FF5'><tfoot id='14FF5'></tfoot><dl id='14FF5'><fieldset id='14FF5'></fieldset></dl></div>

            <tbody id='14FF5'></tbody>
            1. <tfoot id='14FF5'></tfoot>
              • <bdo id='14FF5'></bdo><ul id='14FF5'></ul>
                <legend id='14FF5'><style id='14FF5'><dir id='14FF5'><q id='14FF5'></q></dir></style></legend>

                本文介绍了如何修复“不正确的字符串值"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                在注意到应用程序由于不正确的字符串值错误而倾向于丢弃随机电子邮件后,我继续并切换了许多文本列以使用 utf8 列字符集和默认列整理 (utf8_general_ci) 以便它接受它们.这修复了大部分错误,并使应用程序在遇到非拉丁电子邮件时也不再出现 sql 错误.

                尽管如此,一些电子邮件仍然导致程序命中不正确的字符串值错误:(Incorrect string value: '\xE4\xC5\xCC\xC9\xD3\xD8...' for column '内容'在第 1) 行

                内容列是一个 MEDIUMTEXT 数据类型,它使用 utf8 列字符集和 utf8_general_ci 列整理.在此列中没有我可以切换的标志.

                请记住,除非绝对必要,否则我不想接触甚至查看应用程序源代码:

                • 是什么导致了该错误?(是的,我知道电子邮件中充满了随机垃圾,但我认为 utf8 会非常宽松)
                • 我该如何解决?
                • 这种修复可能产生哪些影响?

                我考虑的一件事是切换到打开二进制标志的 utf8 varchar([some large number]),但我对 MySQL 相当不熟悉,也不知道这样的修复是否有意义.

                解决方案

                "\xE4\xC5\xCC\xC9\xD3\xD8" 不是有效的 UTF-8.使用 Python 测试:

                <预><代码>>>>"\xE4\xC5\xCC\xC9\xD3\xD8".decode("utf-8")...UnicodeDecodeError: 'utf8' 编解码器无法解码位置 0-2 中的字节:无效数据

                如果您正在寻找一种方法来避免数据库中的解码错误,cp1252 编码(又名Windows-1252"又名Windows 西欧")是最宽松的编码 - 每个字节值都是有效的代码点.

                当然它不会再理解真正的 UTF-8,也不会再理解任何其他非 cp1252 编码,但听起来你不太关心这个?

                After noticing an application tended to discard random emails due to incorrect string value errors, I went though and switched many text columns to use the utf8 column charset and the default column collate (utf8_general_ci) so that it would accept them. This fixed most of the errors, and made the application stop getting sql errors when it hit non-latin emails, too.

                Despite this, some of the emails are still causing the program to hit incorrect string value errrors: (Incorrect string value: '\xE4\xC5\xCC\xC9\xD3\xD8...' for column 'contents' at row 1)

                The contents column is a MEDIUMTEXT datatybe which uses the utf8 column charset and the utf8_general_ci column collate. There are no flags that I can toggle in this column.

                Keeping in mind that I don't want to touch or even look at the application source code unless absolutely necessary:

                • What is causing that error? (yes, I know the emails are full of random garbage, but I thought utf8 would be pretty permissive)
                • How can I fix it?
                • What are the likely effects of such a fix?

                One thing I considered was switching to a utf8 varchar([some large number]) with the binary flag turned on, but I'm rather unfamiliar with MySQL, and have no idea if such a fix makes sense.

                解决方案

                "\xE4\xC5\xCC\xC9\xD3\xD8" isn't valid UTF-8. Tested using Python:

                >>> "\xE4\xC5\xCC\xC9\xD3\xD8".decode("utf-8")
                ...
                UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-2: invalid data
                

                If you're looking for a way to avoid decoding errors within the database, the cp1252 encoding (aka "Windows-1252" aka "Windows Western European") is the most permissive encoding there is - every byte value is a valid code point.

                Of course it's not going to understand genuine UTF-8 any more, nor any other non-cp1252 encoding, but it sounds like you're not too concerned about that?

                这篇关于如何修复“不正确的字符串值"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:MySQL 服务器启动错误“服务器退出而不更新 PID 下一篇:如何在 MySQL 中获取下一条/上一条记录?

                相关文章

                最新文章

                1. <legend id='AyZ6g'><style id='AyZ6g'><dir id='AyZ6g'><q id='AyZ6g'></q></dir></style></legend>

                    <bdo id='AyZ6g'></bdo><ul id='AyZ6g'></ul>
                2. <i id='AyZ6g'><tr id='AyZ6g'><dt id='AyZ6g'><q id='AyZ6g'><span id='AyZ6g'><b id='AyZ6g'><form id='AyZ6g'><ins id='AyZ6g'></ins><ul id='AyZ6g'></ul><sub id='AyZ6g'></sub></form><legend id='AyZ6g'></legend><bdo id='AyZ6g'><pre id='AyZ6g'><center id='AyZ6g'></center></pre></bdo></b><th id='AyZ6g'></th></span></q></dt></tr></i><div id='AyZ6g'><tfoot id='AyZ6g'></tfoot><dl id='AyZ6g'><fieldset id='AyZ6g'></fieldset></dl></div>

                  <small id='AyZ6g'></small><noframes id='AyZ6g'>

                  <tfoot id='AyZ6g'></tfoot>