问题:输入中文报错:Incorrect string value
步骤:
1.查看MySQL编码设置
show variables like '%character%';
2.重新设置编码(注意:utf8)
set character_set_client = utf8;
set character_set_server = utf8;
set character_set_connection = utf8;
set character_set_database = utf8;
set character_set_results = utf8;
set collation_connection = utf8_general_ci;
set collation_database = utf8_general_ci;
set collation_server = utf8_general_ci;
修改完成后还是出现那个错误,于是用" s"查看数据库的编码
发现表中字段的编码都是latin1编码的,于是修改了表字段的编码之后就能够输入中文了
参考:
修改数据库编码的命令是:ALTER DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
修改表的编码的命令是:ALTER TABLE `category` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
修改表中字段的编码的命令是:ALTER TABLE `test` CHANGE `dd` `dd` VARCHAR( 45 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
注意:数据库可以接受“utf-8”,但是客户端只认gbk,为了让数据在客户端显示正常,将