I’ve monkey patched ActiveRecord in a Rails app that I work on, and I’m trying to prepare to contribute a pull request. I’m currently getting stuck, trying to get the MySql tests run.
I’m using the provided test/config.yml file and have created a ‘rails’ user with no password. When I then try to run rake mysql:build_databases, I get…
ERROR 1044 (42000) at line 1: Access denied for user ''@'localhost' to database 'activerecord_unittest'
ERROR 1044 (42000) at line 1: Access denied for user ''@'localhost' to database 'activerecord_unittest2'
Any idea how to resolve this?
== EDIT
I added a puts to the Rakefile to see what it was trying to execute, and got…
mysql --user=rails -e "create DATABASE activerecord_unittest DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci "
… which looks fine. Executing that manually, I get the same error. Apparently, the –user option is being ignored. I ran mysql --help, and it looks like --user is the correct option to be passing.
I’ve managed to get it working now.
The error message is very misleading. Actually, the correct username was being sent, but the user did not exist because I did not create it properly, resulting in the error.
Specifying a username of ‘rails’ results in a connection as
'rails'@'localhost', so the username that must be created is'rails'@'localhost', not'rails'. I think I knew this a long time ago, but now I’ve been working with PostgreSQL for a long time, so had forgotten.