Modify the MySQL database character set to UTF8

Source: Internet
Author: User

First Kind

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

Iv. modifying the column character set

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

The second Kind

One is to modify the table's encoding format.

[SQL]View Plain Copy
    1. ALTER table 'table ' DEFAULT CHARACTER SET UTF8;

Modify the encoding format of a field because the table's encoding is changed to a field, so also modify the field modify field only one

[SQL]View Plain Copy
    1. ALTER TABLE ' tablename ' Change ' field name 1 ' Field Name 2 ' VARCHAR ( CHARACTER) SET UTF8 not NULL;

The ultimate way to modify multiple lines

[SQL]View Plain Copy
    1. Alter table ' tablename ' convert to character set UTF8;

Third Kind

1: View the current character encoding method mysql> show variables like '%character% '; +--------------------------+----------------------------+ | variable_name |                    Value |+--------------------------+----------------------------+|character_set_client |latin1 || Character_set_connection |latin1 | | Character_set_database |latin1 | | Character_set_filesystem |binary | | Character_set_results |latin1 | | Character_set_server |latin1 | | Character_set_system |utf8 | | Character_sets_dir | /usr/share/mysql/charsets/|+--------------------------+----------------------------+8 rows in Set (0.00 sec) When the character encoding is latin1, the user inserts a character type (char) record into the data table, which may not display the character type's data properly when displaying this record, so we modify the MySQL character encoding to UTF8. The operation is as follows: Step 2: Modify the MY.CNF configuration file as follows (/ETC/MY.CNF): [client] #password = Your_passwordport = 3306socket =/var/ Lib/mysql/mysql.sockdefault-character-set=utf8 #设置默认Encoded as UTF8 

Modify the MySQL database character set to UTF8

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.