<bdo id='JBmfj'></bdo><ul id='JBmfj'></ul>

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

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

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

      1. 如何让 MySQL 正确处理 UTF-8

        时间:2023-08-19
      2. <tfoot id='JJpvN'></tfoot>

        1. <legend id='JJpvN'><style id='JJpvN'><dir id='JJpvN'><q id='JJpvN'></q></dir></style></legend>
              <tbody id='JJpvN'></tbody>
              <i id='JJpvN'><tr id='JJpvN'><dt id='JJpvN'><q id='JJpvN'><span id='JJpvN'><b id='JJpvN'><form id='JJpvN'><ins id='JJpvN'></ins><ul id='JJpvN'></ul><sub id='JJpvN'></sub></form><legend id='JJpvN'></legend><bdo id='JJpvN'><pre id='JJpvN'><center id='JJpvN'></center></pre></bdo></b><th id='JJpvN'></th></span></q></dt></tr></i><div id='JJpvN'><tfoot id='JJpvN'></tfoot><dl id='JJpvN'><fieldset id='JJpvN'></fieldset></dl></div>
                <bdo id='JJpvN'></bdo><ul id='JJpvN'></ul>

                • <small id='JJpvN'></small><noframes id='JJpvN'>

                  本文介绍了如何让 MySQL 正确处理 UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  对我昨天问的一个问题的回应之一 建议我应该确保我的数据库可以正确处理 UTF-8 字符.我如何用 MySQL 做到这一点?

                  One of the responses to a question I asked yesterday suggested that I should make sure my database can handle UTF-8 characters correctly. How I can do this with MySQL?

                  推荐答案

                  更新:

                  简短回答 - 您应该几乎总是使用 utf8mb4 字符集和 utf8mb4_unicode_ci 归类.

                  Short answer - You should almost always be using the utf8mb4 charset and utf8mb4_unicode_ci collation.

                  修改数据库:

                  ALTER DATABASE dbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
                  

                  见:

                  • Aaron 对此答案的评论 如何制作MySQL正确处理UTF-8

                  两者有什么区别utf8_general_ci 和 utf8_unicode_ci

                  转换指南:https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-conversion.html

                  原答案:

                  MySQL 4.1 及更高版本的默认字符集为 UTF-8.你可以在你的 my.cnf 文件中验证这一点,记得设置 both 客户端和服务器(default-character-setcharacter-set-server).

                  MySQL 4.1 and above has a default character set of UTF-8. You can verify this in your my.cnf file, remember to set both client and server (default-character-set and character-set-server).

                  如果您有要转换为 UTF-8 的现有数据,请转储您的数据库,然后将其作为 UTF-8 重新导入,确保:

                  If you have existing data that you wish to convert to UTF-8, dump your database, and import it back as UTF-8 making sure:

                  • 在查询/插入数据库之前使用SET NAMES utf8
                  • 在创建新表时使用DEFAULT CHARSET=utf8
                  • 此时您的 MySQL 客户端和服务器应该是 UTF-8(参见 my.cnf).请记住,您使用的任何语言(例如 PHP)也必须是 UTF-8.某些版本的 PHP 将使用自己的 MySQL 客户端库,可能不支持 UTF-8.
                  • use SET NAMES utf8 before you query/insert into the database
                  • use DEFAULT CHARSET=utf8 when creating new tables
                  • at this point your MySQL client and server should be in UTF-8 (see my.cnf). remember any languages you use (such as PHP) must be UTF-8 as well. Some versions of PHP will use their own MySQL client library, which may not be UTF-8 aware.

                  如果您确实要迁移现有数据,请记住先备份!当事情没有按计划进行时,可能会发生许多奇怪的数据截断!

                  If you do want to migrate existing data remember to backup first! Lots of weird choping of data can happen when things don't go as planned!

                  一些资源:

                  • 完整的 UTF-8 迁移 (cdbaby.com)
                  • 关于 php 函数的 UTF-8 就绪性 的文章(注意其中的一些信息已过时)
                  • complete UTF-8 migration (cdbaby.com)
                  • article on UTF-8 readiness of php functions (note some of this information is outdated)

                  这篇关于如何让 MySQL 正确处理 UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 node.js 在 mySQL 中进行批量插入 下一篇:你可以在 mysql 的 WHERE 子句中使用别名吗?

                  相关文章

                  最新文章

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

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

                        <bdo id='MSBP0'></bdo><ul id='MSBP0'></ul>

                    1. <tfoot id='MSBP0'></tfoot>