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

老子叫甜甜 提交于 2020-01-12 14:30:33

问题


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:

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.

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


回答1:


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

mysql -u root -p



回答2:


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.

According to the documentation of 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).

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.

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




回答3:


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>



回答4:


A modification for mysql- 5.7.10 on mac mac el capitan

  • 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';


来源:https://stackoverflow.com/questions/9382219/error-1045-28000-access-denied-for-user-rootlocalhost-using-password-ye

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!