Pages

1045 - Access denied for user 'root'

How to fix 1045 - Access denied for user 'root'@'localhost' (using password: NO)
mysql root username/pass not working?
My Solution: Turns out there was no 'root' user created?
I followed these steps:
Code:

/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables
mysql -u root mysql
mysql> INSERT INTO user (Host,User,Password) VALUES('%','root',PASSWORD('desiredPassword'));
flush privileges;
exit;

Restart sql server (kill process running in other terminal 'ctrl+c')
Code:

/etc/init.d/mysql restart

Upon completion, I tried to login and got: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' error.

To fix:
Create the directory if it is not there:
Code:

sudo mkdir /var/run/mysqld/

touch the file to create it
Code:

sudo touch /var/run/mysqld/mysqld.sock

change the ownership of the folder and socket to the mysql user
Code:

sudo chown mysql /var/run/mysqld/
sudo chown mysql /var/run/mysqld/mysqld.sock

start the mysql server
Code:

sudo mysqld

Source