1.安装mysql中选择数据字符集为utf-8
2.创建数据库
create database zhaochao charset utf8;
3.创建表时
create table user(id int ,username varchar(60),userpasswd varchar(60)) charset utf8;
4.插入数据时
set names gbk;
C:UsersAdministrator>mysql -uroot -padmin Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 to server version: 5.0.22-community-nt Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> create database zhaochao charset utf8; Query OK, 1 row affected (0.00 sec) mysql> use zhaochao; Database changed mysql> create table user(id int ,username varchar(60),userpasswd varchar(60)) charset utf8; Query OK, 0 rows affected (0.07 sec) mysql> show variables like '%char%'; +--------------------------+---------------------------------------------------------+ | Variable_name | Value | +--------------------------+---------------------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | C:Program FilesMySQLMySQL Server 5.0sharecharsets | +--------------------------+---------------------------------------------------------+ 8 rows in set (0.00 sec) mysql> insert into user values (1,'赵超','zhaochao'); ERROR 1406 (22001): Data too long for column 'username' at row 1 mysql> set names gbk; Query OK, 0 rows affected (0.00 sec) mysql> insert into user values (1,'赵超','zhaochao'); Query OK, 1 row affected (0.02 sec) mysql> select * from user; +------+----------+------------+ | id | username | userpasswd | +------+----------+------------+ | 1 | 赵超 | zhaochao | +------+----------+------------+ 1 row in set (0.00 sec) mysql> select * from user; +------+----------+------------+ | id | username | userpasswd | +------+----------+------------+ | 1 | 赵超 | zhaochao | | 1 | 赵云 | zhaoyun | +------+----------+------------+ 2 rows in set (0.00 sec) mysql> select * from user; +------+----------+------------+ | id | username | userpasswd | +------+----------+------------+ | 1 | 赵超 | zhaochao | | 1 | 赵云 | zhaoyun | | 1 | 赵云 | zhaoyun | +------+----------+------------+ 3 rows in set (0.00 sec)