ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Note: For MySQL 5.7+ please see answer from @Lahiru to this question. That contains more current information.
For MySQL < 5.7:
The default root password is blank (i.e. empty string) not root
. So you can just login as:
mysql -u root
You should obviously change your root password after installation
mysqladmin -u root password [newpassword]
In most cases you should also set up individual user accounts before working extensively with the DB as well.
I was able to solve this problem by executing this statement
sudo dpkg-reconfigure mysql-server-5.5
Which will change the root password.
You have to reset the password! steps for mac osx(tested and working) and ubuntu
Stop MySQL using
sudo service mysql stop
or
$ sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
$ sudo mysqld_safe --skip-grant-tables --skip-networking
(above line is the whole command)
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
$ mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
As per @IberoMedia's comment, for newer versions of MySQL, the field is called authentication_string
:
mysql> UPDATE mysql.user SET authentication_string =PASSWORD('password') WHERE User='root';
Start MySQL using:
sudo service mysql start
or
sudo /usr/local/mysql/support-files/mysql.server start
your new password is 'password'.
NOTE: for version of mysql > 5.7 try this:
update mysql.user set authentication_string='password' where user='root';