修复由于在文本编辑器中编辑 MySQL 数据库而损坏的序列化数据?
背景:我下载了我的 WordPress 站点数据库的 *.sql 备份,并将旧数据库表前缀的所有实例替换为新实例(例如,从默认 wp_
为 asdfghjkl_
).
Background: I downloaded a *.sql backup of my WordPress site's database, and replaced all instances of the old database table prefix with a new one (e.g. from the default wp_
to something like asdfghjkl_
).
我刚刚了解到 WordPress 在数据库中使用了序列化的 PHP 字符串,而我所做的事情会破坏序列化字符串长度的完整性.
I've just learnt that WordPress uses serialized PHP strings in the database, and what I did will have messed with the integrity of the serialized string lengths.
问题是,我在得知这一点之前删除了备份文件(因为我的网站仍然运行良好),并从那时起安装了许多插件.因此,我无法恢复原状,因此我想知道两件事:
The thing is, I deleted the backup file just before I learnt about this (as my website was still functioning fine), and installed a number of plugins since. So, there's no way I can revert back, and I therefore would like to know two things:
如果可能的话,我该如何解决这个问题?
How can I fix this, if at all possible?
这会导致什么样的问题?
What kind of problems could this cause?
(这篇文章指出,例如 WordPress 博客,可能会丢失它的设置和小部件.但这似乎并没有发生在我身上,因为我的博客的所有设置仍然完好无损.但我不知道内部可能会损坏什么,或者它会带来什么问题未来.因此这个问题.)
(This article states that, a WordPress blog for instance, could lose its settings and widgets. But this doesn't seem to have happened to me as all the settings for my blog are still intact. But I have no clue as to what could be broken on the inside, or what issues it'd pose in the future. Hence this question.)
推荐答案
访问此页面:http://unserialize.onlinephpfunctions.com/
在该页面上,您应该会看到以下示例序列化字符串:a:1:{s:4:"Test";s:17:"unserialize here!";}
.拿一块——s:4:"Test";
.这意味着字符串",4 个字符,然后是实际的字符串.我很确定您所做的事情导致数字字符计数与字符串不同步.使用上述网站上的工具,例如,如果将Test"更改为Tes",您会看到出现错误.
On that page you should see this sample serialized string: a:1:{s:4:"Test";s:17:"unserialize here!";}
. Take a piece of it-- s:4:"Test";
. That means "string", 4 characters, then the actual string. I am pretty sure that what you did caused the numeric character count to be out of sync with the string. Play with the tool on the site mentioned above and you will see that you get an error if you change "Test" to "Tes", for example.
您需要做的是让这些字符数与您的新字符串匹配.如果您没有损坏任何其他编码(删除冒号或其他内容),那么应该可以解决问题.
What you need to do is get those character counts to match your new string. If you haven't corrupted any of the other encoding-- removed a colon or something-- that should fix the problem.
相关文章