简体   繁体   English

在rails上使用ruby的mysql错误消息

[英]mysql error message with ruby on rails

I'm using the Lynda.com tutorial to learn Ruby on Rails. 我正在使用Lynda.com教程学习Ruby on Rails。 In Chapter 6, they go through creating a mysql database and then configuring it for Rails. 在第6章中,他们将创建一个mysql数据库,然后为Rails配置它。 After we create and configure the database, the instructor tests the connection with this command from the root of our rails application 在我们创建和配置数据库之后,讲师将从rails应用程序的根目录中使用此命令测试连接

rake db:schema:dump

which created a schema.rb file in the "db" folder of the rails application. 它在rails应用程序的“db”文件夹中创建了一个schema.rb文件。

However, for me, I got this error message when I ran the rake command 但是,对我来说,运行rake命令时收到此错误消息

rake aborted!
syntax error on line 18, col 2: `  socket: /tmp/mysql.sock'

Tasks: TOP => db:schema:dump => db:load_config
(See full trace by running task with --trace)

I tried to do --trace to check the error but it didn't do anything. 我试图做--trace检查错误,但它没有做任何事情。

My database.yml file (where we configured the database for rails) is the same as the instructors, except his uses mysql and mine says mysql2 for the adapter attribute 我的database.yml文件(我们为rails配置数据库)与教师相同,除了他使用mysql和我的mysql2 for adapter属性

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: simple_cms
  password: secretpassword
  socket: /tmp/mysql.sock              <<---this is line 18 as referred to in error 

Anyways, the error message said syntax error in line 18, but my line 18 is exactly the same as the instructors... 无论如何,错误消息表示第18行语法错误,但我的第18行与教师完全一样......

Any ideas how I can fix this problem? 我有什么想法可以解决这个问题吗?

UPDATE -- this command rake db:schema:dump --trace gave me this output UPDATE - 这个命令rake db:schema:dump --trace给了我这个输出

** Invoke db:schema:dump (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
syntax error on line 18, col 2: `  socket: /tmp/mysql.sock'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load'
/Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/application/configuration.rb:100:in `database_configuration'
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:6
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:176:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:157:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/bin/rake:32
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Tasks: TOP => db:schema:dump => db:load_config

new rails version write in routes.rb file top 新的rails版本写在routes.rb文件顶部

Blog::Application.routes.draw do

  get "demo/index"

don't put |map| 不要把|地图|

I had the same issue today. 我今天遇到了同样的问题。 In your database.yaml file, make sure you have a space between the key: and value. 在database.yaml文件中,确保key:和value之间有空格。 For instance, 例如,

database: simple_cms_development database:simple_cms_development

password: dfdjfdfd 密码:dfdjfdfd

Make sure you have a BLANK SPACE between : and your value. 确保在:和您的值之间有一个BLANK SPACE。

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

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