1. Set up the character set when MySQL is installed
MySQL database is installed at the time. Select the language as UTF8 or GBK so that you can store Chinese in the database.
2. Setting the character set when creating a table
For example:
CREATE TABLE T_department (
Sid varchar Not NULL,
PID varchar not NULL,
Thedata varchar (m) Not NULL
) Engine=innodb DEFAULT Charset=utf8;
3. Change the field character set property in a table
Take the Users table for example: 1. View Table Properties
Mysql> Show create table users;
+-------+-----------------------------------------------------------------------
-------------------------- ----------------------------------------------------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
-------------------------- ----------------------------------------------------+
| users | CREATE TABLE ' users ' (
' userid ' int () default NULL,
' username ' char () character Set latin1 default Null
) Engine=innodb DEFAULT CHARSET=GBK |
+-------+-----------------------------------------------------------------------
------------------------- -----------------------------------------------------+
1 row in Set (0.00 sec)
2. The error occurs when there is data in the table, so changing the username character set does not succeed and requires emptying the data in the Users table
mysql> truncate table users;
Query OK, 3 rows affected (0.01 sec)
3. Re-change the character set of username in the user table
Mysql> ALTER TABLE users modify username char (a) character set GBK;
Query OK, 0 rows affected (0.06 sec)
records:0 duplicates:0 warnings:0
4. It is best to restart MySQL, and then you can insert Chinese
Mysql> INSERT into users values (88, ' Chinese ');
Query OK, 1 row affected (0.01 sec)
mysql> select * from users;
+--------+----------+
| userid | username
| +--------+----------+
| 88 | chinese |
+--------+----------+
1 row in Set (0.00 sec)
Source: http://blog.csdn.net/coder_chang/article/details/54007143