无法在Windows上为rails 3安装mysql2 [英] Can't install mysql2 for rails 3 on Windows
问题描述
无法安装mysql2而没有错误讯息。我试过了我能想到的所有方法,包括使用devkit。
gem install mysql2 - --with-mysql-include = c:/ xampp / mysql / includes
de --with-mysql-lib = c:/ xampp / mysql / lib --with-mysql-config = c:/ xampp / mysql / bin / my
sql_config
临时增强PATH以包含DevKit ...
构建本机扩展。这可能需要一段时间...
错误:安装mysql2时出错:
错误:无法构建gem本机扩展。
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
检查rb_thread_blocking_region()...是
检查for main()in -llibmysql ... no
*** extconf.rb失败***
确保你的库指向/ lib / opt,而不仅仅是/ lib
Windows
-
安装railsinstaller - > www.railsinstaller.org 我将它安装到c:\Rails)
-
安装MySQL (我使用MySQL 5.5) - > dev。
- 用于mySQL安装---
如果您还没有安装这两个文件,您可能需要它们来获取您的M ySQL将
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
$ b -MySQL Server配置 -
端口:3306
windows服务名称:MySQL55
mysql root pass:root(您可以稍后更改)
(username :root)
-MySQL Server配置 -
---对于mySQL安装---
安装mysql2 Gem ---
重要:使用Git Bash Command Line 启动/ 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'
现在,gem应该正确安装
最后将libmysql.dll文件从
C:\程序文件\MySQL\MySQL Server 5.5\lib
到
C:\Rails\Ruby1.9.2\\ \\ bin
---安装mysql2 Gem ---
现在,您将能够在MySQL中使用Rails应用程序,如果您不确定如何创建Rails 3应用程序并读取MySQL ...
---获取一个适用于MySQL的Rails 3应用程序--- <
打开命令提示符(不是Git Bash) - > start / cmd
导航到您的文件夹(c:\Sites)
创建新的rails应用程序
rails新世界
删除文件c:\Sites\world \public\index.html
编辑文件c:\Sites\world\config\routes.rb
添加这一行 - > root: to =>'cities#index'
打开命令提示符(生成视图和控制器)
rails生成scaffold城市ID:整数名称:string CountryCode:string区域:string人口:整数
编辑文件c:\Sites\world\app\models\city.rb至看起来像这样
class City< ActiveRecord :: Base
set_table_namecity
end
编辑文件c :\Sites\world\config\database.yml看起来像这样
开发:
适配器:mysql2
编码:utf8
数据库:world
池:5
用户名:root
密码:root
socket:/tmp/mysql.sock
打开命令提示符 windows cmd,而不是Git Bash(运行您的应用程序!
导航到您的应用程序文件夹(c:\Sites\world)
rails s
在这里打开浏览器 - > http:// localhost:3000
---获取一个使用MySQL的Rails 3应用---
Can't install mysql2 without an error message. I've tried every way I can think of including using 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 ***
Make sure your library points to /lib/opt and not just /lib
Using MySQL with Rails 3 on Windows
Install railsinstaller -> www.railsinstaller.org (I installed it to c:\Rails)
Install MySQL (I used 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 ---
You will now be able to use your Rails app with MySQL, if you are not sure how to create a Rails 3 app with MySQL read on...
--- Get a Rails 3 app going with MySQL ---
Open command prompt(not Git Bash) -> start/cmd
Navigate to your folder (c:\Sites)
Create new rails app
rails new world
Delete the file c:\Sites\world\public\index.html
Edit the file c:\Sites\world\config\routes.rb
add this line -> root :to => 'cities#index'
Open command prompt (generate views and controllers)
rails generate scaffold city ID:integer Name:string CountryCode:string District:string Population:integer
Edit the file c:\Sites\world\app\models\city.rb to look like this
class City < ActiveRecord::Base
set_table_name "city"
end
Edit the file c:\Sites\world\config\database.yml to look like this
development:
adapter: mysql2
encoding: utf8
database: world
pool: 5
username: root
password: root
socket: /tmp/mysql.sock
Open command prompt windows cmd, not Git Bash(run your app!)
Navigate to your app folder (c:\Sites\world)
rails s
Open your browser here -> http://localhost:3000
--- Get a Rails 3 app going with MySQL ---
这篇关于无法在Windows上为rails 3安装mysql2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!