​ 一次比较有意思的经历, 之前买过腾讯云的服务器安装的mysql由于时间过长,密码设置的也相对容易忘记一点,其实网上有一些方案是skip-grant-tables, 然后重置密码的思路, 或者是之前连接过Navicat,然后进去update掉user表, 然后再flush privileges; 退出,重新登录即可;

常规方案

一.windows下

  1.以系统管理员身份运行cmd.

  2.查看mysql是否已经启动,如果已经启动,就停止:net stop mysql

  3.切换到MySQL安装路径下:D:WAMPMySQL-5.6.36;如果已经配了环境变量,可以不用切换了。

  4.在命令行输入:mysqld -nt --skip-grant-tables

  5.以管理员身份重新启动一个cmd命令窗口,输入:mysql -uroot -p,Enter进入数据库。

  6.如果不想改密码,只是想看原来的密码的话,可以在命令行执行这个语句

select host,user,password from mysql.user; // 查看用户和密码

​ 7.如果要修改密码的话,在命令行下依次执行下面的语句

1
2
3
4
use mysql
update user set password=password("new_pass") where user="root";// 'new_pass' 这里改为你要设置的密码
flush privileges;
exit 

​  8.重新启动MYSQL,输入密码登录即可!

但是我不是已经用Navicat记住密码了嘛,也不想更改原来的密码, 能不能通过记住密码的方式,然后想办法找到那个记录,然后将记录解密就可以啦,实际上通过网上查资料,发现这种方式也确实可行, 在此记录一下;

找记录的pwd值

  1. regedit里面找pwd记录的加密值

    a.进入regedit然后展开HKEY_CURRENT_USER

regedit1

​ b.展开SoftWare

regedit2

​ c.展开PremiumSoft

regedit3

​ d.展开【NavicatPG】,如下图所示。

regedit4

​ e.展开Servers, 然后点数据库连接, 再双击Pwd

regedit5

复制【数值数据输入框中的内容】, 比如说我这里随便设定的密码加密后的数据是:“782D6DD3D0#####”

解密pwd值

下面是一段php解密代码,以供参考, php要first line顶行写, 否则报错;

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
namespace FatSmallTools;
class NavicatPassword
{
    protected $version = 0;

    protected $aesKey = 'libcckeylibcckey';

    protected $aesIv = 'libcciv libcciv ';

    protected $blowString = '3DC5CA39';

    protected $blowKey = null;

    protected $blowIv = null;

    

    public function __construct($version = 12)

    {

        $this->version = $version;

        $this->blowKey = sha1('3DC5CA39', true);

        $this->blowIv = hex2bin('d9c7c3c8870d64bd');

    }

    

    public function encrypt($string)

    {

        $result = FALSE;

        switch ($this->version) {

            case 11:

                $result = $this->encryptEleven($string);

                break;

            case 12:

                $result = $this->encryptTwelve($string);

                break;

            default:

                break;

        }

        

        return $result;

    }

    

    protected function encryptEleven($string)

    {

        $round = intval(floor(strlen($string) / 8));

        $leftLength = strlen($string) % 8;

        $result = '';

        $currentVector = $this->blowIv;
        

        for ($i = 0; $i < $round; $i++) {

            $temp = $this->encryptBlock($this->xorBytes(substr($string, 8 * $i, 8), $currentVector));

            $currentVector = $this->xorBytes($currentVector, $temp);

            $result .= $temp;

        }

        

        if ($leftLength) {

            $currentVector = $this->encryptBlock($currentVector);

            $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);

        }

        

        return strtoupper(bin2hex($result));

    }

    

    protected function encryptBlock($block)

    {

        return openssl_encrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING); 

    }

    

    protected function decryptBlock($block)

    {

        return openssl_decrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING); 

    }

    

    protected function xorBytes($str1, $str2)

    {

        $result = '';

        for ($i = 0; $i < strlen($str1); $i++) {

            $result .= chr(ord($str1[$i]) ^ ord($str2[$i]));

        }

        

        return $result;

    }

    

    protected function encryptTwelve($string)

    {

        $result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);

        return strtoupper(bin2hex($result));

    }

    

    public function decrypt($string)

    {

        $result = FALSE;

        switch ($this->version) {

            case 11:

                $result = $this->decryptEleven($string);

                break;

            case 12:

                $result = $this->decryptTwelve($string);

                break;

            default:

                break;

        }

        

        return $result;

    }

    

    protected function decryptEleven($upperString)

    {

        $string = hex2bin(strtolower($upperString));

        

        $round = intval(floor(strlen($string) / 8));

        $leftLength = strlen($string) % 8;

        $result = '';

        $currentVector = $this->blowIv;

        

        for ($i = 0; $i < $round; $i++) {

            $encryptedBlock = substr($string, 8 * $i, 8);

            $temp = $this->xorBytes($this->decryptBlock($encryptedBlock), $currentVector);

            $currentVector = $this->xorBytes($currentVector, $encryptedBlock);

            $result .= $temp;

        }

        

        if ($leftLength) {

            $currentVector = $this->encryptBlock($currentVector);

            $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);

        }

        return $result;

    }

    

    protected function decryptTwelve($upperString)

    {

        $string = hex2bin(strtolower($upperString));

        return openssl_decrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);

    }

}

 

use FatSmallTools\NavicatPassword;

 

//需要指定版本,11或12

//$navicatPassword = new NavicatPassword(12);

$navicatPassword = new NavicatPassword(11);

 

//解密

$decode = $navicatPassword->decrypt('782D6DD3D######');

echo $decode."\n";

运行上述脚本代码后可得密码是Abcd-123

1628223588868

参考资料

https://blog.csdn.net/milkign/article/details/107583169

http://t.zoukankan.com/Zeros-p-6043910.html

https://www.shuzhiduo.com/A/D854L7E25E/