现在的位置: 首页 > 综合 > 正文

MySQL命令行插入中文出错的解决

2018年01月30日 ⁄ 综合 ⁄ 共 457字 ⁄ 字号 评论关闭

最近安装MySQL,使用了UTF-8 ,键表使用了UTF-8,遇到了MySQL命令行插入中文出错的问题。

在Query Browser中直接插入中文没有问题.

  1. create table student(  
  2. id varchar(100) not null default '',  
  3. name varchar(20) default '',  
  4. cardId varchar(20) not null default '',  
  5. age int(3) default '0',  
  6. primary key (id),  
  7. unique key (cardId)  
  8. )engine=InnoDB default charset=utf8;  
  9.  

但是在MySQL命令行中插入中文,居然不行.

设置环境为UTF8,插入仍然失败.

  1. set names utf8;  
  2.  

解决:

  1. set names gbk;  
  2.  
  3. insert into student(id,name,cardId,age) values('1234','伟','05120492',24);  
  4.  

成功.

抱歉!评论已关闭.