Ubuntu ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Ubuntu 》mysql -u root -p 1234时,报错 ERROR 1698 (28000): Access denied for user 'root'@'localhost'

另一篇关于清除密码、重置用户的文章:
First things first. Log in as root and stop the mysql daemon.

sudo /etc/init.d/mysql stop


Now lets start up the mysql daemon and skip the grant tables which store the passwords.

sudo mysqld_safe --skip-grant-tables&

(press Ctrl+C now to disown the process and start typing commands again)

You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.

sudo mysql --user=root mysql


update user set Password=PASSWORD('new-password');
flush privileges;
exit;


Now kill your running mysqld then restart it normally.

sudo killall mysqld_safe&
(press Ctrl+C now to disown the process and start typing commands again)
/etc/init.d/mysql start

You should be good to go. Try not to forget your password again.

====================================
mysql> use mysql;
Database changed
mysql> update user set password=password('123456') where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql>
authentication_string字段
update user set authentication_string=password('1234') where user='root';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1
### 解决 Windows 下 MySQL 错误 1045 (28000) 访问被拒的方法 #### 密码验证机制不匹配 当遇到 `ERROR 1045 (28000)` 的时候,即使确认密码无误也可能无法登录。这可能是由于MySQL版本更新后默认的身份验证插件发生了变化所致[^3]。 对于这种情况,在尝试其他解决方案之前可以先检查当前用户的认证方式: ```sql SELECT User, Host, plugin FROM mysql.user WHERE User='root'; ``` 如果结果显示`plugin`列不是`mysql_native_password`而是其他的值,则可以通过下面命令修改它: ```sql ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password'; FLUSH PRIVILEGES; ``` 请注意替换 `'your_new_password'` 为你想要设置的新密码字符串。 #### 使用安全模式重置密码 另一种常见的情况是因为忘记了 root 用户的密码或者是密码策略过于严格而造成的问题。此时可以在跳过权限表加载的情况下启动服务来绕过正常的安全控制流程从而允许更改凭证信息。 具体操作如下所示: 停止正在运行的服务: ```powershell net stop mysql ``` 以 --skip-grant-tables 参数重启mysqld进程: ```powershell "C:\Program Files\MySQL\MySQL Server X.Y\bin\mysqld.exe" --console --skip-grant-tables ``` 这里假设安装路径为 `"C:\Program Files\MySQL\MySQL Server X.Y\"`, 需要根据实际情况调整路径中的X.Y部分以及整个文件夹名称。 一旦成功进入无需身份验证的状态就可以执行SQL语句重新设定账户密码了: ```sql USE mysql; UPDATE user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES; QUIT; ``` 最后记得按照常规方法再次关闭并正确开启数据库引擎以便应用最新的改动。 #### 修改配置文件降低安全性(临时方案) 作为权宜之计还可以考虑编辑my.ini/my.cnf 文件内的 `[mysqld]` 节点下加入一行 `secure-auth=OFF` 来禁用某些高级别的保护措施使得旧版客户端能够兼容新特性。不过这种方法并不推荐长期使用因为它会削弱系统的整体防护水平。 以上就是在Windows操作系统上处理因错误编号1045所引发的一系列连接失败现象的一些基本思路和技术手段[^1][^2].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值