notes 笔记notes 笔记
Home
Article
Category
Tag
Timeline
Home
Article
Category
Tag
Timeline
  • build

    • 环境变量
  • browse

    • 2fa
    • sse
    • token
  • database

    • mongodb

      • start
    • mysql

      • curd
      • 安装
      • join
      • 多对多
      • 性能优化
      • 表设计
      • 常见问题
  • docker

    • github-actions

      • local
      • prod
    • docker-compose
    • index
    • podman
  • file

    • 文件下载
    • 原生 node.js下载文件
  • git

    • index
    • multiple-github-accounts
    • auto-commit
    • pat
    • rebase
  • linux

    • grep
    • index
    • ssh
    • vim
    • windows
  • network

    • best-proxy-way
    • git-via-https
    • github-push-fail
  • nginx

    • acme.sh
    • cache
    • https
    • index
    • safe
  • node

    • fnm
    • tool
  • obsidian

    • ish
    • start
  • react

    • index
    • set-state
  • summary

    • index
  • vue

    • index
    • typescript
  • libs
  • open-source
  • Problem: Access denied for user 'root'@'localhost' (using password: YES)
    • Option 1: Using MySQL Installer (Recommended for Windows)
    • Option 2: Safe Mode Reset
    • Option 3

Problem: Access denied for user 'root'@'localhost' (using password: YES)

需要修改密码

Option 1: Using MySQL Installer (Recommended for Windows)

  1. Open MySQL Installer from Start Menu
  2. Click "Reconfigure" next to MySQL Server
  3. Follow the wizard to reset root password

Option 2: Safe Mode Reset

# Stop MySQL service
net stop mysql80
# 或者 此电脑->管理->服务->MySQL80,右键选择停止

# Start MySQL in safe mode (skip grant tables)
# 8.0以下
mysqld --skip-grant-tables --skip-networking
# 8.0以上
mysqld --console --skip-grant-tables --shared-memory

# In a new command prompt
mysql -u root

# 在 mysql 面板中 依次执行以下命令
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

# Restart MySQL normally
net start mysql80

# Check your_new_password
mysql -u root -p

实测无效,可以用以下命令试试

mysql> use mysql;
mysql> update user set password=password("your_new_password") where user="root";
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Option 3

  1. 打开 此电脑->管理->服务->MySQL80,右键点击属性找到 mysql 的 my.ini 文件路径
  2. 在 my.ini 所在目录,新建 init_pwd.txt 文件。内容
ALTER user root@'localhost' identified by 'your_new_password';
  1. 停止 mysql 服务,net stop mysql 或者 通过 windows 服务停止MySQL80
  2. 重新初始化 mysql
mysqld --defaults-file="D:\MySQL\MySQL Server 8.0\my.ini" --init-file="D:\MySQL\MySQL Server 8.0\init_pwd.txt"

此命令会删除数据库,需要先备份

  1. 执行后,一直卡在那里,执行 ctrl+c 退出
  2. 重新启动 mysql 服务,可以用新密码登录了
最近更新:: 2025/10/19 23:44
Contributors: qyhever
Prev
表设计