记录-MySQL 修改ROOT密码

Windows环境步骤如下

  1. 停止mysql服务 运行输入services.msc 停止mysql服务
    或者 cmd --> net stop mysql
  1. 在cmd下 输入 mysqld --skip-grant-tables & 启动服务器 光标不动 (不要关闭该窗口)
  1. 新打开cmd 输入mysql -u root -p 不需要密码
use mysql;
update user set password=password('abc') WHERE User='root';
  1. 关闭两个cmd窗口 在任务管理器结束mysqld 进程
  1. 在服务管理页面 重启mysql 服务

密码修改完成

通过修改配置文件的方式

  1. 停止Mysql服务
  2. 找到配置文件,在配置文件的 [mysqld] 下面添加一行
    skip-grant-tables

如下:

[mysqld]
skip-grant-tables 
  1. 启动MySQL

  2. 登录mysql之后,(无需输入密码)
    执行命令修改密码

use mysql;

UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;

## 注意5.7之后密码字段为:authentication_string
UPDATE user SET authentication_string = password ( 'new-password' ) WHERE User = 'root' ;
  1. 退出MySQL
    删除 skip-grant-tables 配置

  2. 启动MySQL

本文地址:https://www.cnblogs.com/inick/p/13823979.html

posted @ 2020-10-16 00:39  iNick  阅读(236)  评论(0编辑  收藏  举报