MySQL 尽管密码正确等,mysqldump 错误 1045 访问被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20059823/
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 19:28:22  来源:igfitidea点击:

mysqldump Error 1045 Access denied despite correct passwords etc

mysqllocalhostaccess-deniedmysql-error-1045windows-xp-sp3

提问by DdlyHeadshot

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

mysqldump:出现错误:1045:尝试连接时拒绝用户“root”@“localhost”的访问(使用密码:YES)

When attempting to export my database with mysqldumpon 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 -uand -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 --databasesinstead 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.

尝试mysqldump在 Windows XP 上导出我的数据库时。用户名是 root,密码正确且仅包含字母数字字符。我尝试了不同的情况,带/不带引号,指定 using -uand -p,指定 using --user=and--password=和其他指定用户/密码等的方法,指定主机(它都是本地的)甚至指定数据库使用--databases而不是空白。使用密码时错误总是相同的,除了没有时出现“NO”消息外,错误总是相同的。我尝试了许多通过搜索找到的修复程序,但都没有成功。一项修复建议检查 mysql.conf,但 Windows 版本似乎没有。凭据(以及命令行参数)与 mysql.exe 完美配合——这个问题似乎只影响 mysqldump.exe。

回答by Boris Pavlovi?

This worked for me

这对我有用

mysqldump -u root -p mydbscheme > mydbscheme_dump.sql

after issuing the command it asks for a password:

发出命令后,它要求输入密码:

Enter password:

entering the password will make the dump file.

输入密码将生成转储文件。

回答by Johnathan Elmore

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.

如果您能够使用 mysql 连接到数据库,但是 mysqldump 出现错误,那么问题可能是您缺乏锁定表的权限。

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

在这种情况下尝试 --single-transaction 选项。

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

回答by user3761176

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.

被拒绝的访问可能是对 Windows 文件系统而不是对 MySQL 数据库;尝试将输出文件重定向到允许您的帐户创建文件的位置。

回答by Andree Wendel

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

尝试在使用 -p 选项时删除空格。这适用于我的 OSX 和 Linux mysqldump:

mysqldump -u user -ppassword ...

回答by Someone

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

您需要在包含 shell 元字符的密码中添加反斜杠,例如 !#'"`&;

回答by hariK

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.

然后,您将收到输入密码的提示。

回答by Anand Mishra

Put The GRANTprivileges:

GRANT特权:

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

回答by UdayKiran Pulipati

Access dined problem solved when I run command prompt in Administratormode.

当我在Administrator模式下运行命令提示符时,访问用餐问题解决了。

Go to Start-> All Programs -> Accessoriesright click on Command Promptclickc on Run as..Select The Following Userselect administrator usernamefrom select option enter password if any click OKbutton.

转到Start-> All Programs -> Accessories右键单击Command Promptclickc 上的Run as..Select The Following Userselect administrator usernamefrom select option 输入密码(如果有任何单击OK按钮)。

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

示例 1:使用命令提示符在 mysql 中备份整个数据库。

In Windows 7 and 8

在 Windows 7 和 8 中

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

In Windows xp

在 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.

它要求密码输入凭据,然后单击 Enter 按钮。

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

示例 2:使用命令提示符在 mysql 中备份/转储特定表。

In Windows 7 and 8

在 Windows 7 和 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

在 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

在 Windows XP 中

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

In windows 7 and 8

在 Windows 7 和 8 中

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

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 MySQLWorkbenchis 32 bit version it is installed in Program Files (x86)folder other wise Program Filesfolder.

注意:在命令提示符下运行时检查 Windows 7、8 中的 MySQL 安装文件夹。如果MySQLWorkbench是 32 位版本,则它安装在Program Files (x86)文件夹 other wiseProgram Files文件夹中。

回答by wcc526

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

mysqldump -h 主机名 -u 用户名 -P 端口 -B 数据库 --no-create-info -p > output.sql

I think you should specify the args

我认为你应该指定参数

回答by zylstra

Doing without the -uand -pworked for me (when I was logged in as root):

没有-u并且-p为我工作(当我以 root 身份登录时):

mysqldump --opt mydbname > mydbname.sql