简体   繁体   中英

Ruby on rails $ mysql configuration

I want to configure mysql instead of Sqlite3. I had already configured the database.yml file:

development:
  adapter: mysql
  database: test
 username:false
 password:neha
 host :localhost
 port:3306

and also installed the mysql gem using gem install mysql

still i stuck out in error...please help me out :\\rails\\TestApp1>ruby script/server

Booting WEBrick Rails 2.3.11 application starting on http://0.0.0.0:3000 :/Ruby192/lib/ruby/1.9.1/syck.rb:135:in load': syntax error on line 13, col 0: test:' (ArgumentError) from C:/Ruby192/lib/ruby/1.9.1/syck.rb:135:in load' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:926:in database_configuration' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:437:in initialize_database' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:141:in process' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:113:in run' from C:/rails/TestApp1/config/environment.rb:9:in ' from :29:in require' from <internal:lib/rubygems/custom_require>:29:in require' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in block in require' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:547:in new_constants_in' from C:/Ruby192/li b/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in require' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/commands/server.rb:84:in ' from :29:in require' from <internal:lib/rubygems/custom_require>:29:in require' from script/server:3:in `' i got this error

@d11wtq:
here is my yml file for mysql configuration:

ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "neha",
:database => "ruby"
)
& where i have to put
require 'mysql'

Looking at that log output you've now posted, it looks like you have haven't formatted that .yml file correctly. The use of whitespace in YAML is absolutely critical. Indent with spaces, not tabs, and make sure your indentation is consistent within each level. It appears that the lines are all aligned differently in your file, which is causing syck (the YAML parser) to throw an Exception.

EDIT | You also want to make the spacing between the key, the semi-colon and the value consistent too. Take pride in the layout of your code and you'll enjoy coding more ;) But pride or not... YAML is (intentionally) picky about whitespace.

Have your yml files properly indented and you will not be getting syntax error anymore. Also add mysql2 compatible version in your Gemfile, so that while you will be deploying it to any server it will take from Gemfile automatically.

您是否将“mysql”添加到 Gemfile 并运行“捆绑安装”?

If you're working on Windows, I know that I didn't have the MySQL C Driver installed on my machine. It's a different download than the MySQL Community Server. You also have to make sure that your PATH has the route to the C driver. Download the driver here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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