这几天在正式环境上部署 Redmine,之前在自己的 Mac 上已经试着部署过一次。 这次由于 CentOS 上部署,以前完全没有遇到过这个问题,实在头大,请教各位! 先说下过程: 先用 rvm 安装 ruby,成功。
$ ruby -v
ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-linux]
然后 gem 安装 rails,成功
$ rails -v
Rails 4.1.8
然后下载 redmine-2.4.7,解压 运行命令
$ ruby script/rails server webrick -e production
然后提示
Could not find gem 'mysql2 (~> 0.3.11) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
根据提示,打命令
gem install mysql2 -v '0.3.17'
报错,以下是错误信息:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-2.1.4/bin/ruby -r ./siteconf20141219-14269-9ceayj.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... yes
checking for mysql.h... no
checking for mysql/mysql.h... yes
checking for errmsg.h... no
-----
errmsg.h is missing. please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/rvm/rubies/ruby-2.1.4/bin/ruby
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
extconf failed, exit code 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.4/gems/mysql2-0.3.17 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.4/extensions/x86_64-linux/2.1.0/mysql2-0.3.17/gem_make.out
但是
$ find / -name errmsg.h
/usr/lib/errmsg.h
/usr/include/mysql/errmsg.h
系统里已经安装好了 mysql 环境了 求助!
2015-1-8 前段时间忙了忙其他项目,今天又重新捡起这个问题研究了一下。 既然 adapter 用不了 mysql2,就只能用 mysql 了,但是又出了问题,大致意思是说从数据库中读出来编码有问题。 按照这位大牛说的解决了: http://www.cnblogs.com/kting/archive/2011/09/15/2177530.html
把他的帖子 copy 过来,就算记录问题了。
感谢各位对我这个问题的回复!十分感谢!!!
以下转自网络,感谢作者
问题现象:
在.html.erb中显示mysql中的中文字符时会出现
incompatible character encodings: UTF-8 and ASCII-8BIT 错误
问题可能原因:
mysql_adapater出来的数据是ASCII-8BIT
解决方法:
修改根目录下的\Ruby192\lib\ruby\gems\1.9.1\gems\activerecord-3.0.9\lib\active_record\connection_adapters中的
mysql_adapter.rb文件
def select(sql, name = nil)
@connection.query_with_result = true
result = execute(sql, name)
rows = []
result.each_hash { |row| rows << row }
result.free
@connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped
# add begin
if @config[:encoding] && @config[:encoding]=="utf8"
rows.each do |row|
row.each do |key, value|
if (value.class == String)
value.force_encoding("UTF-8")
end
end
end
end
# add end
rows
end