运维开发网

MySQL8.0修改密码的正确方法

运维开发网 https://www.qedev.com 2022-08-19 19:03 出处:网络
如果当初设置了一个很复杂的数据库密码,是很可能忘记的,下面这篇文章主要给大家介绍了关于MySQL8.0修改密码的正确姿势,需要的朋友可以参考下

如果当初设置了一个很复杂的数据库密码,是很可能忘记的,下面这篇文章主要给大家介绍了关于MySQL8.0修改密码的正确姿势,需要的朋友可以参考下


前言

更新密码后,mysql始终拒绝连接,无法登录。MySQL8.0不能通过直接修改mysql.user表来更改密码。更改密码的正确方法备注:Clear 空root密码

MySQL8.0不能通过直接修改mysql.user表来更改密码。

因为authentication_string字段只能是MySQL加密的43位字符串密码,其他的会导致错误。如果没有报错,但是无法再次登录mysql,会一直提示无法认证。

参考:MySQL8.0

mysqlgt; USE mysql;Database changedmysqlgt; UPDATE user SET authentication_string="123456" WHERE user="root";Query OK, 1 row affected (0.39 sec)Rows matched: 1 Changed: 1 Warnings: 0mysqlgt; FLUSH privileges; # 刷新保存Query OK, 0 rows affected (0.13 sec)


mysql 5.7.9 之后取消了password 函数,authentication_string=password(quot;123456quot;) 会报错

c:\ WINDOWS \ system32gt;MySQL-u root-p
输入密码:* * * * * *
错误1045 (28000):拒绝用户lsquo的访问;rootrsquo@ lsquolocalhostrsquo(使用密码:是)
1234567891011121314

如果你像这样改了密码,并且无法访问mysql。在表示同情的同时,也为大家提供了详细的解决方案。请查看本文备注:clear 空root密码。


正确更改密码的方式ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "your_password";mysqlgt; USE mysql;Database changedmysqlgt; ALTER USER 'root'@'localhost' IDENTIFIEED WITH mysql_native_password BY "markjun";ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIEED WITH mysql_native_password BY "markjun"' at line 1mysqlgt; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "markjun";Query OK, 0 rows affected (0.18 sec)mysqlgt; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "123456";Query OK, 0 rows affected (0.08 sec)mysqlgt; SELECT user, authentication_string FROM user;+------------------+------------------------------------------------------------------------+| user | authentication_string |+------------------+------------------------------------------------------------------------+| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |+------------------+------------------------------------------------------------------------+4 rows in set (0.00 sec)mysqlgt; FLUSH privileges;Query OK, 0 rows affected (0.38 sec)mysqlgt; quit;ByeF:\MySQL\mysql-8.0.13-winx64\bingt;mysql -u root -pEnter password: *******...mysqlgt;备注: 清空root密码

停止MySQL任务网

mysqld命令mysqld-控制台-跳过-授予-表-共享-内存

输入mysql mysql -u root无需密码。

Clear 空root密码更新用户设置authentication _ string = quotquot其中user = ldquorootrdquo;

另一个终端无需密码即可进入。

F:\MySQL\mysql-8.0.13-winx64\bingt;mysql -u root -pEnter password: *******ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)F:\MySQL\mysql-8.0.13-winx64\bingt;mysql -u rootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 7...Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysqlgt; USE mysql;Database changedmysqlgt; SELECT user, authentication_string FROM user;+------------------+------------------------------------------------------------------------+| user | authentication_string |+------------------+------------------------------------------------------------------------+| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || root | 123456 |+------------------+------------------------------------------------------------------------+4 rows in set (0.34 sec)mysqlgt; UPDATE user SET authentication_string="" WHERE user="root";Query OK, 1 row affected (0.20 sec)Rows matched: 1 Changed: 1 Warnings: 0mysqlgt; SELECT user, authentication_string FROM user;+------------------+------------------------------------------------------------------------+| user | authentication_string |+------------------+------------------------------------------------------------------------+| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED || root | |+------------------+------------------------------------------------------------------------+4 rows in set (0.00 sec)mysqlgt; FLUSH privileges;Query OK, 0 rows affected (0.10 sec)mysqlgt; quit;Bye

停止mysqld任务,Ctrl+C结束任务,或者直接关闭运行mysqld的cmd终端。

你需要先停止运行上面的mysqld任务,否则会得到错误。

f:\ MySQL \ MySQL-8 . 0 . 13-winx 64 \ bingt;NET MySQL
MySQL服务正在启动。
MySQL服务无法启动。

该服务未报告任何错误。

请键入NET HELPMSG 3534以获取更多帮助。

先停止上面的mysqld任务。

f:\ MySQL \ MySQL-8 . 0 . 13-winx 64 \ bingt;NET MySQL
MySQL服务正在启动...
MySQL服务已成功启动。

现在mysql root没有密码了。

f:\ MySQL \ MySQL-8 . 0 . 13-winx 64 \ bingt;mysql-u root-p
输入密码:
欢迎使用MySQL监视器。命令以结尾;或者\g。

...
Type # 39;求助;#39;或者# 39;\ h # 39寻求帮助。类型# 39;\ c # 39清除当前输入语句。

mysqlgt


总结

关于MySQL8.0密码修改的正确姿势这篇文章就到这里了。关于MySQL8.0密码更改姿势的更多信息,请搜索源搜网之前的文章或者继续浏览下面的相关文章

0

精彩评论

暂无评论...
验证码 换一张
取 消