I have not gone too far with the development of the application.
i just did rails new app -d mysql and i did rails s loaded my browser.
Rails homepage loaded and I went inside my app folder, http://localhost:3000/demo/index and surprised to see this error ActiveRecord::ConnectionNotEstablished.
Please suggest some good way to get out of this and continue with my further development.
OS is Windows 7, I already installed mysql adapter and tried many solutions over the stackoverflow similar questions. None are solving my issue. I request serious help.
My database.yml looks like this with regards to development:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: app_development
pool: 5
username: root
password: pass
host: localhost
After creating application, create database using below command
rake db:create
and then start server using rails s
I switched to Ubuntu after trying number of methods to solve the issue on windows. Solved.
Related
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.
I am very new in rails and using windows 7. In my windows machine i ve installed ruby 1.93, rails 3.2, Mysql 5.1 properly (also Install the MYSQL driver using this command "gem install mysql2"). I also put "libmySQL.dll" file into ruby/bin directory. I can create rails project and can run webrick server successfully..database server also get connected(using sqlite). But when i use mysql using "rails new app_name -d mysql" this command....mysql server is not get connected with rails project.
In my database.yml I have:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: untitled5_development
pool: 5
username: root
password:
host: localhost
Sorry for my bad english.
Thanks everyone
Hi you have to set the password for the root user. Also note that older versions of ruby on rails would expect you to comment the database name. If you have not yet created the db.
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.
I'm running ruby 1.9.2 with rails (3.0.7) on windows 7. Had a hard time setting up mysql gems but eventually found out that will have to go with mysql adapter instead of mysql2 on windows7. database.yml looks like this:
development:
adapter: mysql
encoding: utf8
database: bfl
pool: 5
username: root
password:
socket: /tmp/mysql.sock
"rails dbconsole development" command works fine (although it re-prompts me for password). However, I'm hitting the following through application code:
ActiveRecord::StatementInvalid (Mysql::Error: query: not connected: SELECT bfl_user.* FROM bfl_user)
I found a couple of similar errors for other platforms but not for windows7 and the source of those issues were different.
I switched from ruby1.9.2 to ruby1.8.7. Followed this tutorial to get mysql2 working:
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
With 1.9.2, noticed a weird hanging problem with mysql connection.
I'm currently using webrick and lightsql for my Rails 3 development app, but I've finished the app now and need to move it on to MySQL and Apache, because that's what DreamHost uses, and it's probably a more suitable production environment. The only problem is I've never done this in rails before, as this is my first rails app.
Can anyone please point me in the direction of some tutorials for both of these, or advise me how I'm supposed to do it? I'd be eternally grateful! I'll be doing this in development mode first, and testing everything, and if it all works in both of those then I'll begin deployment. I've never done a deployment before either, so that's another thing I have to figure out ><
Thanks!
For change database to MySQL it´s easy.
You need add MySQL gem and remove SQLite gem:
gem mysql2
And change your database.yml (your_app/config/database.yml) to like this:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: yourdb_development
pool: 5
username: root
password: 123456
socket: /tmp/mysql.sock
test:
adapter: mysql
encoding: utf8
reconnect: false
database: yourdb_test
pool: 5
username: root
password: 123456
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
reconnect: false
database: yourdb_production
pool: 5
username: root
password: 123456
socket: /tmp/mysql.sock
If you don´t have experiencie with apache, you can deploy easy in webbynode.com, this guys have a rapid deploy.
Regards.
I've done deployments to Dreamhost using Apache/Passenger and there was just literally nothing to it; you specify the path to your project's root directory and then you are done. I did not make any .htaccess files or otherwise try and configure Apache manually. I freeze all my gems and rails in vendor which simplifies it quite a bit.
petersonferreira probably has answered the database question adequately. I have not personally done that (I always develop in MySQL) so I do not know if you may find any platform differences that you need to manage in your code.
There are a ton of tutorials out there for deploying Rails apps on Dreamhost.
Google is your friend.