MySQL Chinese character garbled problem analysis-mysql tutorial

Source: Internet
Author: User
Tags mysql tutorial
Mysql garbled 90% are Chinese characters will appear garbled, English is not garbled, so we should be able to think of mysql default is to support uft-8 encoding Oh, the solution is simple

Mysql garbled 90% are Chinese characters will appear garbled, English is not garbled, so we should be able to think of mysql default is to support uft-8 encoding Oh, the solution is simple

Solve the problem of garbled code on the webpage, which is defined during program query

The code is as follows:
Db = mysql _ connect ("localhost", "user", "pass ");
Mysql _ db ("message", $ db );
Mysql_query ("set names 'utf8'", $ db );

Set all environments to utf8 encoding. you can use it in the sqlYog query window.

1. show variables like 'character _ set _ % ';

Edit configuration file

1. edit/etc/my. cnf and add it to the [mysql] section.

The code is as follows:
Default_character_set = utf8;


Chinese characters garbled during data import

1: save the data encoding format as UTF-8

Set the default encoding to utf8:

The code is as follows:

Set names utf8;

Set db_name to utf8 by default:

The code is as follows:

Alter database 'DB _ name' default character set utf8 COLLATE utf8_general_ci;

Set the default table tb_name encoding to utf8:

The code is as follows:

Alter table 'TB _ name' default character set utf8 COLLATE utf8_general_ci;

Import:

The code is as follows:

Load data local infile 'C: \ utf8.txt 'into table yjdb;

Phpadmin Chinese garbled characters

Find the libraries folder in the Phpmyadmin folder and modify the select_lang.lib.php file.

A) zh-gb2312 modified to zh-gb2312-utf-8

B) modify the MySQL_charset_map array.

The code is as follows:

Change 'gb2312' => 'utf-8' to 'gb2312' => 'latin1' (some display 'gb2312' => 'gb2312'. The same is true)

C) modify the MySQL_charset_map array.

The code is as follows:

Change 'utf-8' => 'utf-8' to 'utf-8' => 'latin1', and restart httpd.

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.