Home > Database > Mysql Tutorial > body text

ruby中解决mysql中文输入编码问题的简单方法。_MySQL

WBOY
Release: 2016-06-01 13:11:58
Original
1886 people have browsed it

Ruby

在ruby 用ActiveRecord写mysql的时候,想向表中输入中文字符,一直遇到如下的问题,

.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.1/lib/active_record/connection_adapters/mysql_adapter.rb:497:in `execute': Mysql::Error: Incorrect string value: '/xE4/xBD/x8F/xE5/x93/xAA...' for column 'keyword' at row 1: INSERT INTO `relate_worlds` (`keyword`) VALUES (?) (ActiveRecord::StatementInvalid)

突然想到之前在一个地方看到过如下的代码,说不定为该数据库设置一遍编码可以解决,便尝试了一下,结果真的解决了!

mysql> create table relate_worlds(id int auto_increment, keyword varchar(30) not null unique, primary key(id) )engine=innodb default charset=utf8 auto_increment=1;


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template