Mysql garbled 90% are Chinese characters will appear garbled, English is not garbled, so we should be able to think of mysql default is to support uft-8 encoding Oh, the solution is simple
Mysql garbled 90% are Chinese characters will appear garbled, English is not garbled, so we should be able to think of mysql default is to support uft-8 encoding Oh, the solution is simple
Solve the problem of garbled code on the webpage, which is defined during program query
The code is as follows: |
|
Db = mysql _ connect ("localhost", "user", "pass "); Mysql _ db ("message", $ db ); Mysql_query ("set names 'utf8'", $ db ); |
Set all environments to utf8 encoding. you can use it in the sqlYog query window.
1. show variables like 'character _ set _ % ';
Edit configuration file
1. edit/etc/my. cnf and add it to the [mysql] section.
The code is as follows: |
|
Default_character_set = utf8; |
Chinese characters garbled during data import
1: save the data encoding format as UTF-8
Set the default encoding to utf8:
The code is as follows: |
|
Set names utf8; |
Set db_name to utf8 by default:
The code is as follows: |
|
Alter database 'DB _ name' default character set utf8 COLLATE utf8_general_ci; |
Set the default table tb_name encoding to utf8:
The code is as follows: |
|
Alter table 'TB _ name' default character set utf8 COLLATE utf8_general_ci; |
Import:
The code is as follows: |
|
Load data local infile 'C: \ utf8.txt 'into table yjdb; |
Phpadmin Chinese garbled characters
Find the libraries folder in the Phpmyadmin folder and modify the select_lang.lib.php file.
A) zh-gb2312 modified to zh-gb2312-utf-8
B) modify the MySQL_charset_map array.
The code is as follows: |
|
Change 'gb2312' => 'utf-8' to 'gb2312' => 'latin1' (some display 'gb2312' => 'gb2312'. The same is true) |
C) modify the MySQL_charset_map array.
The code is as follows: |
|
Change 'utf-8' => 'utf-8' to 'utf-8' => 'latin1', and restart httpd. |