Rails 3 not able to connect to remote DB with mysql2 gem - ruby-on-rails

I have 2 environments: development and development_with_production_data.
The environments only differ in their database.yml entries:
development:
host: 127.0.0.1
adapter: mysql2
encoding: utf8
database: [REDACTED]_development
username: root
password:
pool: 5
development_with_production_data:
host: [REDACTED]
port: [REDACTED]
adapter: mysql2
encoding: utf8
database: [REDACTED]_production
username: [REDACTED]
password: [REDACTED]
pool: 5
I have verified that the values I have [REDACTED] above are the correct values. I have a gui that can connect just fine and a rails 2 app that connects with the same [REDACTED] values.
Loading up and working on the development environment work perfect, locally.
Loading up and working on the development_with_production_data environment will not even anything but static, cached pages. No error messages, no timeouts, nothing. All I see is this:
coneybeare $ rails s -e development_with_production_data
NOTE: Gem::SourceIndex#all_gems is deprecated with no replacement. It will be removed on or after 2011-10-01.
Gem::SourceIndex#all_gems called from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.13/lib/bundler/rubygems_integration.rb:256
.
=> Booting WEBrick
=> Rails 3.0.7 application starting in development_with_production_data on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-05-09 01:23:48] INFO WEBrick 1.3.1
[2011-05-09 01:23:48] INFO ruby 1.8.7 (2009-06-12) [i686-darwin10]
[2011-05-09 01:23:48] INFO WEBrick::HTTPServer#start: pid=3854 port=3000
I am using rails 3.0.7 and have tried both mysql2 0.3.2 and mysql2 0.2.7
What could be causing this?

I finally solved this by updating my ruby to 1.9.2 on my mac using RVM. Then I had to reinstall the bundle gem, rails gem, and do a bundle install. Previously I had been using 1.8.7 and for some reason, it was causing the hang.

Try to install mysql2 0.2.x because there is some issues with mysql2 0.3.x in rails 3.0.7

Related

Ruby 3.0.4 with Postgres 14 throws segmentation fault

I have
Ruby 3.0.4
Rails 6.1.7
pg 1.4.5
postgresql 14.6
Here is my database.yml file
development:
adapter: postgresql
encoding: utf8
database: olio_development
username: postgres
password: password
pool: 5
host: 127.0.0.1
port: 5432
gssencmode: disable
When I run rake db:create I am getting the following segmentatin fault
/home/usr/.rvm/gems/ruby-3.0.4/gems/pg-1.4.5/lib/pg/connection.rb:626: [BUG] Segmentation fault at 0x00007fd79729a140
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0050 p:---- s:0275 e:000274 CFUNC :connect_poll
c:0049 p:0543 s:0271 e:000270 METHOD /home/suganya/.rvm/gems/ruby-3.0.4/gems/pg-1.4.5/lib/pg/connection.rb:626
The connection fails.
I have verified postgres is running and is on host 127.0.0.1 and post 5432.
Please help me how to resolve this segmentation fault?
I'm seeing a GitHub issue for the pg gem (https://github.com/ged/ruby-pg/issues/493) that matches your problem, so it might be a bug with pg v1.4.5. I would try pinning it to an older version:
gem 'pg', '1.4.4'
And work your way backwards if that still has issues. You can also add your information to the GitHub issue linked above to help the maintainers resolve the issue.

Push Rails / ClearDB App to Heroku Error 'Can't connect to MySQL server on '127.0.0.1'

Every time I run:
git push heroku master
I get the following error:
Running: rake assets:precompile
rake aborted!
Can't connect to MySQL server on '127.0.0.1'
I am running
rails -v Rails 3.2.11
and
ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]
I have installed ClearDB via Heroku CLI and it seems to work fine, but I can't figure out this error.
Here is my yml for production:
production:
adapter: mysql2
encoding: utf8
host: localhost
database: pm_production
username: root
password: root
allow_concurrency: true
pool: 5
Your app is trying to initialize during asset compilation. The heroku docs explicitly recommend you disable app initialization on precompile by modifying your config/application.rb:
config.assets.initialize_on_precompile = false

Rails: Deploying to Heroku, Many Problems

