Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL Access denied for user 'root'@'localhost'

Tags:

mysql

I did the following steps to use MySQL in Ubuntu:

sudo aptitude install php5-mysql mysql-server
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysql -u root mysql

Change root password:

mysql> UPDATE mysql.user SET Password=PASSWORD('SecurePassword') WHERE
User='root';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

Modify /etc/mysql/my.cnf:

[client]
user=root
password=SecurePassword
[mysqld]
...
default-time-zone = '+0:00'

Then:

sudo service mysql start
mysql -u root
mysql> SHOW GRANTS FOR root@localhost
+--------------------------------------------------------------------------------------------------+
 | Grants for root@localhost | 
+--------------------------------------------------------------------------------------------------+
 | GRANT USAGE ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '[here is the Securepassword]' |
 +-------------------------------------------------------------------------------------------------+
 1 row in set (0.00 sec) 

mysql>
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'  WITH GRANT OPTION;

and I receive an error:

Access denied for user 'root'@'localhost' (using password: YES)

like image 806
user2698684 Avatar asked Aug 20 '13 06:08

user2698684


People also ask

How do I fix MySQL error Access denied for user root localhost?

You will get this error when the user user_name does not have the right to access your MySQL database. To resolve the error, you must create a user with the following command: mysql> GRANT ALL ON *. * to user_name@localhost IDENTIFIED BY 'password';

How do I fix root access denied?

If you get the “access denied” error, one way to solve it is by using sudo to log in to mysql and change the root password.

How do I fix Access denied for user root localhost in xampp?

Solution: Actually the problem is not in code, the issue is that by-default mysql in xampp allowed passwordless authentication in mysql, so we have to disable that and it will work as normal. Uncomment Line 19, save file and restart mysql service.

How do I fix MySQL error 1045?

How to fix “Error 1045 (28000) access denied for user 'root'@'localhost' (using password: yes)”? It arises when you perform a fresh installation of MySQL and try to login with a password. The default password of MySQL is blank () (i.e. empty string). So, you can login to the MySQL server using the same password.


1 Answers

It was absolutely correct what you did, but I guess it's not working for one small reason.

You should use identified by password when you are going to grant privileges like this:

mysql> GRANT ALL PRIVILEGES ONE `*`.`*` TO 'root'@'localhost' IDENTIFIED BY PASSWORD
'*A4B6157319038724E3560894F7F932C8886EBFCF' WITH GRANT OPTION;
like image 195
Abhik Dey Avatar answered Oct 27 '22 23:10

Abhik Dey