How to find out the MySQL root password

后端 未结 17 2512
野趣味
野趣味 2020-11-29 15:29

I cannot figure out my MySQL root password; how can I find this out? Is there any file where this password is stored?

I am following this link but I do not have dir

17条回答
  •  佛祖请我去吃肉
    2020-11-29 16:08

    thanks to @thusharaK I could reset the root password without knowing the old password.

    On ubuntu I did the following:

    sudo service mysql stop
    sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking
    

    Then run mysql in a new terminal:

    mysql -u root
    

    And run the following queries to change the password:

    UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
    FLUSH PRIVILEGES;
    

    In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is 'authentication_string'.

    Quit the mysql safe mode and start mysql service by:

    mysqladmin shutdown
    sudo service mysql start
    

提交回复
热议问题