简体   繁体   English

无法rake db:create:all - 无法为{“encoding”=>“utf8”,“username”=>“root”,“adapter”=>“mysql”创建数据库

[英]Cannot rake db:create:all — Couldn't create database for {“encoding”=>“utf8”, “username”=>“root”, “adapter”=>“mysql”

I'm trying to get a rails app up and running on my computer, and I'm having issues with creating the databases. 我正试图在我的计算机上运行一个rails应用程序,我在创建数据库方面遇到了问题。 I've properly installed/setup rails, mysql and have installed the mysql 2.8.1 gem (I verified this with gem list). 我已正确安装/设置rails,mysql并安装了mysql 2.8.1 gem(我用gem列表验证了这一点)。

So now, I'm trying to run 'rake db:create:all' and I'm getting the following error: 所以现在,我正在尝试运行'rake db:create:all',我收到以下错误:

Couldn't create database for {"encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"pyo", "host"=>"localhost", "password"=>nil, "socket"=>"/tmp/mysql.sock"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation) 无法为{“encoding”=>“utf8”,“username”=>“root”,“adapter”=>“mysql”,“database”=>“pyo”,“host”=>“localhost”创建数据库“,”“password”=> nil,“socket”=>“/ tmp / mysql.sock”},charset:utf8,collat​​ion:utf8_unicode_ci(如果手动设置字符集,请确保您具有匹配的排序规则)

Couldn't create database for {"encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"pyo_test", "host"=>"localhost", "password"=>nil, "socket"=>"/tmp/mysql.sock"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation) 无法为{“encoding”=>“utf8”,“username”=>“root”,“adapter”=>“mysql”,“database”=>“pyo_test”,“host”=>“localhost”创建数据库“,”“password”=> nil,“socket”=>“/ tmp / mysql.sock”},charset:utf8,collat​​ion:utf8_unicode_ci(如果手动设置字符集,请确保您具有匹配的排序规则)

I'm currently running 5.5.10 MySQL Community Server (GPL) on Snow Leopard (10.6.6) 我目前在Snow Leopard上运行5.5.10 MySQL社区服务器(GPL)(10.6.6)

And here is what is in my database.yml file 这是我的database.yml文件中的内容

development:
  adapter: mysql
  encoding: utf8
  database: pyo
  username: root
  password:
  socket: /tmp/mysql.sock
  host: localhost

test:
  adapter: mysql
  encoding: utf8
  database: pyo_test
  username: root
  password:
  socket: /tmp/mysql.sock
  host: localhost

I notice how the end of the error says "charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)" -- Is that the issue? 我注意到错误的结尾如何“charset:utf8,collat​​ion:utf8_unicode_ci(如果你手动设置字符集,请确保你有匹配的排序规则)” - 这是问题吗? And if so, how do I fix it? 如果是这样,我该如何解决?

I've been stuck on this thing for hours and can't find anything that helps on Google. 我已经被困在这件事上好几个小时了,找不到任何对谷歌有帮助的东西。 So any help at this point would be much appreciated. 所以在这一点上的任何帮助将非常感激。

Thanks!! 谢谢!!

I know this thread is old but being a IT guy who believes in keeping good solid documentation in one place here goes: 我知道这个帖子已经老了,但是作为一个IT人员,他相信在一个地方保持良好的可靠文档:

The problem actually stems from your "config/database.yml" file. 问题实际上源于您的“config / database.yml”文件。 You are pointing ROR to the wrong location for the MySQL Socket. 您将ROR指向MySQL Socket的错误位置。

I ran into this problem and what it turned out to be is the gem was built on a mac system and the developer did not account for other operating systems by putting his "mysql.sock" file in the "/tmp" directory rather than the "/var/run/mysqld/mysqld.sock" . 我遇到了这个问题,结果是gem是在mac系统上构建的,开发人员没有考虑其他操作系统,只需将他的“mysql.sock”文件放在“/ tmp”目录而不是“/var/run/mysqld/mysqld.sock”。

So his "database.yml" file looked like: 所以他的“database.yml”文件看起来像:

development: adapter: mysql2 #encoding: utf8 database: somedatabase pool: 5 username: someusername password: somepassword socket: /tmp/mysql.sock

Because I was on a Ubuntu System I had to change mine to the following: 因为我在Ubuntu系统上,我不得不改变我的以下内容:

development: adapter: mysql2 #encoding: utf8 database: somedatabase pool: 5 username: someusername password: somepassword socket: /var/run/mysqld/mysqld.sock

Yes the error can be misleading however it has nothing to do with your "encoding" or whether you are using localhost or 127.0.0.1 (At least in linux/UNIX systems these translate to the same thing and are synonymous) 是的错误可能会误导,但它与您的“编码”无关,或者您使用的是localhost还是127.0.0.1 (至少在linux / UNIX系统中这些转换为同一个东西并且是同义词)

Begin Edit 开始编辑

Also it is not good to have encoding commented out like I do above. 如上所述,编码注释也不好。 So I am providing the modification here for reference. 所以我在这里提供修改以供参考。

development: adapter: mysql2 encoding: utf8 database: somedatabase pool: 5 username: someusername password: somepassword socket: /var/run/mysqld/mysqld.sock

End Edit 结束编辑

think I had something like this...fixed by adding this to database.yml: 我认为我有这样的东西......通过将其添加到database.yml来修复:

host: 127.0.0.1

Or in your case, changing it from localhost. 或者在您的情况下,从localhost更改它。

I was getting the same issue with the mysql2 gem. 我遇到了与mysql2 gem相同的问题。 Then I found my MySQL is listening in 'localhost' only and not '127.0.0.1', so I changed it to 'localhost' and now I don't get that issue anymore. 然后我发现我的MySQL只在'localhost'中侦听而不是'127.0.0.1',所以我将它改为'localhost',现在我不再讨论这个问题了。 Everything works now. 现在一切都有效。

I want to share my solution. 我想分享我的解决方案。 I had my database.yml as follow 我有我的database.yml如下

default: &default
  adapter: mysql2
  encoding: utf8
  username: root
  password: 
  host: 127.0.0.1
  port: 3306

development:
  <<: *default
  database: dev.database

My mistake was in this line 我的错误在于这一行

database: dev.database

So, I write without (.) 所以,我写的没有(。)

database: devdatabase

So, after about 3 or 4 days of googling and trying so many different things, I stumbled on this somehow: 所以,经过大约3到4天的谷歌搜索并尝试了很多不同的东西,我偶然发现了这个:

http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/ http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/

And guess what? 你猜怎么着? IT WORKS! 有用! PERFECTLY. 完美。 Which leads me to believe that the problem lies within MySQL 5.5.10. 这让我相信问题出在MySQL 5.5.10中。 Something about it will not just play nice with my ruby/rails environment. 关于它的一些东西不仅仅适用于我的ruby / rails环境。 However, once I followed the instructions on the link above (which include uninstalling mysql and re-installing 5.1), my app now runs perfectly on my local machine. 但是,一旦我按照上面链接上的说明(包括卸载mysql并重新安装5.1),我的应用程序现在可以在我的本地计算机上完美运行。

Hope this helps someone! 希望这有助于某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM