MySQL Latin 1 convert to UTF8

Source: Internet
Author: User

This example environment installs MARIADB 5.5.56 for CentOS 7.4 yum


Environment Preparation: Create Latin1 encoded libraries, tables, data

MySQL--default-character-set=latin1

Show variables like ' char% ';

650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/22/5aa88edd6aaad80fa52253a1bf77a43f.png "title=" QQ picture 20171122112812.png "alt=" 5aa88edd6aaad80fa52253a1bf77a43f.png "/>

Create database Latin;

Show create database Latin;

Use Latin

CREATE TABLE student (ID int,name varchar (), Age Int,class varchar (20));

INSERT into student values (1, ' Zhang San ', 18, ' math ');

INSERT into student values (2, ' John Doe ', 28, ' languages ');

Show create table student;

SELECT * from student;

650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/22/e5647a87bb26387986fa00991040b763.png "title=" QQ picture 20171122113014.png "alt=" E5647a87bb26387986fa00991040b763.png "/>


Official start:

1 Backing up data

Mysqldump--default-character-set=latin1 Latin >latin.sql


2 Modifying the server-side configuration file

Vi/etc/my.cnf added in [mysqld] Segment

Character_set_server = UTF8


3 Restarting the service takes effect

Systemctl Stop MARIADB

Systemctl Start mariadb


4 changing character encoding to UTF8

Sed-n S/LATIN1/UTF8/GP Latin.sql

Sed-i s/latin1/utf8/g Latin.sql


5 Creating a new library import data

MySQL--default-character-set=utf8

Show variables like ' char% ';

650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/22/6769216433c8f11a993095f200e3a552.png "title=" QQ picture 20171122112916.png "alt=" 6769216433c8f11a993095f200e3a552.png "/>

Create Database UTF8;

Show create Database UTF8;

Use UTF8

Source/root/latin.sql


6 Verification

SELECT * from student;

650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/22/d5fb21ff2bfd724e88c76c87504b595e.png "title=" QQ picture 20171122113038.png "alt=" D5fb21ff2bfd724e88c76c87504b595e.png "/>

MySQL Latin 1 convert to 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.