JRuby、Rails 2.3.5、MySQL 数据库未使用 rake db:create:all 创建

发布于 2024-10-01 16:00:01 字数 2000 浏览 6 评论 0原文

基本信息:

Ruby version : 1.8.7
JRuby version: 1.5.3 
Rails version: 2.3.5
Mysql version: Ver 14.14 Distrib 5.1.48, for apple-darwin10.3.0 (i386) using readline 5.1

我一直在努力让 JRuby、Rails 和 MySQL 能够很好地协同工作。我已经走到了死胡同,现在需要一些帮助。

我已经安装了我认为正确的 gem,以允许 JRoR 与 MySQL 对话。我安装的 gems 列表如下。我如何尝试创建 JRoR + MySQL 应用程序如下:

$ jruby -S rails -d mysql app_name
$ cd app_name

打开 Textmate 并通过将所有适配器从“mysql”更改为“jdbcmysql”来配置 config/database.yml。

回到终端:

$ jruby -S script/generate scaffold post title:string content:text
$ rake db:create:all

此时,rake 没有输出任何内容来告诉我数据库已创建。这是尝试运行迁移的结果:

$ rake db:migrate

rake aborted!
The driver encountered an unknown error: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'app_name_development'

我不知道我做错了什么,非常感谢您的帮助。

这是我当前的宝石列表:

$ jruby -S gem list

* LOCAL GEMS *

abstract (1.0.0)
actionmailer (3.0.0, 2.3.5)
actionpack (3.0.0, 2.3.5)
activemodel (3.0.0)
activerecord (3.0.0, 2.3.5)
activerecord-jdbc-adapter (1.0.2, 0.9.7)
activerecord-jdbcmysql-adapter (1.0.2, 0.9.7)
activerecord-jdbcsqlite3-adapter (0.9.7)
activeresource (3.0.0, 2.3.5)
activesupport (3.0.0, 2.3.10, 2.3.5)
after_commit (1.0.8)
arel (1.0.1)
bouncy-castle-java (1.5.0145.2)
builder (2.1.2)
bundler (1.0.2)
columnize (0.3.1)
erubis (2.6.6)
gem_plugin (0.2.3)
i18n (0.4.1)
jdbc-mysql (5.0.4)
jdbc-sqlite3 (3.6.3.054)
jruby-jars (1.5.3)
jruby-openssl (0.7.2)
jruby-rack (1.0.3)
mail (2.2.7)
mime-types (1.16)
mongrel (1.1.5)
polyglot (0.3.1)
rack (1.2.1, 1.0.1)
rack-mount (0.6.13)
rack-test (0.5.6)
rails (2.3.5)
railties (3.0.0)
rake (0.8.7)
riddle (1.1.0)
rspec (1.3.0)
ruby-debug (0.10.3)
ruby-debug-base (0.10.3.2)
rubyzip (0.9.4)
sources (0.0.1)
thinking-sphinx (1.3.20)
thor (0.14.3)
treetop (1.4.8)
tzinfo (0.3.23)
warbler (1.2.1)
will_paginate (2.3.15)

Basic information:

Ruby version : 1.8.7
JRuby version: 1.5.3 
Rails version: 2.3.5
Mysql version: Ver 14.14 Distrib 5.1.48, for apple-darwin10.3.0 (i386) using readline 5.1

I've been having a hell of a time trying to get JRuby, Rails, and MySQL to play nicely together. I've come to a dead end and now need some help.

I have installed what I believe to be the correct gems to allow JRoR to talk with MySQL. The list of gems I have installed are below. How I am trying to create a JRoR + MySQL app is like so:

$ jruby -S rails -d mysql app_name
$ cd app_name

Open up Textmate and configure config/database.yml by changing all adapters from "mysql" to "jdbcmysql".

Back in Terminal:

$ jruby -S script/generate scaffold post title:string content:text
$ rake db:create:all

At this point, rake doesn't spit out anything to tell me the databases were created. Here's the result of trying to run my migration:

$ rake db:migrate

rake aborted!
The driver encountered an unknown error: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'app_name_development'

I have no idea what I'm doing wrong and would greatly appreciate help.

Here's my current gem list:

$ jruby -S gem list

* LOCAL GEMS *

abstract (1.0.0)
actionmailer (3.0.0, 2.3.5)
actionpack (3.0.0, 2.3.5)
activemodel (3.0.0)
activerecord (3.0.0, 2.3.5)
activerecord-jdbc-adapter (1.0.2, 0.9.7)
activerecord-jdbcmysql-adapter (1.0.2, 0.9.7)
activerecord-jdbcsqlite3-adapter (0.9.7)
activeresource (3.0.0, 2.3.5)
activesupport (3.0.0, 2.3.10, 2.3.5)
after_commit (1.0.8)
arel (1.0.1)
bouncy-castle-java (1.5.0145.2)
builder (2.1.2)
bundler (1.0.2)
columnize (0.3.1)
erubis (2.6.6)
gem_plugin (0.2.3)
i18n (0.4.1)
jdbc-mysql (5.0.4)
jdbc-sqlite3 (3.6.3.054)
jruby-jars (1.5.3)
jruby-openssl (0.7.2)
jruby-rack (1.0.3)
mail (2.2.7)
mime-types (1.16)
mongrel (1.1.5)
polyglot (0.3.1)
rack (1.2.1, 1.0.1)
rack-mount (0.6.13)
rack-test (0.5.6)
rails (2.3.5)
railties (3.0.0)
rake (0.8.7)
riddle (1.1.0)
rspec (1.3.0)
ruby-debug (0.10.3)
ruby-debug-base (0.10.3.2)
rubyzip (0.9.4)
sources (0.0.1)
thinking-sphinx (1.3.20)
thor (0.14.3)
treetop (1.4.8)
tzinfo (0.3.23)
warbler (1.2.1)
will_paginate (2.3.15)

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

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

发布评论

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

评论(2

太阳哥哥 2024-10-08 16:00:01

您不需要将数据库名称更改为jdbcmysql。事实上,这样做会失败 db:create(:all)

http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter/

You shouldn't need to change the database name to jdbcmysql. In fact, doing this defeats db:create(:all).

http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter/

路弥 2024-10-08 16:00:01

我注意到“未知数据库'app_name_development'”错误。 app_name_development 真的是database.yml 中数据库的名称吗?只是检查一下,因为如果没有的话,那会很有趣。

我假设您没有使用 root 帐户连接到 MySQL。如果是这样,您正在连接的用户是否有权创建数据库 app_name_development?默认情况下,只有 root 可以创建数据库。您可以通过以下方式授予用户权限:

GRANT CREATE on app_name_development.* to 'user'@'host';

I noticed the "Unknown database 'app_name_development'" error. Is app_name_development really the name of your database in database.yml? Just checking, because if not, that would be very interesting.

I assume you're not connecting to MySQL with the root account. If that's true, does the user you are connecting with have permissions to create the database app_name_development? By default, only root can create databases. You can grant your user permission with something like this:

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