• mysql数据库root密码忘记了,这里有一个简单的方法可以解决


    mysql安装久了,就容易忘记root密码,那么下面这个找回密码的方法将解决你的问题:

    特别注意事项:

    本方法只适合mysql数据库密码遗忘(忘记了)

    这个解决方案的前提是你的电脑里安装了navicat(其他的第三方工具我没试过,不确定是否可以用)

    首先,确保你的navicat或者其他第三方工具之前已经正确连接了你的mysql数据库,只是密码忘记了

    下面是解决方案:

    (1)打开navicat,正常连接数据库

    (2)选择【文件】菜单中的【导出连接】,

    在【导出连接】对话框中选择【mysql】,在【导出密码】选项中打勾,点击【确定】到处文件。

    使用记事本打开导出的文件,找到下图所示信息位置,选择复制;

    (3)查询密码

    打开代码在线运行 - 在线工具

    在删除左侧代码栏中代码,然后复制以下代码:

    1. class NavicatPassword
    2. {
    3. protected $version = 0;
    4. protected $aesKey = 'libcckeylibcckey';
    5. protected $aesIv = 'libcciv libcciv ';
    6. protected $blowString = '3DC5CA39';
    7. protected $blowKey = null;
    8. protected $blowIv = null;
    9. public function __construct($version = 12)
    10. {
    11. $this->version = $version;
    12. $this->blowKey = sha1('3DC5CA39', true);
    13. $this->blowIv = hex2bin('d9c7c3c8870d64bd');
    14. }
    15. public function encrypt($string)
    16. {
    17. $result = FALSE;
    18. switch ($this->version) {
    19. case 11:
    20. $result = $this->encryptEleven($string);
    21. break;
    22. case 12:
    23. $result = $this->encryptTwelve($string);
    24. break;
    25. default:
    26. break;
    27. }
    28. return $result;
    29. }
    30. protected function encryptEleven($string)
    31. {
    32. $round = intval(floor(strlen($string) / 8));
    33. $leftLength = strlen($string) % 8;
    34. $result = '';
    35. $currentVector = $this->blowIv;
    36. for ($i = 0; $i < $round; $i++) {
    37. $temp = $this->encryptBlock($this->xorBytes(substr($string, 8 * $i, 8), $currentVector));
    38. $currentVector = $this->xorBytes($currentVector, $temp);
    39. $result .= $temp;
    40. }
    41. if ($leftLength) {
    42. $currentVector = $this->encryptBlock($currentVector);
    43. $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
    44. }
    45. return strtoupper(bin2hex($result));
    46. }
    47. protected function encryptBlock($block)
    48. {
    49. return openssl_encrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
    50. }
    51. protected function decryptBlock($block)
    52. {
    53. return openssl_decrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
    54. }
    55. protected function xorBytes($str1, $str2)
    56. {
    57. $result = '';
    58. for ($i = 0; $i < strlen($str1); $i++) {
    59. $result .= chr(ord($str1[$i]) ^ ord($str2[$i]));
    60. }
    61. return $result;
    62. }
    63. protected function encryptTwelve($string)
    64. {
    65. $result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
    66. return strtoupper(bin2hex($result));
    67. }
    68. public function decrypt($string)
    69. {
    70. $result = FALSE;
    71. switch ($this->version) {
    72. case 11:
    73. $result = $this->decryptEleven($string);
    74. break;
    75. case 12:
    76. $result = $this->decryptTwelve($string);
    77. break;
    78. default:
    79. break;
    80. }
    81. return $result;
    82. }
    83. protected function decryptEleven($upperString)
    84. {
    85. $string = hex2bin(strtolower($upperString));
    86. $round = intval(floor(strlen($string) / 8));
    87. $leftLength = strlen($string) % 8;
    88. $result = '';
    89. $currentVector = $this->blowIv;
    90. for ($i = 0; $i < $round; $i++) {
    91. $encryptedBlock = substr($string, 8 * $i, 8);
    92. $temp = $this->xorBytes($this->decryptBlock($encryptedBlock), $currentVector);
    93. $currentVector = $this->xorBytes($currentVector, $encryptedBlock);
    94. $result .= $temp;
    95. }
    96. if ($leftLength) {
    97. $currentVector = $this->encryptBlock($currentVector);
    98. $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
    99. }
    100. return $result;
    101. }
    102. protected function decryptTwelve($upperString)
    103. {
    104. $string = hex2bin(strtolower($upperString));
    105. return openssl_decrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
    106. }
    107. };
    108. //需要指定版本两种,11或12
    109. //$navicatPassword = new NavicatPassword(11);
    110. //这里我指定的12的版本,原先指定的11,执行之后的密码是乱码
    111. $navicatPassword = new NavicatPassword(12);
    112. //解密
    113. //$decode = $navicatPassword->decrypt('5658213B');
    114. $decode = $navicatPassword->decrypt('复制出来的密码');
    115. echo $decode."\n";
    116. ?>

    在最下面的位置,将我们在导出文件中复制的内容复制到此处,记得保留单引号点击执行,即可看到root密码,然后复制粘贴到我们的IDE编辑器中,提示成功连接mysql数据库。

  • 相关阅读:
    Vue3封装自定义指令和hooks,并发布npm包
    DBSCAN点云聚类
    【高并发】别闹了,这样理解Java的内存模型才正确(八种操作+同步规则)
    细讲java 桥接
    Unity中神秘的Transform和transform(小写)的关系
    浅谈新能源汽车充电桩的选型与安装
    【移动端网页特效】01-触屏事件和常用对象列表
    部署安装达梦单实例数据库
    C++数据结构X篇_24_归并排序(稳定的排序)
    轧钢切头飞剪机设计及有限元分析
  • 原文地址:https://blog.csdn.net/kingqiji01/article/details/133693639