无法从Windows中的Rails应用程序连接到MySql

时间:2013-10-02 19:48:43

标签: mysql ruby-on-rails ruby windows

我正在尝试在Windows中使用MySQL作为数据库创建Rails应用程序。我创建了一个rails应用程序,它运行得很好。但是当我尝试连接到mySQL数据库时,我遇到了奇怪的错误,经过数小时的谷歌搜索和搜索后我无法解决。也许我在表达一个愚蠢的错误,Rails和Ruby的新手。

以下是我使用MYSQL创建应用程序的方法

  1. 在命令提示符

    rails new sample_app -d mysql

  2. [成功]

    1. 打开一个新的命令提示符窗口和

      C:\ sites \ cd sample_app> rails -s

    2. 现在我收到此错误

      Could not find gem mysq12 (>=0) in any of the gem sources listed in your Gemfile
      Run bundle install to install missing gems
      

      注意:我在没有使用Mysql的情况下创建第一个rails应用程序时没有收到错误。

      1. 接下来,我运行了这个命令

        gem install mysql2

      2. 得到了这个

        Temporarily enhancing PATH to include DevKit...
        Building native extensions.  This could take a while...
        ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.
        
        C:/RailsInstaller/Ruby1.8.7/bin/ruby.exe extconf.rb
        checking for rb_thread_blocking_region()... no
        checking for rb_wait_for_single_fd()... no
        checking for rb_hash_dup()... no
        checking for rb_intern3()... no
        *** 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.
        
        1. 接下来我跑了这个 -

          捆绑安装

        2. 关闭所有命令提示符窗口,打开一个新窗口,移动到我的app目录并键入

          rails -s

        3. 错误:

          could not find gem mysq12 (>=0) in any of the gem sources listed in your Gemfile
          
          Run bundle install to install missing gems
          

          以下是我认为有用的一些信息

          - Rails 3.0.9
          - Ruby 1.8.7
          - rake (10.1.0, 0.8.7)
          - mysql (2.9.1 x86-mingw32)
          - MySql 5.6 installed and running (I have created a DB and tables)
          - OS: Windows 7 64bit
          

          以下是我的database.yaml文件的样子:

          development:
          adapter: mysql2
          encoding: utf8
          reconnect: false
          database: sample_app_development
          pool: 5
          username: root
          password: buiskol
          host: localhost
          

          这是应用程序的gemfile的样子

          source 'http://rubygems.org'
          
          gem 'rails', '3.0.9'
          
          # Bundle edge Rails instead:
          # gem 'rails', :git => 'git://github.com/rails/rails.git'
          
          gem 'mysql2', '~> 2.9.1'
          

          我认为问题是我的mysql2 gem没有正确安装。我不知道我在做错误的地方。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

为什么使用gem' mysql2','〜> 2.9.1'而不是gem" mysql2","〜> 0.3.13&#34 ;?根据{{​​3}},没有任何2.9.1版本,也许你的意思是0.2.9?否则,您正在安装该gem的错误版本,或者使用正确版本安装错误的gem。

您应该使用:

gem "mysql", "~> 2.9.1"

gem "mysql2", "~> 0.3.13"

在您的gem文件中。由于mysql2没有版本2.9.1,请更正拼写错误并再试一次

相关问题