DdlyHeadshot
DdlyHeadshot

Reputation: 831

mysqldump Error 1045 Access denied despite correct passwords etc

This is a tricky one, I have the following output:

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

When attempting to export my database with mysqldump on Windows XP. The username is root, the password is correct and contains only alphanumeric characters. I have tried different cases, with/without quotes, specifying using -u and -p, specifying using --user= and --password= and other methods of specifying user/passwords etc, specifying the host (it's all local) and even specifying the database using --databases instead of just blank. The error is always the same when using a password and always the same except the "NO" message when without. I have tried many fixes found through searches with no success. One fix suggested inspecting mysql.conf, but the Windows build doesn't seem to have one. The credentials (and indeed commandline parameters) work perfectly with mysql.exe - this problem only seems to be affecting mysqldump.exe.

Upvotes: 83

Views: 308261

Answers (30)

Rougher
Rougher

Reputation: 848

I had the same issue. Problem was that I copied this command from internet

mysqldump –u <user_name> –p <db_name> > db.sql

and Ubuntu didn't understand the "-" symbol because difference of encoding. So, solution was to remove this symbol and write by myself.

Upvotes: 5

One
One

Reputation: 93

ENSURE YOU TRY REMOVING AND TYPING THE DASH OVER to make sure that you are actually fighting with the right problem. Be very careful that you actually have a "-". I apparently had some other character that looks very similar. I had a – instead of a -. I had copied the command from somewhere online don't remember where but the point is I spend a lot of time trying to figure it out when I just needed to replace that character.

Upvotes: 0

Sudeep Devkota
Sudeep Devkota

Reputation: 219

This is the solution that worked for me

mysqldump -h hostname.com -u username -p'password' database > dump.sql

Upvotes: 1

majorgear
majorgear

Reputation: 337

I got the same error when I ran the command in a directory that I didn't have write access to.

Test your access by creating an empty file in the directory, and see if you get an error.

Here was my error

mysqldump  -u root librenms -p > librenms.sql
-bash: librenms.sql: Permission denied

I changed to my home directory and then it worked.

cd ~ 
mysqldump  -u root librenms -p > librenms.sql
Enter password:

Do the equivalent on windows, and it may just fix your problem!

Upvotes: 0

Shannon McGee
Shannon McGee

Reputation: 790

I had the same error. Only occurred after moving from my normal work PC to a PC at a different location.

I had to add my public IP ho address to Remote MySQL in my CPanel at my host site

Upvotes: 0

Hank Killinger
Hank Killinger

Reputation: 171

Putting -p as the first option worked for me on Windows Server 2012R2 (in cmd.exe as Admin).

mysqldump.exe –p --user=root  --databases DBname --result-file=C:\DBname.sql

Upvotes: 5

Mohamed Elbahja
Mohamed Elbahja

Reputation: 649

I was having the same issue, for 30min! I found that I was using _p instead of -p, the terminal font confused me!

Upvotes: 2

Dan.
Dan.

Reputation: 727

This solution might be one of the last to try/least likely to be the culprit, but this was my problem...

My problem was that the directory I was trying to dump to needed admin privileges to write to and that's what was causing the mysqldump command to return "Access Denied".

I set the dump file path to my desktop dir and then it worked.

This was on Windows.

Upvotes: 0

hariK
hariK

Reputation: 3069

Don't enter the password with command. Just enter,

mysqldump -u <username> -p <db_name> > <backup_file>.sql

Then you will get a prompt to enter password.

Upvotes: 12

vks
vks

Reputation: 21

If you want to create a mysql data dump, you can use mysqldump command. Following command will create a sql file called xxx.sql at the same location from where this command is run. xxx.sql will have all the necessary sqls to replicate exactly same db schema in any other mysql database.

Command is : mysqldump -u root -ppassword --databases database Name you want to import > xxx.sql

Here root is the mysql root user and password is THIS root user's password.

EXAMPLE: If root user password is hello, database name to export is regdb and xxx.sql is the file where you want to export this regdb, command would be like:

mysqldump -u root -phello --databases regdb > xxx.sql

Note: xxx.sql is the file name where this db will get dumped.

Upvotes: 0

Mark
Mark

Reputation: 61

Tried most of the above with no joy. Looking at my password, it had characters that might confuse a parser. I wrapped the password in quotes and the error was resolved. -p"a:@#$%^&+6>&FAEH"

Using 8.0

Upvotes: 0

Raul
Raul

Reputation: 66

In my case, I could access correctly with mysql.exe but not with mysqldump.exe.

The problem was the port for my connection was not the default one (3306) and I had to put the mysqldump port work with (-P3307)

mysqldump -u root -p -P3307 my_database > /path/backup_database

Upvotes: 2

refex
refex

Reputation: 163

For me it worked when I omitted the password.

So mysqldump -u user dbname > dump.sql

Upvotes: 0

Robert Sinclair
Robert Sinclair

Reputation: 5446

For MAMP PRO users (or anyone who's mysql is in a weird location) be prepared to specify the mysql full path from the boonies and also specify full path to your user local folder where you want to dump the file or you'll get the "permission denied error"..

Following worked for me after 3 hours of research:

/Applications/MAMP/Library/bin/mysqldump  -u root -proot YOUR_DB > /Users/YOUR_USER/yourdump2.sql

Upvotes: 1

David Tonhofer
David Tonhofer

Reputation: 15338

I had the problem that there were views that had a bad "DEFINER", which is the user that defined the view. The DEFINER used in the view had been removed some time ago as being "root from some random workstation".

Check whether there might be a problem by running:

USE information_schema; 
SELECT DEFINER, SECURITY_TYPE FROM views;

I modified the DEFINER (actually, set the DEFINER to root@localhost and the SQL SECURITY value to INVOKER so the view is executed with the permissions of the invoking user instead of the defining user, which actually makes more sense) using ALTER VIEW.

This is tricky as you have to construct the appropriate ALTER VIEW statement from information_schema.views, so check:

Upvotes: 0

ThorSummoner
ThorSummoner

Reputation: 18199

Mysql replies with Access Denied with correct credentials when the mysql account has REQUIRE SSL on

The ssl_ca file (at a minimum) had to be provided in the connection paramiters.

Additional ssl parameters might be required and are documented here: http://dev.mysql.com/doc/refman/5.7/en/secure-connection-options.html


Also posted here https://stackoverflow.com/a/39626932/1695680

Upvotes: 1

zylstra
zylstra

Reputation: 801

Doing without the -u and -p worked for me (when I was logged in as root):

mysqldump --opt mydbname > mydbname.sql

Upvotes: 4

UdayKiran Pulipati
UdayKiran Pulipati

Reputation: 6677

Access dined problem solved when I run command prompt in Administrator mode.

Go to Start-> All Programs -> Accessories right click on Command Prompt clickc on Run as.. Select The Following User select administrator username from select option enter password if any click OK button.

Example 1: For entire database backup in mysql using command prompt.

In Windows 7 and 8

C:\Program Files <x86>>\MySQL\MySQL Server 5.5\bin>mysqldump test -u root -p >testDB.sql
Enter Password: *********

In Windows xp

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump test -u root -p >testDB.sql
Enter Password: *********

It asks password for credentials enter password and click on Enter button.

Example 2: For specific table backup / dump in mysql using command prompt.

In Windows 7 and 8

C:\Program Files <x86>>\MySQL\MySQL Server 5.5\bin>mysqldump test -u root -p images>testDB_Images.sql
Enter Password: *********

In Windows xp

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump test -u root -p images>testDB_Images.sql
Enter Password: *********

Dumpt file will be created under folder

In windows xp

C:\Program Files\MySQL\MySQL Server 5.5\bin

In windows 7 and 8

C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin

Note: Check MySQL installation folder in Windows 7, 8 while run in command prompt. If MySQLWorkbench is 32 bit version it is installed in Program Files (x86) folder other wise Program Files folder.

Upvotes: 8

Andree Wendel
Andree Wendel

Reputation: 343

Try to remove the space when using the -p-option. This works for my OSX and Linux mysqldump:

mysqldump -u user -ppassword ...

Upvotes: 29

Florian Storck
Florian Storck

Reputation: 509

I discovered a running apache process acessing the MYSQL causing this error. So I suggest to ensure that all processes which might interact with the DB are shutdown beforehand.

Upvotes: 0

CoR
CoR

Reputation: 3914

I had the same error for last 2 days. Tried bunch of things. Nothing worked.
But this did work:
Create another user. Grant it everything.
mysqldump -u new_user db_name > db_name.sql //no error

Upvotes: 0

user4669696
user4669696

Reputation: 1

Go to Start-> All Programs -> Accessories right click on Command Prompt click on Run as administrator

In the command prompt using CD command Go to MySQL bin folder and run the below command

mysqldump --user root --password=root --all-databases>dumps.sql

it will create dumps.sql file in the bin folder itself.

Upvotes: -2

Max
Max

Reputation: 1213

I had to remove the single ticks after the password flag:

--password=mypassword

and NOT

--password='mypassword'

Upvotes: 1

Someone
Someone

Reputation: 171

You need to put backslashes in your password that contain shell metacharacters, such as !#'"`&;

Upvotes: 17

McLinux
McLinux

Reputation: 11

mysqldump -u (user) -p(passwd) -h (host_or_IP) database_to_backup > backup_file.sql

example:

mysqldump -u god -pheaven -h 10.0.10.10 accounting > accounting_20141209.sql

this would create sql backup file for the accounting database on server 10.0.10.10. Sometimes your error is seen when localhost is not in config. Designating ip of server may help.

Upvotes: 1

wcc526
wcc526

Reputation: 4115

mysqldump -h hostname -u username -P port -B database --no-create-info -p > output.sql

I think you should specify the args

Upvotes: 6

Johnathan Elmore
Johnathan Elmore

Reputation: 2254

If you're able to connect to the database using mysql, but you get an error for mysqldump, then the problem may be that you lack privileges to lock the table.

Try the --single-transaction option in that case.

mysqldump -h database.example.com -u mydbuser -p mydatabase --single-transaction  > /home/mylinuxuser/mydatabase.sql

Upvotes: 43

Roland
Roland

Reputation: 1

In Past same problem occurred to me after I copied the mysqldump statement from a MS Word file.

But When typing the statement directly, everything worked fine.

In hex editor the "-" of the not working statement was represented by the unicode char e2 80 93 (http://www.fileformat.info/info/unicode/char/2013/index.htm)

In sort, type password directly and check the copy paste code as the uni-code (or other encoding) strings might cause an issue..

Upvotes: 0

Anand Mishra
Anand Mishra

Reputation: 430

Put The GRANT privileges:

GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'%' IDENTIFIED BY 'password';

Upvotes: 7

user3761176
user3761176

Reputation: 321

The access being denied is probably to the Windows file system not to the MySQL database; try redirecting the output file to a location where your account is allowed to create files.

Upvotes: 22

Related Questions