Bug #34144 Password error when piping output from mysqldump to mysql CLI in single command
Submitted: 29 Jan 2008 19:16
Reporter: Chris Calender Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S3 (Non-critical)
Version:All OS:Windows
Assigned to: Assigned Account CPU Architecture:Any
Tags: -p option, access denied, command-line interface, Enter password, password error, redirect

[29 Jan 2008 19:16] Chris Calender
Description:
When you specify the --user and --password options when piping mysqldump output to mysql (via mysql CLI) with one command, you'll get an "Access Denied" error on Windows.

This works with Linux, but not with Windows.

In the following output, note that you see "Enter password: Enter password:" (that is, it's listed twice in a row).

No matter what password you enter first, and hit "enter", you'll get the "error: 1045: Access denied" error.  It will then hang for a moment, and if you hit "enter" once more, you'll get a second "error: 1045: Access denied" error, and then back to the command line prompt.

How to repeat:
Try the following command on Windows (this would simply dump your mysql.users table and import it to the 'test' database):

mysqldump -uroot -p mysql users | mysql -uroot -p test

You'll see the following output:

Enter password: Enter password: ***********

mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Suggested fix:
Perhaps this is not even a MySQL bug, but rather a shell redirect problem with Windows.
[29 Jan 2008 19:21] Chris Calender
Work-around is to add the 'user' and 'password' options under the [mysqldump] section in your my.ini, for example:

[mysqldump]
user=user_name
password=mysqldump_user_password

(You may want to create a specific user account just for using mysqldump).
[19 May 2009 1:36] Jim Winstead
It looks to me like this should be handled okay, as we use _getch() to read the password from the console on Windows. But perhaps the shell redirection confuses this. The relevant code is in get_tty_password() in client/get_password.c.