无法在Windows上为rails 3安装mysql2
没有错误消息无法安装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 – > http://www.railsinstaller.org (我将它安装到c:\ Rails)
-
安装MySQL (我使用MySQL 5.5) – > dev.mysql.com/downloads/installer/
—用于mySQL安装—
如果你还没有安装这两个文件,你可能需要它们来让你的MySQL运行
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
使用默认安装Developer Machine
-MySQL Server配置 –
港口:3306
Windows服务名称:MySQL55
mysql root pass:root(以后你可以改一下)
(用户名:root)
-MySQL Server配置 –—用于mySQL安装—
—安装mysql2gem—
重要: 使用Git Bash命令行 (这是使用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 \包括”’
现在gem应该已经正确安装
最后从中复制libmysql.dll文件
C:\ Program Files \ MySQL \ MySQL Server 5.5 \ lib
至
C:\ Rails的\ Ruby1.9.2 \ BIN—安装mysql2gem—
如果您不确定如何使用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’
打开命令提示符(生成视图和控制器)
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应用程序---
这个命令对我有用,请确保使用完整版的1.7.3
gem install -v=0.2.7 mysql2 -- --with-mysql-include=C:\xampp\mysql\include --with-mysql-lib=C:\xampp\mysql\lib\opt --with-mysql-config=c:\xampp\mysql\bin\mysql_config
只是想我会为后代更新这个。 使用最新版本的rails安装程序(截至本文发布之日)并使用Win 7,我碰巧安装了xampp,这是我的过程。 首先运行并安装rails安装程序。 现在安装我做的mysql gem …
C:\Sites>gem install mysql2 -v 0.3.16 --platform=ruby -- --with-mysql-dir=C:\xam pp\mysql
请注意,在我的配置中,我正在运行xampp,hince我将C:\ xampp \ mysql作为mysql目录路径传递。
接下来将libmysql.dll从C:\ xampp \ mysql \ lib复制到C:\ RailsInstaller \ Ruby1.9.3 \ bin。 现在所有的数据库都与rails相关,并为您提供“正常工作”。 例如用mysql创建一个新的rails应用程序…
rails new the_next_facebook -d mysql
…并且您应该已经设置了默认的config / database.yml文件以使用mysql。 只需确保您的用户名/ pw正常