Πώς να μετατρέψει το χαρακτήρα - σύνολο και παραβολή της βάσης δεδομένων WordPress

Από τότε WordPress 2.2, WordPress υποστηρίζει το χαρακτηριστικό γνώρισμα που επιτρέπει στο χρήστη για να καθορίσει και τα δύο Χαρακτήρας βάσεων δεδομένων WordPress - σύνολο και παραβολή με τις τιμές DB_CHARSET και DB_COLLATE στο αρχείο WP-config.php. Με αυτές τις τιμές που καθορίζονται, WordPress θα χρησιμοποιήσει οριζόμενο characterset βάσεων δεδομένων (charset) και την παραβολή βάσεων δεδομένων (δηλ. διαταγή είδους των γραμμάτων, των αριθμών, και των συμβόλων ενός χαρακτήρα - το σύνολο) κατά τη σύνδεση μιας βάσης δεδομένων παρουσιάζει.

Εντούτοις, στις υπάρχουσες εγκαταστάσεις WordPress που αναβαθμίζονται από την προηγούμενη έκδοση WordPress ή θέτουν όχι ρητά σε ένα Unicode utf-8 charset την παραβολή, ο χαρακτήρας βάσεων δεδομένων προεπιλογής - το σύνολο οργανώνεται κανονικά ως Latin1 (προεπιλογή σχεδόν σε όλη την εγκατάσταση MySQL) με την παραβολή latin1_swedish_ci. Εάν τρέχετε ένα δίγλωσσο ή πολύγλωσσο blog με WordPress, μπορείτε να αντιμετωπίσετε το πρόβλημα στο χαρακτήρα που κωδικοποιεί όταν γράφονται οι θέσεις blog σας σε άλλες ξένες γλώσσες, ή όταν εξάγετε και στήριγμα η βάση δεδομένων και η πιό πρόσφατη προσπάθεια να επανεισαχθεί η απόρριψη βάσεων δεδομένων σε περίπτωση αποτυχίας βάσεων δεδομένων ή μετανάστευσης και κίνησης κεντρικών υπολογιστών. Το σύμπτωμα είναι προφανές, οι θέσεις WordPress ή οι σελίδες σας περιέχουν τους αλλοιωμένους, παράξενους και αστείους χαρακτήρες, κάποτε ακριβώς μέρη;;;;; (σημάδια ερώτησης), που καθιστούν τη βάση δεδομένων WordPress με τη σκληρή εργασία σας άχρηστη και την παραγωγή δυσανάγνωστη. (Αιτία Μαΐου επίσης κοντά λανθασμένη παραβολή charset)

Η καλύτερη λύση στο πρόβλημα κωδικοποίησης χαρακτήρα σε WordPress είναι να μετατραπεί το charset ή η βάση δεδομένων και η παραβολή σε utf-8 ή Unicode. Εντούτοις, ΔΕΝ ΜΠΟΡΕΙΤΕ απλά να συνδέσετε με MySQL μέσω του κοχυλιού ή του phpMyAdmin και ελπίζοντας όλα τα χειρόγραφά σας θα μετατρέψουν ωραία. Όπως εξηγεί κοντά Οδηγός μετατροπής βάσεων δεδομένων WordPress, μετατρέψτε το χαρακτήρα - τα σύνολα απαιτούν ότι χρησιμοποιώντας το MySQL ΑΛΛΑΞΤΕ την ΕΠΙΤΡΑΠΕΖΙΑ εντολή. Κατά τη μετατροπή του χαρακτήρα - τα σύνολα, όλοι οι τομείς ΚΕΙΜΕΝΩΝ (και παρόμοιος) μετατρέπονται σε utf-8, αλλά εκείνη η μετατροπή ΘΑ ΣΠΑΣΕΙ το υπάρχον ΚΕΙΜΕΝΟ επειδή η μετατροπή αναμένει τα στοιχεία για να είναι σε latin1, αλλά WordPress μπορεί να είχε αποθηκεύσει unicode τους χαρακτήρες σε μια βάση δεδομένων latin1, και κατά συνέπεια, τα στοιχεία μπόρεσαν να καταλήξουν ως απορρίματα μετά από μια μετατροπή!

