I am trying get my first simple project in rails to run. I have installed wamp. And trying to make use of that same mysql db server installed with wamp. But I decided to make use of webrick, and not apache. Hoping that the configuration would be easier.
I edited the database.yml file and the gemfile under my projects directory:
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
# 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: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
production:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
And here's gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.5'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
I used the command gem install mysql because mysql2 doesn't work for me.
What I did was to launch wampserver and stopped the apache service. It would take forever to load:
http://localhost:3000/rails/info/properties
Then webrick would crash. But if I do not launch wamp, I get this:
Did you configure mysql to run on a port other than 3306? If you're using a different port than that, you'll need to edit as follows:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
port: 3306 #replace with the correct port
If that doesn't work, also try changing localhost to 127.0.0.1 in order to force it to use TCP. Sometimes it tries to use sockets and cannot find the socket file.
Related
I installed Ruby on Rails, MySQL Server 5.6, and the mysql2 gem on my Windows 7 computer. MySQL Server 5.6 runs on port 3000. My database.yml file is:
# MySQL2
# gem install mysql2
# Ensure the mysql2 gem is defined in your Gemfile
# gem 'mysql2'
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo1_development
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
# 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: mysql2
encoding: utf8
reconnect: false
database: demo1_test
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo1
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
I ran "bundle install" with the following Gemfile:
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use mysql2 as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
gem 'devise'
gem 'protected_attributes'
gem 'terminator'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
I could run the "bundle install", "rake db:create" and "rake db:migrate" commands without any problems. I started the MySQL server and typed "rails s" in the command line. The result was the following:
WARN TCPServer Error: Permission denied - bind (2)
Exiting
I made sure to open port 3000 in Windows Firewall, and allow rails to communicate through the firewall.
Typing "rails s -p 80" works, and the web application works on localhost:80, but the fields won't work because MySQL Server will not run on port 80.
Am I missing something? How can I get the Rails server and web app to work?
It looks like you're trying to run both the database AND the rails web server on port 3000.
EDIT: To clarify, you should probably run the rails server at port 3000 (the default), and run mysql on a different port.
Whatever port you run mysql on, put that port in your database.yml settings under "port:".
I think you should be using port 3306? This is what my connection string looks like and it works fine.
staging:
adapter: mysql2
encoding: utf8
host: 10.0.0.16
database: my_database
port: 3306
username: my_username
password: my_password
Note that the port of your webserver and your database are two different things. I run my webserver normally on port 3000 and mysql on 3306. I think 3306 is the default port used for mysql.
I just created a new Rails 4 app with MySql as follows:
rails new mysqltest -d mysql
And modified the database.yml with the right credentials.
I generated a sample contoller and updated the routes for root route.
When I start using WEBrick in production,
rails s -e production
The site works. I see the index page.
When I start using Passenger without 3000 port, I see the following error:
database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
Passsenger is running in Production environment.
My database.yml
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.sock
# 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: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.sock
The case I used in database.yml file and the apache config file were different.
Both should be same. eg. production.
In apache config, I gave as Production. After changing it to production it worked.
Source - https://groups.google.com/forum/#!topic/phusion-passenger/Kr-R0gSw6i8
Did you create your local production database?
rake db:create:all
RAILS_ENV=production bundle exec rake db:migrate
Is your database.yml file setup properly to use a production database?
Do you have a mysql gem in your gem file.
Common problems.
I am trying to make a rails 3.1 app using mysql, its my first time using it
I am getting an error when I try to rake db:create
The Error
Can't connect to local MySQL server through socket '/tmp/mysql.socket' (2) Couldnt create database for {database.yml info in here}
(if you set the charset manually, make sure you have a matching collation)
I was looking at this link http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard/ which was posted in this question here rake db:create - collation issues
but I dont think that applies, doesnt mysql get installed when i do install gem mysql 'gem-version'?
can someone please help me solve this error? I am also running osx 10.7
Thank you very much in advance!
This is what my gem file looks like
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem "mysql2"
gem "activerecord-mysql2-adapter"
gem 'pry'
gem 'pry-debugger'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :development, :test do
gem 'rspec-rails', '~> 2.0'
gem 'database_cleaner'
gem 'shoulda-matchers'
end
gem 'jquery-rails'
my database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: Training_development
pool: 5
username: root
password:
host: localhost
# 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: mysql2
encoding: utf8
reconnect: false
database: Training_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: Training_production
pool: 5
username: root
password:
host: localhost
I'm using windows xp 32 pro, bit, sp3. the latest version of railsinstaller, and mysql2 gem
i have been trying to solve this error all this week. When i run rake db:create I see this error
this is what i see when i trace the error
i have solved this error by downloading the zipped version of mysql Connector/C 6.0.2 for 32 bit and copying libmysql.dll from mysql-connector-c-noinstall-6.0.2-win32-vs2005\lib
to C:\RailsInstaller\Ruby1.9.2\bin
now when I run rake db:create i see
and this is what i see when i trace the error
i hope these info will help you, to help me solve the problem :)
#phoet
my gemfile
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'cucumber'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'capybara'
gem 'rspec', '2.8'
gem 'rspec-rails', '2.8'
gem 'launchy'
gem 'spork'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
my db config
development:
adapter: mysql
database: selvista
username: root
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: mysql
database: selvista_test
username: root
pool: 5
timeout: 5000
production:
adapter: mysql
database: selvista_prod
username: root
pool: 5
timeout: 5000
should my adapter be mysql2?
You can try to put mysql2 on your adapter lines in you database.yml.
development:
adapter: mysql2
database: selvista
username: root
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: mysql2
database: selvista_test
username: root
pool: 5
timeout: 5000
production:
adapter: mysql2
database: selvista_prod
username: root
pool: 5
timeout: 5000
I am diligently trying to get mysql up and running for my first rails app ever.
I keep getting the following error when running rake db:setup RAILS_ENV="production":
rake aborted!
dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dyl Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2 /mysql2.bundle
/Users/chris/rails_projects/sienab/Rakefile:4
(See full trace by running task with --trace)
I am running snow leopard, mysql 5.5, gem mysql2, rails 3.
Any help is great. many thanks.
database.yml below
# SQLite version 3.x
# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
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: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: sienab_production
pool: 5
username: username
password: password
host: localhost
Looks like you need to install the mysql2 libs:
sudo apt-get install libmysqlclient-dev libmysqlclient16
Also, I suggest you use gem 'mysql2','0.2.7' in your Gemfile if you're using Rails 3.0.x.
Don't forget to run bundle install after making this change.