ERROR 1045 (28000): Access denied for user

My local MySQL has no password for root user. I have added a new user with password and I’m trying to login to MySQL. This is what I got!

G:\XAMPP\mysql\bin>mysql -ugaja -p
Enter password: ****************
ERROR 1045 (28000): Access denied for user ‘gaja’@’localhost’ (using password: YES)

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

What I have done?

  1. Stop Mysql from XAMPP console
  2. Start the mysql from command line as given below
    g:\xampp\mysql\bin\mysqld.exe --skip-grant-tables
  3. From another cmd I logged in to Mysql
    mysql -u root
  4. Set the password string for root user
    UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
    FLUSH PRIVILEGES;
  5. Check if passwordless login is allowed still.
    G:\XAMPP\mysql\bin>mysql -u root
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  6. Lets login with password now
    G:\XAMPP\mysql\bin>mysql -u root -p
    Enter password: ********
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.6.21 MySQL Community Server (GPL)
  7. Remove the anonymous user account
    DROP USER ''@'localhost';
  8. Let me try to login with the user I’ve created newly
    G:\XAMPP\mysql\bin>mysql -u gaja -p
    Enter password: ****************
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 5.6.21 MySQL Community Server (GPL)

Enjoy!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s