Ο οδηγός παρέχει έναν πολύ τραχύ και ασαφή οδηγό δεδομένου ότι μια λύση στο πώς να μετατρέψει πραγματικά τους πίνακες βάσεων δεδομένων WordPress MySQL από έναν χαρακτήρα - θέστε άλλος, συνήθως utf-8. Εντούτοις, ο οδηγός λειτουργεί πραγματικά, αν και η διαδικασία μπορεί να είναι μεγάλη. Για να μετατρέψουν, τα βήματα σχετικά γενικά είναι να αλλαχτεί κάθε ΚΕΙΜΕΝΟ και οι σχετικοί τομείς μέσα σε κάθε WP παρουσιάζουν στη ΣΤΑΓΌΝΑ, κατόπιν αλλάζουν το χαρακτήρα - σύνολο βάσης δεδομένων και αλλάζουν τελικά τους τομείς ΣΤΑΓΌΝΩΝ πίσω στο ΚΕΊΜΕΝΟ. Φαίνεται εύκολος, αλλά πόσο μακρύς θα έπαιρνε για να μετατρέψει τόσους πολλούς τομείς σε τόσους πολλούς πίνακες; Furthermore, you will also need to remember the original type and length or values of all fields.

andersapt has posted a conversion script named convert_to_utf8_sql_generator.txt which automatically generates a list of SQL statements and commands need to fully convert your WordPress database to UTF8 based on the guide. However, there seems to be a minor bug with the script, although the author claimed it worked, where in my case, it simply won’t generate the list of SQL commands to run due to the error “PHP Fatal error: Call to a member function get_results() on a non-object in convert.php on line 37″. Once fixed, with this script in hand we can easily and quickly convert the database, tables and fields to use utf8_general_ci collation.

Note: I have tried out UTF-8 Database Converter plugin, but it’s a failure. It seemed like the author change to character set directly.

