文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

如何解决Mysql数据库报ERROR 1045 28000报错以及MySQL忘记密码的找回方法

2024-04-02 19:55

关注

这期内容当中小编将会给大家带来有关如何解决Mysql数据库报ERROR 1045 28000报错以及MySQL忘记密码的找回方法,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

案例:Mysql数据库报ERROR 1045 (28000)报错;同时该方法适用于忘记MySQL Password找回;重新安装mysql手动清空mysqld.log日志文件导致初始Password丢失Password修改;

案例1:

[root@zrbapp02 lib]# 

[root@zrbapp02 lib]# mysql -uroot -pmysql

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[root@zrbapp02 lib]# 

[root@zrbapp02 lib]# 

案例2:

[root@zrbapp02 ~]# echo "" > /var/log/mysqld.log   ----清空mysqld.log日志文件后查不到

[root@zrbapp02 ~]# 

[root@zrbapp02 ~]# grep 'temporary password' /var/log/mysqld.log   --mysqld.log日志文件查不到初始Password

[root@zrbapp02 ~]# 

[root@zrbapp02 ~]# 

[root@zrbapp02 ~]# systemctl restart mysqld

[root@zrbapp02 ~]# 

解决方法:

1、修改/etc/my.cnf文件中[mysqld]段增加skip-grant-tables跳过认证

[root@zrbapp02 lib]# vi /etc/my.cnf

#socket=/mysqldb/mysql/mysql.sock

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]

skip-grant-tables

#

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

#

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

#

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

#datadir=/var/lib/mysql

datadir=/mysqldb/mysql

socket=/var/lib/mysql/mysql.sock

#socket=/mysqldb/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

wq!  ----保存并退出

2、重启mysql数据库

[root@zrbapp02 lib]# systemctl restart mysqld

[root@zrbapp02 lib]# 

3、免密登录数据库并修改Password

[root@zrbapp02 lib]# 

[root@zrbapp02 lib]# mysql 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.24 sec)

mysql> 

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> 

mysql> 

mysql> update mysql.user set authentication_string=password('mysql') where user='root';

Query OK, 1 row affected, 1 warning (0.14 sec)

Rows matched: 1  Changed: 1  Warnings: 1

mysql> 

mysql>  flush privileges ;

Query OK, 0 rows affected (0.00 sec)

mysql> 

mysql> exit

Bye

[root@zrbapp02 lib]# 

[root@zrbapp02 lib]# 

4、注释掉skip-grant-tables

[root@zrbapp02 lib]# vi /etc/my.cnf

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]

#skip-grant-tables

#

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

#

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

#

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

#datadir=/var/lib/mysql

datadir=/mysqldb/mysql

socket=/var/lib/mysql/mysql.sock

#socket=/mysqldb/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

wq!   ----保存并退!

5、重启mysql数据库

[root@zrbapp02 lib]# systemctl restart mysqld

[root@zrbapp02 lib]# 


6、使用新Password登录数据库

[root@zrbapp01 ~]# 

[root@zrbapp01 ~]# mysql -uroot -pmysql

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 4

Server version: 5.7.25

Copyright (c) 2000, 2019, 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> 

mysql> show databases;   --查看数据库时要求使用ALTER USER  rest Password

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> 

mysql> alter user'root'@'localhost' identified by'mysql';   ----重置Password提示Password规则问题,不能使用简单Password;

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

mysql> 

mysql> 

若需要设置简单Password则按以下设置Password规则即可;

mysql> set global validate_password_policy=0;

Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_mixed_case_count=0;

Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_number_count=3;

Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_special_char_count=0;

Query OK, 0 rows affected (0.01 sec)

mysql> set global validate_password_length=3;

Query OK, 0 rows affected (0.00 sec)

mysql> alter user'root'@'localhost' identified by'mysql';

Query OK, 0 rows affected (0.00 sec)

mysql> 

mysql> 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)

mysql> 

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> 

mysql> 

上述就是小编为大家分享的如何解决Mysql数据库报ERROR 1045 28000报错以及MySQL忘记密码的找回方法了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