Converting MySQL Database Contents to UTF-8
VOCICI Comment J'ai Converti Le Contenu de MA BASE DE DONNées WordPress En UTF-8. C'ES? A M'A Pris Longtemps Pour Compre Comment Le Faire!
A Few Weeks Ago, I Discovered (To My Horror) That My Site Was Not Utf-8, As I Thought It Was. Checking My Pages In The Validator ProductueD this error:
The Character Encoding Specified in The Http Header (ISO-8859-1) IS DIFFERENT from The Value In The XML Declaration (UTF-8). I will use the value from the http header (ISO-8859-1).
In All Likeliness, My Server Adds A Default Header (ISO-8859-1) To the page server to WordPress, I Was Careful to Save All My Import Files AS UTF-8, And i Honestly Thought That Everything i Had Imported Into The Database WAS UTF-8. Somewhere In The Process, IT Got Switch Back to ISO-8859-1 (Latin-1).
The Solution To make Sure Sure The Pages Served Aresed UTF-8, As Specified In The Meta Tags of My HTML Pages, IS TO Add The Following Line to .htaccess:
AddDefaultCharset Off
(If One Wanted to Force UTF-8, AddDefaultcharset UTF-8 Would Do IT, But Actually, It's Better To Leave The Possibility To Serve Pages with Different Encodings, ISN 'ket?)
Now, When I Did That, of Course, All the Accented Characters in My Site Went Beserk - Proof if IT WAS NEEDTED That My Database Content Was NOT UTF-8. Here Is The Story of What I Went Through (And It Took Many Days to find the solution, believe me, although it takes only 2 minutes to do once everything is ready) to convert my database content from ISO-8859-1 to UTF-8 Thanks a lot to all those who helped me through this -. and They area!
First Thing, Dump The Database. I Always Forget The Command for Dumps, So Here It Is: MySQLDUMP --Opt -u Root -P WordPress> WordPress.sql
As we're going to be doing stuff, IT Might Be wise to make a copy of the working Wordpress Database. I Did That by Creating a New Database In PHPMYADMIN, AND IMPORTINGMPASE:
Mysql -u root -p WordPress-Backup Then, conversion. I tried a PHP script, I tried BBEdit, and they seemed to mess up. (Though as I had other issues elsewhere, they may well have worked but I mistakenly thought the problem was coming from there.) Anyway, command -LINE Conversion with iconv is Much Easier to do: Iconv -f ISO-8859-15 -t utf8 wordpress.sql> WordPress-iconv.sql THEN, IMPORT INTO the DATABASE. I First Imported It Into Another Database, Edited WP-Config.php To Point To The New Database, And Checked That Everything WAS OK: Mysql -u root -p WordPress-UTF8 Once I Was Happy That It Was Working, I Imported My Converted Dump INTO The WordPress Production Database: Mysql -u root -p wordpress On the way there, I had some trouble with MySQL. The MySQL dump more or less put the content of all my weblog posts on one line. For some reason, it did not cause any problems when importing the dump before conversion, to create The Backup Database, But It Didn't Play Nice After Conversion. I got this error when Trying to import: Error 1153 AT LINE 378: GOT A Packet Bigger Tan 'Max_Allowed_packet' Line 378 Contained Half My Weblog Posts ... And Was Obviously Bigger THAN THE 1MB LIMIT for max_allowed_packet (The Whole Dump IS Around 2MB). I had to edit my.cnf (/etc/mysql/my.cnf on my system) and change the value for max_allowed_packet in the section title [mysqld]. I set it to 8MB. Then, i had to stop mysql and restart IT : mysqladmin -u root -P shutdown to stop it, and mysqld_safe & to start it again (as root) .this is not necessarily the best woman to do it, and it might not work like That on your system, But it's what i Did and the site is now back up again. comments Welcome, And Hope this Can Be Useful to others! Http://climbtothestars.org/archives/2004/07/18/converting-mysql-database-contents-to-utf-8/