Gem::LoadError Specified 'mysql2' for database adapter - mysql

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

Related

Ruby On Rails data migration from sqlite3 to mysql regarding to many to many relations

I have a sqlite3 database in my rails app which has a development.sqlite3 file. I want to convert the database to mysql.Here are the steps I take but still I have problems :
1.First I add and install gem 'seed_dump' to add the data into my seed.rb (By running rake db:seed:dump) because I really need to migrate my data .
2.Change the database.yml configuration to mysql setting.
development:
adapter: mysql2
encoding: utf8
database: MyDB
username: root
password: ****
production:
adapter: mysql2
encoding: utf8
database: MyDB
username: root
password: ****
3.Run rails db:create then rails db:schema:load.
4.Then loading the data from seed by running rake db:seed:dump
The problem is my many to many relations data (which has a table in db schema ) can't be imported in mysql from my seed.rb.
The thing I wanna know is that is there any other safe way to migrate my data from sqlite3 to mysql instead of writing them into seed.rb and then read them ?
As I was looking for another way to resolve the issue I've found what is declared here. I followed the steps facing to another error of mysql : Data is too long for column summary . To skip this error I turned off mysql strict mode like this in database.yml:
config/database.yml
development:
adapter: mysql2
encoding: utf8
database: myDB
username: root
password: ****
host: localhost
strict: false
production:
adapter: mysql2
encoding: utf8
database: myDB
username: root
password: ****
host: localhost
strict: false
This solution is more clear than using gem 'seed_dump' which has problems with has and belongs to many relations!

localhost:3000 database adapter

If my localhost:3000 page is showing "Database adapter postgresql", does this mean postgresql is running and not mysql?
Background: I originally installed postgresql and later installed mysql.
My database.yml file currently contains the following so I'm not sure where I'm going wrong here.
development:
adapter: mysql2
host: localhost
database: projects
username: root
password:
pool: 5
timeout: 5000
1: add gem 'mysql2' in your gemfile
2: run bundle install
3: mysql -u root # for do login and create db
4: mysql> create Database projects;
Hope this help you !!!

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.

Rails: error: database configuration does not specify adapter

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".

Connecting Ruby and MySQL

I am in windows 7 and I installed ruby 1.9.2p180 and MySQL 5.5.15 and mysql gem.
now how can I connect ruby to mysql ?
You can create a new rails app with mysql instead of the default sqlite by using:
rails new APPNAME -d mysql
Or the long form:
rails new APPNAME --database=mysql
You can then take a look at the generated file config/database.yml to see the settings used for mysql. You will need to set up your username, password and database in here. Don't forget that with mysql, you will need to create the database manually for each environment.
Sample config/database.yml:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: test_database
pool: 20
username: root
password: root
host: localhost
socket: /var/run/mysqld/mysqld.sock
Just install mysql2 gem and when you want to create a new project run
rails new APPNAME --database=mysql