content_image/727959.jpg
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 latin1  character set and latin1_swedish_ci  collation in particular contexts as an alternative to the defaults of utf8mb4  and utf8mb4_0900_ai_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: 

CREATE DATABASE mydb CHARACTER SET latin1 COLLATE latin1_swedish_ci; 

Tables created in the database use latin1  and latin1_swedish_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 ’latin1’  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=latin1  command-line option to achieve the same effect as SET NAMES ’latin1’ . 

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

<img src='content_image/727959.jpg'>

## Note 

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.17, “CREATE PROCEDURE and CREATE FUNCTION Statements” .) 

• Specify character settings at server startup.  To select a character set and collation at server startup, use the --character-set-server  and --collation-server  options. For example, to specify the options in an option file, include these lines: 

[mysqld] character-set-server=latin1 collation-server=latin1_swedish_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 SET NAMES  or equivalent after they connect, as described previously. You might be tempted to start the server with the -- init_connect="SET NAMES ’latin1’"  option to cause SET NAMES  to be executed automatically for each client that connects. However, this may yield inconsistent results because the init_connect value is not executed for users who have the CONNECTION_ADMIN  privilege (or the deprecated SUPER privilege). 

• 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: 

