MySql不能输入中文之1366错误

来源:互联网 发布:手机登录淘宝卖家中心 编辑:程序博客网 时间:2024/05/16 00:54
mysql插入中文报错:incorrect string value:...
1、查看当前table的字符编码
  show create table tname;确认为gbk或者utf8。
2、进入安装目录下的 my.ini修改配置,
有两个地方需要修改,一个是client端的还有一个是server端的
1. # CLIENT SECTION 
2. # ----------------------------------------------------------------------  
3. #  
4. # The following options will be read by MySQL client applications.  
5. # Note that only client applications shipped by MySQL are guaranteed  
6. # to read this section. If you want your own MySQL client program to 
7. # honor these values, you need to specify it as an option during the  
8. # MySQL client library initialization.  
9. #  
10. [client]  
11. port=3306  
12. [mysql]  
13. default-character-set=gbk
13. #default-character-set=utf8
14.  
15. # SERVER SECTION 
16. # ----------------------------------------------------------------------  
17. #  
18. # The following options will be read by the MySQL Server. Make sure that  
19. # you have installed the server correctly (see above) so it reads this   
20. # file.  
21. #  
22. [mysqld]  
23. # The TCP/IP Port the MySQL Server will listen on 
24. port=3306  
25.  
26. #Path to installation directory. All paths are usually resolved relative to this.  
27. basedir="C:/Program Files/MySQL/MySQL Server 6.0/" 
28. #Path to the database root  
29. datadir="C:/Program Files/MySQL/MySQL Server 6.0/Data/" 
30. # The default character set that will be used when a new schema or table is 
31. # created and no character set is defined  
32. default-character-set=gbk
32. #default-character-set=utf8

还要在创建数据库的时候 指定 default charset=gbk
创建表的时候最好也加上。
create table data(
        id int primary key auto_increment,
        sid varchar(256) not null,
        name varchar(256) not null,
        longitude decimal(10,6) not null,
        latitude decimal(9,6) not null,
        jam_level integer(1) not null,
        description text,
        insert_time timestamp not null,
        update_time timestamp not null
)default charset=gbk
按以上操作后,中文可以插入mysql数据库中了(最好此时重启下mysql服务:net stop mysql,net start mysql)。
原创粉丝点击