Ruby on Rails 耙子错误

发布于 2024-08-19 05:15:50 字数 1789 浏览 3 评论 0原文

编辑:解决了问题,感谢这个论坛帖子:http://forums.aptana.com/viewtopic.php?f=20&t=7563&p=27407&hilit=libmysql.dll#p27407。谢谢大家!

我已经开始学习 RoR 并一直在尝试使用 rake db:migrate 但我不断收到相同的错误。我可以使用 C:\dev\railslist>mysql -u root Railslist_development -p 连接到 MySQL 数据库。 rake db:migrate --trace 生成以下内容:

C:\dev\railslist>rake db:migrate --trace
(in C:/dev/railslist)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Mysql::Error: query: not connected: CREATE TABLE 'schema_migrations' ('version'
varchar(255) NOT NULL) ENGINE=InnoDB
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract_adapter.rb:219:in 'rescue in log'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract_adapter.rb:202:in 'log'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/mysql_adapter.rb:323:in 'execute'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract/schema_statements.rb:114:in 'create_table'
...

我的 database.yml 文件如下:

development:
  adapter: mysql
  database: railslist_development
  username: root
  password: **********
  host: localhost

  ...

编辑: 抱歉,我混淆了...我 可以使用 mysql connect localhost 连接到 MySQL 数据库 - 它会生成一长串命令和变量。另外,如果我输入 mysql -h localhost -u root -p ,我可以登录 MySQL 提示符。澄清一下:我可以通过命令行连接到 MySQL 数据库,但是在 RoR Rake 中会产生错误。

EDIT: Solved the problem, thanks to this forum post: http://forums.aptana.com/viewtopic.php?f=20&t=7563&p=27407&hilit=libmysql.dll#p27407. Thanks everyone!

I've started learning RoR and have been trying to use rake db:migrate but I keep getting the same error. I can connect to the MySQL database using C:\dev\railslist>mysql -u root railslist_development -p.
rake db:migrate --trace produces the following:

C:\dev\railslist>rake db:migrate --trace
(in C:/dev/railslist)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Mysql::Error: query: not connected: CREATE TABLE 'schema_migrations' ('version'
varchar(255) NOT NULL) ENGINE=InnoDB
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract_adapter.rb:219:in 'rescue in log'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract_adapter.rb:202:in 'log'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/mysql_adapter.rb:323:in 'execute'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract/schema_statements.rb:114:in 'create_table'
...

My database.yml file is as follows:

development:
  adapter: mysql
  database: railslist_development
  username: root
  password: **********
  host: localhost

  ...

EDIT: Sorry, I got mixed up there... I can connect to the MySQL database using mysql connect localhost - it produces a long list of commands and variables. Also if I enter mysql -h localhost -u root -p I can log into the MySQL prompt. So to clarify: I can connect to the MySQL database via the command line, however in RoR Rake produces an error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨落星ぅ辰 2024-08-26 05:15:50

在此澄清一下 - 问题是客户端 MySQL 库当前无法与 Rails 2.3 一起使用。

要解决此问题:

  1. 下载旧版本的客户端库 此处
  2. 将此文件放入您的 ruby​​ bin 目录中
  3. 重新启动您的 MySQL 服务

    [1]: [1]: http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll“此处”

To clarify here - the problem is that the client MySQL library does not work currently with Rails 2.3.

To fix this:

  1. Download an older version of the client library here
  2. Drop this file in your ruby bin directory
  3. Restart your MySQL service

    [1]: [1]: http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll "here"

请止步禁区 2024-08-26 05:15:50

我本身并没有回答你的问题,但既然你刚刚学习,为什么现在不坚持使用更简单的 sqlite 呢?

I'm not answering your question per se, but since you're just learning, why not stick to the simpler sqlite for now?

虚拟世界 2024-08-26 05:15:50

未创建数据库。

使用 MySql 时,在运行 rake db:migrate 之前,您应该创建数据库:

rake db:create

或者通过 SQL 命令手动创建数据库。

mysql -h localhost -u root -p
> CREATE DATABASE railslist_development;

我希望这对你有帮助。

The DB is not created.

When using MySql, before running rake db:migrate you should create the DB doing:

rake db:create

Or create the database manually via SQL commands.

mysql -h localhost -u root -p
> CREATE DATABASE railslist_development;

I hope this helps you.

信仰 2024-08-26 05:15:50

这几乎肯定是因为您的 mysql 实例未运行,或者您尚未将 config/database.yml 配置为指向适合您的环境(通常是开发)的正确数据库。这里有一些可以尝试的事情 -

  • 检查你的 config/database.yml -
    你的主机在哪里(如果没有主机
    列出,它将连接到本地主机)
  • 尝试运行 mysql -h localhost 并
    查看mysql是否正在运行。

编辑:
如果您无法连接到本地主机数据库,那么问题就在那里,而不是 Rails 的问题。确保它正在运行,并且您的权限设置正确以允许从您的计算机进行连接。另外,尝试从本地计算机以 root 身份进行连接,看看这是否是一个更细粒度的问题(例如您启用了本地连接,但不适用于您在 Rails 中使用的用户)。

编辑2:
在这种情况下,您的问题可能是您的数据库尚未创建。只需转到命令行并输入以下内容:

mysql -u root -p -e 'createdatabaserailslist_development;'

这应该会创建数据库并允许您运行迁移。

This is almost definitely because your mysql instance is not running or you haven't configured config/database.yml to be pointed at the right database for your environment (usually Development). Here are a couple of things to try -

  • Check your config/database.yml -
    where is your host (if no host
    listed, it'll connect to localhost)
  • Try running mysql -h localhost and
    see if mysql is running.

EDIT:
If you're not able to connect to your localhost database, then the problem is there, not with Rails. Make sure you have it running, and that your permissions are set correctly to allow connection from your machine. Also, try connecting as root from your local machine, to see if it's a more granular issue (such as you have local connections enabled, but not for the user you're using in Rails).

EDIT 2:
In this case, your problem likely is that your database has not been created. Simply go to a command line and type the following:

mysql -u root -p -e 'create database railslist_development;'

This should create the database and allow you to run your migration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文