What is the difference between setting the directive default-character-set under [client] as opposed to [mysqld]?

dba.stackexchange https://dba.stackexchange.com/questions/13395

  •  16-10-2019
  •  | 
  •  

Question

Reference: https://stackoverflow.com/a/8690422/784637

Correct me if I'm wrong, but the best answer suggests a way to force everything being inputted into the database to be encoded in utf-8 and everything going out of the database to be encoded in utf-8.

What's the difference between the following two:

[client]
default-character-set=utf8

[mysqld]
default-character-set = utf8

Does the directive under [mysqld] force all the writes to the database to be encoded under a certain format and the directive under [client] force all of the output to be encoded in a certain format?

For example if the following two directives are set:

[client]
default-character-set=utf8

[mysqld]
default-character-set = utf8

and a there's a php string $var that is encoded in latin1, if that string is inserted into the database, it will be stored in the database as utf-8. But if a select statement is performed to retrieve that value, it would be encoded in latin1.

Was it helpful?

Solution

[client]
default-character-set=utf8

This option can force client programs to use specific character set. This is normally unnecessary. However, when character_set_system differs from character_set_server or character_set_client, and you input characters manually (as database object identifiers, column values, or both), these may be displayed incorrectly in output from the client or the output itself may be formatted incorrectly. In such cases, starting the mysql client with --default-character-set=system_character_set—that is, setting the client character set to match the system character set—should fix the problem.

[mysqld]
default-character-set = utf8

MySQL Server has a server character set and a server collation. These can be set at server startup on the command line or in an option file and changed at runtime. The server character set and collation are used as default values if the database character set and collation are not specified in CREATE DATABASE statements. They have no other purpose.

Conclusion: Client setting is at session level whenever client connects to server, server forces clients to use specific charset however this is not necessary. Mysqld section charset indicates that server is configured to use particular charset by default however you can change charset at any level Database,Table and Column level you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top