Convert utf8 to gbk utf8 to gbk
Use the set names character set
Character_set_client
Character_set_result
Character_set_connection these three items are set as set names gbk in the cmd black window; at that time, the data file layer and the system management layer are utf8. during The cmd window query, the data is retrieved from the file and passed through the data management layer and then to character_set_result. in this process, there should be encoding conversion problems. convert from utf8 to gbk? Then, if this conversion happens, there should be garbled characters.
Reply to discussion (solution)
Yes, and your file code must be gbk.
If you use cmd to directly connect to the mysql client, mysql automatically converts
If you execute php in cmd, the output depends on the php file encoding.
From the database to php is an IO, and from php echo to cmd is also an IO. pay attention to the encoding changes before and after the two IO
You said that cmd should be windows. windows cmd follows the system encoding by default. for example, for windows in simplified Chinese, cmd uses cp936 (equivalent to gbk) encoding by default, this encoding can be changed permanently through the registry, or temporarily using the "chcp xxx" command, where xxx is the encoding number, 936 is equivalent to gbk, 65001 is equivalent to UTF-8
At the beginning of cmd, enter chcp 65001 and press Enter. the cmd window is equivalent to UTF-8 encoding output.
Note: cpxxx is a Microsoft-defined code, which is slightly different from the corresponding general-purpose code. Generally, these differences are not involved in use, so the above statements are "equivalent"
I learned to add my favorite to my favorites.
As long as your data field connection proofreader is a Chinese series (gbk, big5, utf8, UCS-2, UTF-16 ....)
In this case, you only need to set the names character set, and then you can operate according to the character set you need.
Mysql completes code conversion for you.