Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Reference: http://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.

share|improve this question
    
Just realized the directive under the [client] indicates the character set the client will use to send SQL statements to the server. It also specifies the character set that the server should use for sending results back to the client. This is from dev.mysql.com/doc/refman/5.0/en/charset-connection.html –  user784637 Feb 19 '12 at 4:01

1 Answer 1

up vote 1 down vote accepted
[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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.