跳到主要内容

3、排错

mysql排错

案例:mysqladmin修改默认密码是时报错-2024.4.6==(已解决)==

故障环境:

mysql-5.7.29
centos7.6 1810
mysqladmin -uroot -p'LufavlMka6,!'   password magedu

自己这里测试时报错了:

[root@vm-template ~]#awk '/temporary password/{print $NF}' /data/mysql/mysql.log
?Ny,T;oKg5t>
[root@vm-template ~]#

mysqladmin -uroot -p'?Ny,T;oKg5t>'   password magedu

[root@vm-template ~]#mysqladmin -uroot -p'?Ny,T;oKg5t>'   password magedu
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Your password has expired. To log in you must change it using a client that supports expired passwords.'
[root@vm-template ~]#

📌 gpt

[root@vm-template ~]#mysqladmin -uroot -p'?Ny,T;oKg5t>'   password magedu
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Your password has expired. To log in you must change it using a client that supports expired passwords.'

当MySQL用户的密码过期时,您将无法用常规方法或常规客户端更改密码,因为它们可能不支持密码过期功能。在这种情况下,您需要使用支持密码过期的客户端来重置密码。对于MySQL,通常意味着您需要直接连接到MySQL服务器并通过命令行进行操作。

请按照以下步骤操作:

  1. 使用支持密码过期的MySQL客户端登录。打开终端,并尝试:

    mysql -uroot -p
  2. 系统会提示您输入密码,这时输入您的旧密码 ?Ny,T;oKg5t>

  3. 如果MySQL版本支持,登录后您可能会被提示修改密码。如果是,请按提示操作。

  4. 如果没有自动提示,或者提示不起作用,您可以在MySQL提示符下运行以下命令来设置新密码:

    SET PASSWORD = PASSWORD('您的新密码');

    或者,若MySQL版本为5.7.6或更新,应使用以下命令:

    ALTER USER 'root'@'localhost' IDENTIFIED BY '您的新密码';

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'xyy520';

    请确保将 '您的新密码' 替换为您想要的新密码。

  5. 执行完上述命令后,退出MySQL:

    quit
  6. 现在您应该可以使用新密码通过mysqladmin或其他客户端工具连接到MySQL了。

如果您在这个过程中遇到任何问题,请再次检查您的MySQL服务器的版本和配置,因为不同版本可能需要略有不同的操作。

📌 再次测试(测试OK,符合预期)

[root@vm-template ~]#mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.7.29

Copyright (c) 2000, 2020, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xyy520';
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye
[root@vm-template ~]#mysql -uroot -pxyy520
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)

mysql> \q
Bye
[root@vm-template ~]#