One of the principles----Modifying the database character set is that the new character set contains the font to >= the original character set font, otherwise the existing data may become garbled.
If there is no data in the database for the time being, we can execute the command directly. If a table is present in the database, the table's character set is not changed as the character set of the database changes.
ALTER DATABASE dbname Character Set Charset_name
If there is data in the database, you can actually execute the command, but it will leave a problem, that is, the character set of the table of the previously existing data, but only for the newly added table or record to take effect.
In this case, we can modify the character set by another method.
Simulate the environment, simulate changing the character set of database A from latin1 to GBK (the parameters in the following statement are the specific meanings of your own)
1.export the existing table structure in a database (table A is present in a database)
Mysqldump-uroot-p--default-character-set=gbk-d A >table_create.sql
2. Manually set the table structure in Table_create.sql to GBK
The specific is:
CREATE TABLE ' A ' ( ' id ' int (one) default NULL) Engine=innodb default CHARSET=GBK;
3. Verify that the application is no longer modifying data for all tables in a database, and then export all data
Mysqldump-uroot-p--quick--no-create-info--extended-insert--default-character-set =latin1 A>A_data.sql
4. Open A_data.sql and modify the set NAMES latin1 to set NAMES GBK.
/*!40101 SET NAMES GBK */;
5. Delete the previous database
6. Create a database with the same name using the new character set
Create DATABASE A default CharSet GBK;
7. Use Table_create.sql to create a table
Mysql-uroot-p A <table_create.sql
8.import data, using A_data.sql
Mysql-uroot-p A <a_data.sql
So far, we have completely modified the character set of a database from Latin1 to GBK
MySQL modifies the character set of the database