9

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!

mavix
  • 2,488
  • 6
  • 30
  • 52
  • 6
    "using password: YES" means that you are using a password, not that "YES" is that password. – Borealid Feb 21 '12 at 17:32
  • 2
    1045 error explained here: http://www.webyog.com/faq/content/23/18/en/error-no-1045-connection-denied.html – Man_k Aug 06 '12 at 11:25

4 Answers4

8

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

mysql -u root -p
feeela
  • 29,399
  • 7
  • 59
  • 71
  • That worked, thanks. Is there somewhere I can learn more about the various commands and things I need to use terminals? Are they significantly different for Windows and Linux? – mavix Feb 21 '12 at 17:40
  • No, the commands aren't different for the `mysql` command line client on Windows or Linux. But they can differ from version to version (of `mysql`). I think you should read the manual: http://dev.mysql.com/doc/refman/5.5/en/mysql.html On Linux you can also use `man mysql` to get a quick overview. – feeela Feb 22 '12 at 12:00
  • Just a note for Mac users that if you change your root password, this login command uses whatever password you set within mysql, not your Mac's root password. – Kelsey Hannan Aug 20 '15 at 02:00
  • @Kelseydh This is true for any OS, not just Mac. – feeela Aug 20 '15 at 10:02
3

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.

Community
  • 1
  • 1
Paul Williams
  • 1,554
  • 7
  • 40
  • 75
  • "If you FORGOT the password to root, and have changed it, you will have to subsequently reinstall easyPHP." If you have forgotten your MySQL-root-password, you'll need to reinstall MySQL, not easyPHP… – feeela Feb 22 '12 at 12:02
  • With easyPHP, I don't think you can just reinstall MySQL. Most of the suites don't install just PHP, MySQL, etc individually but as a collective group. If you just installed MySQL, PHP, and say Apache separately, then yes, you would just reinstall MySQL. In the users case, he installed MySQL as a part of easyPHP. – Paul Williams Feb 22 '12 at 13:29
0
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>
agkaiser
  • 19
  • 2
0

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';
Mohit Nigam
  • 454
  • 5
  • 10