• mysql 5.7忘记密码


    1、

    https://blog.csdn.net/zzzcl112/article/details/80484495?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase

    以上的修改密码改为了命令:

    UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword') WHERE User = 'root' AND Host = 'localhost';

    否则会报错;

    ————————————————

    方法二:

    该方法先修改mysql配置文件使其可以无密码登录,让后修改密码,之后便复原配置文件

    修改/etc/my.cnf

    vim /etc/my.cnf 

    配置文件添加skip-grant-tables

    [root@VM_0_8_centos ~]# vim /etc/my.cnf
    
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    skip-grant-tables                       此处!!!!!!
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    

    保存后重启mysql

    systemctl restart mysql

    即可免密登录,命令行输入mysql直接登录

    选择mysql数据库,输入下列命令重置密码,'new-password'即为所设置密码

    USE mysql;
    UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword') WHERE User = 'root' AND Host = 'localhost';
    修改完成后输入exit退出,重新回到/etc/my.cnf该文件删除之前添加语句即可完成
  • 相关阅读:
    寒假刷题之2——Decoder
    寒假刷题之5——竹简文
    一位ACMer的心得,,,
    OD使用教程22 调试篇22
    OD使用教程22 调试篇22
    递归和分治思想4|八皇后问题 数据结构和算法34
    递归和分治思想4|八皇后问题 数据结构和算法34
    字符串 数据结构和算法35
    KMP算法(养成篇) 数据结构和算法36
    OD使用教程23 调试篇23
  • 原文地址:https://www.cnblogs.com/yaok430/p/13677418.html
Copyright © 2020-2023  润新知