5.10.1. The Character Set Used for Data and Sorting
By default, MySQL uses the
West European) character set and the
latin1_swedish_ci collation that sorts
according to Swedish/Finnish rules. These defaults are suitable
for the United States and most of Western Europe.
All MySQL binary distributions are compiled with
--with-extra-charsets=complex. This adds code
to all standard programs that enables them to handle
latin1 and all multi-byte character sets
within the binary. Other character sets are loaded from a
character-set definition file when needed.
The character set determines what characters are allowed in
identifiers. The collation determines how strings are sorted by
ORDER BY and
clauses of the
You can change the default server character set and collation
--collation-server options when you start the
server. The collation must be a legal collation for the default
character set. (Use the
statement to determine which collations are available for each
character set.) See Section 5.2.1, “mysqld Command Options”.
The character sets available depend on the
--with-extra-charsets= options to
configure, and the character set
configuration files listed in
| complex | all | none
See Section 2.8.2, “Typical configure Options”.
If you change the character set when running MySQL, that may
also change the sort order. Consequently, you must run
myisamchk -r -q
on all tables, or your indexes may not be ordered correctly.
When a client connects to a MySQL server, the server indicates
to the client what the server's default character set is. The
client switches to this character set for this connection.
You should use
when escaping strings for an SQL query.
mysql_real_escape_string() is identical to
except that it takes the
handle as the first parameter so that the appropriate character
set can be taken into account when escaping characters.
If the client is compiled with paths that differ from where the
server is installed and the user who configured MySQL didn't
include all character sets in the MySQL binary, you must tell
the client where it can find the additional character sets it
needs if the server runs with a different character set from the
You can do this by specifying a
--character-sets-dir option to indicate the
path to the directory in which the dynamic MySQL character sets
are stored. For example, you can put the following in an option
You can force the client to use specific character set as
This is normally unnecessary, however.