MySQL root password change

前端 未结 22 2827
被撕碎了的回忆
被撕碎了的回忆 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:39

    On MySQL 8.0.4+

    To update current root user:

    select current_user();
    set password = 'new_password';
    

    To update other user:

    set password for 'otherUser'@'localhost' = 'new_password';
    

    To set password policy before updating password:

    set global validate_password.policy = 0;
    set password = 'new_password';
    set password for 'otherUser'@'localhost' = 'new_password';
    

    Other / better way to update root password:

    mysql_secure_installation
    

    Want to stick with 5.x authentication so you can still use legacy apps?

    On my.cnf

    default_authentication_plugin = mysql_native_password
    

    To update root:

    set global validate_password.policy = 0;
    alter user 'root'@'localhost' identified with mysql_native_password by 'new_password';
    

提交回复
热议问题