我有一些问题时,试图安装mysql2宝石为Rails。当我试图通过运行bundle install或gem install mysql2来安装它时,它会给我以下错误:
安装mysql2错误:错误:未能建立gem本地扩展。
我如何解决这个问题并成功安装mysql2?
我有一些问题时,试图安装mysql2宝石为Rails。当我试图通过运行bundle install或gem install mysql2来安装它时,它会给我以下错误:
安装mysql2错误:错误:未能建立gem本地扩展。
我如何解决这个问题并成功安装mysql2?
当前回答
如果你仍然有问题....
试着安装
sudo apt-get install ruby1.9.1-dev
其他回答
在Debian Stretch上,适合我的包是default-libmysqlclient-dev
Sudo apt-get update && apt-get install -y default-libmysqlclient-dev
在Ubuntu (18.04)
我能够通过运行以下程序来解决这个问题:
sudo apt-get install build-essential libmysqlclient-dev
gem install mysql2
参考
根据https://github.com/brianmario/mysql2/issues/1175,我用
gem install mysql2 -- \
--with-mysql-lib=/usr/local/Cellar/mysql/8.0.26/lib \
--with-mysql-dir=/usr/local/Cellar/mysql/8.0.26 \
--with-mysql-config=/usr/local/Cellar/mysql/8.0.26/bin/mysql_config \
--with-mysql-include=/usr/local/Cellar/mysql/8.0.26/include
I got the gem built on Mac OS X 10.6.6 by 1) Ensuring the Developer tools package is installed 2) Downloading the current MySQL package (5.5.8 in my case) from Source 3) Installing the cmake tool from cmake.org 4) Following the instructions in section 2.11 of INSTALL-SOURCE from the mysql distribution files 5) sudo gem install mysql2 -- --srcdir=/usr/local/mysql/include The gem built successfully, but there are two errors in the documentation that rdoc and ri complain about. But now when I try to require 'mysql2' I get a
LoadError: no such file to load -- mysql2/mysql2
我希望我得到的错误是libmysqlclient.16。Dylib无法找到,因为我们在另一篇文章中找到了(搜索install_name_tool)。
我的$PATH有/usr/local/mysql在里面(这是我的源代码和构建文件所在的位置),所以我有点难住了。如果有人有什么想法,我会在睡了几个小时后再来看看。
这里有一个解决方案,希望对Windows用户有帮助!
在Windows上使用Rails 3使用MySQL
安装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 ---
安装mysql2 Gem 重点:使用Git Bash命令行(这是安装在railsinstaller) -> start/Git Bash ——with-mysql-lib="c:\Program Files\MySQL\ Server 5.5\lib"——with-mysql-include="c:\Program Files\MySQL\ Server 5.5\include"' 现在gem应该已经正确安装了 最后复制libmysql.dll文件 C:\Program Files\MySQL\MySQL Server 5.5\lib 来 Rails C: \ \ Ruby1.9.2 \ bin 安装mysql2 Gem
你现在将能够使用你的Rails应用程序与MySQL,如果你不确定如何创建一个Rails 3应用程序与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
添加到gemfile
gem 'mysql2'
打开命令提示符窗口cmd,而不是Git Bash(运行你的应用程序!) 导航到应用程序文件夹(c:\Sites\world)
rails s
在这里打开浏览器-> http://localhost:3000
用MySQL开发一个Rails 3应用程序