Can't Connect to MySql From Rails Application in Windows - mysql

I am trying to create a Rails application in windows with MySQL as the Database. I have created a rails app and it runs just as fine. But when I try to connect to the mySQL database I am getting weird errors, which I was unable to solve after hours of Googling and hunting around. Maybe I am performing a silly mistake, new to Rails and Ruby.
Here is how I proceeded in creating the app with MYSQL
In command prompt
rails new sample_app -d mysql
[success]
Opened a new command prompt window and
C:\sites\cd sample_app> rails -s
Now I get this error
Could not find gem mysq12 (>=0) in any of the gem sources listed in your Gemfile
Run bundle install to install missing gems
Note: I didn't get the error when I created my first rails app without using Mysql.
Next, I ran this command
gem install mysql2
And got this
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby1.8.7/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
checking for rb_hash_dup()... no
checking for rb_intern3()... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Next I ran this one -
bundle install
Closed all command prompt windows, opened a new one, moved to my app directory and typed
rails -s
Error:
could not find gem mysq12 (>=0) in any of the gem sources listed in your Gemfile
Run bundle install to install missing gems
Here are some information which I think will be useful
- Rails 3.0.9
- Ruby 1.8.7
- rake (10.1.0, 0.8.7)
- mysql (2.9.1 x86-mingw32)
- MySql 5.6 installed and running (I have created a DB and tables)
- OS: Windows 7 64bit
Here is how my database.yaml file looks like:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: sample_app_development
pool: 5
username: root
password: buiskol
host: localhost
Here is how the gemfile of the app looks like
source 'http://rubygems.org'
gem 'rails', '3.0.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2', '~> 2.9.1'
I think the problem is that my mysql2 gem is not properly installed. I am not sure where I am doing the mistake. Any help will be much appreciated.

Why are you using gem 'mysql2', '~> 2.9.1' instead of gem "mysql2", "~> 0.3.13"? According to this, there isn't any 2.9.1 version, maybe you meant 0.2.9 ? Otherwise, you're installing the wrong version of that gem, or the wrong gem with the right version.
You should use:
gem "mysql", "~> 2.9.1"
or
gem "mysql2", "~> 0.3.13"
in your gem file. Since there's no version 2.9.1 for mysql2, correct the typo and try again

Related

How can I solve this Mysql2 gem error in CentOS 8?

I need to setup ruby on rails with MySQL
I already have installed MYSQL
when I do Bundle install it shows following error.
Fetching mysql2 0.3.21
Installing mysql2 0.3.21 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
I am using Cent-os 8
anyone can help
Thanks
Run first this command gem 'mysql2', '~> 0.3.21' in terminal and when finish then try bundle again

Rails: bundle doesn't show installed mysql2 gem

I know may be this is a popular problem but i try many solutions and not get to finish
I try to install mysql in rails with
gem install mysql2
And I get the result
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.18
1 gem installed
But when i try to execute the command
bundle show mysql2
I get
Could not find gem 'mysql2'.
All these command execute in my application root directory
What is the problem ?
bundle show lists the names and versions of all gems that are required by your Gemfile, so at first you should add mysql2 gem to it:
gem 'mysql2'

Where is the Gemfile in Windows 7 located?

i need some help at ruby on rails specially with ruby gems.
If i use the "rails generate scaffold something", I get always the failure:
"Specified 'mysql2' for database adapter, but the gem is not loaded. Add 'gem' mysql2 to your Gemfile(Gem::LoadError)"
If i use the command "gem -list" mysql2(0.3.15) will show up in this list.
After some search i read(Install mysql adapter gem install)
that i should edit the Gemfile and add gem 'mysql2', "~>0.3.15" instead of gem 'mysql2' in Gemfile.
So my problem is now where is this Gemfile located. I use ruby on Windows 7, and i installed Ruby with the "railsinstaller-2.2.2"
Regards, dot

Getting mysql gem working with ruby-1.9.3 on rvm

I am trying to setup mysql gem on ruby-1.9.3 installed with rvm. I want to set up the 'redmine'. To install mysql gem I used -->
sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/bin/mysql_config
When I issue --> RAILS_ENV=production rake db:migrate, I get
/Users/myth/.rvm/gems/ruby-1.9.3-p0#global/gems/bundler-1.1.2/lib/bundler/runtime.rb:211: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
cannot load such file -- mysql
However I have successfully deployed redmine1.3 on default ruby1.8.7 installation of OSX with installing mysql gem the very same way.
I want to work on the latest trunk with ruby-1.9.3
How can I resolve the issue? I have been searching the mailing list and found similar posts, however could not solve the problem.
I also struggled with this question. I could not get redmine working with mysql and ruby 1.9.3.
The answer is very easy and simple. For ruby 1.9.3 together with redmine you have to use the gem mysql2 !
In http://www.redmine.org/projects/redmine/wiki/RedmineUpgrade#Option-1-Downloaded-release-targz-or-zip-file it is also written to change the database adapter from mysql to mysql2.
So install gem install mysql2 and also keep sure to have a
database.yml with msql2 adapter:
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: redmine
encoding: utf8

How to resolve Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.)

I am running a rails3 app on Dreamhost: not the best call but I need it operational before I can pitch migrating to Heroku.
I am using rails 3.2.1, and ruby 1.8.7 with
gem 'mysql2', '~> 0.2.7'
in my Gemfile...
I get the following error when I deploy and reload:
Please install the mysql adapter: gem install activerecord-mysql-adapter (mysql is not part of the bundle. Add it to Gemfile.)
I have tried gem 'mysql2', gem 'mysql2', '< 0.3' and get the exact same issue.
Any other ideas?
First try adding config.assets.initialize_on_precompile = false to your application.rb.
Then make sure your DATABASE_URL var starts with mysql2:// instead of mysql://
In general when rails is trying to be helpful it will try to generate the name of an adapter gem based on whatever you have in your database.yml. If that gem doesn't exist it's a good indication that something with the adapter line is wrong
for mysql2 the adapter type needs to be mysql2 as well
database.yml
adapter: mysql2
I had the same problem and after checking if you have in database.yml that you have adapter:mysql2 you should check if you have the gem of mysql loaded.
in your Gemfile you should have the line : gem "mysql2" and not other database like sqlite3 which was my case.
Hope this helps.
I get into the same situation of trying to set up mysql with Ruby on Rails for my
Windows Vista platform installed with MySQL 5.5 and Rails Installer for Ruby 1.93.
After getting the adapter and connector for mysql2, I still get this error message : "rubygems_integration.rb:143:in block in replace_gem': Please install the mysql2
adapter:gem install activerecord-mysql2-adapter` (mysql2 is not part of the b
undle. Add it to Gemfile.) (LoadError)"
I checked the my gem directory "Ruby1.9.3\lib\ruby\gems\1.9.1\gems" and see
both activerecord-mysql2-adapter-0.0.3 and mysql2-0.3.11-x86-mingw32 are there and
the database.yaml file is correctly updated.
The missing piece is here:http://www.mohanarun.com/how-to-install-mysql-adapter-ruby-gem-in-windows/
After restarting the MySQL server and update the gem file as stated in the above URL. It works.
I hope this will work for you.