Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 36.3Mb
PDF (A4) - 36.4Mb
Man Pages (TGZ) - 235.6Kb
Man Pages (Zip) - 347.1Kb
Info (Gzip) - 3.3Mb
Info (Zip) - 3.3Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  Character Sets, Collations, Unicode  /  Configuring Application Character Set and Collation

10.5 Configuring Application Character Set and Collation


  • Specify character settings per database. For example, applications that use one database might use the default of latin1, whereas applications that use another database might use 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 as the defaults for all applications, without having to specify them at server startup.



The examples shown here assume use of the utf8 character set and utf8_general_ci collation in particular contexts as an alternative to the defaults of latin1 and latin1_swedish_ci.

  • Specify character settings per database.  To create a database such that its tables use a given default character set and collation for data storage, use a CREATE DATABASE statement like this:

      CHARACTER SET utf8
      COLLATE utf8_general_ci;

    Tables created in the database use utf8 and utf8_general_ci by default for any character 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 SET NAMES 'utf8' statement after connecting. The statement can be used regardless of connection method (the mysql client, PHP scripts, and so forth).

    In some cases, it may be possible to configure the connection to use the desired character set some other way. For example, to connect using mysql, you can specify the --default-character-set=utf8 command-line option to achieve the same effect as SET NAMES 'utf8'.

    For more information about configuring client connections, see Section 10.4, “Connection Character Sets and Collations”.


    If you use ALTER DATABASE to change the database default character set or collation, existing stored routines in the database that use those 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 Section 13.1.16, “CREATE PROCEDURE and CREATE FUNCTION Statements”.)





  • Specify character settings at MySQL configuration time.  To select a character set and collation if you configure and build MySQL from source, use the DEFAULT_CHARSET and DEFAULT_COLLATION CMake options:

    cmake . -DDEFAULT_CHARSET=utf8 \


