2

我试图让我的 Rails 应用程序使用 MySQL 而不是默认的 SQLite。我创建了一个新项目,强制使用似乎可以正常工作的 MySQL。

它在 Gem 文件中添加了 gem 条目,如下所示:

source 'https://rubygems.org'

    gem 'rails', '3.2.13'

    # Bundle edge Rails instead:
    # gem 'rails', :git => 'git://github.com/rails/rails.git'

    gem 'mysql2'

当我运行 bundle 命令时,它显示它使用 mysql gem:

Using mysql2 <0.3.11>

我还配置了 database.yml 文件,如下所示:

development:
 adapter: mysql2
 encoding: utf8
 reconnect: false
 database: dbname
 pool: 5
 username: uname
 password: pass
 host: hostname

test:
 development:
 adapter: mysql2
 encoding: utf8
 reconnect: false
 database: dbname
 pool: 5
 username: uname
 password: pass
 host: hostname

production:
 development:
 adapter: mysql2
 encoding: utf8
 reconnect: false
 database: dbname
 pool: 5
 username: uname
 password: pass
 host: hostname

但是当我尝试运行 rails 服务器时,我得到了这个:

C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/l ib/mysql2/mysql2.rb:2:in require': 126: The specified module could not be found . - C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-min gw32/lib/mysql2/1.9/mysql2.so (LoadError) from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11- x86-mingw32/lib/mysql2/mysql2.rb:2:in'来自 C:/RailsInstaller/ Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2.rb:9:in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11- x86-mingw32/lib/mysql2.rb:9:in'来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/ gems/1.9.1/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:72:inblock (2 levels) in require' 来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9 .1/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:70:inblock in require' 来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler- 1.3.4/lib/bundler/runtime.rb:59:in each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:59:inrequire' 来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/lib/bundler.rb :132:在require' from C:/Users/n00151956/Desktop/RubyProjects/Demo/config/application.rb: 7:in'来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:53:in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:53:inblock in '来自 C:/RailsInstaller/ Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:50:in tap' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:50:in' 来自 script/rails:6:in require' from script/rails:6:in'

我能够让 Rails 服务器使用默认 SQLite 运行,但对于我来说,我无法让它与 MySQL 一起使用。如果有人可以帮助我解决这个问题,那将是很大的帮助!

谢谢

4

2 回答 2

3
  1. 从 - mysql-connector下载 libmysql.dll 文件并将其放在 C:\RailsInstaller\Ruby1.9.3\bin 应该在这里图片
  2. 以管理员身份打开命令提示符并按以下方式启动 mysql 服务器:C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql

更新

development:
  adapter: mysql2
  database: proj_development
  username: root
  password: pass
  host: 127.0.0.1
  socket: /tmp/mysql.sock

test:
  adapter: mysql2
  database: proj_test
  username: root
  password: pass
  host: 127.0.0.1
  socket: /tmp/mysql.sock

production:
  adapter: mysql2
  database: proj_production
  username: root
  password: pass
  host: 127.0.0.1
  socket: /tmp/mysql.sock
于 2013-05-28T19:35:27.743 回答
1

安装 Mysql如果你没有安装它。

  1. 下载MySQL-connector(zip 文件)- 下载 noinstall 版本(不用于安装)。你应该把它提取到c:\mysql-connector-c-your-version-download

  2. libmysql.dllc:\mysql-connector-c-your-version-download到复制C:\RailsInstaller\Ruby1.9.3\bin

  3. 安装 MySQL gem

    gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-your-version-download

于 2013-05-28T19:44:45.907 回答