heroku db:pull cant connect to my DB in ubuntu - ruby-on-rails

So I recently updated ubuntu to 11.04 and then downgraded back to 11.04 because I hated unity. Anyway, after I reinstalled 11.40 I had to clone all my old heroku apps and tried to run heroku db:pull to pull the DB and have it imported into my mysql db but I keep getting this error:
Failed to connect to database:
Sequel::AdapterNotFound -> LoadError: no such file to load -- mysql2
my gem file has gem 'mysql2', '< 0.3' and I gem installed taps already via RVM. I never had this issue when I ran db:pull before so I dont know what the problem is.
Im running ruby 1.9.2 with rails 3.0

run :
gem install mysql2 than heroku db:pull again ...
if you get this error with the previous "gem install mysql2" :
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
probably libmysqlclient-dev package should be installed :
sudo apt-get install mysql-server mysql-server-5.1 libmysqlclient-dev mysql-client-5.1 mysql-common
than
gem install mysql2
... or eventually run
locate mysql_config
then replace the resulting path, with in the following command path :
sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

You may have mysql2 in your Gemfile but have you done a bundle install - i.e. do you have the mysql2 gem installed ?

run :
gem install taps then heroku db:pull again
It may be work?

Related

Rails - Gem Error while installing pg (1.1.3), and Bundler cannot continue

I am still fairly new to Rails. I am trying to push to Heroku and I am getting errors.
The first error is when I run a Bundle Install I get this error message:
"An error occurred while installing pg (1.1.3), and Bundler cannot continue.
Make sure that gem install pg -v '1.1.3' succeeds before bundling."
I have tried to run this command
gem install pg -v '1.1.3'
But it fails and gives me this error message:
"ERROR: Error installing pg:
ERROR: Failed to build gem native extension."
Does anyone have a solution to this?
I had the exact same problem, and solved it by running sudo apt install postgresql-contrib libpq-dev. Then bundle worked just fine.
if you're using OSX, you could try running
brew install postgresql
and then installing the gem
TL;DR; If you installed the Postgres using the PostgresAPP instead of BREW then the problem might be that you don't have the postgres bin folder in the $APTH
The solution is to find the Posgres app installation folder an in it the /bin folder.
In my case if I run which postgres doesn't work which means I don't have it in my $PATH, so what I did is I navigated to: cd /Applications/Posgres.app then to Contents and then to Versions until I found the latest folder:
/Applications/Postgres.app/Contents/Versions/latest/bin
Now, with this I can install the PG GEM by providing the path to the bin folder of my Postgres app installation
Finally, in the terminal in the root of my Rails project I ran where I provide the postgres config file path to the GEM installer:
gem install pg -v '1.2.3' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
I encountered the same problem. I am using Ubuntu. I installed Postgres using this Ubuntu guide. After installing Postgres, I ran this code sudo apt install postgresql-contrib libpq-dev then bundle install.
The accepted answer is not correct. If you installed postgresql-contrib and libpq-dev as mentioned in Cesar Faria answer, and you still getting the same error, most probable you missed the list of packages which are considered essential for building Debian packages. All that packages included in build-essential package. So, all you need to do to get rid of the error is the command below.
sudo apt install libpq-dev build-essential
try instaling with pg-config like this:
gem install pg -v 1.1.3 -- --with-pg-config=/usr/pgsql-9.X/bin/pg_config.
In pg-config path mention the posgtres version installed in you're system.
Postgresql needs to be in local in order to install gem pg. Try this
brew install postgresql
and the re-install bundle
bundle install
or
If you are using yum. Try this
sudo yum install postgresql-devel
The following is only for your local environment:
Note: Update the command below to match your version postgresql/13.2/...
> brew install postgres
> sudo gem install pg -v '1.1.4' --source 'https://rubygems.org/' -- --with-pg-config=/usr/local/Cellar/postgresql/13.2/bin/pg_config
Also, make sure to start your server > pg_ctl -D /usr/local/var/postgres start

MySQL gem install error on Windows 7

