简体   繁体   English

在Rails 4中无法连接到MySQL数据库

[英]Cannot Connect to MySQL Database in Rails 4

I'm new to Rails and I'm going through a tutorial on Lynda.com, Rails 4 Essentials. 我是Rails的新手,正在学习Lynda.com上的Rails 4 Essentials教程。 I'm on a Windows 7 x64 machine and I'm trying to connect the MySQL database to the Rails app. 我在Windows 7 x64计算机上,正在尝试将MySQL数据库连接到Rails应用程序。 I've successfully created the database and created a new user. 我已经成功创建了数据库并创建了一个新用户。

I had issues running the mysql2 gem and I could only get version 0.3.11 to work (it's on version 0.3.16 as of this post). 我在运行mysql2 gem时遇到问题,只能使用0.3.11版本才能工作(截至本文发布时,它的版本为0.3.16)。 I copied the libmysql.dll from the C:\\Program Files\\MySQL\\MySQL Connector.C 6.1\\lib to my C:\\RailsInstaller\\Ruby2.0.0\\bin directory as the instructions stated. 我按照说明将C:\\ Program Files \\ MySQL \\ MySQL Connector.C 6.1 \\ lib中的libmysql.dll复制到了C:\\ RailsInstaller \\ Ruby2.0.0 \\ bin目录中。

Everything seems to be ok at this point. 此时一切似乎都还可以。

I configured my database.yml file to match my database credentials (I had to create this from scratch, nothing was generated when I ran mysql2). 我配置了database.yml文件以匹配我的数据库凭据(我必须从头开始创建此文件,运行mysql2时什么也没有生成)。

 #config\\database.yml development: adapter: mysql2 database: simple_cms_development username: craig password: password host: 127.0.0.1 socket: /tmp/mysql.sock test: adapter: mysql2 database: simple_cms_test username: craig password: password host: 127.0.0.1 socket: /tmp/mysql.sock production: adapter: mysql2 database: simple_cms_production username: craig password: password host: 127.0.0.1 socket: /tmp/mysql.sock 

I got to try to connect my database with MySQL using: 我必须尝试使用​​以下方法将数据库与MySQL连接:

 rake db:schema:dump 

and I get this crap: 我得到这个废话:

 LoadError: cannot load such file -- mysql2/2.0/mysql2 

I see a directory called mysql2/1.9 and there is a file called mysql.so in there but there is no 2.0. 我看到一个名为mysql2 / 1.9的目录,并且有一个名为mysql.so的文件,但是没有2.0。

Any ideas? 有任何想法吗? Thanks! 谢谢!

The joys of developing on a windows machine :) 在Windows机器上开发的乐趣:)

I suggest you check this question - it looks like the same problem. 我建议您检查此问题-它看起来像是同样的问题。

Error "...cannot load such file -- mysql2/2.0/mysql2 (LoadError)". 错误“ ...无法加载此类文件-mysql2 / 2.0 / mysql2(LoadError)”。 On Windows XP with Ruby 2.0.0 在装有Ruby 2.0.0的Windows XP上

I managed to get passed this issue by starting fresh. 我设法从头开始解决了这个问题。 I followed these set of videos to set up Ruby, MySQL, and Rails on my Windows 7 x64 machine. 我按照这些视频集在Windows 7 x64计算机上设置Ruby,MySQL和Rails。

http://youtu.be/C5S7vjN6GLc http://youtu.be/C5S7vjN6GLc

Worked like a gem, I'm rockin' and rollin' now. 像宝石一样工作,我现在摇摇晃晃。

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

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