MySQL 5.5 正确配置 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y ES)

本文介绍了一种在Windows环境下重置MySQL服务器管理员(root)密码的方法。步骤包括:停止MySQL服务、临时启动MySQL服务并禁用权限表检查、登录MySQL、更新root用户的密码、刷新权限、重新启动MySQL服务并验证新密码。

第一步:C:\Program Files (x86)\MySQL\bin>net stop mysql
mysql 服务正在停止.
mysql 服务已成功停止。


第二步:

mysql>C:\Program Files (x86)\MySQL\bin>mysqld --skip-grant-tables


第三步:

C:\Program Files (x86)\MySQL\bin>net start mysql
mysql 服务正在启动 ..

mysql 服务已经启动成功。


第四步:

C:\Program Files (x86)\MySQL\bin>mysql -u root mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.38 MySQL Community Server (GPL)


Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


第五步:

mysql> UPDATE user SET Password=PASSWORD('root') where USER='root';
Query OK, 3 rows affected (0.07 sec)
Rows matched: 3  Changed: 3  Warnings: 0

第六步:
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

第七步:
mysql> quit
Bye

第八步:
C:\Program Files (x86)\MySQL\bin> net start mysql

请求的服务已经启动。


第九步:
C:\Program Files (x86)\\MySQL\bin> mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.38 MySQL Community Server (GPL)


Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement


mysql>
当在winx系统下安装mysql出现ERROR 1045(28000):Access denied for user root @ localhost. (using password: YES)错误时,可参考以下解决办法: 1. **检查是否密码过期问题**:可以设置密码永久不过期。若host为'localhost',使用语句`alter user 'root'@'localhost' password expire never;`;若host被更改为'%',则使用`alter user 'root'@'%' password expire never;`,否则系统会报“ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'”的错误 [^3]。 2. **刷新权限并重置密码**:首先执行`FLUSH PRIVILEGES;`来刷新权限,然后使用通用语法`ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';`重置密码(适用于MySQL 5.7+ 和 8.0 ),最后执行`EXIT;`退出。之后重启MySQL服务 [^4]。 3. **检查用户账号密码**:确认输入的root账号密码是否正确,可能是输入的密码有误导致拒绝访问 [^2][^5]。 4. **检查配置文件my.ini**:配置文件可能存在错误,可参考以下配置进行修改: ```ini [mysqld] # 设置3306端口 port=3306 # 设置mysql的安装目录 basedir=D:\Program Files (x86)\mysql-8.0.22-winx64 # 设置mysql数据库的数据的存放目录 datadir=D:\Program Files (x86)\mysql-8.0.22-winx64\data # 允许最大连接数 max_connections=200 # 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统 max_connect_errors=10 # 服务端使用的字符集默认为UTF8 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB # 默认使用“mysql_native_password”插件认证 default_authentication_plugin=mysql_native_password [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [client] # 设置mysql客户端连接服务端时默认使用的端口 port=3306 default-character-set=utf8 ``` [^5]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值