This is a tricky one, I have the following output:
mysqldump: Got error: 1045: Access denied for user \'root\'@\'localhost\' (using password: YES) when tr
For me it worked when I omitted the password.
So mysqldump -u user dbname > dump.sql
mysqldump -u user dbname > dump.sql