I'm trying to make the mysql client connect to a mysql server without requiring the password to be given interactively. Steps taken:

1) First create a mylogin.cnf file

$ mysql_config_editor set --user=<user> --password --host=<host>
Enter password:

2) File created successfully:

$ ls -la .mylogin.cnf
-rw-------. 1 urmt urmt  136 Dec 19 11:01 .mylogin.cnf
$ mysql_config_editor print --all
user = <user>
password = *****
host = <host>

3) Connect using mysql client

$ mysql <dbname>
ERROR 1045 (28000): Access denied for user '<user>'@'<host>' (using password: NO)

Is there a default value/configuration somewhere that makes the client ignore the password in mylogin.cnf? The user and host properties were read correctly from the file.

I am able to connect just fine if I provide the password on the command line:

$ mysql -p <dbname>
Enter password: 
Reading table information...

MySQL client version is 5.6.22, MySQL Server version is 5.6.22, both on Oracle Linux 6. Client and server are on different hosts.


9 Answers 9


Any way you do this, you're probably going to have a password saved somewhere. Even MySQL 5.6 login-path is easily decryptable by anyone with the motivation. That warning said, this would be an easy solution.

In your environment script (eg ~/.profile or ~/.bashrc), set

alias mysql='mysql -uUser -pPasswd -hHostname'

(putting in your desired User, Passwd, and Hostname, of course.)

After shell relogin, you should be able to simply do


... which will use your alias and connect to the DB and ignore any passwords in .my.cnf files.

Security note: If there are other users on your server, you might want to chmod 700 your profile script so the password is not as easily accessed by others. Any admin with root or sudo will be able to see it still; no way around that.

  • This is a work-around to the actual problem, but I'm fine this. I accept this answer with the disclaimer to future readers that the proper way to do it is the Nawaz answer, but that doesn't work on my environment for an unknown reason. Thanks! Mar 2, 2015 at 8:11
  • 2
    -1 this neither answers the query of the OP nor does it avoid to store a password in a file. the password is now stored in .profile instead of .mylogin.cnf. But now the password is displayed by the ps command.
    – miracle173
    Aug 5, 2015 at 5:49
  • @miracle, please validate your claim that ps will reveal the password. On my systems, the password shows masked as xxxxxxx in the ps output. If your MySQL client is not acting like mine, please post which mysql version and distro are you running. And do you have a better answer to the OP's actual question? Aug 5, 2015 at 6:41
  • 2
    @joshua: End-User Guidelines for Password Security: "Use a -pyour_pass or --password=your_pass option on the command line(...)This is convenient but insecure."
    – miracle173
    Aug 5, 2015 at 7:45

use following command to set login path first

mysql_config_editor set --login-path=lgpath --user=root -p

and then use below command to login mysql

mysql --login-path=lgpath

Help about mysql login path options can bee seen by

mysql_config_editor set --help

  • I tried setting a login path explicitly as you suggested, but unfortunately it has the same behavior: $ mysql_config_editor print --all [lgpath] user = <user> password = ***** host = <host> $ mysql --login-path=lgpath ERROR 1045 (28000): Access denied for user '<user>'@'<host>' (using password: NO) Feb 2, 2015 at 10:46

I had the same issue as OP, but the answers in this thread confused me. Vinay Mandala's link actually worked for me. Reposted here for clarity.

My issue:

ERROR 1045 (28000): Access denied for user '<user>'@'<host>' (using password: NO)

It proves that mysql_config_editor does not handle special characters in the password properly.


When mysql_config_editor prompts you for the password, make sure that you surround the password in double quotes ("). Afterwards, you can login just fine.

  • 1
    "Me too" I was having issues with the .mylogin.cnf not storing a password correctly. Quoting it solved it
    – Stavr00
    Oct 29, 2020 at 15:43

I was getting this error, except it said (using password: YES)

The reason as mentioned by Giovanni was because of a "#" in the password. I found that a workaround is to insert quotes around your password when prompted. The same restriction exists with plain-text passwords using .my.cnf.


The Nawaz answer is correct. I have little to add. I suggest you do some attempts with the environment variable MYSQL_TEST_LOGIN_FILE to crate a new configuration file, just in case the default file is corrupt. Use also --no-defaults to skip .cnf files. If the password contains the char #, mysql login-path doesn't work.

$ export MYSQL_TEST_LOGIN_FILE=$HOME/mylogin.cnf

$ mysql_config_editor set --login-path=mytest --host= --port=5622 --user=mytest --password
Enter password:

-rw------- 1 mysql mysql 288 Feb 27 14:25 mylogin.cnf

$ mysql --no-defaults --login-path=mytest test
  • This environment variable was not set. I set it but I got exactly the same behavior. It ignored the password in mylogin.cnf. Mar 2, 2015 at 8:11
  • Are you sure the user who exec mysql command is mysql? If not, change the owner of mylogin.cnf and it should works :)
    – Iazel
    Dec 21, 2015 at 12:31

I am encountering a similar issue as the original poster. I suspect it has to do with characters in the password which do not get encrypted/decrypted properly.

To confirm try changing the password to something simple and see if this issue goes away.

  • I had the same issue. As Plazgoth pointed out, i had a special character in the password and it was not working. What worked for me is the suggestion from the user bglad on this post Jun 27, 2018 at 14:08

I had this problem with a shell script. My script was changing the $HOME value and this caused the --login-path=*** to appear to be ignored. When I stopped changing the $HOME value then it started working.


NOTE if you are trying to run the pathunder the linux user root -- You cannot simply use sudo. You must log in as root IE

user@server:$ sudo su
user@server:$ Enter Password
root@server:$ mysql_config_editor set --login-path=data-main --user=<user> --password --host=<host>
root@server:$ Enter Password
root@server:$ exit
user@server:$ ...

Also as mentioned in other posts here .. You must use double quotes around your mysql password if it contains anything other than alphanumeric characters.


This post is a bit old and I stumbled upon this as I had the same issue for last one week. I was getting the below error.

mysqldump: [Warning] /home/<user>/.mylogin.cnf should be readable/writable only by current user.
mysqldump: Got error: 1045: Access denied for user '<user>'@'localhost' (using password: NO) when trying to connect

None of the solutions stated above worked. Tried to edit the .mylogin.cnf file using the below.

mysql_config_editor set --login-path=dba --host=localhost --user=<user> --password

This too didn't work. So tried printing all that is configured using the below.

mysql_config_editor print --all

This gave an error as below.

WARNING : Login file does not have the required file permissions.
Please set the mode to 600 & run the command again.
operation failed. : No such file or directory

.mylogin.cnf had 660 (rw-rw----) permissions. Though it is certainly one step above 600, I just changed the permissions to 600 (rw-------) and voila, it worked. It seems "only by current user" warning is something we overlook. It's weird. But this is what worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.