Reputation: 39
I have been trying to reset the root password of MySQL.
I have used to two methods to reset. But I didnt get it.
Following steps are done, But it doesn't work for me:
Stopped running of MySQL services and created a mysql-init.txt file.
mysql-init.txt
contains:USE mysql; UPDATE mysql.user SET Password=PASSWORD('vikash') WHERE User = 'root'; FLUSH PRIVILEGES;
I have opened the command prompt and i typed the following:
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld.exe --defaults-file="my.ini" --init-file="C:\\Users\\user-name\\Desktop\\mysql-init.txt" --console
The ERROR which I got is as follows:
Could not open required defaults file: C:\Program Files\MySQL\MySQL Server 5.6\bin\my.ini Fatal error in defaults handling. Program aborted
I simply opened the command prompt and typed as follows:
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqladmin -uroot -psample password
vikash
I got the error as:
Warning: Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
Please help me to reset the password.
Upvotes: 2
Views: 14537
Reputation: 403
Below is the process to reset the root user password, when we forgot the root user password or missed to recollect the password provided during installation.
sudo /etc/init.d/mysql stop
sudo mkdir -p /var/run/mysqld sudo chown mysql:mysql /var/run/mysqld
sudo mysqld_safe --skip-grant-tables &
mysql -uroot mysql>use mysql; mysql>update user set authentication_string=password('root123') where user='root';
mysql>update user set plugin="mysql_native_password" where User='root'; mysql>flush privileges; quit;
sudo /etc/init.d/mysql stop sudo /etc/init.d/mysql start
mysql -uroot -proot123
The URLs for reference.
Upvotes: 6
Reputation: 17511
Try stopping mysql service
/etc/init.d/mysqld stop
Run the safe executable skipping grants
mysqld_safe --skip-grant-tables &
(the trailing ampersand gets you back to the command line)
Then connect as root without password
mysql -uroot
You'll be in the mysql prompt where you can update root's password.
EDIT: I just saw you're using windows. Ok, then your first method should almost work. Instead of "UPDATE mysql.user" the file should read
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('vikash');
Then run
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld.exe --init-file=C:\Users\user-name\Desktop\mysql-init.txt
I'm curious about the executable though... all those blank spaces can probably get windows confused. Perhaps it would be easier to create your init file in the same folder as the executable so you just have to run
mysqld.exe --init-file=mysql-init.txt
There might be other executables in there. mysqld-nt, mysqld-safe, etc. If mysqld doesn't work, try the others too.
Upvotes: 1