MySQL database character set garbled and library character set change

Source: Internet
Author: User

Unified Character Set guaranteed not garbled: suggested Chinese and English environment Choice UTF8

1.Linux system language

/etc/sysconfig/i18n

Lang= "Zh_cn.utf8"

2.mysql client

Temporary:

Set names UTF8;

Permanent:

configuration file my.cnf

[Client]

Default-charater-set=utf8


3.mysql server

[Mysqld]

Character-set-server=utf8

4.MySQL build database Build Table statement

Specify character Set Build library

Create DATABASE Oldboy_utf8 default Character set uft8 collate utf8_general_ci;

Specifying a character set to build a table

CREATE TABLE Student (

ID int (4) NOT NULL auto_increment,

Name Char (a) is not NULL,

Primary KEY (ID)

) Engine=inonodb auto_increment=10 Default Charset=utf8

5. character set of the development program


simulate The actual process of Modifying a database of the latin1 character set into a GBK character Set

1. Export table Structure

Mysqldump-uroot-p--default-character-set=latin1-d dbname >alltatale.sql

--default-character-set=latin1 connecting the- D only guide table structure with latin1

2. Edit alltable.sql to change latin1 to GBK

Sed replacement

3. Ensure that the database is not updated, export all data

Mysqldump-uroot-p--quick--no-create-info--extended-insert--default-character-set=latin1 dbname >alldata.sql

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/8B/0F/wKioL1hDvOXQXg4pAAKbP5wYnIA523.png "title=" Picture 1.png "alt=" Wkiol1hdvoxqxg4paakbp5wynia523.png "/>

4. Open alldata.sql to modify the set names latin1 to set names GBK; or modify the server and client of the system)

5. building a library

Create DATABASE dbname default CharSet bgk;

6. Create a table and execute alltable.sql

Mysql-uroot-p Dbname<alltable.sql

7. Import Data

Mysql-uroot-dbname < Alldata.sql


MySQL database character set garbled and library character set change

Related Article

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.