MySQL mysqldump:得到错误:1045 拒绝访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23744866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:32:09  来源:igfitidea点击:

mysqldump: Got error: 1045 Access denied

mysqlmysqldump

提问by KyleBunga

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

我已登录 AWS 实例并尝试将 mysql 数据库复制到 .sql 文件。我正在使用命令:

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

我可以使用与上述相同的凭据直接登录到 mysql,但仍然出现相同的错误。我为上面的命令尝试了很多不同的方法,但似乎是权限问题或类似问题。在 phpmyadmin 中查看时,用户确实拥有数据库的所有权限,所以我不确定出了什么问题?有什么建议?谢谢

回答by meda

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

检查以确保您没有运行不同的 mysql 实例

回答by KyleBunga

Thank you all for your input! It got me thinking about what else it could possibly be. I then tried using the -hparameter 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

谢谢大家的意见!这让我开始思考它可能是什么。然后我也尝试使用该-h参数,该参数不适用于"localhost"。当我使用 AWS 实例的私有 IP 地址时,它终于奏效了。
mysqldump -h [PrivateIPAdress] -u [UserName] -p [DatabaseName] > [Database].sql

回答by thebignoob

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.

我不确定,但值得一试,因为你说你可以登录到那台机器。