jjzjj

mysql - 无法 rake 分贝 :create:all -- Couldn't create database for {"encoding"= >"utf8", "username"= >"root", "adapter"= >"mysql"

coder 2023-10-03 原文

我正在尝试在我的计算机上启动并运行一个 Rails 应用程序,但我在创建数据库时遇到了问题。我已经正确安装/设置 rails、mysql 并安装了 mysql 2.8.1 gem(我用 gem list 验证了这一点)。

现在,我正在尝试运行“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)

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)

我目前在 Snow Leopard (10.6.6) 上运行 5.5.10 MySQL Community Server (GPL)

这是我的 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

我注意到错误的结尾是这样写的:“字符集:utf8,排序规则:utf8_unicode_ci(如果您手动设置字符集,请确保您有匹配的排序规则)”——这是问题所在吗?如果是这样,我该如何解决?

我已经在这件事上停留了几个小时,在 Google 上找不到任何有用的东西。因此,我们将不胜感激。

谢谢!!

最佳答案

我知道这个帖子已经过时了,但作为一个相信将良好可靠的文档保存在一个地方的 IT 人员来说:

问题实际上源于您的“config/database.yml”文件。您将 ROR 指向 MySQL 套接字的错误位置。

我遇到了这个问题,结果是 gem 是在 mac 系统上构建的,开发人员没有考虑其他操作系统,将他的“mysql.sock”文件放在“/tmp”目录中而不是“/var/run/mysqld/mysqld.sock”。

所以他的“database.yml”文件看起来像:

开发: 适配器:mysql2 #编码:utf8 数据库:一些数据库 游泳池:5 用户名:某个用户名 密码:一些密码 套接字:/tmp/mysql.sock

因为我使用的是 Ubuntu 系统,所以我必须将我的更改为以下内容:

开发: 适配器:mysql2 #编码:utf8 数据库:一些数据库 游泳池:5 用户名:某个用户名 密码:一些密码 套接字:/var/run/mysqld/mysqld.sock

是的,该错误可能会产生误导,但它与您的“编码”无关,也与您使用的是 localhost 还是 127.0.0.1 无关(至少在 linux/UNIX 系统中,这些翻译成相同的东西并且是同义词)

开始编辑

另外像我上面那样把encoding注释掉也是不好的所以我在这里提供修改以供引用。

开发: 适配器:mysql2 编码:utf8 数据库:一些数据库 游泳池:5 用户名:某个用户名 密码:一些密码 套接字:/var/run/mysqld/mysqld.sock

结束编辑

关于mysql - 无法 rake 分贝 :create:all -- Couldn't create database for {"encoding"= >"utf8", "username"= >"root", "adapter"= >"mysql",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5575876/

有关mysql - 无法 rake 分贝 :create:all -- Couldn't create database for {"encoding"= >"utf8", "username"= >"root", "adapter"= >"mysql"的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - 如何从 format.xml 中删除 <hash></hash> - 2

    我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为

  4. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  5. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  6. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  7. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  8. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  9. ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作 - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request

  10. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

随机推荐