How to reset mysql root password?
I have a little problem with my phpmyadmin, in fact I accidentally delete multiple user accounts. Since it is impossible to connect without the error:
# 1045 - Access denied for user 'root' @ 'localhost' (using password: NO)
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root'; FLUSH PRIVILEGES;
does not work, or I didn’t understood how it worked. I’m on FreeBSD 8.1, my version of PhpMyadmin is 2.11. Thank you in advance for your answers.
8 Answers 8
sudo stop mysql sudo mysqld --skip-grant-tables --skip-networking mysql mysql> update mysql.user set password = password('your_new_password') where user = 'root'; mysql> flush privileges; mysql> exit; sudo mysqladmin shutdown sudo start mysql
please don’t post the exact same answer multiple times. If the question is a duplicate, flag it as such.
missing from the above snippet — though explained in the offsite summary. 1) After running the first sudo mysqld. , switch to a different terminal window. 2) Prompt for the the new password when running mysqladmin shutdown: sudo mysqladmin shutdown -u root -p
For mysql 5.7.16 or later I found this (from mysql.com) to be the working solution. Below are some points which are different compared to previous older versions
1) I used the below command to run mysql in safe mode as per some other references which actually worked fine for me (mysql 5.7.16 ubuntu 16.04).
mysqld_safe --skip-grant-tables --skip-networking
2) The below update stmt is NOT working for later version (ie. 5.7 and above)
-- NOT Working for 5.7 and later UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root'; FLUSH PRIVILEGES;
INSTEAD use below for 5.7.6 and later
UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost'; FLUSH PRIVILEGES;
OR user below for 5.7.5 or earlier versions.
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
I am Using MySQL Server 8 and this is how I solved this problem.
create a file and name it accordingly. I’ve named it as reset.txt. put below content in the file but change MyNewPass. This will be your new SQL password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Stop my SQL server (Go to services and search MYSQL and right-click on it and stop )
Now open a cmd in your bin folder of My SQLserver directory. in my case it’s
C:\Program Files\MySQL\MySQL Server 8.0\bin
execute the following command.
mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file mt24">)" data-controller="se-share-sheet" data-se-share-sheet-title="Share a link to this answer" data-se-share-sheet-subtitle="" data-se-share-sheet-post-type="answer" data-se-share-sheet-social="facebook twitter devto" data-se-share-sheet-location="2" data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f" data-se-share-sheet-license-name="CC BY-SA 4.0" data-s-popover-placement="bottom-start">Share)" title="">Improve this answeranswered Feb 10, 2020 at 11:54 Ravinda LakshanRavinda Lakshan1,00614 silver badges14 bronze badges