MySQL root password change

前端 未结 22 2816
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 18:30

I have been trying to reset my MySQL root password. I have run the mysqld_safe --skip-grant-tables, updated the root password, and checked the user table to make sure it is

相关标签:
22条回答
  • 2020-11-29 18:42

    In MySQL 5.7, the password is replaced with 'authentication_string'.

    use

    update user set authentication_string=password('myfavpassword') where user='root';
    
    0 讨论(0)
  • 2020-11-29 18:44
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
    

    You can find Resetting the Root Password in the MySQL documentation.

    0 讨论(0)
  • 2020-11-29 18:44

    I searched around as well and probably some answers do fit for some situations,

    my situation is Mysql 5.7 on a Ubuntu 18.04.2 LTS system:

    (get root privileges)

    $ sudo bash
    

    (set up password for root db user + implement security in steps)

    # mysql_secure_installation
    

    (give access to the root user via password in stead of socket)

    (+ edit: apparently you need to set the password again?)

    (don't set it to 'mySecretPassword'!!!)

    # mysql -u root
    
    mysql> USE mysql;
    mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
    mysql> set password for 'root'@'localhost' = PASSWORD('mySecretPassword'); 
    mysql> FLUSH PRIVILEGES;
    mysql> exit;
    
    # service mysql restart
    

    Many thanks to zetacu (and erich) for this excellent answer (after searching a couple of hours...)

    Enjoy :-D

    S.

    Edit (2020):

    This method doesn't work anymore, see this question for future reference...

    0 讨论(0)
  • 2020-11-29 18:44

    For the current latest mysql version (8.0.16), none of these answers worked for me.

    After looking at several different answers and combining them together, this is what I ended up using that worked:

    update user set authentication_string='test' where user='root';
    

    Hope this helps.

    0 讨论(0)
  • 2020-11-29 18:46

    This worked for me -

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

    https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html

    0 讨论(0)
  • 2020-11-29 18:47

    Found it! I forgot to hash the password when I changed it. I used this query to solve my problem:

    update user set password=PASSWORD('NEW PASSWORD') where user='root';

    I forgot the PASSWORD('NEW PASSWORD') and just put in the new password in plain text

    0 讨论(0)
提交回复
热议问题