5

I am logged into an AWS instance and trying to copy a mysql database to a .sql file. I am using the command:

mysqldump -u [username] -p [databasename] > [database].sql

Then entering the password and the following message comes up.

"mysqldump: Got error: 1045: Access denied for user '[username]'@'localhost' (using password: YES) when trying to connect."

I can login directly to mysql using the same credentials as above, but still get the same error. I have tried a bunch of different ways for the command above, but it seems to be an issue with permissions or something similar. The user does have all privileges for the database when looking in phpmyadmin so I am not sure what is wrong? Any suggestions? Thanks

ρss
  • 5,115
  • 8
  • 43
  • 73
KyleBunga
  • 193
  • 1
  • 1
  • 7
  • It also looks like a duplicate of [mysqldump Error 1045 Access denied despite correct passwords etc](http://stackoverflow.com/q/20059823). – jww Apr 02 '16 at 00:50
  • Also see [How to have MySQL entitle the root user?](http://superuser.com/q/1060360) on Super User. It attempts to avoid resetting passwords. – jww Apr 02 '16 at 11:27

3 Answers3

6

This works for me:

mysqldump -uroot -pxxxx dbname > dump.sql

or you can specify the host:

mysqldump -h localhost.localdomain -uroot -pxxxx dbname > dump.sql

Check to make sure you don't have different instances of mysql running

meda
  • 45,103
  • 14
  • 92
  • 122
4

Thank you all for your input! It got me thinking about what else it could possibly be. I then tried using the -h parameter as well, which wouldn't work with "localhost". It finally worked when I used the Private IP Address for the AWS instance.
mysqldump -h [PrivateIPAdress] -u [UserName] -p [DatabaseName] > [Database].sql

Shoaib Iqbal
  • 1,208
  • 11
  • 21
KyleBunga
  • 193
  • 1
  • 1
  • 7
1
mysqldump -u [username] -p
ENTER YOUR PASSWORD
USE [databasename]
SOURCE /path/to/[database].sql

I am not sure, but worth a try because you said you are able to login into that machine.

thebignoob
  • 471
  • 5
  • 11