windows搭建rails环境中,mysql2 gem 安装error问题
windows搭建rails环境中,mysql2 gem 安装error问题
可以尝试使用下面几种方法:
1. Uninstalling and reinstalling the gem will often solve this issue with no need to download and move files around by hand. From your rails app directory:
> gem uninstall mysql2 You have requested to uninstall the gem: mysql2-0.3.11 database_cleaner-0.9.1 depends on [mysql2 (>= 0)] If you remove this gems, one or more dependencies will not be met. Continue with Uninstall? [Yn] Y Successfully uninstalled mysql2-0.3.11 > bundle install Fetching gem metadata from http://rubygems.org/...... Fetching gem metadata from http://rubygems.org/.. Using rake (0.9.2) Using i18n (0.6.1) ... <SNIP> ... Installing mysql2 (0.3.11) with native extensions ... <SNIP> ... Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
2.
I had the same problem as you, or at least the symptom was the same.
Background: I was using Rails 3, the mysql2 gem, and MySQL community server version 5.5.21 (32-bit) installed locally on my Windows machine. I grabbed the client library (libmysql.dll
) from the MySQL installation and copied it to my ruby installation's bin
folder.
When I ran bundle exec rake db:create
, I got the same error message as you and I thought "Hey, how can the client library be outdated when I got it from the latest MySQL release?"
There's a helpful message that is shown when you gem install mysql2
. Unfortunately, if you install the gem with Bundler, Bundler eats the message. Here it is:
========================================================================= You've installed the binary version of mysql2. It was built using MySQL Connector/C version 6.0.2. It's recommended to use the exact same version to avoid potential issues. At the time of building this gem, the necessary DLL files where available in the following download: http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick And put lib\libmysql.dll file in your Ruby bin directory, for example C:\Ruby\bin
3.
If you are using 64bit version of mysql and 32bit version of ruby, then check this solution on http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
You basically have to download a single connector from mysql website, and compile mysql or mysql2 with connector you downloaded.
for Ruby 1.9.2:
gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32
for Ruby 1.9.3: (showing mysql2 variant)
gem pristine mysql2 -- --with-mysql-config=C:\mysql-connector-c-noinstall-6.0.2-win32
Note the use of forward slashes for the directory where MySQL Connector/C was extracted.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话