I suffered the same strange behaviour.
When I use in my script the command:
/usr/bin/mysqldump -h localhost -u root -pmy#rootpassword mysql --tables db >> mysql-db_2017-03-17_09-50-35.sql
I get the Warning:
Warning: Using a password on the command line interface can be insecure.
So I changed my Backup Scripts to
/usr/bin/mysqldump --login-path=backups mysql --tables db >> mysql-mysql-db_2017-03-17_08-24-07.sql
But that gave me the Error:
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
The official MySQL Documentation recommends to try the Configuration with the "mysql" command
To connect to the local server, use this command:
shell> mysql --login-path=client
And actually I found that I get the same Error this way:
$ mysql --login-path=backups
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
I could not make any sense of it until I stumbled over this comment at the bottom of the MySQL Documentation:
Password string with character "#" in it will cause authentication
failure because when strings are read, hash characters are treated as
the start of a comment.
That took me to the MySQL Bug Page:
There I found the suggested Workaround that worked for me:
A workaround is to enter the password in quotes "pass#pass".
Enclose all strings in quotes.
So I retyped my Password into the "mysql_config_editor":
$ mysql_config_editor set --login-path=scripts --host=localhost --user=root --password
Enter password: -> typeing: "my#rootpassword" <- including the character >"<
WARNING : 'scripts' path already exists and will be overwritten.
Continue? (Press y|Y for Yes, any other key for No) : y
And finally the Login succeeded:
$ mysql --login-path=scripts
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 139
Server version: 5.6.35-log Distributed by The IUS Community Project
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.