使用 rake db:create 创建 Rails DB 时出错 [英] Error creating Rails DB using rake db:create

查看:51
本文介绍了使用 rake db:create 创建 Rails DB 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 rails 的 入门在我的 OSX 10.6.3 机器上使用指南.

I'm attempting to get my first "hello world" rails example going using the rails' getting started guide on my OSX 10.6.3 box.

当我执行第一个 rake db:create 命令(我使用的是 mysql)时,我得到:

When I go to execute the first rake db:create command (I'm using mysql) I get:

simon@/Users/simon/source/rails/blog/config: rake db:create  (in /Users/simon/source/rails/blog) Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"blog_development", "pool"=>5, "password"=>nil, "socket"=>"/opt/local/var/run/mysql5/mysqld.sock"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)

我发现很多 stackoverflow 问题都通过以下建议解决了这个问题:

I found plenty of stackoverflow questions addressing this problem with the following advice:

  1. 验证用户名和密码是否正确(我在我的开发箱上运行时没有 root 密码)

  1. Verify that user and password are correct (I'm running w/ no password for root on my dev box)

验证套接字是否正确 - 我可以捕捉套接字,所以我认为它是正确的

Verify that the socket is correct - I can cat the socket, so I assume it's correct

验证用户是否可以创建数据库(如您所见,root 可以连接并创建此数据库没有问题)

Verify that the user can create a DB (As you can see root can connect and create a this DB no problem)

simon@/Users/simon/source/rails/blog/config: mysql -uroot -hlocalhost欢迎使用 MySQL 监视器.命令以 ; 结尾或\g.你的 MySQL 连接 ID 是 16服务器版本:5.1.45源码分发

simon@/Users/simon/source/rails/blog/config: mysql -uroot -hlocalhost Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 16 Server version: 5.1.45 Source distribution

输入帮助";或 '\h' 寻求帮助.输入 '\c' 清除当前输入语句.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 创建数据库 blog_development;查询正常,1 行受影响(0.00 秒)

mysql> create database blog_development; Query OK, 1 row affected (0.00 sec)

为了确保这不是字符集问题,我也尝试过:

to ensure that this wasn't a charset issue I also tried:

mysql> create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)

注意:这是我的database.yaml:

Note: here is my database.yaml:

development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: blog_development
  pool: 5
  username: root
  password:
  socket: /opt/local/var/run/mysql5/mysqld.sock
#  host: localhost

请注意,我尝试将套接字切换到 localhost 没有效果.

Note that I tried switching socket to localhost with no effect.

对这里可能发生的事情有任何想法吗?

Any idea on what might be going on here?

推荐答案

感谢大家的帮助.看起来问题与我在 OSX 下安装 mysql gem 有关.

Thanks for all the help guys. Looks like the problem had to do with my install of the mysql gem under OSX.

@tim 在我进行下一步并起身后,控制台出现错误,因此我进行了一些搜索并找到了这个 有用的话题.

@tim after I proceeded to the next step and got up and going I got an error on the console, so I did a bit of searching and found this helpful thread.

在我卸载我的 ruby​​ gems gem uninstall mysql 之后,我使用这个命令(来自线程)安装了正确的 mysql gems:

After I uninstalled my ruby gems gem uninstall mysql I installed the proper mysql gems using this command (from the thread):

export ARCHFLAGS="-arch i386 -arch x86_64" ;gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

在执行这个之后,我能够成功运行 rake db:create 并继续.

After executing this one I was able to successfully run rake db:create and proceed.

谢谢!!

这篇关于使用 rake db:create 创建 Rails DB 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