mysql密码不会更新

jslywgbw  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(285)

我试着用在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'
ws51t4hk

ws51t4hk1#

显然,我需要确保 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
也没有提到插件,我也不知道这是否是一个特定的东西。所以我怀疑这个解决方案是否足够,但对我来说,它起了作用。

相关问题