Rails: error: database configuration does not specify adapter - mysql

The Rails application I'm developing is running fine on my local machine (MAC). When I upload it to the server (Centos 6.2 Linux, with Rails 3.2.3 and Passenger installed), and try to start the application (by entering the URL into my browser), I get the following error message:
Ruby (Rack) application could not be started There appears to be a
database problem.
Your application's database configuration file might be written
incorrectly. Please check it and fix any errors.
The database server may not be running. Please check whether it's
running, and start it if it isn't.
Error message:
database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified) Exception class:
ActiveRecord::AdapterNotSpecified
Note that when I ran rake db:create and rake db:migrate, both of these tasks ran fine and the databases are created and migrated properly.
Following is my database.yml file:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: acme_development
pool: 5
username: root
password: ***********
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: acme_test
pool: 5
username: root
password: *****************
socket: /tmp/mysql.sock
Any ideas?

Phusion Passenger defaults to the "production" environment, as documented. It looks like you assume "development". In that case, set "RackEnv development".

Related

Openshift RoR. Cant connect to db through mysql.sock

I have Openshift RoR app. When I trying to run some rake task which uses DB, it gives me error:
rake aborted!
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
When I pushed my app 1st time there was no socket value in database.yml, I added it later trying to fix this issue, set it to env variable of socket, which is:
"/var/lib/openshift/some_key/mysql//socket/mysql.sock
" In mysql.log I have this same socket too. So I don't understand where is this "/var/lib/mysql/mysql.sock" came from. I guess I need rebuild my app somehow, but it only restarts on "push" now. Or is this wrong idea?
EDIT: Here is my database.yml from .openshift/config. As i mentioned i added "soket: <%=ENV['OPENSHIFT_MYSQL_DB_SOCKET']%>" later, after first push. I just tried 'force_clean_build' marker, it didn't help though.
development:
adapter: mysql2
database: database
username: root
password: psswd
host: localhost
test:
adapter: mysql2
database: database
username: root
password: psswd
host: localhost
production:
adapter: mysql2
database: "<%=ENV['OPENSHIFT_APP_NAME']%>"
username: "<%=ENV['OPENSHIFT_MYSQL_DB_USERNAME']%>"
password: "<%=ENV['OPENSHIFT_MYSQL_DB_PASSWORD']%>"
host: <%=ENV['OPENSHIFT_MYSQL_DB_HOST']%>
port: <%=ENV['OPENSHIFT_MYSQL_DB_PORT']%>
soket: <%=ENV['OPENSHIFT_MYSQL_DB_SOCKET']%>
Turned out server didn't run all necessary rake:db tasks on deploy. That's why I was getting 'We are sorry...' error. And to run rake tasks through ssh, You need to add "RAILS_ENV=production" before it, like this:
RAILS_ENV=production rake db:setup
This 2 problems (not necessarily connected) made it look for me, like there is problem with DB config.

Cannot Connect to MySQL Database in Rails 4

I'm new to Rails and I'm going through a tutorial on Lynda.com, Rails 4 Essentials. I'm on a Windows 7 x64 machine and I'm trying to connect the MySQL database to the Rails app. I've successfully created the database and created a new user.
I had issues running the mysql2 gem and I could only get version 0.3.11 to work (it's on version 0.3.16 as of this post). I copied the libmysql.dll from the C:\Program Files\MySQL\MySQL Connector.C 6.1\lib to my C:\RailsInstaller\Ruby2.0.0\bin directory as the instructions stated.
Everything seems to be ok at this point.
I configured my database.yml file to match my database credentials (I had to create this from scratch, nothing was generated when I ran mysql2).
#config\database.yml
development:
adapter: mysql2
database: simple_cms_development
username: craig
password: password
host: 127.0.0.1
socket: /tmp/mysql.sock
test:
adapter: mysql2
database: simple_cms_test
username: craig
password: password
host: 127.0.0.1
socket: /tmp/mysql.sock
production:
adapter: mysql2
database: simple_cms_production
username: craig
password: password
host: 127.0.0.1
socket: /tmp/mysql.sock
I got to try to connect my database with MySQL using:
rake db:schema:dump
and I get this crap:
LoadError: cannot load such file -- mysql2/2.0/mysql2
I see a directory called mysql2/1.9 and there is a file called mysql.so in there but there is no 2.0.
Any ideas? Thanks!
The joys of developing on a windows machine :)
I suggest you check this question - it looks like the same problem.
Error "...cannot load such file -- mysql2/2.0/mysql2 (LoadError)". On Windows XP with Ruby 2.0.0
I managed to get passed this issue by starting fresh. I followed these set of videos to set up Ruby, MySQL, and Rails on my Windows 7 x64 machine.
http://youtu.be/C5S7vjN6GLc
Worked like a gem, I'm rockin' and rollin' now.

Gem::LoadError Specified 'mysql2' for database adapter

I am using ruby and rails in window 7. I am create a basic blog application which is given by ruby and rails site
I have create db connection with mysql like this
development:
adapter: mysql2
encoding: utf8
database: message
username: root
password:
pool: 5
socket: /tmp/mysql.sock
timeout: 5000
Now i am getting error. I have search but not get so many ans but that is not related to window :(
Please help me, how can create connection with db
Gem::LoadError
Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile.
Tthis

Rails Can't connect to MySQL server on 'localhost'

I'm having no end of trouble with my Rails 3 app's Mysql connection, though I have studied countless relevant threads. My error message:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `connect': Can't connect to MySQL server on 'localhost' (10061) (Mysql2::Error)
(Before you flag this as a duplicate question, consider whether you can find another thread with pertinent advice I have not followed.)
My efforts thus far:
I have copied the libmysql.dll file from <mysql installation>/bin to <ruby installation>/bin.
I have the mysql2 gem in the bundle, and it was installed with the connector (--with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32):
> bundle show mysql2
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32
I believe my database.yml file is configured correctly:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: tq_development
pool: 5
username: root
password: pinney
host: localhost
try replacing localhost with 127.0.0.1 (in workbench and yml)
Have you ran rake db:create yet on the project in question?
I agree with the above....Make sure it works with workbench or some other GUI tool and you can connect using the info the database.yml file.
If not....come back and give us another holler.

cant connect from rails to mysql

im struggling to connect to my mysql service running on my local windows 7 machine- I am getting the following error when trying to rake migrations or access through the web browser-
Mysql2::Error (Can't connect to MySQL server on 'localhost' (10061)):
i have left the mysql user/pass as default - this is my yaml conf file
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
port: 3306
encoding: utf8
reconnect: false
database: events_development
pool: 5
username: root
password:
host: localhost
# 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: mysql2
encoding: utf8
reconnect: false
database: events_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: events_production
pool: 5
username: root
password:
host: localhost
the thing is i can login using root through mysql on the command line and also running phpmyadmin through xampp- so i have narrowed it down to a firewall issue? or permissions issues? everything is running localhost on my machine
update
i turned windows firewall off and it made no difference
Make sure you've granted localhost privileges. Info here.
i restarted the machine and restarted the servers- seemed to work
I'am a bit confused? Localost => Port (10061) ?
Maybe try to add port: 3306 everywhere.
Do you started the Server in dev env?