Can't install mysql2 for rails 3 on Windows

2020-08-01 11:54发布

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

3条回答
forever°为你锁心
2楼-- · 2020-08-01 12:05

This is the command that works for me, make sure you use the full version of 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 
查看更多
仙女界的扛把子
3楼-- · 2020-08-01 12:11

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 ---

查看更多
唯我独甜
4楼-- · 2020-08-01 12:19

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. First run and install the rails installer. Now to install the mysql gem I did...

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.

Next copy libmysql.dll from C:\xampp\mysql\lib to C:\RailsInstaller\Ruby1.9.3\bin. Now all the DB related to rails with hopfully 'just work' for you. For instance to create a new rails app with mysql do...

rails new the_next_facebook -d mysql

...and you should get your default config/database.yml file already setup to use mysql. Just make sure your username/pw are OK

查看更多
登录 后发表回答