im struggling to connect to my mysql service running on my local windows 7 machine- I am getting the following error when trying to rake migrations or access through the web browser-
Mysql2::Error (Can't connect to MySQL server on 'localhost' (10061)):
i have left the mysql user/pass as default - this is my yaml conf file
# 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
port: 3306
encoding: utf8
reconnect: false
database: events_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: events_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: events_production
pool: 5
username: root
password:
host: localhost
the thing is i can login using root through mysql on the command line and also running phpmyadmin through xampp- so i have narrowed it down to a firewall issue? or permissions issues? everything is running localhost on my machine
update
i turned windows firewall off and it made no difference
Make sure you've granted localhost privileges. Info here.
i restarted the machine and restarted the servers- seemed to work
I'am a bit confused? Localost => Port (10061) ?
Maybe try to add port: 3306 everywhere.
Do you started the Server in dev env?
Related
I am working on setting up a basic RoR app. All my databases are MySQL and local, my database,yml file is included. I am trying to access a basic view but am still getting the ActiveRecord::ConnectionNotEstablished error. What am I doing wrong?
# database.yml
development:
adapter: mysql2
encoding: utf8
database: *****_dev
username: ****
password: *****
host: 127.0.0.1
port: 3306
# 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: *****_test
username: ****
password: *****
host: 127.0.0.1
port: 3306
production:
adapter: mysql2
encoding: utf8
database: *****_prod
username: ****
password: *****
host: 127.0.0.1
port: 3306
MySQL2 in the gem file:
gem 'mysql2', '~>0.3.10'
So when go to type in: http://localhost:3000/controller/view I get: ActiveRecord::ConnectionNotEstablished
What else can I include that would be helpful?
Thanks in advance.
Have a look at your /etc/mysql/my.cnf and check for the binding address of the mysql deamon. It probably doesnt bind to any ip. Then it will use unix sockets which are by the way faster then ip connections,...
Option name for the bind address is bind-address if theres no match it wont bind to any address. Also have a look for socket which specifies the path to the unix socket. You can use the socket like this in your database.yml
development:
adapter: mysql2
encoding: utf8
database: *****_dev
username: ****
password: *****
socket: /path/to/the/socket/mysql.sock
That should do it for you,...
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".
I have created a new server to host a rails 3.2 app with a mysql server hosted on the same server.
I keep getting 'xxxxx-xxxxx.linode.com' is not allowed to connect to this MySQL server (Mysql2::Error)
I have checked over all the config and it seems correct. I can access the mysql server using the mysql command, sequal pro and also was able to do a rake db:migrate like this:
bundle exec rake db:migrate RAILS_EV=production
I am using passenger and this is my database.yml
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: nst_production
pool: 5
host: localhost
username: root
password: password
timeout: 5000
Any ideas ?
You better try to connect via socket.
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: nst_production
pool: 5
socket: /tmp/mysql.sock
username: root
password: password
timeout: 5000
I'm creating my first ROR application.
Details:
creating new app ->
rails new simple_cms -d mysql
creating a controller and a corresponding view -->
rails generate controller demo index
Then when after i started the rails server, the http://localhost:3000 page works perfectly fine. but when i try to go to the page that I just created, http://localhost:3000/demo/index, it spurts out a MYSQL error:
Access denied for user 'root'#'localhost' (using password: NO)
At first, I think it's just a database connection problem, so I've gone through the MYSQL interface and create a new database called: simple_cms_development
and I have also made a corresponding user: simple_cms
with granted privileges.
and lastly, I have configured the database.yml file to fit the details:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: simple_cms
password: developer
host: localhost
But still, it spits out the same mysql problem:
Access denied for user 'root'#'localhost' (using password: NO)
Please. to anyone who knows how to use mysql as a database for rails app..A help would be really appreciated. Thank you so much!
UPDATE: This is all what's inside on the database.yml file
# 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: simple_cms_development
pool: 5
username: root
password: developer
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: simple_cms_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_production
pool: 5
username: root
password:
host: localhost
I found that you need to add the following line to config/database.yml:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
host: your_host # <----- normally localhost
database: the_db_I_made
pool: 5
username: the_user_I_made
password: the_password
socket: /var/lib/mysql/mysql.sock
Only reason that can cause your issue is that you are loading your server with different environment. I think that in your case you are loading your server under production mode.
When I type rails server in my CMD the server works and I can go to localhost:3000.
But after i get this messege in the CMD and the same message in the browser on localhost:3000 in the errors section.
Started GET "/rails/info/properties" for 127.0.0.1 at 2010-12-02 21:14:55 +0200
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: NO)):
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_request_and_response.erb (30.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/diagnostics.erb within rescues/layout (97.0ms)
What is the issue?
here this is the database.yml file:
# 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: mysql2
encoding: utf8
reconnect: false
database: simple_cms_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: simple_cms_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_production
pool: 5
username: root
password:passwordex
host: localhost
I know you already found the solution to your problem, but I'm going to post this as an answer anyways, for those who might stumble across this same issue.
Having the same exact Access denied for user 'user'#'localhost' (using password: NO) problem, it turns out my database.yml file was malformatted. The reason? YAML doesn't allow certain characters: I happened to be using a '!' in my password, and for whatever reason, the YAML parser reading this database.yml file ignored my password line like it wasn't there, hence the (using password: NO), even though I explicitly declared it.
Solution? Changed my password not to include any YAML special characters. I suppose there might be a way to escape it, though. Annoying nonetheless.
You're using root for your mysql user, but not supplying the root password in config/database.yml.
Incidentally, while its usually ok in development, using the root mysql user in production or for staging is a Very Bad Idea™.
here's a typical mysql config section:
production:
adapter: mysql
database: app_production
username: root
password: password
pool: 5
timeout: 5000
encoding: utf8