站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
建站程序
开发
服务器
办公软件
开发教程
服务器教程
软件使用教程
运营教程
热门电子书
WordPress教程
宝塔面板教程
CSS教程
Shopify教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:Converting Database Character Sets
”
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
Xxf3325
(
讨论
|
贡献
)
2008年8月15日 (五) 11:20的版本
(新页面: This article addresses, in general, the process of converting your WordPress
MySQL
database tables
from one [[WordPress:Glo...)
(差异) ←上一版本 |
最后版本
(
差异
) |
下一版本→
(
差异
)
跳转至:
导航
、
搜索
警告:您正在编辑的是本页面的旧版本。
如果您发布该更改,该版本后的所有更改都会丢失。
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
This article addresses, in general, the process of converting your WordPress [[WordPress:Glossary#MySQL|MySQL]] [[WordPress:Database Description|database tables]] from one [[WordPress:Glossary#Character set|character set]] to another. '''Warning: character set conversion is not a simple process. Please complete a backup of your database before attempting any conversion.''' ==The History== Up to and including WordPress [[WordPress:Version 2.1.3]], most WordPress databases were created using the ''latin1'' character set and the ''latin1_swedish_ci'' [[WordPress:Glossary#Collation|collation]]. ==Character set and collation can now be defined== Beginning with [[WordPress:Version 2.2]], WordPress allows the user to define both the database character set and the collation in their [[WordPress:Editing wp-config.php|wp-config.php]] file. Setting the [[WordPress:Editing wp-config.php#Database character set|DB_CHARSET]] and [[WordPress:Editing wp-config.php#Database collation|DB_COLLATE]] values in ''wp-config.php'' causes WordPress to create the database with the appropriate settings. But, the setting can only be designated for new installations, not for 'already installed' copies of WordPress. The rest of this article will explain how to convert the character set and collation for existing WordPress installations. ==Converting your database== Before beginning any conversion, please backup your database. [[WordPress:Backing Up Your Database]] has easy-to-follow instructions. For discussion purposes, it is assumed you have a database in the '''latin1''' character set that needs converting to a '''utf8''' character set. ===The Problem=== To convert character sets requires using the the MySQL ALTER TABLE command. When converting the character sets, all TEXT (and similar) fields are converted to UTF-8, but that conversion will BREAK existing TEXT because the conversion expects the data to be in latin1, but WordPress may have stored unicode characters in a latin1 database, and as a result, data could end up as garbage after a conversion! ===The Solution=== The solution is to ALTER all TEXT and related fields to their binary counterparts, then alter the character set and finally change the binary data type fields back to TEXT. Example steps: # Place notice that blog is out of service # Backup database # ALTER TABLE wp_users MODIFY display_name BLOB; # ...ALTER TABLE commands for all other tables/columns... # ALTER DATABASE wordpress charset=utf8; # ALTER TABLE wp_users charset=utf8; # ...ALTER TABLE command for all other tables... # ALTER TABLE wp_users MODIFY display_name TEXT CHARACTER SET utf8; # ...ALTER TABLE for all other tables/columns... # Add DB_CHARSET and DB_COLLATE definitions to [[WordPress:Editing_wp-config.php|wp-config.php]] # Place blog back on-line The string field types need to be converted to their binary field types counterparts. The list is as follows: * CHAR -> BINARY * VARCHAR -> VARBINARY * TINYTEXT -> TINYBLOB * TEXT -> BLOB * MEDIUMTEXT -> MEDIUMBLOB * LONGTEXT -> LONGBLOB This information was originally posted by member g30rg3x in [http://wordpress.org/support/topic/117955 Forum Thread 117955]. ENUM and SET have more specific conversion rules: Set the character set to binary, or to UTF8 if you are sure that no ENUM or SET field has special characters that might get garbled during conversion. The SQL for this is: * ALTER TABLE wp_links CHANGE link_visible link_visible ENUM('Y','N') CHARACTER SET utf8; The field name does need to be repeated, as well as the ENUM specification. When specifying BINARY and VARBINARY, the field length also needs to be specified, and needs to be the same value as the original CHAR and VARCHAR field length. In other words, VARCHAR(200) becomes VARBINARY(200). So, in Steps 3 and 4 change CHAR, VARCHAR, TEXT, ENUM, and SET fields to their binary counterparts (BLOB, VARBINARY, etc), in Step 5 switch the database to utf8, in Steps 6 and 7 switch all the tables to utf8, and finally, in Steps 8 and 9 return the binary fields back to the respective CHAR, VARCHAR, TEXT, ENUM, and SET data types with the utf8 character set. The key to the conversion is that a field with a binary data type, unlike CHAR, VARCHAR, TEXT, ENUM, and SET fields, will not be converted to garbage when the database and tables are switched to utf8. ====Conversion Scripts and Plugins==== In the WordPress Forums, Member andersapt, in [http://wordpress.org/support/topic/117955 Forum Thread 117955] submitted a conversion script, [http://kunde.apt.no/aso/wordpress/convert_to_utf8_sql_generator.txt Convert UTF8 SQL Generator], to automatically convert a WordPress database. (This link is currently dead.) A plugin, [http://g30rg3x.com/utf8-database-converter/ UTF-8 Database Converter], is available from g30rg3_x. Carefully review the readme file included with the plugin. This plugin corrupts data in modern versions of Wordpress. ==Discussions on character sets== *http://trac.wordpress.org/ticket/2828 *http://trac.wordpress.org/ticket/2942 *http://trac.wordpress.org/ticket/3184 *http://trac.wordpress.org/ticket/3517 *http://trac.wordpress.org/ticket/4219 *http://comox.textdrive.com/pipermail/wp-testers/2007-May/004510.html *http://jonkenpon.com/2007/02/20/making-your-wordpress-database-portable-because-it-probably-isnt-right-now/ *http://wordpress.org/support/topic/101135 *http://wordpress.org/support/topic/116746 *http://wordpress.org/support/topic/117865 *http://wordpress.org/support/topic/117955 *http://wordpress.org/support/topic/117999 *http://wordpress.org/support/topic/118781 *http://wordpress.org/support/topic/119611 *http://wordpress.org/support/topic/119750 *http://wordpress.org/support/topic/119858 *http://wordpress.org/support/topic/119998 *http://wordpress.org/support/topic/119999 *http://wordpress.org/support/topic/120029 *http://wordpress.org/support/topic/120065 *http://wordpress.org/support/topic/120135 *http://wordpress.org/support/topic/120352 *http://wordpress.org/support/topic/120397 *http://wordpress.org/support/topic/120414 *http://wordpress.org/support/topic/120466 *http://wordpress.org/support/topic/120562 *http://wordpress.org/support/topic/120687 *http://wordpress.org/support/topic/144884 ==Resources== *[http://en.wikipedia.org/wiki/Character_set Character set at Wikipedia] *[http://en.wikipedia.org/wiki/Unicode Unicode at Wikipedia] *[http://en.wikipedia.org/wiki/UTF-8 UTF-8 at Wikipedia] *[http://dev.mysql.com/doc/refman/5.0/en/charset-general.html Character sets and collation at MySQL] *[http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html Character Sets and Collations That MySQL Supports] *[http://gentoo-wiki.com/TIP_Convert_latin1_to_UTF-8_in_MySQL Gentoo tip on converting latin1 to utf8 in MySQL] *[http://alexking.org/blog/2008/03/06/mysql-latin1-utf8-conversion Alex King's blog about latin1 to utf8 conversion]
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)