How to reset the forgotten MySQL root password?

前端 未结 2 591
别那么骄傲
别那么骄傲 2020-12-22 00:37

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 wo

2条回答
  •  無奈伤痛
    2020-12-22 01:27

    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.

提交回复
热议问题