Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix serialized data broken due to editing MySQL database in a text editor?

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_).

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:

  1. How can I fix this, if at all possible?

  2. What kind of problems could this cause?

(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.)

like image 334
its_me Avatar asked Feb 28 '13 15:02

its_me


People also ask

How does MySQL store serialized data?

The workaround: use MEDIUMBLOB or just BLOB , as long as those types are sufficient to store your serialized data. Associate serialized data with other more relational data. Ability to store and fetch serialized data according to transaction scope, COMMIT, ROLLBACK.

What is serialization in MySQL?

In addition to storing metadata about database objects in the data dictionary, MySQL stores it in serialized form. This data is referred to as serialized dictionary information (SDI). InnoDB stores SDI data within its tablespace files. NDBCLUSTER stores SDI data in the NDB dictionary.

What is serialized in Wordpress?

Developers often choose to store specific information in the database like theme options, or settings. Typically this data is serialized in the database so it can be copied or restored easily without compromising the integrity of the information.


1 Answers

Visit this page: http://unserialize.onlinephpfunctions.com/

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.

like image 153
s_ha_dum Avatar answered Nov 02 '22 21:11

s_ha_dum