记录忘记mysql root密码过程

今天查看了一下mysql数据库,发现数据库密码忘记了。为此在这里总结一下,重置root密码的过程
数据库的目录结构
在这里插入图片描述
这里我使用的终端是git bash ,不是doc
在mysql/bin目录下打开git bash

 ./mysqld  --defaults-file="E:\xx\db\my.ini"  --console --skip-grant-tables
2021-04-22T05:51:47.056604Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-04-22T05:51:47.056604Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2021-04-22T05:51:47.056604Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2021-04-22T05:51:47.056604Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-04-22T05:51:47.056604Z 0 [Note] E:\xxx\db\bin\mysqld.exe (mysqld 5.7.20) starting as process 8964 ...
2021-04-22T05:51:47.066627Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2021-04-22T05:51:47.066627Z 0 [Note] InnoDB: Uses event mutexes
2021-04-22T05:51:47.066627Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier
2021-04-22T05:51:47.066627Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2021-04-22T05:51:47.067683Z 0 [Note] InnoDB: Number of pools: 1
2021-04-22T05:51:47.068680Z 0 [Note] InnoDB: Not using CPU crc32 instructions
2021-04-22T05:51:47.071666Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-04-22T05:51:47.080648Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-04-22T05:51:47.105676Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-04-22T05:51:47.355617Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-04-22T05:51:47.355617Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-04-22T05:51:47.365710Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB.
2021-04-22T05:51:47.373612Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-04-22T05:51:47.373612Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-04-22T05:51:47.374609Z 0 [Note] InnoDB: Waiting for purge to start
2021-04-22T05:51:47.425677Z 0 [Note] InnoDB: 5.7.20 started; log sequence number 260393122
2021-04-22T05:51:47.426692Z 0 [Note] InnoDB: Loading buffer pool(s) from E:\xxx\data\ib_buffer_pool
2021-04-22T05:51:47.426692Z 0 [Note] Plugin 'FEDERATED' is disabled.
2021-04-22T05:51:47.441673Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2021-04-22T05:51:47.441673Z 0 [Note] Server hostname (bind-address): '*'; port: 33036
2021-04-22T05:51:47.441673Z 0 [Note] IPv6 is available.
2021-04-22T05:51:47.442608Z 0 [Note]   - '::' resolves to '::';
2021-04-22T05:51:47.442608Z 0 [Note] Server socket created on IP: '::'.
2021-04-22T05:51:47.490608Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210422 13:51:47
2021-04-22T05:51:47.496649Z 0 [Note] E:\FFA\db\bin\mysqld.exe: ready for connections.
Version: '5.7.20'  socket: ''  port: 33036  MySQL Community Server (GPL)
2021-04-22T05:51:47.496649Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
2021-04-22T05:51:47.497668Z 0 [Note] Beginning of list of non-natively partitioned tables
2021-04-22T05:51:47.637673Z 0 [Note] End of list of non-natively partitioned tables

然后这个使用navicat连接
在这里插入图片描述
连接成功

  • 这里出了一点小问题,不知道为啥用mysql -uroot 命令一直连不上系统(不知道为啥,求大佬解答)
  • 在这里插入图片描述

然后在navicat中执行下面代码,root密码就重置成功

update mysql.user set authentication_string=password('123456') where user='root';
flush privileges;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!如果您忘记了 Windows 系统上 MySQLroot 密码,可以按照以下步骤重置密码: 1. 打开命令提示符(Command Prompt)或 PowerShell,以管理员身份运行。 2. 进入 MySQL 的安装目录,一般默认安装路径为 `C:\Program Files\MySQL\MySQL Server\<版本号>\bin`。 3. 在命令提示符中输入以下命令,然后按回车键执行: ``` mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server \<版本号>\my.ini" --init-file=C:\mysql-init.txt --console ``` 这里 `<版本号>` 是 MySQL 的版本号,您需要将其替换为您实际安装的版本号。 4. 创建一个文本文件(例如 `mysql-init.txt`),将以下内容复制到文件中: ``` ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; ``` 将 `'新密码'` 替换为您想要设置的新密码。请注意,这里的密码应该是强密码,并且不要忘记将其记录下来。 5. 保存并关闭文件。 6. 回到命令提示符或 PowerShell,按下 `Ctrl + C` 组合键停止正在运行的 MySQL 服务器。 7. 然后再次在命令提示符或 PowerShell 中输入以下命令,然后按回车键执行: ``` mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server \<版本号>\my.ini" --console ``` 8. MySQL 服务器将以初始化模式启动,并且将加载我们在 `mysql-init.txt` 文件中定义的 SQL 脚本。在加载完成后,您将看到一条消息表示密码已重置。 9. 关闭命令提示符或 PowerShell。 10. 重新打开命令提示符或 PowerShell,以管理员身份运行。 11. 在命令提示符或 PowerShell 中输入以下命令,然后按回车键执行: ``` mysql -u root -p ``` 您将被要求输入密码,将新密码输入即可登录到 MySQL。 希望这些步骤可以帮助您重置 Windows 系统上 MySQLroot 密码!如果有任何问题,请随时向我提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值