MySQL Modify character Set

Source: Internet
Author: User

First, modify the My.ini configuration file (MySQL configuration file)

Character_set_server = UTF8 #设置字符集


Restart MySQL database service

View the current database character set

Show VARIABLES like ' character% ';


Second, modify the database character set

ALTER DATABASE name character set UTF8;

PS: After modifying the database character set, the MySQL database needs to be restarted.


Third, modify the table character set

ALTER table name DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci


Generate all tables Modify Character Set statements:

SELECT table_name,concat (' ALTER TABLE ', table_name, ' DEFAULT CHARACTER SET ', A.default_character_set_name, ' COLLATE ', a . Default_collation_name, '; ') ExecuteSQL from INFORMATION_SCHEMA. Schemata A,information_schema. TABLES b
WHERE A.schema_name=b.table_schema
and a.default_collation_name!=b.table_collation
and b.table_schema= ' database name '


Iv. modifying the column character set

ALTER table table name change column name VARCHAR (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT null;


Generate all columns modify character Set statements:

Select B.table_name,b.column_name,b.character_set_name,b.collation_name
, CONCAT (' ALTER TABLE ', B.table_name, ' MODIFY ', B.column_name, ', B.data_type, ' (', B.character_maximum_length, ') ', Case when B.column_default was NULL then ' ELSE CONCAT (' DEFAULT \ ', B.column_default, ' \ ') END, ' COMMENT \ ', b.column_com ment, ' \ '; ') ExecuteSQL
From INFORMATION_SCHEMA. TABLES A,information_schema. COLUMNS b where b.character_set_name is not NULL and A.table_schema=b.table_schema and A.table_name=b.table_name
and A.table_collation!=b.collation_name
and a.table_schema= ' database name '

MySQL Modify character Set

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.