使用 rake db:create 创建 Rails DB 时出错

发布于 2024-08-29 16:00:21 字数 1635 浏览 4 评论 0原文

我正在尝试使用 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 问题都通过以下建议解决了这个问题:

  1. 验证该用户并密码正确(我在我的开发盒上运行时没有 root 密码)

  2. 验证套接字是正确的 - 我可以捕获套接字,所以我假设它是正确的

  3. 验证用户可以创建数据库(如您所见,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:

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

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

  3. 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 distribution

    Type '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 技术交流群。

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

发布评论

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

评论(6

許願樹丅啲祈禱 2024-09-05 16:00:21

感谢大家的帮助。看起来这个问题与我在 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!!

这个俗人 2024-09-05 16:00:21

这可能有很多原因。

  • 你的数据库设置是utf8字符集吗?
  • 套接字的路径是否正确,因为它因操作系统而异。
  • 你重新安装了mysql gem吗? sudo gem install mysql
  • 可能是MySQL,你可能想将版本降级到5.0

除此之外,我不确定。

It could be a number of things.

  • Is your database set for utf8 character set?
  • Is the path to the socket correct, since it varies from OS.
  • Have you reinstalled the mysql gem? sudo gem install mysql
  • It might be MySQL, you might want to downgrade the version to 5.0

Other than that, I'm not sure.

天荒地未老 2024-09-05 16:00:21

你应该在这里发布你的database.yml

为了让你的测试更好,我会尝试创建一个数据库UTF-8来看看你的数据库是否支持utf-8

create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci

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

create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci
追我者格杀勿论 2024-09-05 16:00:21

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 the blog/ 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.

孤独难免 2024-09-05 16:00:21

我刚刚遇到了同样的问题:它是一个旧的 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.

凉墨 2024-09-05 16:00:21

使用以下命令重新安装 mysql-server 和 mysql-client:

sudo apt-get install mysql-server mysql-client

然后需要安装一些库以使 MySQL 可用于 ruby​​:

sudo apt-get install libmysql-ruby

这一切都解决了我的问题。试试吧! :)

Re-install mysql-server and mysql-client using this command:

sudo apt-get install mysql-server mysql-client

and then some libraries you need to install to make MySQL available to ruby:

sudo apt-get install libmysql-ruby

This all solved my problem. Try it !!! :)

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