Oracle 5.0 Reference Manual page 799

Table of Contents

Advertisement

Configuring the Character Set and Collation for Applications
• Specify character settings per database. For example, applications that use one database might
require utf8, whereas applications that use another database might require sjis.
• Specify character settings at server startup. This causes the server to use the given settings for all
applications that do not make other arrangements.
• Specify character settings at configuration time, if you build MySQL from source. This causes the
server to use the given settings for all applications, without having to specify them at server startup.
When different applications require different character settings, the per-database technique provides
a good deal of flexibility. If most or all applications use the same character set, specifying character
settings at server startup or configuration time may be most convenient.
For the per-database or server-startup techniques, the settings control the character set for
data storage. Applications must also tell the server which character set to use for client/server
communications, as described in the following instructions.
The examples shown here assume use of the
Specify character settings per database. To create a database such that its tables will use a given
default character set and collation for data storage, use a
CREATE DATABASE mydb
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
Tables created in the database will use
columns.
Applications that use the database should also configure their connection to the server each time
they connect. This can be done by executing a
statement can be used regardless of connection method: The
In some cases, it may be possible to configure the connection to use the desired character set some
other way. For example, for connections made using mysql, you can specify the
character-set=utf8
'utf8'.
For more information about configuring client connections, see
Sets and
Collations".
If you change the default character set or collation for a database, stored routines that use the
database defaults must be dropped and recreated so that they use the new defaults. (In a stored
routine, variables with character data types use the database defaults if the character set or collation
are not specified explicitly. See
Syntax".)
Specify character settings at server startup. To select a character set and collation at server
startup, use the
--character-set-server
example, to specify the options in an option file, include these lines:
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
These settings apply server-wide and apply as the defaults for databases created by any application,
and for tables created in those databases.
It is still necessary for applications to configure their connection using
after they connect, as described previously. You might be tempted to start the server with the
--init_connect="SET NAMES 'utf8'"
automatically for each client that connects. However, this will yield inconsistent results because the
[456]
value is not executed for users who have the
init_connect
utf8
and
utf8
SET NAMES 'utf8'
[266]
command-line option to achieve the same effect as
Section 13.1.9,
"CREATE PROCEDURE
[403]
[456]
779
character set and
utf8_general_ci
CREATE DATABASE
by default for any character
utf8_general_ci
statement after connecting. The
client, PHP scripts, and so forth.
mysql
Section 10.1.4, "Connection Character
and
and
--collation-server
SET NAMES
option to cause
SET NAMES
SUPER
collation.
statement like this:
--default-
SET NAMES
CREATE FUNCTION
[403]
options. For
or equivalent
to be executed
[578]
privilege.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents