简体   繁体   English

无法在 Windows 上为 rails 3 安装 mysql2

[英]Can't install mysql2 for rails 3 on Windows

Can't install mysql2 without an error message.无法安装 mysql2 而没有错误消息。 I've tried every way I can think of including using devkit.我已经尝试了所有我能想到的方法,包括使用 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确保您的库指向 /lib/opt 而不仅仅是 /lib

Using MySQL with Rails 3 on Windows在 Windows 上使用带有 Rails 3 的 MySQL

  • Install railsinstaller -> www.railsinstaller.org (I installed it to c:\Rails)安装 railsinstaller -> www.railsinstaller.org (我将它安装到 c:\Rails)

  • Install MySQL (I used MySQL 5.5) -> dev.mysql.com/downloads/installer/安装 MySQL (我用的是 MySQL 5.5)-> dev.mysql.com/downloads/installer/

--- for mySQL installation --- --- 用于 mySQL 安装 ---

If you dont already have these two files installed you might need them to get your MySQL going如果您还没有安装这两个文件,您可能需要它们来让您的 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 vcredist_x86.exe -> http://www.microsoft.com/download/en/details.aspx?id=5555 dotNetFx40_Full_x86_x64.exe -> http://www.microsoft.com/details/ =17718

Use default install Developer Machine使用默认安装开发者机器

-MySQL Server Config- -MySQL服务器配置-
port: 3306端口:3306
windows service name: MySQL55 windows 服务名称:MySQL55
mysql root pass: root (you can change this later) mysql root pass:root(你可以稍后更改)
(username: root) (用户名:root)
-MySQL Server Config- -MySQL服务器配置-

--- for mySQL installation --- --- 用于 mySQL 安装 ---


--- Install the mysql2 Gem --- --- 安装 mysql2 Gem ---

Important: Do this with Git Bash Command Line (this was installed with railsinstaller) -> start/Git Bash重要提示:使用 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\include"' 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\包括”'

Now the gem should have installed correctly现在 gem 应该已经正确安装了

Lastly copy the libmysql.dll file from最后复制 libmysql.dll 文件
C:\Program Files\MySQL\MySQL Server 5.5\lib C:\Program Files\MySQL\MySQL Server 5.5\lib
to
C:\Rails\Ruby1.9.2\bin C:\Rails\Ruby1.9.2\bin

--- Install the mysql2 Gem --- --- 安装 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...如果您不确定如何使用 MySQL 创建 Rails 3 应用程序,您现在可以将 Rails 应用程序与 MySQL 一起使用,请继续阅读...


--- Get a Rails 3 app going with MySQL --- --- 获取一个带有 MySQL 的 Rails 3 应用程序 ---

Open command prompt(not Git Bash) -> start/cmd打开命令提示符(不是 Git Bash)-> start/cmd
Navigate to your folder (c:\Sites)导航到您的文件夹 (c:\Sites)
Create new rails app创建新的 Rails 应用程序

rails new world

Delete the file c:\Sites\world\public\index.html删除文件 c:\Sites\world\public\index.html
Edit the file c:\Sites\world\config\routes.rb编辑文件 c:\Sites\world\config\routes.rb
add this line -> root:to => 'cities#index'添加这一行 -> 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编辑文件 c:\Sites\world\app\models\city.rb 看起来像这样

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

Edit the file c:\Sites\world\config\database.yml to look like this编辑文件 c:\Sites\world\config\database.yml 看起来像这样

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!)打开命令提示符windows cmd,而不是 Git Bash(运行您的应用程序!)
Navigate to your app folder (c:\Sites\world)导航到您的应用文件夹 (c:\Sites\world)

rails s

Open your browser here -> http://localhost:3000在此处打开浏览器-> http://localhost:3000

--- Get a Rails 3 app going with MySQL --- --- 获取一个带有 MySQL 的 Rails 3 应用程序 ---

Just thought I would update this for posterity.只是想我会为后代更新这个。 With the latest version of the rails installer for windows (as of the date of this post) and using Win 7, and I happen to have xampp installed here was my process.使用 windows 的最新版本的 rails 安装程序(截至本文发布之日)并使用 Win 7,我碰巧在这里安装了 xampp 是我的过程。 First run and install the rails installer.首先运行并安装 rails 安装程序。 Now to install the mysql gem I did...现在安装 mysql gem 我做了...

C:\Sites>gem install mysql2 -v 0.3.16 --platform=ruby -- --with-mysql-dir=C:\xam
pp\mysql

Note that in my configuration I am running xampp, hince I am passing the C:\xampp\mysql as the mysql dir path.请注意,在我的配置中,我正在运行 xampp,因此我将 C:\xampp\mysql 作为 mysql 目录路径传递。

Next copy libmysql.dll from C:\xampp\mysql\lib to C:\RailsInstaller\Ruby1.9.3\bin.接下来将 libmysql.dll 从 C:\xampp\mysql\lib 复制到 C:\RailsInstaller\Ruby1.9.3\bin。 Now all the DB related to rails with hopfully 'just work' for you.现在所有与 Rails 相关的数据库都为您“工作”。 For instance to create a new rails app with mysql do...例如,要使用 mysql 创建一个新的 rails 应用程序...

rails new the_next_facebook -d mysql

...and you should get your default config/database.yml file already setup to use mysql. ...并且您应该已经设置了默认的 config/database.yml 文件以使用 mysql。 Just make sure your username/pw are OK只需确保您的用户名/密码没问题

This is the command that works for me, make sure you use the full version of 1.7.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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM