Home  >  Article  >  Database  >  MySQL命令行插入中文出错的解决

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

WBOY
WBOYOriginal
2016-06-07 14:51:461033browse

最近安装MySQL,使用了UTF-8 ,键表使用了UTF-8,遇到了MySQL命令行插入中文出错的问题。 在Query Browser中直接插入中文没有问题. createtablestudent( idvarchar(100)notnulldefault'', namevarchar(20)default'', cardIdvarchar(20)notnulldefault'', age

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

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

  create table student(  
  id varchar(100) not null default '',  
  name varchar(20) default '',  
  cardId varchar(20) not null default '',  
  age int(3) default '0',  
  primary key (id),  
  unique key (cardId)  
  )engine=InnoDB default charset=utf8;  

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

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

  set names utf8;  

  解决:

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

  成功.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn