Welcome to the Linux community forum and interact with 2 million technical staff. Recently, you have encountered database coding problems, which makes your system feel as uncomfortable as a beautiful girl but suddenly finds her illiterate, in fact, there are many coding problems, and there are many designs for encoding in mysql (especially). Here we will make a screening: 1mysql encoding is used below
Welcome to the Linux community forum and interact with 2 million technical staff> recently, we have encountered database coding problems, it makes your system feel as uncomfortable as a beautiful girl suddenly finds that she is not literate. In fact, many times it is a coding problem, and there are many places for mysql (especially) to design encoding, here is a screening: 1 mysql code is used below
Welcome to the Linux community forum and interact with 2 million technicians>
Recently, you have encountered database Encoding Problems, which make your system look like a beautiful girl but suddenly finds it as hard to read. In fact, many times it is a coding problem, while mysql (especially) there are a lot of places to design the code. Here is a screening:
1 mysql code
Run the following command to view the current default encodings of mysql:
Showvariables like 'character \ _ set \ _ % ';
The default mysql encoding is displayed;
Showvariables like 'collation _ % ';
Set the corresponding encoding in my. cnf:
[Client]
Default-character-set = utf8
[Mysqld]
Collation_server = utf8_general_ci
Character_set_server = utf8
[Mysql]
Default-character-set = utf8
[Mysqldump]
Default-character-set = utf8
2 database code:
Create database if not exists my_db default charset utf8COLLATE utf8_general_ci;
3. Data Table Encoding
/*! 40101 SET @ saved_cs_client
= @ Character_set_client */;
/*! 40101 SET character_set_client = utf8 */;
CREATETABLE 'access '(
'Id' int (8) unsigned not null AUTO_INCREMENT,
'Role _ id' smallint (6) unsigned not null,
'Node _ id' smallint (6) unsigned not null,
Primary key ('id '),
KEY 'nodeid' ('node _ id ')
) ENGINE = MyISAM AUTO_INCREMENT = 364 DEFAULTCHARSET = utf8;
/*! 40101 SET character_set_client = @ saved_cs_client */;
4. During the transfer
Sometimes you need to store the database, but if the database is transferred to the new database, it will be garbled. You may need:
# Mysqldump -- default-character-set utf8-u root-pmypass mydb> mydb. SQL
5. Query
Sometimes, although the SQL file encoding of mysql, database, data table, and exported data is normal, garbled characters still occur during query, probably because encoding is also required during query, function names are similar. in php + mysql, they are:
Mysql_query ('set names utf8 ');