MySQL 用户 'root'@'localhost' 的错误 1045 (28000) 访问被拒绝(使用密码:YES)

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

error 1045 (28000) access denied for user 'root'@'localhost' (using password: YES)

mysqlcommand-lineroot

提问by mavix

Please forgive me for being a complete beginner:

请原谅我是一个完整的初学者:

I am trying to log into my very first mySQL database that I installed using easyPHP on my windows machine, using the cmd line. I am going to the \mysql\bin and entering the command:

我正在尝试使用 cmd 行登录到我在 Windows 机器上使用 easyPHP 安装的第一个 mySQL 数据库。我要去\mysql\bin 并输入命令:

mysql -u root

in order to log in, but I am getting the following message:

为了登录,但我收到以下消息:

error 1045 (28000) access denied for user 'root'@'localhost' (using password: YES)

Why is it using the password "YES"? Shouldn't there be no password at all? Do I need to restart mySQL or something? If so, how do I do that? If it's relevant, I did try to create the database using phpmyadmin, but had a few problems entering columns and decided I'd be better off working from the command line so I could learn all the commands as I went along.

为什么使用密码“YES”?不应该根本没有密码吗?我需要重新启动 mySQL 还是什么?如果是这样,我该怎么做?如果相关,我确实尝试使用 phpmyadmin 创建数据库,但是在输入列时遇到了一些问题,我决定最好从命令行工作,这样我就可以学习所有命令。

Please keep in mind that this is my first time ever trying to work with a database, so be kind to me!

请记住,这是我第一次尝试使用数据库,所以请善待我!

采纳答案by feeela

To have mysql asking you for a password, you also need to specify the -p-option:

要让 mysql 要求您输入密码,您还需要指定-p-option:

mysql -u root -p

回答by Paul Williams

When logging into MYSQL using the command line, you also have to specify the password if any. Your error message is telling you that the user "root" has a password attached to it. Not necessarily that the password is "YES" when you were installing easyPHP, it should have either provided you with a default password or allowed you to enter a password of your choosing.

使用命令行登录 MYSQL 时,您还必须指定密码(如果有)。您的错误消息告诉您用户“root”附加了密码。当您安装 easyPHP 时,密码不一定是“YES”,它应该为您提供默认密码或允许您输入您选择的密码。

According to the documentation of easyPHP:

根据easyPHP的文档:

[v1.6] My scripts worked perfectly with 1.5 but now I get this error : Warning: Forbidden access for user: 'user@localhost' (password: YES) when I want to connect to MySql.

Only the root user (without password) has the rights to connect to the database. Either modify your scripts to use it, or add the user you need (phpMyAdmin/users and privileges: See phpMyAdmin's documentation for more information).

[v1.6] 我的脚本与 1.5 完美配合,但现在出现此错误:警告:当我想连接到 MySql 时,禁止用户访问:'user@localhost'(密码:YES)。

只有 root 用户(没有密码)才有权连接到数据库。修改您的脚本以使用它,或添加您需要的用户(phpMyAdmin/users 和权限:有关详细信息,请参阅 phpMyAdmin 的文档)。

mysql -u root -p

mysql -u root -p

Now if you changed your root user password, you will need to specify that when prompted. Otherwise simply hit <Enter>on your keyboard.

现在,如果您更改了 root 用户密码,则需要在出现提示时指定该密码。否则只需敲击<Enter>键盘即可。

If you FORGOT the password to root, and have changed it, you will have to subsequently reinstall easyPHP.

如果您忘记了 root 的密码,并且已经更改了它,那么您必须随后重新安装 easyPHP。

回答by agkaiser

agk-hp:~/$mysql
ERROR 1045 (28000): Access denied for user 'greg'@'localhost' (using  password: NO)
agk-hp:~/$sudo cat /etc/mysql/debian.cnf|grep password
 password = t7753my3D2x4yfQm

agk-hp:~/$mysql -u debian-sys-maint -p  
Enter password: {t7753my3D2x4yfQm} 
Welcome to the MySQL monitor.  Commands end with ; or \g.

mysql> use mysql;

mysql> grant all privileges on *.* to 'root'@'localhost';
mysql> grant all privileges on *.* to 'greg'@'localhost';


agk-hp:~/$mysql
mysql>

回答by Mohit Nigam

A modification for mysql- 5.7.10 on mac mac el capitan

mac mac el capan 对mysql-5.7.10 的修改

  • sudo /usr/local/mysql/support-files/mysql.server stop
  • sudo mysqld_safe --skip-grant-tables

    Now open new window/tab on terminal and type

  • "mysql -u root"
  • use mysql
  • update user set authentication_string=password('yourpassword') where user='root';
  • 须藤/usr/local/mysql/support-files/mysql.server 停止
  • 须藤 mysqld_safe --skip-grant-tables

    现在在终端上打开新窗口/选项卡并输入

  • “mysql -u root”
  • 使用 mysql
  • 更新用户集 authentication_string=password('yourpassword') where user='root';