重置Mysql密码

  • Linux系统
  1. 停止MySQL进程
    #service mysqld restart
    # /etc/init.d/mysql stop
    或
    # killall -TERM mysqld(不推荐)
  2. 以安全模式启动MySQL
    # mysqld_safe –skip-grant-tables &
    或,
    # mysqld_safe --skip-grant-tables >/dev/null 2>&1 &
  3. 登陆MYSQL
    # mysql -u root
    或,
    # /usr/local/mysql/bin/mysql -u root mysql
  4. 更改ROOT密码
    use mysql;
    select host, user, password from user;
    update user set password=password(“newpassword”) where user=”root”
    flush privileges;
  5. 退出控制台,重启MYSQL服务
    service mysqld restart
    或,
    /etc/init.d/mysql restart
原文地址:https://www.cnblogs.com/juzii/p/4434085.html