MySQL database modified database encoding, field encoding and table encoding (GO)

Source: Internet
Author: User

Recently looked at the Kigg framework, found that in the EF + MySQL database, the data is garbled, using the tool (Navicat ) to view the structure of the table category found Kigg database is latin1 encoded by default (default Charset=latin1), as follows:

CREATE TABLE ' category ' (' Id ' binary (+) ' is not null, ' UniqueName ' varchar () '
' Name ' varchar (+) is not NULL,
' Createdat ' datetime not NULL,
PRIMARY KEY (' Id '),
KEY ' Ix_category_uniquename_createdat ' (' UniqueName ', ' Createdat ')
) Engine=innodb DEFAULT charset=latin1;

I changed the encoding format of the table to UTF8. View table The DDL of the Category Discovery table becomes,

CREATE TABLE ' category ' (

' Id ' binary (+) is not NULL,
' UniqueName ' varchar (+) Character Set Latin1 not NULL,
' Name ' varchar (character) set Latin1 not NULL,
' Createdat ' datetime not NULL,
PRIMARY KEY (' Id '),
KEY ' Ix_category_uniquename_createdat ' (' UniqueName ', ' Createdat ')
) Engine=innodb DEFAULT Charset=utf8;

The encoding type of the column (field) that was previously defined in the original table is not changed by the encoding format of the table, or latin1 (Latin format), but the new column is of type UTF8 format. This shows that the data encoding format in MySQL has been granular to the unit "column". The database encoding format can be specified when the database is being built, and the formatting of the tables and columns will be formatted as the default format. If you want to change the encoding format of the database later, you want to change the format of the previous table and the column encoding, you will have to change it all over. So, we want to make no worry about the encoding format of the database, as long as the MySQL installation directory below X:\Program file\mysql5 find a My.ini file, open with Notepad to find

default-character-set= the encoding format you want to set. You can modify its format. Build a library in the back, build a table, build a field and don't make any other settings, unless you want to ask for it.

The Kigg example of EF + MYSQL is garbled because the program is submitted to the database because the file is in UTF8 format, but the format of the field received in the database is latin1 format, so just change the column to UTF8 format.

Summary: For users of Microsoft-only SQL Server, it is very rare to view the encoding format of database data, because Microsoft has helped users with the corners of the work, so that we ignore a lot of important things. In MySQL to note the database, the table, the column corresponding to the encoding format does not contain the relationship, and ultimately determine the content in what encoding format to save or define the column when the encoding specified (' Name ' varchar () character Set latin1 not NULL,), Setting the encoding format for libraries and tables is only equivalent to setting the default encoding format for your own next level.

Http://www.cnblogs.com/seebook/archive/2010/11/06/1870649.html

1. Modify the encoding of the database
Modify the encoding of the database (test) to UTF8, such as:
ALTER DATABASE ' test ' DEFAULT CHARACTER SET UTF8 COLLATE utf8_bin;

2. Modify the encoding of the table
Change the encoding of the table (test) to UTF8, such as:
ALTER TABLE ' test ' DEFAULT CHARACTER SET UTF8 COLLATE utf8_bin;

3. Modifying the encoding of a field
Modify the encoding of the field (name) in the table (test) to UTF8, such as:
ALTER TABLE ' test ' change ' name ' ' name ' VARCHAR (Ten) CHARACTER SET UTF8 COLLATE utf8_bin not NULL;

Http://www.cnblogs.com/linuxer/archive/2012/09/24/2870515.html

MySQL database modify database encoding, field encoding and table encoding (GO)

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.