mysql - MySQL密码不会更新
问题描述
我尝试使用我在 Google 上找到的任何内容来重置我的 MySQL 密码,但是它系统地失败了。这是我尝试的三件事:
$ read -s password
$ echo ${#password}
10
$ echo "use mysql; update user set authentication_string=password('$password') where user='root';" | sudo mysql -uroot
$ echo "use mysql; select authentication_string from user where user='root';" | sudo mysql -uroot
authentication_string
*B69D82770841AB22761D61C3C7DED4FBE78D99C7
$ mysql -uroot "-p$password"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
$ sudo mysqladmin -u root password "$password"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
$ mysql -uroot "-p$password"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
$ echo "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('$password');" | sudo mysql -uroot
$ mysql -uroot "-p$password"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
我也在更新和测试之间尝试了所有这三个echo "flush privileges" | sudo mysql -uroot
,但仍然Access denied
.
这是我的mysql版本
$ sudo mysql --version
mysql Ver 14.14 Distrib 5.7.23, for Linux (x86_64) using EditLine wrapper
为什么更新我的密码对这三种方式没有影响?
编辑
我也试过(因为我使用> = 5.7.6):
$ echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '$password';" | sudo mysql -uroot
$ echo "flush privileges; " | sudo mysql -uroot
$ mysql -uroot "-p$password"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
编辑 2
我也尝试过,按照https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html:
$ echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '$password';" > changepw.sql
$ chmod 777 changepw.sql
$ sudo service mysql stop
$ sudo mysqld --init-file=`pwd`/changepw.sql &
$ sudo service mysql restart
$ mysql -uroot "-p$password"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
解决方案
显然,我需要确保mysql_native_password
使用了该插件,然后才能ALTER USER
正常工作。
$ read -s password
$ echo ${#password}
$ echo "use mysql; update user set plugin='mysql_native_password'; FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY '$password'; " | sudo mysql -uroot -p
我在这里找不到任何关于ALTER USER
不工作的默认行为:
https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
也没有提到插件,我也不知道这是否是 Ubunt 18 特有的。所以我怀疑这个解决方案是否足够,但对我来说它有效。
推荐阅读
- javascript - 将 Google DFP 广告单元标题(“广告”)添加到所有具有白色背景和内边距的广告
- angular - 角度材料侧边栏显示水平
- git - 按下“变基并合并”后,已验证的签名消失了
- powerbi - 有没有办法将书签按钮的数量转换为 PowerBI 中的下拉列表/切片器?
- node.js - 在一个 Firebase 云函数中使用 100 多个路由并将路由拆分到多个云函数时,性能有何不同?
- php - Laravel ui 安装后登录错误
- jquery - Jquery if/else 与下面的代码冲突
- laravel - Vue 有时在我的 Laravel + Bootstrap 4 应用程序中加载太晚(?)
- graphql - GraphQL / Strapi - 无法按字符串字段过滤
- clickhouse - ClickHouse 上由 '_nd' 完成的表格的目的是什么