I’m writing a script to perform some database maintenance, and MySQL is not accepting the username I’m trying to pass it.
I have a MySQL user and database named ‘abc_wpsites’, as well as a user and database named ‘abc_wpsitesdev’. Here, I’m trying to access abc_wpsitesdev, but MySQL continually attempts to access with the account ‘abc_wpsites’ instead.
abc.com [~]# mysql -uabc_wpsitesdev --password='(redacted)' -h localhost abc_wpsitesdev
ERROR 1045 (28000): Access denied for user 'abc_wpsites'@'localhost' (using password: YES)
abc.com [~]# mysql --user='abc_wpsitesdev' --password='(redacted)' -h localhost abc_wpsitesdev
ERROR 1045 (28000): Access denied for user 'abc_wpsites'@'localhost' (using password: YES)
abc.com [~]# mysql --user='abc_wpsitesfff' --password='(redacted)' -h localhost abc_wpsitesdev
ERROR 1045 (28000): Access denied for user 'abc_wpsites'@'localhost' (using password: YES)
Notice how each attempt at experimenting with the username still results in an attempt to access MySQL via the ‘abc_wpsites’ account. Any thoughts on what’s going on here?
Also, I should mention that I can connect via other methods with the appropriate credentials (e.g. via MySQL), so this seems to be some sort of problem with my understanding/the operation of MySQL’s CLI interface.
I wouldn’t suggest passing your login information that way. This means your password is
Instead create at script.cnf file that is NOT world readable.
The contents will look like
Change your command line call to
mysql –defaults-file=/path/to/script.cnf -h localhost abc_wpsitesdev
mysql
Edit
Your other comment said you could connect as other users. If you have root access to this db run
select user, host, passowrd from mysql.users;
Compare the one that’s not working with others that are.
The passwords that are stored will be hashes of the actual values. Are they all the same length? If one is significantly longer or shorter it could be the password was stored with an old password hashing method used in versions 4.x and earlier.
What is the host for the account you are trying to connect through? Is it ‘localhost’ or an IP address? If it is your IP address this likely might be the problem. Since your command line call is connecting to localhost this will tell it to connect through a unix socket (/var/lib/mysql/mysql.sock perhaps). MySQL differentiates these connections from ones coming through the TCP stack.
You could alternatively specify your full (non 127.0.0.1) IP address on the commandline if this is the case like
mysql -u blah -pblah -h 1.2.3.4