code viewing method and Explanation:You need to log in as root to see how the database is encoded (the command logged in as root: >mysql-u root–p, then two times the root user's password), to view the database encoding command: >show variables Like ' character% '; +--------------------------+----------------------------+| variable_name | Value |+--------------------------+----------------------------+| character_set_client | Latin1 | | character_set_connection | Latin1 | | Character_set_database | Latin1 | | Character_set_filesystem | binary | | Character_set_results | Latin1 | | Character_set_server | Latin1 | | Character_set_system | UTF8 | | Character_sets_dir | /usr/share/mysql/charsets/|+--------------------------+----------------------------+ from the above information, the database encoding is latin1, Need to be modified to GBK or UTF8, where Character_set_client: encoding the client, the character set used in the query sent by the client character_set_connection: encoding used for establishing the connection; character_ Set_database: The encoding of the database, the character set set used by a library in the database server, and the character set settings specified when the server was installed if it was not specified when the library was built. Character_set_results: Encoding of the result set;to be
verified:
as long as the above to ensure that the same encoding method, there will be no garbled problem. Character_set_server: The encoding of the database server; The default character set specified when the server is installed. Character_system: The character set used by the database system. Another command to view the database encoding: >show VARIABLES like ' collation% ';
MySQL storage principles for character encoding
program configuration file. Connection string: Charset=utf8, Description:Query statements are sent to the server using this encoding format NOTE: The query results are still delivered in the format of the reverse data.
Query Statement execution logic:1. Program Configuration connection string: Charset=utf8, the query statement using "Charset=utf8" encoding of this format is sent to the server 2. MySQL converts the received query statement into the format specified by Character_set_client, 3. Then turn to character_set_connection specified format 4. The character_set_connection is then converted to an internal manipulation character-using the CHARACTER set setpoint for each data field-if the above value does not exist, the default CHARACTER set SetPoint of the corresponding data table is used (M Ysql extension, non-SQL standard);-If the above value does not exist, the default CHARACTER set value of the corresponding database is used;-if the above value does not exist, use the Character_set_server setpoint. 5. Convert the operation result from the internal operation character set to Character_set_results.
executing the statement execution logic1. Program Configuration connection string: Charset=utf8, the execution statement using "Charset=utf8" encoding of this format is sent to the server 2. MySQL converts the received query statement into the format specified by Character_set_client, 3. Then turn to character_set_connection specified format 4. Then convert character_set_connection to internal action character -use character set setpoint for each data field; - If the above value does not exist, the default CHARACTER set value of the corresponding data table (MySQL extension, non-SQL standard); -If the above value does not exist, the default of the corresponding database is used CHARACTER set setpoint; -If the above values do not exist, use the Character_set_server setpoint. 5. Convert the operation result from the internal operation character set to character_set_database storage