使用 rake db:create 创建 Rails DB 时出错
我正在尝试使用 Rails 的 入门指南 在我的 OSX 10.6.3 机器上。
当我执行第一个 rake db:create
命令(我使用的是 mysql)时,我得到:
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 问题都通过以下建议解决了这个问题:
验证该用户并密码正确(我在我的开发盒上运行时没有 root 密码)
验证套接字是正确的 - 我可以捕获套接字,所以我假设它是正确的
验证用户可以创建数据库(如您所见,root 可以连接并创建此数据库,没有问题)
simon@/Users/simon/source/rails/blog/config: mysql -uroot -hlocalhost 欢迎使用 MySQL 监视器。命令以 ; 结尾或\g。 您的 MySQL 连接 ID 是 16 服务器版本:5.1.45 源码分发
输入“帮助”;或“\h”寻求帮助。输入“\c”清除当前输入语句。
mysql>创建数据库blog_development; 查询正常,1 行受影响(0.00 秒)
以确保这不是字符集问题我也尝试过:
mysql> create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
注意:这是我的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
请注意,我尝试将套接字切换到本地主机,但没有效果。
知道这里可能发生什么吗?
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.
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)
I found plenty of stackoverflow questions addressing this problem with the following advice:
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
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
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.1.45 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the current input statement.
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)
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
Note that I tried switching socket to localhost with no effect.
Any idea on what might be going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
感谢大家的帮助。看起来这个问题与我在 OSX 下安装 mysql gem 有关。
@tim 在我继续下一步并起身走后,我在控制台上遇到了错误,所以我做了一些搜索,发现了这个 有用的帖子。
卸载 ruby gems
gem uninstall mysql
后,我使用此命令(从线程)安装了正确的 mysql gems: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
并继续。谢谢!!
Thanks for all the help guys. Looks like the problem had to do with my install of the mysql gem under OSX.
@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.
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
After executing this one I was able to successfully run
rake db:create
and proceed.Thanks!!
这可能有很多原因。
sudo gem install mysql
除此之外,我不确定。
It could be a number of things.
sudo gem install mysql
Other than that, I'm not sure.
你应该在这里发布你的database.yml
为了让你的测试更好,我会尝试创建一个数据库UTF-8来看看你的数据库是否支持utf-8
You should post here your database.yml
To make your test better, i would try to create a database UTF-8 to see if your database supports utf-8
blog_development
数据库是否已存在?如果是这样,您可以继续下一步。
尝试在
blog/
目录中运行ruby script/server
。如果没有出错,那么您应该能够导航到
localhost:3000
并从这里继续教程 http://guides.rubyonrails.org/getting_started.html#hello-rails。如果 ruby script/server 出现错误,请给我留言。
Does the
blog_development
database already exist?If so, you can just continue to the next step.
Try running
ruby script/server
in theblog/
directory.If it doesn't error out, then you should be able to navigate to
localhost:3000
and continue the tutorial from here http://guides.rubyonrails.org/getting_started.html#hello-rails.Leave me a comment if
ruby script/server
errors out.我刚刚遇到了同样的问题:它是一个旧的 mysql gem,不是最新的。重新安装 mysql gem 就成功了。
I just had the same issue : it was an old mysql gem which was not up to date. Re-installing the mysql gem did the trick.
使用以下命令重新安装 mysql-server 和 mysql-client:
然后需要安装一些库以使 MySQL 可用于 ruby:
这一切都解决了我的问题。试试吧! :)
Re-install mysql-server and mysql-client using this command:
and then some libraries you need to install to make MySQL available to ruby:
This all solved my problem. Try it !!! :)