Guide to Convert WordPress Database Character Set to UTF8 (Unicode)

  1. Take the WordPress blog offline by placing a out-of-service or maintenance notice.
  2. Backup database - this is very important, nothing is guaranteed to work. If you’re using cPanel or other control panel, it’s best to perform a database backup from the control panel itself, where you can restore the database in one piece instead of by SQL statements, in the case of normal dump.
  3. Download the fixed convert_to_utf8_sql_generator.txt script and save it with a PHP extension.
  4. Modify the script to input the database name your WordPress blog is using. Locate the following text:

    Tables_in_DATABASENAME

    The DATABASENAME in red is the only thing that you need to change to match your WordPress database name. It should looks like this after change, for instance,

    Tables_in_wp_mydigitallife

  5. Upload the convert_to_utf8_sql_generator.php (or you can rename to a shorter name such as convert.php) to the base root WordPress installation directory, where wp-config.php is also located.
  6. Now, call and browse the script from any web browser. To do this, simply add convert_to_utf8_sql_generator.php (or any name you give to the script) to the end of your blog URL (i.e http://www.mywebsite.com/convert_to_utf8_sql_generator.php) and press Enter. A long list of SQL statements will be generated on the web page.
  7. Ensure that your post_content and post title fields on wp_posts table DOES NOT belongs to any indexes or FULLTEXT indexes. Else the type of the fields may not be converted to BLOB with one of the errors list below. Some plugins, such as related posts tend to add indexes to these fields. In this case, temporarily drop the indexes.

    ERROR 1170 (42000): BLOB/TEXT column ‘post_content’ used in key specification without a key length

    ERROR 1283 (HY000): Column ‘post_content’ cannot be part of FULLTEXT index

  8. Login to your server shell by Telnet or SSH. You can skip this part of using Unix shell if you intend to use phpMyAdmin to do the dirty work, but I have not tried it. So if you do, do feedback on whether it can be done.
  9. Connect to MySQL server from the shell.
  10. Issue the following command first in MySQL prompt:

    use DATABASENAME;

    Again, replace DATABASENAME in red to the actual WordPress database name.

  11. Then copy and paste the whole list of SQL statements auto generated by the conversion script, and paste them into the MySQL prompt. Each and every SQL command should now be processed and executed by MySQL one by one. You may need to press Enter key to finish off the last one.
  12. During the processing, the similar error messages related to key length as mentioned may appears. In my case, the conversion to BLOB failed with such message in the following fields:

    wp_categories.category_nicename
    wp_comments.comment_approved
    wp_links.link_visible
    wp_options.option_name
    wp_postmeta.meta_key
    wp_posts.post_status
    wp_posts.post_name
    wp_posts.post_type
    wp_usermeta.meta_key
    wp_users.user_login

    All these fields are unlikely to contains non-ASCII characters. And fields such as category_nicename (category slug) and post_name (post slug) have been URL encoded (where your URL with unsafe non-alphanumeric characters will be replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs). Initial encoding of byte codes and character assignments for UTF-8 is consistent with ASCII, so direct conversion of these fields to UTF8 should not bring too much problem.

  13. Edit the wp-config.php file to add in DB_CHARSET and DB_COLLATE definitions. Add the following two lines, preferably under the section of MySQL Settings:

    define(’DB_CHARSET’, ‘utf8′);
    define(’DB_COLLATE’, ”);

    As explained in WordPress Codex, DB_COLLATE is left blank (null) so that the database collation will be automatically assigned by MySQL based on the database character set.

  14. Recreate the indexes and/or FULLTEXT indexes been dropped, if any.
  15. Activate the blog back into production mode.
  16. Check your blog to see if everything and every characters is okay.
  17. Delete the PHP script.

IMPORTANT: This is a machine translated page which is provided "as is" without warranty. Machine translation may be difficult to understand. Please refer to original English article whenever possible.

Share and contribute or get technical support and help at My Digital Life Forums.


15 Responses to “How to Convert Character Set and Collation of WordPress Database”

  1. g30rg3_x
    June 23rd, 2007 04:27
    1

    Hi…
    I have to say (in my favor) that m not changing directly the database character set, please review my plugin and you will see that first it will convert your database binary and them to utf8 and finally it will put everything like before encoding but obviously with the UTF-8 character set…

    I prefer to do and a..
    ALTER TABLE table_name CONVERT TO CHARACTER SET binary
    Than just make a mysql sentence for every text/string field, because as you can see the problems comes with key and some index value and the BLOB field type change.
    Converting truth the sentence that my plugin use will transform all char to binary, all varchar to varbinary, all text (tynitext, text, mediumtext, longtext) to his binary representations (tinyblob, blob, mediumblob, longblob) and finally just set enum and set types with the collation binary.

    I just came here to say this in favor and by the way the majority of the problems of my plugins are related to host configurations and other things that obviously i can control.

    BTW its a better to solution to avoid problems of key and index by just setting the correct binary representation rather than using blob in all the way.

    Greetings from mexico and sorry for all mistyping problems.

  2. fotizo φωτίζω » Blog Archive » Wordpress 2.1 -> 2.2.1
    July 11th, 2007 16:00
    2

    [...] MySQL 本身的問題,便一知半解地去亂 set,結果一樣。。。 (5:00) 直至我讀完這篇文章,發現是 WP 由 2.1 升至 2.2.1 之後,閱讀 db 的 script 真的變了,讀不了 SQL db [...]

  3. How to Backup and Restore (Export and Import) MySQL Databases Tutorial » My Digital Life
    July 21st, 2007 15:33
    3

    [...] If this case, use –default-character-set=charset_name option to specify the character set or convert the database to UTF8. Get help or contribute tips or tricks at My Digital Life [...]

  4. Wordpress 2.2 UTF Konvertierung | Blog[CHA] v2
    September 4th, 2007 18:57
    4

    [...] die Schnauze. Mit etwas mehr Hartnäckigkeit bei der Suche konnte ich am Ende dann doch noch eine passende Konvertierungsanleitung finden, die auf mystische Art und Weise sowohl auf das fehlerhafte Plugin hinweist, als auch die [...]

  5. Chris
    September 16th, 2007 02:04
    5

    Why don’t you just link the file directly here?

    It is pain to register just to download the file.

  6. curo.dk » Blog Archive » Wordpress charset problem and solution
    September 16th, 2007 03:15
    6

    [...] to convert my database to UTF8 so my blog doesn’t look funny. The plugin didn’t work, another site requires registration (how lame), so I came up with my own solution which is KISS all the [...]

  7. admin
    September 16th, 2007 03:59
    7

    Hi Chris, sorry for inconveniences, it’s so that users can discuss any bugs on the script on the forum when needed.

  8. Isotipo
    September 29th, 2007 03:23
    8

    [...] la codificación de acentos, ñ y símbolos para que funcionara bien. Para problemas recomiendo este artículo que indica los pasos para convertir tu bbdd a codificación [...]

  9. Octaedro » Una soluci
    November 17th, 2007 07:55
    9

    [...] ponga, siempre hay algo que me va a salir desconfigurado: los posts o los comentarios. He probado

  10. Back on track! | isa costa * the geek side
    November 19th, 2007 03:35
    10

    [...] ficheiro wp-config.php e deixar os valores das constantes DB_CHARSET e DB_COLLATE em branco. Outra solução é converter a base de dados toda para UTF-8, o que para mim já soa a [...]

  11. Sergio Nascimento
    December 14th, 2007 03:05
    11

    Hi, it worked fine for me using MyPHPAdmin.

    Thanks for the article.

  12. Media Addicted
    February 27th, 2008 01:20
    12

    I’m using PHPmyAdmin and try to convert my database to utf-8, but…PHPmA interrupts the process with the first error message (concering key length as mentioned in ur guide).

    Is there a way to make PHPmA ignore errors / to proceed the other tables?

    Thx in advance!

  13. // If I have absolutely nothing to say : 2008030101
    March 2nd, 2008 01:52
    13

    [...] How to convert character set and collation of wordpress database?  [...]

  14. Larry Hirscg
    March 19th, 2008 03:32
    14

    I must applaud you for publishing this. After hours of searching for an easy solution, when my provider moved my database to an “upgraded” platform, I was able to follow your instructions and and get the character set changed. I used the phpmyadmin to execute the code and deleted the lines that had errors. It ran perfectly and I only needed to edit a few slugs that had odd character in them. Fabulous!

  15. Links for 2008-03-30 [del.icio.us] » Festival BD-Comminges
    March 31st, 2008 13:09
    15

    [...] How to Convert Character Set and Collation of WordPress Database Guide to Convert WordPress Database Character Set to UTF8 (Unicode) — » My Digital Life [...]

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting


Custom Search

New Articles

Incoming Search Terms for the Article

phpmyadmin change Collation - MySQL convert collation - mysql convert character set - convert collation - mysql convert encoding - mysql convert charset - oracle COLLATE - convert charset - php convert characters - mysql convert - change collation phpmyadmin - phpmyadmin character set - wordpress collation - phpmyadmin change table collation - wordpress charset - wordpress latin1_swedish_ci - mysql convert utf8 - oracle convert character set - phpmyadmin change encoding - oracle convert - mysql convert database encoding - collation convert - mysql convert table encoding - convert collation mysql - php convert character set - mysql convert character encoding - oracle character set - phpmyadmin collation - phpmyadmin change database collation - convert latin1_swedish_ci to utf8 - convert mysql collation - mysql convert character - convert collate - mysql convert database charset - php convert charset - latin1_swedish_ci wordpress - php convert character encoding - characterset - sql convert charset - mysql convert char - wordpress database encoding - sql php convert chinese - mysql charset converter - how to convert Object of class wpdb to string in php - funny characters phpmyadmin - latin1_swedish_ci wordpress database - mysql convert database character set - mysql collation conversion - mysql convert characters - change collation mysql - mysql CONVERT TO CHARACTER SET - convert character set - mysql change collation for all tables - php convert text encoding - php convert latin1 to utf8 - convert table collation mysql - convert_to_utf8_sql_generator.txt - collation change - wordpress charset problem with bulgarian - wordpress database convert - wordpress database collation - convert character encoding - php convert latin1 - wordpress change collation - CONVERT DATABASE TO UTF8 - MySQL convert to unicode - auto convert latin1 to utf-8 mysql php function - wordpress database name - convert mysql charset - mysql change collation - mysql "cannot be part of FULLTEXT index" - wordpress character sets - mysql change database encoding - oracle collation - latin1_swedish_ci to utf8 -