<br />
<b>Warning</b>:  strpos() expects parameter 1 to be string, array given in <b>/home/theserverside/public_html/wp-includes/blocks.php</b> on line <b>20</b><br />
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sql &#8211; The Server Side Technology</title>
	<atom:link href="https://www.theserverside.technology/it/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.theserverside.technology/it</link>
	<description>in-depth information for tech pros</description>
	<lastBuildDate>Tue, 08 Oct 2019 22:32:20 +0000</lastBuildDate>
	<language>it-IT</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.18</generator>
	<item>
		<title>WordPress and MySQL: fixing the wp_options table</title>
		<link>https://www.theserverside.technology/it/2019/10/08/wordpress-and-mysql-fixing-the-wp_options-table/?pk_campaign=feed&#038;pk_kwd=wordpress-and-mysql-fixing-the-wp_options-table</link>
					<comments>https://www.theserverside.technology/it/2019/10/08/wordpress-and-mysql-fixing-the-wp_options-table/?pk_campaign=feed&#038;pk_kwd=wordpress-and-mysql-fixing-the-wp_options-table#respond</comments>
		
		<dc:creator><![CDATA[Guglielmo Mengora]]></dc:creator>
		<pubDate>Tue, 08 Oct 2019 22:32:17 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Web Technologies]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://www.theserverside.technology/?p=1390</guid>

					<description><![CDATA[<div style="margin: 5px 5% 10px 5%;"><img src="https://www.theserverside.technology/wp-content/uploads/2019/10/wordpress-1920-300x199.jpg" width="300" height="199" title="" alt="" /></div><div>
<p class="has-drop-cap">We had a weird problem when moving a WordPress website for a customer: after DUMPing it out of MySQL, we noted that the wp_options table had a problem, namely the table had no primary key and no index on the option_name field. We noted that because the WordPress website, once moved, looked akward and wrong, missing some key pieces and it also seemed to use settings that were old. The reason was that, with primary key missing, lots of duplicate records were stored inside the table and I&#8217;m pretty sure it was not what the website was meant to do. Field option_id was set to 0 in most cases when it should have been an auto-incremented integer plus it seemed that the website was not updating settings, rather it was storing a new copy of them each time.</p>



<p>The akward look was probably due to WordPress not being able to load-up the most recent settings but the weird thing was that it was working like a charm on its existing server. However, we noticed that the source server was running MySQL 5.1 while the destination was instead running MySQL 5.7. MySQL is that weird beast where everything can happen but anyway that 5.1 version was really really old. I would expect such things not to happen in an enterprise world (never had such problems with SQL Server) but&#8230;</p>



The problem



<p>So the first problem we had to solve was re-enabling primary key for field option_id and its indices but we couldn&#8217;t add a primary key on that field since thousands of record were using the same key (zero) so we had to find a way to update them with a unique value. The best solution would be to have consecutive integers though that wouldn&#8217;t ensure that we are restoring the right order. But I&#8217;m afraid there&#8217;s no real way to be sure about that. However, when enumerating records one might assume that the table scan would populate results from the oldest to the newest. Not sure about this but we might try.</p>



<p>So we basically developed a stored procedure that would scan that table and update each record to set a new option_id. One of the key problems with this is that you need to perform only an update at a time because you cannot use any relevant key to uniquely get the record given that option_id is zero. Other fields might be the same for multiple records so for example if we try to select records based on option_name we might have multiple records update with the same option_id and we wouldn&#8217;t solve our problems.</p>



<p>We might just hope that we&#8217;re lucky enough so that scanning for zero keys and updating just a single record would just update in the same order. Anyway, the key to change the table design is to have different keys, it is not strictly necessary to have the same order though quirks might happen if we don&#8217;t do that. The real important thing is to ensure we won&#8217;t [...]<img src="https://stats1.vaisulweb.cloud/piwik.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fwww.theserverside.technology%2Fit%2F2019%2F10%2F08%2Fwordpress-and-mysql-fixing-the-wp_options-table%2F%3Fpk_campaign%3Dfeed%26pk_kwd%3Dwordpress-and-mysql-fixing-the-wp_options-table&amp;action_name=WordPress%20and%20MySQL%3A%20fixing%20the%20wp_options%20table&amp;urlref=https%3A%2F%2Fwww.theserverside.technology%2Fit%2Ffeed%2F" style="border:0;width:0;height:0" width="0" height="0" alt="" /></div>]]></description>
		
					<wfw:commentRss>https://www.theserverside.technology/it/2019/10/08/wordpress-and-mysql-fixing-the-wp_options-table/?pk_campaign=feed&#038;pk_kwd=wordpress-and-mysql-fixing-the-wp_options-table/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<enclosure url="https://www.theserverside.technology/wp-content/uploads/2019/10/wordpress-1920.jpg" length="417896" type="image/jpg" />
<media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://www.theserverside.technology/wp-content/uploads/2019/10/wordpress-1920-300x199.jpg" width="300" height="199" medium="image" type="image/jpeg">
	<media:copyright>The Server Side Technology</media:copyright>
	<media:title></media:title>
	<media:description type="html"><![CDATA[]]></media:description>
</media:content>
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.theserverside.technology/wp-content/uploads/2019/10/wordpress-1920-300x199.jpg" width="300" height="199" />
	</item>
	</channel>
</rss>
