mysqldump: Got error: 1045 Access denied - mysql

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

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

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

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.

Related

Back-up of all tables in a database as sql file

I am trying to create a back-up of all tables in a large mysql database having all tables as .sql file, this is what I am trying:
`mysqldump -h localhost --user=username --password --tab=/tmp/test
db_name`
this is the error i get:
`Got error: 1045: "Access denied for user 'username#%' (using password: YES)" when executing 'SELECT INTO OUTFILE'`
I have spent lot of time searching for a solution for this error but I could not find anyone that could solve the issue.
Of course the directory test permissions are ok, I have already checked that.
Thank you.
Don't enter the password with command. Just enter,
mysqldump -h localhost -u username -p db_name > backup_file.sql
Then you will get a prompt to enter password. Enter that and it should do the trick.
Thanks

AWS EC2 Crontab auto backup RDS MySQL database

In my EC2 Linux, I would like to create a cron job to auto backup a MySql DB in AWS RDS. I had tried to run
/usr/bin/mysqldump -u dbusername -p'dbpassword' dbname > /path/backup.sql
but I got an error
"Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 1045: Access denied for user 'dbusername'#'localhost' (using password: YES) when trying to connect".
What is wrong and how do I change the 'dbusername'#'localhost' to 'dbusername'#'xxx.xxxxxxxx.xx-xxxxxx-x.rds.amazonaws.com'?
I had also tried to write a MySql script to download backup.sh but unable to as it cannot go beyond
mysql -u 'dbusername' --password="dbpassword" -h 'xxx.xxxxxxxx.xx-xxxxxx-x.rds.amazonaws.com'
it is able to login but it shows the MySQL prompt
>
anything beyond that e.g.
> use db;
it will show
Warning: Using a password on the command line interface can be insecure.
mysqldump -u dbusername -p'dbpassword' -h hostname.here.com dbname > /path/backup.sql
The same -h works for all mysql* commands, e.g. if you want to connect to RDB:
mysqldump -u user -p'pass' -h db.us-east-1.rds.amazonaws.com dbname

How can I fix the MySQL 'access denied' errors after db restore?

I exported all databases of a MySQL server by:
mysqldump -u root -p --all-databases > /tmp/dbs.sql
Then I copied the file (by scp) on another server, which has the same MySQL version, and imported it with:
mysql -u root -p < dbs.sql
I can access to MySQL only as root. With other users, I obtain:
~$ mysql -u jag -p
Enter password:
ERROR 1045 (28000): Access denied for user 'jag'#'localhost' (using password: YES)
However, selecting all users in mysql.user table, I can see that all user accounts where imported. So, how can I overcome this problem, without resetting all user passwords?
You need to specify username and password, you can try this:
mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME
Note that there is no space between -p parameter and password!
You can check this: http://dev.mysql.com/doc/refman/5.0/en/connecting.html
After following all the similar answers for this issue, I've solved it in CentOS with this:
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
please make sure to grant privileges to that user u want to restore with, in this case 'jag'

Updating a database in a server using command-line

I have been searching for a while to find a good answer to my problem.
I have a new server where I would like to run a script in .php which uses a database to store some data. What I have done so far is:
Place the .php file in the server with the help of Putty.
Create a database in phpmyadmin, export it and place it in the same folder of my project in putty.
Run php5 crawl.php > logfile.log 2&>1&
but it doesn't update the database.
I am little bit confused with the steps I have to make in order to make it work. I have been reading also this article http://www.aspkin.com/using-putty-to-import-a-database/ but when I run the
mysql -u dbusername -p databasename < backupname.sql
I get this error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Any idea what I might be doing wrong?
if it's a local machine you may not have a password on it for root - so remove the -p tag.
Otherwise you want to specify the password in there with it, without a space, like so:
mysql -u dbusername -pYourPassword databasename < backupname.sql
zcat /path/to/file.sql.gz | mysql -uroot -p your_database

MySQL will connect on the command line with u/p but not mysqldump

It's driving me mad!
I can connect to my server's MySQL via Terminal using:
mysql -u admin -p and then password fine.
Trying the same with:
mysqldump --user admin --password=mypassword test123 > /backups/test.sql
just gets me mysqldump: Got error: 1045: Access denied for user
Any words of wisdom for me, do I need to grant more priviledges to admin?
Thanks,
Chris
Your mysqldump commandline is wrong. use
--user=admin
or
-u admin
As i see, you do the wrong command, because is: mysqldump --user=admin --password=mypassword test123 > /backups/test.sql i suggest to add --opt and -h serverip just to be sure.