I am using Windows 7 and creating connection to MySQL2. I need to install gem. I am following these steps. Could someone please review them:
Add the following to the Gemfile: gem 'mysql2', '~> 0.3.15'
Run the following in cmd: gem install mysql2 -v '0.3.15'
Go to the application using cmd and run this code: bundle install
When I perform step (3), I get the following error:
An error occurred while installing mysql2 (0.3.15), and bundler cannot
continue make sure that `gem install mysql2 -v "0.3.15" ' succeeds
before bundling..
My application resides on the D drive and I am using Windows 7.
I have found a solution that works on Ubuntu.
My mistake was that had not installed the my-sql library before trying to connect.
Please follow these steps to do this. Run the following commands:
sudo apt-get install mysql-client libmysqlclient-dev
sudo gem install mysql2
Add the following to the gemfile
gem 'mysql2', '~> 0.3.15'
And then run:
bundle install

Error in running rails server

I got this error
Could not find mysql2-0.3.13 in any of the sources
Run `bundle install` to install missing gems.
I tried to gem install mysql2 but without luck, it didn't fix it. I'm using wampp server and copied the libmysql.ddl to the bin folder of ruby. I also tried adding the path to the gem install just like this.
gem install mysql2 --platform=ruby -- ‘-with-mysql-lib=”C:\wamp\bin\mysql\mysql5.5.24\lib” -with-mysql-include=”C:\wamp\bin\mysql\mysql5.5.24\include”‘
Any ideas on how to fix this? THanks!
First, make sure you have mysql installed on your machine.
If you have an Ubuntu distribution, try:
sudo apt-get install libmysql-ruby libmysqlclient-dev
then try to install the gem again.
I installed mysql2 from sources like this
# i experienced some troubles with mysql2 0.3.13 installing
gem fetch mysql2 -v 0.3.12
gem install mysql2-0.3.12.gem -- ' --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\include\mysql" --with-mysql-lib="c:\Program Files (x86)\MariaDB 5.5\lib" '
But after each Gemfile updating and bundle install, bundler is installing precompiled version of mysql2 gem and it's very annoying. After manual removing precompiled gem rails app started successfully
P.S. You also need installed Ruby DevKit.

Switching to postgresql for heroku deployment of rails application

I have a rails application currently using sqlite3. Following this guide:
https://devcenter.heroku.com/articles/rails3 I'm trying to switch to postgresql. I changed my gemfile but when I run bundle install I get this error:
Errno::EACCES: Permission denied - /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.0/.gemtest
An error occured while installing pg (0.14.0), and Bundler cannot continue.
Make sure that gem install pg -v '0.14.0' succeeds before bundling.
so I try gem install pg -v '0.14.0' and get this error:
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.0/.gemtest
I found a few people with similar problems but I couldn't get it working. This is my first time trying to deploy a rails application so I don't have much intuition about what I'm doing.
Are you sure postgres itself is installed / correct?
the pg gem is the rails adapter, but you also need postgres itself on the machine.
e.g.
brew install postgresql
initdb /usr/local/var/postgres
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
rails new myapp -D postgresql
...
bundle install (install pg gem)

Bundler won't install mysql2

First of all I've gone through dozens of posting here on SO and google and haven't been able to find an answer.
I'm trying to install mysql2 with bundler and it won't do it.
Running on Ubuntu Server 11.04 Natty
Here's some background info:
ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
gem -v
1.8.24
rails -v
Rails 3.2.5
$ mysql --version
mysql Ver 14.14 Distrib 5.1.62, for debian-linux-gnu (x86_64) using readline 6.2
I have gem "mysql2", "~> 0.3.11" in my Gemfile
When I do bundle install it goes through the process and it finishes successfully (No Errors) but it doesn't install mysql2. When I do bundle show, mysql2 is not listed.
I've tried a gazillion of things recommended here and on forums and still can't get mysql2 to install with bundler.
Any ideas?
Thanks.
For mysql2 you need to install the dev files on your server.
try first:
sudo apt-get install libmysqlclient-dev
Then check first your GemFile in your RoR App Dir - I have this line in my GemFile:
gem 'mysql2', '0.3.11'
run bundle:
bundle install
or try the command from Emily first then run bundle install:
gem install mysql2 -v=0.3.11
bundle install
I hope it helps
So after many tries, reading, and pulling my hair out I found out what was the problem, so I'm posting it for those that might run into the same situation.
The reason why bundler wouldn't install mysql2 is because the gem was inside this platforms structure, see below:
platforms :mri_19, :mingw_19 do
group :mysql do
gem "mysql2", "0.3.11"
end
end
So all I did was to move just gem "mysql2", "0.3.11" by itself to the top of the Gemfile and run bundle install and that did it! Now mysql2 is listed under bundle show and my rails application is running now.
Thanks every one that tried to help!

Resources