Mysql modifies character sets

Source: Internet
Author: User


View the encoding: show variables like 'collation _ % '; show variables like 'character _ set _ %'; Modify: MySQL: Modify the default character set and convert the character set (MySQL 5.X) 1. modify the default character set of the MySQL database (mysql database default character set) alter database testdb default character set = gb2312; -www.2cto.com-2. modify the default character set of a MySQL DATA table (mysql table default character set) alter table ip_to_country default character set = gb2312; Note: Modify the default character set of MySQL at the database or data table level, for stored words The data is unchanged. Only new tables or columns are added to start using the new character set. 3. mySQL has a data table ip_to_country In the mysql table character set. In the past, the data in character columns in this table was stored in utf8 encoding format. Now, you want to convert it to gb2312 encoding format. You need to use the MySQL character set conversion command: convert to character set alter table ip_to_country convert to character set gb2312; -www.2cto.com-Note: convert to also changes the default character set of ip_to_country from utf8 to gb2312. 4. convert the character set of a column in the MySQL DATA table (mysql column character set) alter table ip_to_country modify country_name varchar (50) character set gb2312; this statement converts the character set of a single column country_name to gb2312. This is rarely used in practice, because in most cases, the character set of the entire table is changed. MySQL Character Set modification command (10:57:31) label: mysql Character Set it MySQL Character Set modification command 1. modify server level. temporary changes: mysql> set global character_set_server = utf8; B. permanent change: shell> vi/etc/my. cnf [mysqld] default-character-set = utf8 2. modify database level. temporary changes: mysql> set global character_set_database = utf8; B. permanent modification: You can change the server level to -www.2cto.com-3. modify the TABLE-level mysql> Alter TABLE table_name default charset utf8; the change takes effect permanently. example of modifying a column-level modification: mysql> Alter TABLE 'products' CHANGE 'products _ model' VARCHAR (20) character set utf8 COLLATE utf8_general_ci null default null; the change takes effect permanently. change the connection Character Set. temporary changes: mysql> set names utf8; B. permanent change: shell> vi/etc/my. cnf added in [client]: default-character-set = utf8 author DouglasLau

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.