• 修改配置文件

      1. [mysqld]
      2. # 跳过密码验证
      3. skip-grant-tables
    • 重启 mysql

      systemctl restart mysqld

    • 进入 mysql

      mysql # 不用输入账号和密码

    • 修改密码
      • 注意 5.7 后字段为 authentication_string 之前为 password
      • 注意密码需要用 passwrod() 函数进行包裹

        use mysql;

    update user set authentication_string=password(““) where user = “root”;

    flush privileges; quit

    • 删除配置文件的 skip-grant-tables

    • 重启 mysql 即可