Current location - Trademark Inquiry Complete Network - Trademark inquiry - How to solve the Chinese garbled code in MySQL database
How to solve the Chinese garbled code in MySQL database
Mysql data garbled problems may have the following three reasons:

1. The server itself is set, for example, it still stays in latin 1 version;

2.2. Language family settings of table (including characters and sorting rules);

3. Connection language settings of client programs (such as php and Java);

Recommend Utf8! ! ! !

To avoid the Chinese garbled problem of mysql, you can try the following methods:

1, for the version problem, it is recommended to go to official website to update the latest version or a more useful version;

2, create a database, create a table without setting the character encoding will cause the problem of garbled code:

When creating a database: create a database test.

Character set' utf8'

Organize "utf8 _ general _ ci";

Create table database_user (

` ID` varchar(40) NOT NULL default ' ',

` userid ` varchar(40)NOT NULL default ' ',

)ENGINE = InnoDB DEFAULT CHARSET = utf8;

3, for the third case, the reference method:

Edit the file /etc/my.cnf in the linux server and add default _ character _ set = utf8 in the [mysql] section.

If only debugging encounters garbled problems:

When writing a connection URL, add? Use unicode = true & ampcharacterencoding = utf-8 parameter;

And add "set names utf8" or "set names gbk" instruction in the webpage code to tell MySQL to use utf-8 or gbk for connection.

Utf8 or gbk