MySQL database table garbled _ MySQL

Source: Internet
Author: User
MySQL database table garbled solution bitsCN.com

MySQL database table garbled solution

It is very important to specify the encoding when creating a mysql database. many developers use the default encoding, but from my experience, coding databases can avoid garbled characters caused by import and export.

The standard we follow is that the encoding of databases, tables, fields, and pages or texts should be unified.

Many mysql database tools (except phpmyadmin, which are occasionally used and feature-intensive) do not support specifying database encoding during creation. of course, you can change it to my. ini to solve this problem, but you need to restart mysql, but the following statement will be more effective

GBK: create database test2 default character set gbk COLLATE gbk_chinese_ci;

UTF8: create database 'test2' default character set utf8 COLLATE utf8_general_ci

Note: If it is not set through the my. ini configuration file, it is only valid in the current status and will expire after the database service is restarted. Therefore, if you want to modify the my. ini file without garbled characters, you can specify UTF8 during database creation as follows:

| Character_set_client | utf8 |

| Character_set_connection | utf8 |

| Character_set_database | utf8 |

| Character_set_filesystem | binary |

| Character_set_results | utf8 |

| Character_set_server | latin1 |

| Character_set_system | utf8

Note this configuration | character_set_server | latin1 cannot be set to UTF8

Garbled characters still occur during interaction.

Only when UTF8 is set in my. ini will all be changed to UTF8

-------------------------

Mysql encoding command

SET character_set_client = utf8;

SET character_set_connection = utf8;

SET character_set_database = utf8;

SET character_set_results = utf8;

SET character_set_server = utf8;

SET collation_connection = utf8_bin;

SET collation_database = utf8_bin;

SET collation_server = utf8_bin;

Configure the default encoding in my. ini

Default-character-set = utf8

Connect to the database and set the encoding

Jdbc: mysql :/// 192.168.0.5: 3306/test? CharacterEncoding = utf8

Common coding UTF-8 in java; GBK; GB2312; ISO-8859-1;

Corresponds to the UTF-8, gbk, gb2312, and latin1 codes in the mysql database.

---------------------------

URL = jdbc: mysql: // yourIP/college? User = root & password = yourPassword & useUnicode = true & characterEncoding = gbk

When creating a DATABASE: CREATE database 'database'

Character set 'utf8'

COLLATE 'utf8 _ general_ci ';

2. create table 'database _ user '(

'Id' varchar (40) not null default '',

'Userid' varchar (40) not null default '',

) ENGINE = InnoDB default charset = utf8;

3. when setting a URL, jdbc: mysql: // localhost/database? SeUnicode = true; characterEncoding = UTF-8

Alter database 'test' default character set utf8 COLLATE utf8_bin

Alter table 'category' default character set utf8 COLLATE utf8_bin

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.