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
Put The GRANT
privileges:
GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'%' IDENTIFIED BY 'password';
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
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
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.
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:
Doing without the -u
and -p
worked for me (when I was logged in as root):
mysqldump --opt mydbname > mydbname.sql