mysql - 无法在 Windows 上安装 mysql2 for Rails 3

标签 mysql ruby-on-rails ruby rubygems

如果没有错误消息,则无法安装 mysql2。我已经尝试了所有我能想到的方法,包括使用 devkit。

gem install mysql2 -- --with-mysql-include=c:/xampp/mysql/inclu
de --with-mysql-lib=c:/xampp/mysql/lib --with-mysql-config=c:/xampp/mysql/bin/my
sql_config

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/Ruby192/bin/ruby.exe extconf.rb --with-mysql-include=c:/xampp/
mysql/include --with-mysql-lib=c:/xampp/mysql/lib --with-mysql-config=c:/xampp/m
ysql/bin/mysql_config
checking for rb_thread_blocking_region()... yes
checking for main() in -llibmysql... no
*** extconf.rb failed ***

确保您的库指向/lib/opt 而不仅仅是/lib

最佳答案

在 Windows 上将 MySQL 与 Rails 3 结合使用

  • 安装railsinstaller -> www.railsinstaller.org(我将其安装到c:\Rails)

  • 安装 MySQL(我使用 MySQL 5.5)-> dev.mysql.com/downloads/installer/

--- for mySQL installation ---

If you dont already have these two files installed you might need them to get your MySQL going

vcredist_x86.exe -> http://www.microsoft.com/download/en/details.aspx?id=5555 dotNetFx40_Full_x86_x64.exe -> http://www.microsoft.com/download/en/details.aspx?id=17718

Use default install Developer Machine

-MySQL Server Config-
port: 3306
windows service name: MySQL55
mysql root pass: root (you can change this later)
(username: root)
-MySQL Server Config-

--- for mySQL installation ---


--- Install the mysql2 Gem ---

Important: Do this with Git Bash Command Line(this was installed with railsinstaller) -> start/Git Bash

gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"'

Now the gem should have installed correctly

Lastly copy the libmysql.dll file from
C:\Program Files\MySQL\MySQL Server 5.5\lib
to
C:\Rails\Ruby1.9.2\bin

--- Install the mysql2 Gem ---


如果您不确定如何使用 MySQL 创建 Rails 3 应用程序,您现在可以将 Rails 应用程序与 MySQL 结合使用,请继续阅读...

<小时/>

--- 获取使用 MySQL 的 Rails 3 应用 ---

打开命令提示符(不是 Git Bash)-> start/cmd
导航到您的文件夹 (c:\Sites)
创建新的 Rails 应用

rails new world

删除文件 c:\Sites\world\public\index.html
编辑文件 c:\Sites\world\config\routes.rb
添加此行 -> root :to => 'cities#index'

打开命令提示符(生成 View 和 Controller )

rails generate scaffold city ID:integer Name:string CountryCode:string District:string Population:integer



编辑文件 c:\Sites\world\app\models\city.rb 如下所示

class City < ActiveRecord::Base
 set_table_name "city"
end

编辑文件 c:\Sites\world\config\database.yml 如下所示

development:
adapter: mysql2
encoding: utf8
database: world
pool: 5
username: root
password: root
socket: /tmp/mysql.sock

打开命令提示符 windows cmd,而不是 Git Bash(运行您的应用程序!)
导航到您的应用文件夹 (c:\Sites\world)

rails s

在此处打开浏览器 -> http://localhost:3000

--- 获取使用 MySQL 的 Rails 3 应用 ---

关于mysql - 无法在 Windows 上安装 mysql2 for Rails 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5836959/

相关文章:

带撇号的 PHP 和 MySql 查询

php - MySQL 在整数前不存储零(字段设置为文本(或 varchar))

mysql - SQL SELECT 来自多个表或 JOIN

mysql - 迭代 MySQL 记录并在 GoLang 中创建一个 JSON

ruby - 错误 - 迭代期间无法将新 key 添加到哈希中

ruby - 如何通过 Rubocop 指示打开 & :read as argument to File.

Ruby:n `[]=':字符串不匹配(IndexError)

ruby-on-rails - 有什么好的方法可以暂时阻止 ActiveRecord 执行查询吗?

ruby-on-rails - 在 Sonar 插件中调试 Ruby 和 Rails 代码

ruby-on-rails - rails 从 Rack 渲染 html