忘记 mysql 密码怎么办

code

[root@xxx ~]# vi /etc/my.cnf

在[mysqld]中添加

skip-grant-tables

例如:

[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

修改密码

复制代码
[root@xxx ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.32, for Linux (x86_64) using EditLine wrapper
[root@xxx ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@xxx ~]# ps -ef|grep mysql
mysql 1582 1 0 2020 ? 00:19:28 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 14597 126576 0 19:35 pts/2 00:00:00 grep --color=auto mysql
[root@xxx ~]# kill -9 1582
[root@xxx ~]# 
[root@xxx ~]# /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
2021-01-08T11:36:11.650443Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-08T11:36:11.652252Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.32) starting as process 14688 ...
2021-01-08T11:36:11.654799Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2021-01-08T11:36:11.654839Z 0 [ERROR] Aborting

2021-01-08T11:36:11.654888Z 0 [Note] Binlog end
2021-01-08T11:36:11.654946Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

Initialization of mysqld failed: 0
[root@xxx ~]# ps -ef|grep mysql
mysql 14656 1 3 19:36 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 14705 126576 0 19:36 pts/2 00:00:00 grep --color=auto mysql
[root@xxx ~]# 
[root@xxx ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32 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> 
mysql> update user set authentication_string=password('123456') where user='root';
ERROR 1046 (3D000): No database selected
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> update user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges;
mysql> exit
Bye
[root@xxx ~]#
复制代码

 



 

 

 

 

 

 

 

 

posted @   anobscureretreat  阅读(83)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2020-01-08 python 获取系统平台
2020-01-08 python if __name__ == "__main__": 的含义
2020-01-08 python 显示上午下午
2019-01-08 python ros 订阅robot_pose获取机器人位置
2019-01-08 python ros 重新设置机器人的位置
2019-01-08 c 宏的定义
2019-01-08 dos与unix系统的格式转化
点击右上角即可分享
微信分享提示