久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔

WordPress:Converting Database Character Sets

來自站長(zhǎng)百科
跳轉(zhuǎn)至: 導(dǎo)航、? 搜索

This article addresses, in general, the process of converting your WordPress MySQL database tables from one character set to another. Warning: character set conversion is not a simple process. Please complete a backup of your database before attempting any conversion.

這篇文章主要講述將你的WordPressMySQL 數(shù)據(jù)庫(kù)表格從一種字符集轉(zhuǎn)會(huì)為另一種字符集的過程。注意: 轉(zhuǎn)變字符集并不是個(gè)簡(jiǎn)單,在嘗試任何轉(zhuǎn)換之前,請(qǐng)備份你的數(shù)據(jù)庫(kù)。

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 collation.

直到并且包括WordPress2.1.3版本在內(nèi),大多數(shù)WordPress是使用latin1字符集創(chuàng)建的,使用latin1_swedish_ci整理。

Character set and collation can now be defined[ ]

現(xiàn)在可以定義字符集和整理了[ ]

Beginning with WordPress:Version 2.2, WordPress allows the user to define both the database character set and the collation in their wp-config.php file. Setting the DB_CHARSET and 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.

2.2版本開始,WordPress允許用戶在各自的wp-config.php 文件中定義數(shù)據(jù)庫(kù)字符集和???。 在wp-config.php 中設(shè)置DB_CHARSETDB_COLLATE 參數(shù)值,會(huì)使得WordPress使用適當(dāng)?shù)脑O(shè)置創(chuàng)建數(shù)據(jù)庫(kù)。但是,只有新的安裝,才有這個(gè)設(shè)置, '已經(jīng)安裝的'WordPress沒有這個(gè)設(shè)置。這篇文章的剩余部分,解釋了怎樣為當(dāng)前安裝的WordPress轉(zhuǎn)換字符集和??薄?

Converting your database[ ]

轉(zhuǎn)變你的數(shù)據(jù)庫(kù)[ ]

Before beginning any conversion, please backup your database. WordPress:Backing Up Your Database has easy-to-follow instructions.

在開始任何操作之前,請(qǐng)備份你的數(shù)據(jù)庫(kù)。備份你的數(shù)據(jù)庫(kù)有簡(jiǎn)單容易掌握的說明。

For discussion purposes, it is assumed you have a database in the latin1 character set that needs converting to a utf8 character set.

為了便于討論,加入你在latin1字符集中有個(gè)數(shù)據(jù)庫(kù),這個(gè)數(shù)據(jù)庫(kù)需要轉(zhuǎn)變到utf8字符集。

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!

要轉(zhuǎn)變字符集,需要使用MySQL ALTER TABLE command。轉(zhuǎn)變字符集的時(shí)候,所有的文本(和相似的)欄,都轉(zhuǎn)變?yōu)閁TF-8,但是轉(zhuǎn)變會(huì)會(huì)破壞當(dāng)前的文本,因?yàn)檗D(zhuǎn)變期望數(shù)據(jù)是在latin1,但是WordPress可能將統(tǒng)一的字符儲(chǔ)存在latin1數(shù)據(jù)庫(kù),因此,轉(zhuǎn)變后,數(shù)據(jù)可能變成沒用的亂碼。

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.

解決辦法就是將所有的文本和相關(guān)的欄,更改為對(duì)應(yīng)的二進(jìn)制,然后更改字符集,然后再將二進(jìn)制數(shù)據(jù)類型重新更改為文本。

Example steps: 例子步驟:

  1. Place notice that blog is out of service
  2. Backup database
  3. ALTER TABLE wp_users MODIFY display_name BLOB;
  4. ...ALTER TABLE commands for all other tables/columns...
  5. ALTER DATABASE wordpress charset=utf8;
  6. ALTER TABLE wp_users charset=utf8;
  7. ...ALTER TABLE command for all other tables...
  8. ALTER TABLE wp_users MODIFY display_name TEXT CHARACTER SET utf8;
  9. ...ALTER TABLE for all other tables/columns...
  10. Add DB_CHARSET and DB_COLLATE definitions to wp-config.php
  11. Place blog back on-line



  1. 張貼通知,博客不能夠正常運(yùn)行
  2. 備份數(shù)據(jù)庫(kù)
  3. 更改表格 wp_users 更改 display_name 博客;
  4. ...為所有其它的表格/欄更改表格命令行...
  5. 更改數(shù)據(jù)庫(kù) wordpress charset=utf8;
  6. 更改表格 wp_users charset=utf8;
  7. ...ALTER TABLE command for all other tables...
  8. 更改表格 wp_users MODIFY display_name 文本字符集 utf8;
  9. ...為所有其它的表格/欄更改表格...
  10. wp-config.php添加DB_CHARSET 和DB_COLLATE定義
  11. 使博客重新上線,運(yùn)行