Trying to deploy my rails app to Heroku for the first time, I ran into many problems. The app crashed, and you can look at the logs in the image: http://i.stack.imgur.com/bsx1b.png
Even worse, when I tried to look at my application locally, it failed to work on postgreSQL environment.It worked fine when I went back to use sqLite3 in database.yml. I thought the problem might be that I actually have to install postgreSQL, in addition to adding pg gem and running bundle install.
I went ahead to install PostgreSQL with the one-click installer (Windows 7 64bit). After reboot, a simple rails server or bundle install commands started failing, so I reinstalled the entire ruby & rails.
Now rails server command works fine, and it prompts a different error when I try to look at my app on local environment. So right now I have pgAdmin III and Rails
PG::Error
fe_sendauth: no password supplied
I tried to follow this, but I couldn't find "pg_hba.conf." I guess the answer was based on a different OS.
And now again, the bundler is not working, giving me errors...
Questions:
1) Was I right to install postgreSQL with the one-click installer? Because this caused my ROR to "crash" somehow, and I had to reinstall rails altogether. 2) I think I am going to delete everything related to postgreSQL, reinstall Rails, and start everything from beginning. What are the steps that I have to take? All the references I've looked at do not seem to fit Windows environment.
In my gemfile, I have
gem 'pg'
gem 'thin'
In my database, I have
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: utf8
database: mangfeel_development
pool: 5
timeout: 5000
# 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: utf8
database: mangfeel_test
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: utf8
database: mangfeel_production
pool: 5
timeout: 5000
Errors I'm getting at this moment, after installing PostgreSQL:
c:\ruby\myapp>rails server
C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:926:in `report_activate_error': Could not find RubyGem railties (>= 0) (Gem::LoadError)
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:244:in `activate_dep'
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:236:in `activate'
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:1307:in `gem'
from C:/RailsInstaller/Ruby1.9.3/bin/rails:18:in `<main>'
When I run bundle install:
Gem::InstallError: The 'json' native gem requires installed build tools
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occurred while installing json (1.7.5), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.5'` succeeds before bundling.
So I will just remove pgAdminIII, PostgreSQL, Ruby on Rails entirely, and start from scratch.
I thought deploying wasn't going to be this hard, but moving from SQLite3 to PostgreSQL is taking more time and effort than I thought it would. I would really appreciate some help on this problem.
------------------------------------------------------------------------------------------------------------------------
UPDATE: AFTER REINSTALLING EVERYTHING, I'M DOING THE SETUP AGAIN FROM SCRATCH.
I checked that my SQLite3 version app worked fine. So I moved onto setting up postgreSQL. I got the following error when I first set up my postgreSQL. By setting up, I mean editing config/database.yml and installing the gem 'pg' and removing the gem 'sqlite3.' When I tried to connect to localhost:3000, I got the following error:
ActiveRecord::ConnectionNotEstablished
After some research, I found that there could be more steps to setting the db. So I ran the bundle command,
bundle exec rake db:setup
But then in the console, I got the following error when I ran bundle exec rake db:setup.
Couldn't create database for {"adapter"=>"postgresql", "host"=>"localhost", "encoding"=>"utf8", "database"=>"db/myapp_test", "pool"=>5, "timeout"=>5000}
rake aborted!
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
c:/ruby/myapp/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:schema:load => environment
When I tried to connect to localhost:3000, I got the above error again, instead of ActiveRecord::ConnectionNotEstablished.
Question: What did I do wrong, and how do I solve the problem?
If you have error:
PG::Error
fe_sendauth: no password supplied
You have good news, your app can work with PostgreSQL database now. (But you need to configure some thing)
After installing PostgreSQL, you can create new rails app using PostgreSQL by command:
rails new my_app -d postgresql
This is database.yml will be created:
development:
adapter: postgresql
encoding: unicode
database: my_app_development
pool: 5
username: my_app
password:
test:
adapter: postgresql
encoding: unicode
database: my_app_test
pool: 5
username: my_app
password:
production:
adapter: postgresql
encoding: unicode
database: my_app_production
pool: 5
username: my_app
password:
You see that, three database has username and password field, this is account user in Postgresql, three database in database.yaml file will created by this user. So you need to provide username and password for it. Default after install Postgresql, it created a user with username is postgresql and password is postgresql. You can use it.
If you want to use other user, just open pgAdmin III and create new user by right click on Login Roles and choose New login role to create new user with password. Then put that username and password to database.yaml file.
After that, all you need now, is find and open pg_hba.conf file to make some configure for app can work with PostgreSQL. I'm not using Windows for a long time, so I'm not sure where it is, but you can find in folder you installed PostgreSQL. Example, if you install on E:\ partition, maybe you can find it in:
E:\PostgreSQL\version\data
After you found it, open and find a line:
# "local" is for Unix domain socket connections only
local all all ident sameuser
Change it to:
# "local" is for Unix domain socket connections only
local all all md5
Then restart your Postgresql database. To create database for app, run rake db:create or rake db:create:all. Now your app can using PostgreSQL database now, so happy :).
I am not an expert on Rails, but here is one of my YAML files for a recent deployment i did on heroku with POSTGRES
development:
adapter: postgresql
host: localhost
database: dbname_development
production:
adapter: postgresql
host: localhost
database: dbname_production
Seems like you are missing a parameter called host in case of postgres deployment
Steps to Move From SQLite3 to PostgreSQL on Windows, for an Existing Rails App to Deploy To Heroku:
In your Gemfile, find gem 'sqlite3' and change it to gem 'pg'. Run bundle install.
Download Postgres from here. Choose the one-click installer and select your OS environment (32 or 64 bit). During installation, do NOT choose to install any extra software it recommends you to install. It will possibly mess up your existing Rails and you will have to reinstall Rails.
Now go to config/database.yml, and change it to the following format. The current one is set for SQLite3 and is missing some fields necessary for PostgreSQL.
development:
adapter: postgresql
encoding: unicode
database: my_app_development
pool: 5
username: my_app
password:
test:
adapter: postgresql
encoding: unicode
database: my_app_test
pool: 5
username: my_app
password:
production:
adapter: postgresql
encoding: unicode
database: my_app_production
pool: 5
username: my_app
password:
The adapter is different, and there are fields for username and password. The default username and password is postgresql, but if it doesn't work (it didn't work for me), then go to your pgAdmin, create a new login role to make another username/password (check the option to make it a super user) and use that.
4, At this point, you can create a new app by running
rails new my_app -d postgresql
Run your local server, and try connecting to localhost:3000 to see if the welcome page is showing.
5, If everything is working fine, then all you need to do is create a new PostgreSQL database, and migrate your existing models to it. Run
rake db:create:all
rake db:migrate
Done! Now check if your existing app is working fine locally, and try deploying your app to Heroku.

