I've been trying for a good while to get Rails to talk to MySQL. I was able to install the 'mysql2' gem (v0.2.7), create a new rails app defaulting to MySQL:
rails new mytest -d mysql
and bundle install everything.
However, when I run rake db:create, it simply hangs, no errors, no anything.
Running rake db:create --trace hangs at '** Execute db:create'.
My database.yml configuration:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: mytest_development
pool: 5
username: root
password: passwordforrootuser
host: localhost
Using:
Windows 7 (64-bit)
MySQL 5.5 Server (32-bit)
Ruby 1.9.2
Really at my wit's end. Help???
Might be worth a try, if you include:
socket: /tmp/mysql.sock
My setup, normally looks like:
adapter: mysql2
encoding: utf8
reconnect: false
database: foobar_development
pool: 5
username: root
password: ***************
socket: /tmp/mysql.sock
Related
When I start the debug for development I get this message:
Connecting to database specified by database.yml
then, nothing happen, I wait for long time, and nothing happen, although database setting is correct
If I start the server with development with no debugging, it will start normally
Any idea ? where to check for this issue ?
EDIT
database.yml:
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On Mac OS X with macports:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
development:
adapter: postgresql
encoding: unicode
database: dcaclab_development
pool: 5
username: samir
password: 123456
# adapter: postgresql
# encoding: unicode
# database: jerry
# pool: 5
# username: tom
# password: myPassword
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# The server defaults to notice.
#min_messages: warning
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: dcaclab_development
pool: 5
username: samir
password: 123456
production:
adapter: postgresql
encoding: unicode
database: dcaclab_development
pool: 5
username: samir
password: 123456
EDIT 2
/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)
/usr/local/rvm/gems/ruby-1.9.3-p125#global/gems/ruby-debug-ide-0.4.17.beta14/bin/rdebug-ide --dispatcher-port 33169 --port 46779 -- /root/RubymineProjects/dcaclab/script/rails server -b 0.0.0.0 -p 3000 -e development
Fast Debugger (ruby-debug-ide 0.4.17.beta14, ruby-debug-base 0.11.30.pre10) listens on 127.0.0.1:46779
Update: Running
RAILS_ENV=development rake db:create
... works. But the rake commands without the RAILS_ENV prefix don't. What gives?
For some reason, I am no longer able to interact with my development database at all anymore.
I've tried rake db:create, and it makes my test database fine, but the dev one is not created at all.
I'm using the postgresapp.com, and up until just recently, it was working flawlessly. No changes to my config/database.yml file have been made recently, nor to any of my app config files.
I can connect to my test database fine with psql -h localhost redtail_test, and it uses the same connection credentials as my dev box, so I'm reasonably sure it's not a connection issue with PG--unless it's a weird one.
redtail git:master ❯ rake db:create
redtail_test already exists
redtail git:master ❯ psql -h localhost redtail
psql: FATAL: database "redtail" does not exist
Has anyone ran into this issue?
common: &common
encoding: utf8
postgres: &postgres
adapter: postgresql
user: postgres
password:
min_messages: WARNING
development: &development
<<: *common
<<: *postgres
host: localhost
database: redtail
memory: &memory
<<: *common
adapter: sqlite3
host: localhost
database: ":memory:"
test: &test
<<: *common
<<: *postgres
host: localhost
database: redtail_test
production:
adapter: postgresql
encoding: utf8
database: redtail
cucumber:
<<: *test
I have a Rails 3.2.1 project that I'm trying to run my specs on.
When I run:
rake
rake aborted! PG::Error: ERROR: invalid value for parameter
"search_path": "example" DETAIL: schema "example" does not exist :
SET search_path TO example
From what I can work out, rake db:test:prepare drops the test database and then attempts to recreate it from the schema.rb. The thing is, database.yml has the line
schema_search_path: example
so when it tries to reconnect, it fails with the above error.
I think my question is, how can I get rake db:test:prepare to setup the schema_path too?
One solution is to add a bit of code to the db:create task that creates the schema. Put this in a rake task, for exmaple 'APP_ROOT/lib/tasks/db_create_schema.rake'
namespace :db do
task :create do
config = Rails.configuration.database_configuration[Rails.env].merge!({'schema_search_path' => 'public'})
ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection.execute("CREATE SCHEMA schema_name")
end
end
https://gist.github.com/4280172
You should set the schema_search_path in your config/database.yml
e.g.
development:
adapter: postgresql
encoding: unicode
database: test
pool: 5
username: user
password: password
#host: localhost
#port: 5432
# Schema search path. The server defaults to $user,public
schema_search_path: example
I've a Refinery app, works great locally.
Created a bamboo stack on Heroku.
When I try to push I can see this:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Then I open it up in browser:
"We're sorry, but something went wrong."
$ heroku logs
Rendered vendor/bundle/ruby/1.9.1/gems/refinerycms-authentication-2.0.2/app/views/refinery/users/new.html.erb within refinery/layouts/login (82.3ms)
2012-03-15T14:43:25+00:00 app[web.1]: Completed 500 Internal Server Error in 1269ms
full output is here
Any help is great, thanks!
+++
Update:
Updated the stack to Cedar and made Ruby env 1.9.3
$ heroku config
DATABASE_URL => ..
GEM_PATH => vendor/bundle/ruby/1.9.1
LANG => en_US.UTF-8
PATH => bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV => production
RAILS_ENV => production
RUBY_VERSION => ruby-1.9.3-p0
SHARED_DATABASE_URL => ..
$ heroku info --app mimacohuoncedar
=== mimacohuoncedar
Addons: Basic Logging, Shared Database 5MB
Database Size: (empty)
Git URL: git#heroku.com:mimacohuoncedar.git
Owner: ..
Repo Size: 9M
Slug Size: 19M
Stack: cedar
Web URL: http://mimacohuoncedar.herokuapp.com/
$ heroku logs now shows this:
this-updated
Where to go on? Thanks
Dont know if you managed to fix this but I ran into the same issue using the Cedar stack. Found this article on Heroku that seemed to do the trick for me. Ran the line in terminal and it pushed first time.
I am seeing this same error, and the accepted answer did not solve it for me;
This blog however, did the trick. The blog title refers to Rails 3.2, but I'm on 3.1 and was seeing this same error.
The blog recommended adding this line to application.rb.
config.assets.initialize_on_precompile = false
The meaning, as summarized from the article;
This option prevents the Rails environment from being loaded when the assets:precompile task is executed. Because Heroku precompiles assets before setting the database configuration, you need to set this configuration to false or you Rails application will try to connect to an unexisting database.
Added the line and pushed, everything seems good now.
That output looks suspiciously like Cedar stack and not Bamboo - give http://devcenter.heroku.com/articles/labs-user-env-compile a go. That should sort you out.
I have a basic rails3 app that I am deploying on site5. I have installed all the required gems, using bundler, and when I try to run rake db:migrate or rake db:schema:load, I get:
# rake RAILS_ENV=production db:schema:load
(in /home/xxx/rails/costfinder)
rake aborted!
Access denied for user 'root'#'localhost' (using password: YES)
My config/database.yml has:
production:
adapter: mysql2
database: xxx_costfinder_production
user: ****
password: ******
encoding: utf8
reconnect: true
pool: 5
socket: /tmp/mysql.sock
I have no idea why rails is trying to connect as root. Any suggestions? My experience is with rails2, this is my first stab at a rails3 app.
Aieeee, it's username, not user