I am standing up a new Ubuntu server running MySQL. I have Capistrano set up on my development server and am trying to deploy:cold after running deploy:setup. After the deploy script tries to run
executing "cd /home/adm1n/www/knowit/releases/20121112152400 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
I keep getting this message:
Rake Aborted!
Access denied for user 'specialusername'@'localhost' (using password: YES)
Tasks: TOP => environment
I have ‘specialusername’ created in my database on the mysql server for both localhost and %.
I removed the empty user ‘ ‘ @ localhost row in the user database.
I have added the IP address of the server to my my.cnf file and commented out the 127.0.0.1 line.
Here is my deploy.rb file for production:
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: mydatabasename
username: specialusername
password: crazypassword
socket: /tmp/mysql.sock
pool: 5
timeout: 5000
I think that I may not be understanding how this works. On my Site5 server I have never had to specify which host I was accessing mysql from. But in all my reading it seems that I must specify a specific user@hostname. This makes it a little difficult if I am deploying from many different locations around the country as I travel. OR do I merely need to use the hostname of my laptop regardless of my current IP address? Thanks for any insight and solutions you can provide. I have not found any articles that have provided me precisely what I need to fix this issue.
There are two ways to connect to a MySQL server.
First, using a UNIX socket, such as
/tmp/mysql.sock, in which case there is no “host”, so authentication usesusername@localhost. This will work only with connection from the same machine.Second, using a TCP/IP connection. In this case, the server listen to a specific port on the box running the database, and the way to connect to it is to provide a host + port number. The port number can be optional (the default will be used), and host can be given by hostname or by ip address. This allows to connect locally or remotely.
Note: I have no way to actually verify this (no access to your server), so below is just a possible explanation …
In
mysql -u knowitdbadmin -p -h192.168.0.50, a host (-h) is given, so TCP/IP is used, causing authentication to useusername@hostnameorusername@%rules, but this will not useusername@localhost.In
mysql -u knowitdbadmin -p, no host (-h) is given, so the default UNIX socket is used, causing authentication to useusername@localhost(and therefore fails).If you want to disable access using a UNIX socket (/tmp/mysql.sock) and username@localhost, and always use a TCP/IP connection, do it all the way:
* remove grants to username@localhost (done)
* always specify a host/IP (+ port) in configuration files from your application.
I think the problem is with:
try using a hostname + port number instead.
As a side note, if you somehow have SQL access to the database itself, starting with 5.5, a new table
performance_schema.host_cachewill show you all the reasons a connection is failing, which saves a lot of time when troubleshooting things like this.