[wp-testers] DB_CHARSET and DB_COLLATE in wp-config.php

Ryan Boren ryan at boren.nu
Fri May 4 18:18:19 GMT 2007


On 5/4/07, Jennifer Hodgdon <yahgrp at poplarware.com> wrote:
> Here are my questions [and possibly correct answers I dug around to find]:
>
> a) If I have an existing wp-config file, do I need to add DB_COLLATE
> and DB_CHARSET to it when I upgrade to 2.2?
>
> [I am not sure what the answer is; probably not for most people?]

No.   Only those who know about charsets and MySQL should mess with
this on upgrades.  If you change this to a value that does not match
your existing tables, your queries will go boom.  First you have to
convert your tables and all data in them to the charset specified in
DB_CHARSET.

> b) What are the possible values, and why would anyone want to change
> them?
>
> [I am not sure about who really needs to change the defaults --
> non-European languages? List of possible values is at
> http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html ]

Most people, regardless of the language they speak, should not need to
change them.

> c) Where can I find out more about collation and character sets?
>
> [ http://dev.mysql.com/doc/refman/5.0/en/charset-general.html ]

That's a good jumping off point.

> d) What does WP use these values for?
>
> [From reading the code, I think WP uses them to define the character
> set/collation when creating new database tables (probably not when
> altering existing tables?). WP also uses the character set in a SET
> NAMES call when first connecting to MySQL, but I don't know enough
> about the subject to comment on how this would affect the user.]

We use it when creating new tables during fresh installs with MySQL
4.1.0 or greater.  We don't change the tables during upgrade since we
would have to do charset conversion.  SET NAMES sets the charset of
the MySQL client, connection, and results to match the charset of the
tables.  If they don't all match, MySQL will try to do character
conversion, which we don't want.  See here:

http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

Those upgrading from previous version should not add DB_CHARSET to
their wp-config.php because that will cause SET NAMES to set the
charset of the client and connection to something that might not match
the tables.

So, basically, if you are doing a fresh install, don't change the
value of DB_CHARSET.  If you are doing an upgrade, don't add
DB_CHARSET.  These are there for contrary people who like to have
difficult lives.  :-)

In the future, we might automatically convert existing tables to UTF-8
during upgrade, or at least provide a script that folks can run that
will do it for them if they so choose.

Ryan


More information about the wp-testers mailing list