Topic: Error Mysql2

Hello everybody,


I just installed RoR on my server and i have a problem with mysql2.

It's weird, installation is OK, my project works, but i can't connect mysql ...

When i do "rake db:create", it's OK, it works perfectly.
But when i connect on my app, it's impossible to see something :

Mysql2::Error
Access denied for user 'root'@'localhost' (using password: NO)

# 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
  host: localhost
  encoding: utf8
  reconnect: false
  database: basetest_dev
  pool: 5
  username: ****
  password: ****
  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
  host: localhost
  encoding: utf8
  reconnect: false
  database: basetest_test
  pool: 5
  username: ****
  password: ****
  socket: /var/run/mysqld/mysqld.sock
 
production:
  adapter: mysql2
  host: localhost
  encoding: utf8
  reconnect: false
  database: basetest_prod
  pool: 5
  username: ****
  password: ****
  socket: /var/run/mysqld/mysqld.sock

I don't understand ... rake db:create works !
Someone has a solution ?

Last edited by mpbmika (2012-03-13 22:58:56)

Re: Error Mysql2

Are you able to connect to MySQL using those credentials? Like in the terminal or using something like navicat?

Re: Error Mysql2

Yes i can ...
That's why i dont understand what is the problem hmm

Re: Error Mysql2

The error message says that you don't use any password

Access denied for user 'root'@'localhost' (using password: NO)

But you do uise it in your database.yml config:

development:
  adapter: mysql2
  host: localhost
  encoding: utf8
  reconnect: false
  database: basetest_dev
  pool: 5
  username: ****
  password: ****
  socket: /var/run/mysqld/mysqld.sock

So check that before.

Re: Error Mysql2

yes, you have to edit your database.yml file in your config file with your username and password

Re: Error Mysql2

Hello

Thank you for your reply, but my database.yml is correctly defined ...
I just hide the username and password because i don't want to show you the username and the password ...

Suppose that :
my username is : test
my password is : test

I can login with PHPMyAdmin correctly and with the command mysql on "putty"

But i can't connect with rails  !