ActiveRecord::ConnectionNotEstablished with PostgreSQL 9.1.3 and RoR 3.2.5

I just installed PostgreSQL with homebrew:
$ brew install postgresql
I installed the pg gem with:
$ gem install pg -- --with-pg-config= '/usr/local/var/postgres/postgresql.conf'
I changed my app's database.yml to
development:
  adapter: postgresql
  encoding: unicode
  database: rails_dev
  pool: 5
  username: vise890
  password:
test:
  adapter: postgresql
  encoding: unicode
  database: rails_test
  pool: 5
  username: vise890
  password:
production:
  adapter: postgresql
  encoding: unicode
  database: ddb
port: 5432
  pool: 5
  username: postgres
  password: admin
However, whenever i load any page I get the error:
ActiveRecord::ConnectionNotEstablished
I can connect to the db with pgAdmin (u:vise890 P:{none}) and i see the databases.
I am doing example3 from the Ruby on Rails Tutorial
If you want to check the whole thing: Sample App github branch
Thanks in advance guys!
Ok, nevermind. I started from scratch and it worked. Here's the walkthrough in case you are interested

Error in Ruby while installing spree

Hello friends I am newbie in Rails.I installed rails in my ubuntu 10.10. As per my project requirement I installed
spree.Then I made application using command
rails new mystore
then I created the store application, switched to its folder to continue work directly in that application with command
$ cd mystore
then I made install spree_sample by the command
rake spree_sample:install
After that I made populating my database with this command then it showed error like this
rake aborted!
syntax error on line 20, col -1: `test:
adapter: mysql2
encoding: utf8
reconnect: false
database: mystore_test
pool: 5
username: root
password:root
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: mystore_production
pool: 5
username: root
password:root
I was using this site for reference.Just have a look on it.I want to make spree commerce in ruby on rails.So please help me.I am newbie to rails.
You have syntax error in your database.yml config file. That's not related to Spree or to Ruby.
Should be "password: root" instead of "password:root"

Resources