To modify the character set of a database library table

Source: Internet
Author: User

To modify the character set of a database library table


Data Character Set modification steps

Corresponding to the existing database to modify the character set, cannot be directly through the "ALTER DATABASE character set *"

or "ALTER TABLE tablename Character set *", both commands do not update the existing recorded character set, but only the newly created table or record takes effect.


There is already a record of the character set adjustment, you must want to export the data, modified character set after re-import to complete


Modify the database default encoding

ALTER DATABASE name CharSet character set name


ALTER DATABASE lvnian1 CharSet UTF8;

ALTER DATABASE lvnian1 character set GBK;


########################################

mysql> help ALTER DATABASE;

Name: ' ALTER DATABASE '

Description:

Syntax:

ALTER {DATABASE | SCHEMA} [Db_name]

Alter_specification ...

ALTER {DATABASE | SCHEMA} db_name

UPGRADE DATA DIRECTORY NAME


Alter_specification:

[DEFAULT] CHARACTER SET [=] Charset_name

| [DEFAULT] COLLATE [=] Collation_name

For example:

mysql> CREATE DATABASE Lvnian1;

Query OK, 1 row affected (0.01 sec)


Mysql> Show CREATE Database lvnian1\g;

1. Row ***************************

Database:lvnian1

Create database:create Database ' lvnian1 '/*!40100 DEFAULT CHARACTER SET latin1 */

1 row in Set (0.00 sec)


ERROR:

No query specified


mysql> ALTER DATABASE lvnian1 CharSet UTF8;

Query OK, 1 row Affected (0.00 sec)


Mysql> Show CREATE Database lvnian1\g;

1. Row ***************************

Database:lvnian1

Create database:create Database ' lvnian1 '/*!40100 DEFAULT CHARACTER SET UTF8 */

1 row in Set (0.00 sec)


ERROR:

No query specified


Mysql>

mysql> ALTER DATABASE lvnian1 character set GBK;

Query OK, 1 row Affected (0.00 sec)


Mysql> Show CREATE Database lvnian1\g;

1. Row ***************************

Database:lvnian1

Create database:create Database ' lvnian1 '/*!40100 DEFAULT CHARACTER SET GBK */

1 row in Set (0.00 sec)


ERROR:

No query specified


Mysql>

#####################################################

Summarize a character set that modifies an existing record

For example: Now it is latin1 instead of UTF8

1, build the database and build the statement export, SED batch modified to UTF8

2. Export all data

3. Modify MySQL server and client code to UTF8

4, delete the original library table has data

5. Import new build database already built table statement

6. Import all MySQL data


###########################################################

###########################################################

###########################################################

###########################################################


This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1699450

To modify the character set of a database library table

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.