I just installed MySQL on Ubuntu and the root user can\'t log in :)
How can I recover or find out my password? Using blank for password does not work.
For RHEL-mysql 5.5:
/etc/init.d/mysql stop
/etc/init.d/mysql start --skip-grant-tables
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
mysql -uroot -pnewpwd
mysql>
Hmm Mysql 5.7.13 to reset all I did was:
$ sudo service mysql stop
To stop mysql
$ mysqld_safe --skip-grant-tables &
Start mysql
$ mysql -u root
Just like the correct answer. Then all I did was do what @eebbesen did.
mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('NEW-password-HERE');
Hope it helps anyone out there :)
I realize that this is an old thread, but I thought I'd update it with my results.
Alex, it sounds like you installed MySQL server via the meta-package 'mysql-server'. This installs the latest package by reference (in my case, mysql-server-5.5). I, like you, was not prompted for a MySQL password upon setup as I had expected. I suppose there are two answers:
Solution #1: install MySQL by it's full name:
$ sudo apt-get install mysql-server-5.5
Or
Solution #2: reconfigure the package...
$ sudo dpkg-reconfigure mysql-server-5.5
You must specific the full package name. Using the meta-package 'mysql-server' did not have the desired result for me. I hope this helps someone :)
Reference: https://help.ubuntu.com/12.04/serverguide/mysql.html
It is actually very simple. You don't have to go through a lot of stuff. Just run the following command in terminal and follow on-screen instructions.
sudo mysql_secure_installation
You can reset the root password by running the server with --skip-grant-tables
and logging in without a password by running the following as root (or with sudo):
# service mysql stop
# mysqld_safe --skip-grant-tables &
$ mysql -u root
mysql> use mysql;
mysql> update user set authentication_string=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
# service mysql stop
# service mysql start
$ mysql -u root -p
Now you should be able to login as root with your new password.
It is also possible to find the query that reset the password in /home/$USER/.mysql_history
or /root/.mysql_history
of the user who reset the password, but the above will always work.
Note: prior to MySQL 5.7 the column was called password
instead of authentication_string
. Replace the line above with
mysql> update user set password=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';