The string field types need to be converted to their binary field types counterparts. The list is as follows:

字符串欄的類型應(yīng)該轉(zhuǎn)變?yōu)橄鄳?yīng)的二進(jìn)制欄類型。列表如下:

  • CHAR -> BINARY
  • VARCHAR -> VARBINARY
  • TINYTEXT -> TINYBLOB
  • TEXT -> BLOB
  • MEDIUMTEXT -> MEDIUMBLOB
  • LONGTEXT -> LONGBLOB
  • CHAR -> BINARY
  • VARCHAR -> VARBINARY
  • TINYTEXT -> TINYBLOB
  • TEXT -> BLOB
  • MEDIUMTEXT -> MEDIUMBLOB
  • LONGTEXT -> LONGBLOB

This information was originally posted by member g30rg3x in Forum Thread 117955.

ENUM and SET have more specific conversion rules:

這個(gè)信息,最初是由g30rg3x成員在論壇主題 117955上發(fā)表的。

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.

如果你確定沒有ENUM 或者 SET field中不能轉(zhuǎn)變的字符,請(qǐng)將字符集設(shè)置為二進(jìn)制的,或者設(shè)置為UTF8

The SQL for this is: SQL是:

  • ALTER TABLE wp_links CHANGE link_visible link_visible ENUM('Y','N') CHARACTER SET utf8;
  • 更改表格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.

不需要重復(fù)欄的名稱和ENUM規(guī)定。

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).

規(guī)定二進(jìn)制和VARBINARY的時(shí)候,也要規(guī)定欄的長(zhǎng)度,而且需要與原始的CHAR和VARCHAR欄的長(zhǎng)度相同。換句話說,VARCHAR(200) 變成了 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.

因此,在第三步和第四步,更改CHAR, VARCHAR, TEXT, ENUM,并且將欄設(shè)置為相應(yīng)的二進(jìn)制(BLOB, VARBINARY, 等等),在第五步中,將數(shù)據(jù)庫(kù)轉(zhuǎn)變?yōu)閡tf8,在第六步和第七步中,將所有的表格轉(zhuǎn)變?yōu)閡tf8,最后,在第八步和第九步中,將二進(jìn)制欄重新返回為各自的CHAR, VARCHAR, TEXT, ENUM,并且使用utf8字符集設(shè)置數(shù)據(jù)類型。

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.

轉(zhuǎn)換的關(guān)鍵在于,帶有二進(jìn)制數(shù)據(jù)類型的欄,不像CHAR, VARCHAR, TEXT, ENUM和SET欄,當(dāng)數(shù)據(jù)庫(kù)和表格轉(zhuǎn)變?yōu)閡tf8,這種欄,不會(huì)變?yōu)閬y碼。

Conversion Scripts and Plugins[ ]

轉(zhuǎn)變腳本和插件[ ]

In the WordPress Forums, Member andersapt, in Forum Thread 117955 submitted a conversion script, Convert UTF8 SQL Generator, to automatically convert a WordPress database. (This link is currently dead.)

在WordPress論壇中,成員andersapt在論壇主題 117955中遞交了一個(gè)轉(zhuǎn)變腳本,Convert UTF8 SQL Generator,自動(dòng)轉(zhuǎn)變WordPress數(shù)據(jù)庫(kù)。(這個(gè)鏈接當(dāng)前不能夠運(yùn)行。)

A plugin, 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.

插件UTF-8 數(shù)據(jù)庫(kù)轉(zhuǎn)換器,可以在g30rg3_x得到。仔細(xì)閱讀插件中的readme文件,這個(gè)插件破壞了新版本中的WordPress的數(shù)據(jù)。

Discussions on character sets[ ]

字符集討論[ ]












Resources[ ]

資源[ ]