Mysql Chinese garbled solution _ MySQL

Source: Internet
Author: User
Recently, mysql was used in the project, but the Chinese garbled text problem suddenly occurred. I tried a variety of solutions and finally solved the garbled text problem. I summarized the solution and gave some reference to those who encountered the same problem. Cause of Chinese garbled characters 1. when installing mysqlserver, there was a problem with the collation setting. 2. I created a number of recent projects and used mysql. However, the Chinese garbled characters suddenly occurred. I tried a variety of solutions and finally solved the garbled problem, summarize the solution and give some reference to those who encounter the same problem.

Chinese garbled characters

1. when installing mysqlserver, the sequence set settings are incorrect.
2. there is a problem with the set setting when creating a database.
3. the sequence set settings are incorrect during table creation.
4. the consumer set setting on the client is incorrect.
You can run the following command to view the sequence set:

show variables like "%char%";

Common sequence set

1. common coding UTF-8 in java; GBK; GB2312; ISO-8859-1;
2. utf8, gbk, gb2312, and latin1 in the mysql database
We recommend that you use utf8 format. utf8 can be compatible with all characters in the world.

Mysql set setting command

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 when creating a database.

SET encoding = utf8; SET character_set_connection = utf8; SET character_set_database = utf8; SET encoding = utf8; SET encoding = utf8; SET collation_connection = utf8_bin; SET collation_database = utf8_bin; SET collation_server = utf8_bin;

Set mysqlserver encoding

To set the encoding of mysqlserver, you need to reinstall the mysql service. The process is as follows:
1. open the command prompt (administrator). If you do not run it as administrator, an error may occur.
2. go to the bin directory under the mysql installation directory.
3. close the service

net stop mysql

4. uninstall

mysqld -remove

5. modify the mysql configuration file and find the my. ini file in the mysql installation directory.

Modify the configuration file and add it to the configuration file.

character-set-server=utf8

Paste my configuration file

[Mysqld] # set character-set-server = utf8 # change the path to your mysql installation directory basedir = D: \ develeper \ mysql5.6 datadir = D: \ develeper \ mysql5.6 \ datasql_mode = NO_ENGINE_SUBSTITUTION, STRICT_TRANS_TABLES

My profile: http://pan.baidu.com/s/1qW3hqri

6. install

mysqld -install

7. start the service

net start mysql

Character set specified during creation

1. set character sets when creating a database

Create database testdb default character set utf8; # create a database

2. set the character set when creating a table

use testdb;create table student( id char(50) primary key, sname varchar(100) not null, age int )engine=innodb default charset=utf8;

3. set the character set of the client by connecting strings.

jdbc:mysql://localhost:3306/testdb?characterEncoding=utf8

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.