MySQL Chinese garbled solution method

Source: Internet
Author: User

Recent projects have been used to MySQL. But suddenly appeared in Chinese garbled problem. Try a variety of solutions, finally solve the garbled problem, summed up the solution, to meet the same problem people a little reference.

Reasons for Chinese garbled characters

1. Problem with encoding set when installing MySQLServer
2. There is a problem with the encoding set when creating the database
3. There is a problem with the encoding set when creating the table
Problem with 4.client encoding set setup
Ability to view the encoding set by command:

show variables like "%char%";

Use encoding sets frequently

1.java in the regular use of coding UTF-8; GBK; gb2312;iso-8859-1;
2. Encoding utf8;gbk;gb2312;latin1 in the corresponding MySQL database
It is recommended to use the UTF8 format, UTF8 compatible with all the characters in the world

MySQL Encoding set settings command

Note: Assuming that the content is not set through the My.ini configuration file, it is only valid in the current state and is invalidated when the database service is restarted. So if you want to not have garbled only change My.ini file, database encoding can be specified UTF8

when creating a database

mysql设置编码命令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;

Set MySQLServer encoding

Sets the encoding of the MySQLServer. You need to install the MySQL service again, such as the following steps:
1. Open a command prompt (administrator). Assume that an error may occur if you do not perform as an administrator
2. Go to the Bin folder under the MySQL installation folder
3. Close the service

stop mysql

4. Uninstall

mysqld -remove

5. Change the MySQL configuration file. Locate the My.ini file under the MySQL installation folder

Change config file, add in config file

character-set-server=utf8

Paste out my configuration file

[mysqld]##这里把路径改改为你的mysql安装文件夹basedir=D:\develeper\mysql5.6 datadir=D:\develeper\mysql5.6\data

My configuration file: Http://pan.baidu.com/s/1qW3hqri

6. Installation

mysqld -install

7. Start the service

start mysql

Specify character set when creating

1. Set the character set when creating a database

create database testdb default character set utf8;#建立数据库

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, the client character set settings. Set by the connection string.

jdbc:mysql://localhost:3306/testdb?

characterEncoding=utf8

MySQL Chinese garbled solution method

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.