<?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>Autarchy of the Private Cave &#187; mysql</title> <atom:link href="https://bogdan.org.ua/tags/mysql/feed" rel="self" type="application/rss+xml" /><link>https://bogdan.org.ua</link> <description>Tiny bits of bioinformatics, [web-]programming etc</description> <lastBuildDate>Wed, 28 Dec 2022 16:09:04 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>https://wordpress.org/?v=3.8.27</generator> <item><title>MySQL as NoSQL with HandlerSocket: 750000 qps</title><link>https://bogdan.org.ua/2011/01/25/mysql-as-nosql-with-handlersocket-750000-qps.html</link> <comments>https://bogdan.org.ua/2011/01/25/mysql-as-nosql-with-handlersocket-750000-qps.html#comments</comments> <pubDate>Tue, 25 Jan 2011 16:36:11 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[HandlerSocket]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[NoSQL]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=1348</guid> <description><![CDATA[HandlerSocket provides a direct access to InnoDB storage, bypassing SQL interpretation layer. With in-RAM data, it may raise MySQL performance to 750000 queries per second.]]></description> <content:encoded><![CDATA[<p>HandlerSocket provides a direct access to InnoDB storage, bypassing SQL interpretation layer. With in-RAM data, it may <a
href="http://yoshinorimatsunobu.blogspot.com/2010/10/using-mysql-as-nosql-story-for.html">raise MySQL performance to 750000 queries per second</a>.</p><p><a
href="http://bogdan.org.ua/wp-content/uploads/2011/01/mysql_handlersocket.png"><img
src="http://bogdan.org.ua/wp-content/uploads/2011/01/mysql_handlersocket-500x299.png" alt="" title="mysql_handlersocket" width="500" height="299" class="alignleft size-medium wp-image-1351" /></a></p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmysql-as-nosql-with-handlersocket-750000-qps.html&amp;linkname=MySQL%20as%20NoSQL%20with%20HandlerSocket%3A%20750000%20qps" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmysql-as-nosql-with-handlersocket-750000-qps.html&amp;linkname=MySQL%20as%20NoSQL%20with%20HandlerSocket%3A%20750000%20qps" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmysql-as-nosql-with-handlersocket-750000-qps.html&amp;linkname=MySQL%20as%20NoSQL%20with%20HandlerSocket%3A%20750000%20qps" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmysql-as-nosql-with-handlersocket-750000-qps.html&amp;linkname=MySQL%20as%20NoSQL%20with%20HandlerSocket%3A%20750000%20qps" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmysql-as-nosql-with-handlersocket-750000-qps.html&amp;linkname=MySQL%20as%20NoSQL%20with%20HandlerSocket%3A%20750000%20qps" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmysql-as-nosql-with-handlersocket-750000-qps.html&#038;title=MySQL%20as%20NoSQL%20with%20HandlerSocket%3A%20750000%20qps" data-a2a-url="https://bogdan.org.ua/2011/01/25/mysql-as-nosql-with-handlersocket-750000-qps.html" data-a2a-title="MySQL as NoSQL with HandlerSocket: 750000 qps"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2011/01/25/mysql-as-nosql-with-handlersocket-750000-qps.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>MongoDB is web-scale</title><link>https://bogdan.org.ua/2011/01/25/mongodb-is-web-scale.html</link> <comments>https://bogdan.org.ua/2011/01/25/mongodb-is-web-scale.html#comments</comments> <pubDate>Mon, 24 Jan 2011 22:58:41 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[Misc]]></category> <category><![CDATA[MongoDB]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[NoSQL]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=1344</guid> <description><![CDATA[Disclaimer: don&#8217;t take this video seriously.]]></description> <content:encoded><![CDATA[<p>Disclaimer: don&#8217;t take this video seriously.</p><p><object
width="480" height="390"><param
name="movie" value="http://www.xtranormal.com/site_media/players/jwplayer.swf"></param><param
name="allowFullScreen" value="true"></param><param
name="allowscriptaccess" value="always"></param><param
name="flashvars"value="height=390&#038;width=480&#038;file=http://newvideos.xtranormal.com/web_final_lo/574b3910-afc9-11df-914b-003048d69c21_27_web_final_lo_web_finallo-flv.flv&#038;image=http://newvideos.xtranormal.com/web_final_lo/574b3910-afc9-11df-914b-003048d69c21_27_web_final_lo_poster.jpg&#038;link=http://www.xtranormal.com/watch/6995033&#038;searchbar=false&#038;autostart=false"/><embed
src="http://www.xtranormal.com/site_media/players/jwplayer.swf" width="480" height="390" allowscriptaccess="always" allowfullscreen="true" flashvars="height=390&#038;width=480&#038;file=http://newvideos.xtranormal.com/web_final_lo/574b3910-afc9-11df-914b-003048d69c21_27_web_final_lo_web_finallo-flv.flv&#038;image=http://newvideos.xtranormal.com/web_final_lo/574b3910-afc9-11df-914b-003048d69c21_27_web_final_lo_poster.jpg&#038;link=http://www.xtranormal.com/watch/6995033&#038;searchbar=false&#038;autostart=false"></embed></object><object
width="480" height="390"><param
name="movie" value="http://www.xtranormal.com/site_media/players/embedded-xnl-stats.swf"></param><param
name="allowFullScreen" value="true"></param><param
name="allowscriptaccess" value="always"></param><embed
src="http://www.xtranormal.com/site_media/players/embedded-xnl-stats.swf" width="1" height="1" allowscriptaccess="always"></embed></object></p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmongodb-is-web-scale.html&amp;linkname=MongoDB%20is%20web-scale" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmongodb-is-web-scale.html&amp;linkname=MongoDB%20is%20web-scale" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmongodb-is-web-scale.html&amp;linkname=MongoDB%20is%20web-scale" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmongodb-is-web-scale.html&amp;linkname=MongoDB%20is%20web-scale" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmongodb-is-web-scale.html&amp;linkname=MongoDB%20is%20web-scale" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2011%2F01%2F25%2Fmongodb-is-web-scale.html&#038;title=MongoDB%20is%20web-scale" data-a2a-url="https://bogdan.org.ua/2011/01/25/mongodb-is-web-scale.html" data-a2a-title="MongoDB is web-scale"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2011/01/25/mongodb-is-web-scale.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Search and replace in a MySQL table</title><link>https://bogdan.org.ua/2009/10/27/search-and-replace-in-a-mysql-table.html</link> <comments>https://bogdan.org.ua/2009/10/27/search-and-replace-in-a-mysql-table.html#comments</comments> <pubDate>Tue, 27 Oct 2009 07:37:34 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[how-to]]></category> <category><![CDATA[Notepad]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[replace]]></category> <category><![CDATA[search]]></category> <category><![CDATA[snippet]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=917</guid> <description><![CDATA[This query performs a table-wide search-and-repalce: UPDATE `table_name` SET `table_field` = REPLACE(`table_field`,&#8217;string to search for and replace&#8217;,'replacement string&#8217;); If you need a database-wide search-and-replace, you could try this script (I haven&#8217;t tested/used it myself). Beware of the following gotchas: wrong query syntax may ruin the field you are performing replace on, so always backup first! [&#8230;]]]></description> <content:encoded><![CDATA[<p>This query performs a table-wide search-and-repalce:</p><blockquote><p>UPDATE `table_name` SET `table_field` = REPLACE(`table_field`,&#8217;string to search for and replace&#8217;,'replacement string&#8217;);</p></blockquote><p>If you need a database-wide search-and-replace, you could try <a
href="http://blog.irmsgeekwork.com/phpmysql-full-database-search-and-replace" class="broken_link" rel="nofollow">this script</a> (I haven&#8217;t tested/used it myself).</p><p>Beware of the following gotchas:</p><ol><li>wrong query syntax may ruin the field you are performing replace on, so <strong>always backup first!</strong></li><li>be sure to provide &#8220;search-for&#8221; string as specific as possible, or you will get<strong> unexpected replacements</strong> (e.g. replacing <em>mini</em> with <em>little</em> will also convert all <em>minivans</em> into <em>littlevans</em>); also, do use WHERE clause when necessary to limit the number of rows modified</li><li>the function in the example is <strong>case-sensitive</strong>, so replacing all <em>minivans</em> with <em>vehicles</em> won&#8217;t replace <em>Minivans</em>. However, I believe there exists a case-insensitive version of REPLACE function</li></ol><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F10%2F27%2Fsearch-and-replace-in-a-mysql-table.html&amp;linkname=Search%20and%20replace%20in%20a%20MySQL%20table" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F10%2F27%2Fsearch-and-replace-in-a-mysql-table.html&amp;linkname=Search%20and%20replace%20in%20a%20MySQL%20table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F10%2F27%2Fsearch-and-replace-in-a-mysql-table.html&amp;linkname=Search%20and%20replace%20in%20a%20MySQL%20table" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F10%2F27%2Fsearch-and-replace-in-a-mysql-table.html&amp;linkname=Search%20and%20replace%20in%20a%20MySQL%20table" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F10%2F27%2Fsearch-and-replace-in-a-mysql-table.html&amp;linkname=Search%20and%20replace%20in%20a%20MySQL%20table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2009%2F10%2F27%2Fsearch-and-replace-in-a-mysql-table.html&#038;title=Search%20and%20replace%20in%20a%20MySQL%20table" data-a2a-url="https://bogdan.org.ua/2009/10/27/search-and-replace-in-a-mysql-table.html" data-a2a-title="Search and replace in a MySQL table"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2009/10/27/search-and-replace-in-a-mysql-table.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to fix &#8220;MySQL server has gone away&#8221; (error 2006)</title><link>https://bogdan.org.ua/2008/12/25/how-to-fix-mysql-server-has-gone-away-error-2006.html</link> <comments>https://bogdan.org.ua/2008/12/25/how-to-fix-mysql-server-has-gone-away-error-2006.html#comments</comments> <pubDate>Thu, 25 Dec 2008 16:34:08 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Debian]]></category> <category><![CDATA[error]]></category> <category><![CDATA[fix]]></category> <category><![CDATA[mysql]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=464</guid> <description><![CDATA[Source: George from vbulletin team. Two most common reasons (and fixes) for the MySQL server has gone away (error 2006) are: Server timed out and closed the connection. How to fix: check that wait_timeout variable in your mysqld&#8217;s my.cnf configuration file is large enough. On Debian: sudo nano /etc/mysql/my.cnf, set wait_timeout = 600 seconds (you [&#8230;]]]></description> <content:encoded><![CDATA[<p>Source: <a
href="http://www.vbulletin.com/forum/member.php?u=245" class="broken_link" rel="nofollow">George</a> from <a
href="http://www.vbulletin.com/forum/showthread.php?t=70410" class="broken_link" rel="nofollow">vbulletin team</a>.</p><p>Two most common reasons (and fixes) for the <strong>MySQL server has gone away (error 2006)</strong> are:</p><ol><li>Server timed out and closed the connection. How to fix: check that <strong>wait_timeout</strong> variable in your mysqld&#8217;s my.cnf configuration file is large enough. On Debian: <strong>sudo nano /etc/mysql/my.cnf</strong>, set <strong>wait_timeout = 600</strong> seconds (you can tweak/decrease this value when error 2006 is gone), then <strong>sudo /etc/init.d/mysql restart</strong>. I didn&#8217;t check, but the maximal value for <strong>wait_timeout</strong> might be around 28800 seconds (8 hours).</li><li>Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection. You can increase the maximal packet size limit by increasing the value of <strong>max_allowed_packet</strong> in my.cnf file. On Debian: <strong>sudo nano /etc/mysql/my.cnf</strong>, set <strong>max_allowed_packet = 64M</strong> (you can tweak/decrease this value when error 2006 is gone), then <strong>sudo /etc/init.d/mysql restart</strong>.</li></ol><p>If you get <strong>MySQL server has gone away (error 2006)</strong> when using MySQL ODBC driver &#8211; give <a
href="http://bogdan.org.ua/2008/12/25/how-to-fix-mysql-server-has-gone-away-error-2006.html#comment-103489">this hint</a> a try.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F12%2F25%2Fhow-to-fix-mysql-server-has-gone-away-error-2006.html&amp;linkname=How%20to%20fix%20%E2%80%9CMySQL%20server%20has%20gone%20away%E2%80%9D%20%28error%202006%29" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F12%2F25%2Fhow-to-fix-mysql-server-has-gone-away-error-2006.html&amp;linkname=How%20to%20fix%20%E2%80%9CMySQL%20server%20has%20gone%20away%E2%80%9D%20%28error%202006%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F12%2F25%2Fhow-to-fix-mysql-server-has-gone-away-error-2006.html&amp;linkname=How%20to%20fix%20%E2%80%9CMySQL%20server%20has%20gone%20away%E2%80%9D%20%28error%202006%29" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F12%2F25%2Fhow-to-fix-mysql-server-has-gone-away-error-2006.html&amp;linkname=How%20to%20fix%20%E2%80%9CMySQL%20server%20has%20gone%20away%E2%80%9D%20%28error%202006%29" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F12%2F25%2Fhow-to-fix-mysql-server-has-gone-away-error-2006.html&amp;linkname=How%20to%20fix%20%E2%80%9CMySQL%20server%20has%20gone%20away%E2%80%9D%20%28error%202006%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2008%2F12%2F25%2Fhow-to-fix-mysql-server-has-gone-away-error-2006.html&#038;title=How%20to%20fix%20%E2%80%9CMySQL%20server%20has%20gone%20away%E2%80%9D%20%28error%202006%29" data-a2a-url="https://bogdan.org.ua/2008/12/25/how-to-fix-mysql-server-has-gone-away-error-2006.html" data-a2a-title="How to fix “MySQL server has gone away” (error 2006)"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2008/12/25/how-to-fix-mysql-server-has-gone-away-error-2006.html/feed</wfw:commentRss> <slash:comments>54</slash:comments> </item> <item><title>Less than an hour of GoDaddy MySQL5 database downtime today</title><link>https://bogdan.org.ua/2008/03/26/less-than-an-hour-of-godaddy-mysql5-database-downtime-today.html</link> <comments>https://bogdan.org.ua/2008/03/26/less-than-an-hour-of-godaddy-mysql5-database-downtime-today.html#comments</comments> <pubDate>Wed, 26 Mar 2008 13:04:08 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[Misc]]></category> <category><![CDATA[downtime]]></category> <category><![CDATA[godaddy]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[PHP]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2008/03/26/less-than-an-hour-of-godaddy-mysql5-database-downtime-today.html</guid> <description><![CDATA[Must have been some maintenance, as I didn&#8217;t notice any changes in PHP/MySQL versions since the 7th of March. Update: it seems as though since that short MySQL outage everything is faster at GoDaddy shared hosting. Did they upgrade database server(s)? I have no idea, but I like the change.]]></description> <content:encoded><![CDATA[<p>Must have been some maintenance, as I didn&#8217;t notice any changes in PHP/MySQL versions since the 7th of March.</p><p><ins
datetime="2008-04-06T07:01:54+00:00">Update:</ins> it seems as though since that short MySQL outage everything is faster at GoDaddy shared hosting. Did they upgrade database server(s)? I have no idea, but I like the change.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F26%2Fless-than-an-hour-of-godaddy-mysql5-database-downtime-today.html&amp;linkname=Less%20than%20an%20hour%20of%20GoDaddy%20MySQL5%20database%20downtime%20today" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F26%2Fless-than-an-hour-of-godaddy-mysql5-database-downtime-today.html&amp;linkname=Less%20than%20an%20hour%20of%20GoDaddy%20MySQL5%20database%20downtime%20today" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F26%2Fless-than-an-hour-of-godaddy-mysql5-database-downtime-today.html&amp;linkname=Less%20than%20an%20hour%20of%20GoDaddy%20MySQL5%20database%20downtime%20today" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F26%2Fless-than-an-hour-of-godaddy-mysql5-database-downtime-today.html&amp;linkname=Less%20than%20an%20hour%20of%20GoDaddy%20MySQL5%20database%20downtime%20today" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F26%2Fless-than-an-hour-of-godaddy-mysql5-database-downtime-today.html&amp;linkname=Less%20than%20an%20hour%20of%20GoDaddy%20MySQL5%20database%20downtime%20today" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F26%2Fless-than-an-hour-of-godaddy-mysql5-database-downtime-today.html&#038;title=Less%20than%20an%20hour%20of%20GoDaddy%20MySQL5%20database%20downtime%20today" data-a2a-url="https://bogdan.org.ua/2008/03/26/less-than-an-hour-of-godaddy-mysql5-database-downtime-today.html" data-a2a-title="Less than an hour of GoDaddy MySQL5 database downtime today"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2008/03/26/less-than-an-hour-of-godaddy-mysql5-database-downtime-today.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>How to improve MySQL application performance</title><link>https://bogdan.org.ua/2008/03/06/how-to-improve-mysql-application-perfromance-performance.html</link> <comments>https://bogdan.org.ua/2008/03/06/how-to-improve-mysql-application-perfromance-performance.html#comments</comments> <pubDate>Thu, 06 Mar 2008 14:48:43 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[application]]></category> <category><![CDATA[developer]]></category> <category><![CDATA[hints]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[presentation]]></category> <category><![CDATA[storage engine]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2008/03/06/how-to-improve-mysql-application-perfromance.html</guid> <description><![CDATA[Juicy presentation, even for seasoned MySQL developers. &#124; View You can also download the PDF version of the presentation. Many more MySQL performance presentations.]]></description> <content:encoded><![CDATA[<p>Juicy presentation, even for seasoned MySQL developers.</p><div
style="margin-bottom: 15px;width:425px;text-align:left" id="__ss_245799"><object
style="margin:0px" width="425" height="355"><param
name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=how-to-kill-mysql-performance-1201635569837936-3"/><param
name="allowFullScreen" value="true"/><param
name="allowScriptAccess" value="always"/><embed
src="http://static.slideshare.net/swf/ssplayer2.swf?doc=how-to-kill-mysql-performance-1201635569837936-3" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object><div
style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a
href="http://www.slideshare.net/?src=embed"><img
src="http://static.slideshare.net/swf/logo_embd.png" style="border:0px none;margin-bottom:-5px" alt="SlideShare"/></a> | <a
href="http://www.slideshare.net/techdude/how-to-kill-mysql-performance?src=embed" title="View 'How to Kill Mysql Performance' on SlideShare">View</a></div></div><p><span
id="more-269"></span><br
/> You can also download the <a
href="http://bogdan.org.ua/wp-content/uploads/2008/03/jay_pipes-kill_mysql_performance.pdf" title="15 ways to kill MySQL application performance">PDF version of the presentation</a>.</p><p>Many more <a
href="http://www.mysqlperformanceblog.com/mysql-performance-presentations/">MySQL performance presentations</a>.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F06%2Fhow-to-improve-mysql-application-perfromance-performance.html&amp;linkname=How%20to%20improve%20MySQL%20application%20performance" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F06%2Fhow-to-improve-mysql-application-perfromance-performance.html&amp;linkname=How%20to%20improve%20MySQL%20application%20performance" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F06%2Fhow-to-improve-mysql-application-perfromance-performance.html&amp;linkname=How%20to%20improve%20MySQL%20application%20performance" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F06%2Fhow-to-improve-mysql-application-perfromance-performance.html&amp;linkname=How%20to%20improve%20MySQL%20application%20performance" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F06%2Fhow-to-improve-mysql-application-perfromance-performance.html&amp;linkname=How%20to%20improve%20MySQL%20application%20performance" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F06%2Fhow-to-improve-mysql-application-perfromance-performance.html&#038;title=How%20to%20improve%20MySQL%20application%20performance" data-a2a-url="https://bogdan.org.ua/2008/03/06/how-to-improve-mysql-application-perfromance-performance.html" data-a2a-title="How to improve MySQL application performance"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2008/03/06/how-to-improve-mysql-application-perfromance-performance.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Convert MySQL database from one encoding/collation into another</title><link>https://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html</link> <comments>https://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html#comments</comments> <pubDate>Fri, 08 Feb 2008 19:17:45 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[Notepad]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[collation]]></category> <category><![CDATA[convert]]></category> <category><![CDATA[database]]></category> <category><![CDATA[encoding]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[latin1]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[script]]></category> <category><![CDATA[utf8]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html</guid> <description><![CDATA[Most frequent use: convert database from latin1_swedish to utf8_general_ci. Original script found at: MySQL and UTF-8. Update: the original script had an error, it would generate queries likes this one (note the bold part): ALTER TABLE `links` CHANGE `link_rel` `link_rel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT NULL; This is clearly wrong syntax [&#8230;]]]></description> <content:encoded><![CDATA[<p>Most frequent use: <a
title="self-link" href="http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html">convert database from latin1_swedish to utf8_general_ci</a>.<br
/> Original script found at: <a
href="http://www.phpwact.org/php/i18n/utf-8/mysql" class="broken_link" rel="nofollow">MySQL and UTF-8</a>.</p><p><ins
datetime="2008-02-22T21:50:28+00:00">Update:</ins> the original script <u>had an error</u>, it would generate queries likes this one (note the bold part):</p><blockquote><p>ALTER TABLE `links` CHANGE `link_rel` `link_rel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci <strong>NOT NULL  DEFAULT NULL</strong>;</p></blockquote><p>This is clearly wrong syntax (and logic). I fixed this by making comparison to NULL strict (with three equal signs instead of two):</p><blockquote><p> // Does the field default to null, a string, or nothing?<br
/> if ($row['Default'] === NULL)</p></blockquote><p><ins
datetime="2008-06-27T07:23:50+00:00">Update 2:</ins> based on comment by <em>banesto</em>, I modified the script; now it does not require specifying the from_collation, it&#8217;s sufficient to specify to_collation (which will be used for all the fields and tables). The modified code is:</p><blockquote><p>if ($row['Collation'] == &#8221; || $row['Collation'] == $convert_to)<br
/> continue;</p></blockquote><p><ins
datetime="2010-06-28T11:58:11+00:00">Update 3:</ins> the long-lasting, re-appearing NOT NULL DEFAULT NULL problem is finally fixed.</p><p><ins
datetime="2010-06-28T12:11:38+00:00">Update 4:</ins> incorporated Russ&#8217;s fix to skip numeric fields (in order to leave autoincrement values intact).</p><p>Here&#8217;s the script itself: (to copy-paste: first click the &#8220;Plain text&#8221; header)<br
/> <span
id="more-255"></span></p><div
id="ig-sh-1" class="syntax_hilite"><div
class="code"><ol
class="php" style="font-family:monospace;"><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000000; font-weight: bold;">&lt;?php</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// Original script (v1.0) by/from: http://www.phpwact.org/php/i18n/utf-8/mysql</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// Improved/modified (v1.05) by Bogdan http://bogdan.org.ua/</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// Last updated: 2010-06-28</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// this script will output all queries needed to change all fields/tables to a different collation</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// it is HIGHLY suggested you make a MySQL backup prior to running any of the generated queries</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// this code is provided AS IS and without any warranty</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// add text/plain header when used not as a CLI script; PHP CLI SAPI shouldn't output headers</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #990000;">header</span><span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">&quot;Content-Type: text/plain&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// precaution</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #990000;">die</span><span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">&quot;Make a backup of your MySQL database, then remove this line from the code!&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #990000;">set_time_limit</span><span
style="color: #009900;">&#40;</span><span
style="color: #cc66cc;">0</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// collation you want to change to:</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$convert_to</span> &nbsp; <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">'utf8_general_ci'</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// character set of new collation:</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$character_set</span><span
style="color: #339933;">=</span> <span
style="color: #0000ff;">'utf8'</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// DB login information - *modify before use*</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$username</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">'user'</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$password</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">'pass'</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$database</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">'database_name'</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$host</span> &nbsp; &nbsp; <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">'localhost'</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">//-- usually, there is nothing to modify below this line --//</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// show TABLE alteration queries?</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$show_alter_table</span> <span
style="color: #339933;">=</span> <span
style="color: #009900; font-weight: bold;">true</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #666666; font-style: italic;">// show FIELD alteration queries?</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$show_alter_field</span> <span
style="color: #339933;">=</span> <span
style="color: #009900; font-weight: bold;">true</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #990000;">mysql_connect</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$host</span><span
style="color: #339933;">,</span> <span
style="color: #000088;">$username</span><span
style="color: #339933;">,</span> <span
style="color: #000088;">$password</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #990000;">mysql_select_db</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$database</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000088;">$rs_tables</span> <span
style="color: #339933;">=</span> <span
style="color: #990000;">mysql_query</span><span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">&quot; SHOW TABLES &quot;</span><span
style="color: #009900;">&#41;</span> or <span
style="color: #990000;">die</span><span
style="color: #009900;">&#40;</span><span
style="color: #990000;">mysql_error</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #b1b100;">while</span> <span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$row_tables</span> <span
style="color: #339933;">=</span> <span
style="color: #990000;">mysql_fetch_row</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$rs_tables</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#123;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #000088;">$table</span> <span
style="color: #339933;">=</span> <span
style="color: #990000;">mysql_real_escape_string</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$row_tables</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;0&amp;#93;);</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #666666; font-style: italic;">// Alter table collation</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #666666; font-style: italic;">// ALTER TABLE `account` DEFAULT CHARACTER SET utf8</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$show_alter_table</span><span
style="color: #009900;">&#41;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">echo</span><span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">&quot;ALTER TABLE `<span
style="color: #006699; font-weight: bold;">$table</span>` DEFAULT CHARACTER SET <span
style="color: #006699; font-weight: bold;">$character_set</span>;<span
style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #000088;">$rs</span> <span
style="color: #339933;">=</span> <span
style="color: #990000;">mysql_query</span><span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">&quot; SHOW FULL FIELDS FROM `<span
style="color: #006699; font-weight: bold;">$table</span>` &quot;</span><span
style="color: #009900;">&#41;</span> or <span
style="color: #990000;">die</span><span
style="color: #009900;">&#40;</span><span
style="color: #990000;">mysql_error</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #b1b100;">while</span> <span
style="color: #009900;">&#40;</span> <span
style="color: #000088;">$row</span> <span
style="color: #339933;">=</span> <span
style="color: #990000;">mysql_fetch_assoc</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$rs</span><span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#123;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span> <span
style="color: #000088;">$row</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;'Collation'&amp;#93; == '' || $row&amp;#91;'Collation'&amp;#93; == $convert_to )</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #b1b100;">continue</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;">// Is the field allowed to be null?</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span> <span
style="color: #000088;">$row</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;'Null'&amp;#93; == 'YES' )</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #000088;">$nullable</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">' NULL '</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">else</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000088;">$nullable</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">' NOT NULL '</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;">// Does the field default to null, a string, or nothing?</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span> <span
style="color: #000088;">$row</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;'Default'&amp;#93; === NULL &amp;&amp; $row&amp;#91;'Null'&amp;#93; == 'YES' )</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #000088;">$default</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">&quot; DEFAULT NULL &quot;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">elseif</span> <span
style="color: #009900;">&#40;</span> <span
style="color: #000088;">$row</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;'Default'&amp;#93; != '' )</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #000088;">$default</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">&quot; DEFAULT '&quot;</span><span
style="color: #339933;">.</span><span
style="color: #990000;">mysql_real_escape_string</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$row</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;'Default'&amp;#93;).&quot;'&quot;;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #b1b100;">else</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000088;">$default</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">''</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;">// sanity check and fix:</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$nullable</span> <span
style="color: #339933;">==</span> <span
style="color: #0000ff;">' NOT NULL '</span> <span
style="color: #339933;">&amp;&amp;</span> <span
style="color: #000088;">$default</span> <span
style="color: #339933;">==</span> <span
style="color: #0000ff;">' DEFAULT NULL '</span><span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#123;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000088;">$default</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">''</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">echo</span> <span
style="color: #0000ff;">&quot;/* Warning: wrong combination of 'default value' and 'NULL-flag' detected - and fixed! */<span
style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">echo</span> <span
style="color: #0000ff;">&quot;/* Diagnostics: row&amp;#91;Null&amp;#93; = '<span
style="color: #006699; font-weight: bold;">$row</span>&amp;#91;Null&amp;#93;', row&amp;#91;Default&amp;#93; = &quot;</span> <span
style="color: #339933;">.</span> <span
style="color: #990000;">mysql_real_escape_string</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$row</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;'Default'&amp;#93;) . &quot;, MySQL version: &quot; . mysql_get_server_info() . &quot; */\n&quot;;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #009900;">&#125;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;">// Don't alter INT columns: no collations, and altering them drops autoincrement values</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #990000;">strpos</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$row</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;'Type'&amp;#93;, 'int') !== false) {</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #000088;">$show_alter_field</span> <span
style="color: #339933;">=</span> <span
style="color: #009900; font-weight: bold;">False</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">else</span> <span
style="color: #009900;">&#123;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000088;">$show_alter_field</span> <span
style="color: #339933;">=</span> <span
style="color: #009900; font-weight: bold;">True</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;">// Alter field collation:</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;">// ALTER TABLE `tab` CHANGE `field` `field` CHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$show_alter_field</span><span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#123;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000088;">$field</span> <span
style="color: #339933;">=</span> <span
style="color: #990000;">mysql_real_escape_string</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$row</span><span
style="color: #339933;">&amp;</span><span
style="color: #666666; font-style: italic;">#91;'Field'&amp;#93;);</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #b1b100;">echo</span> <span
style="color: #0000ff;">&quot;ALTER TABLE `<span
style="color: #006699; font-weight: bold;">$table</span>` CHANGE `<span
style="color: #006699; font-weight: bold;">$field</span>` `<span
style="color: #006699; font-weight: bold;">$field</span>` <span
style="color: #006699; font-weight: bold;">$row</span>&amp;#91;Type&amp;#93; CHARACTER SET <span
style="color: #006699; font-weight: bold;">$character_set</span> COLLATE <span
style="color: #006699; font-weight: bold;">$convert_to</span> <span
style="color: #006699; font-weight: bold;">$nullable</span> <span
style="color: #006699; font-weight: bold;">$default</span>;<span
style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span
style="color: #339933;">;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #009900;">&#125;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #009900;">&#125;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #000000; font-weight: bold;">?&gt;</span></div></li></ol></div></div><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F02%2F08%2Fconvert-mysql-database-from-one-encodingcollation-into-another.html&amp;linkname=Convert%20MySQL%20database%20from%20one%20encoding%2Fcollation%20into%20another" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F02%2F08%2Fconvert-mysql-database-from-one-encodingcollation-into-another.html&amp;linkname=Convert%20MySQL%20database%20from%20one%20encoding%2Fcollation%20into%20another" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F02%2F08%2Fconvert-mysql-database-from-one-encodingcollation-into-another.html&amp;linkname=Convert%20MySQL%20database%20from%20one%20encoding%2Fcollation%20into%20another" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F02%2F08%2Fconvert-mysql-database-from-one-encodingcollation-into-another.html&amp;linkname=Convert%20MySQL%20database%20from%20one%20encoding%2Fcollation%20into%20another" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2008%2F02%2F08%2Fconvert-mysql-database-from-one-encodingcollation-into-another.html&amp;linkname=Convert%20MySQL%20database%20from%20one%20encoding%2Fcollation%20into%20another" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2008%2F02%2F08%2Fconvert-mysql-database-from-one-encodingcollation-into-another.html&#038;title=Convert%20MySQL%20database%20from%20one%20encoding%2Fcollation%20into%20another" data-a2a-url="https://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html" data-a2a-title="Convert MySQL database from one encoding/collation into another"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html/feed</wfw:commentRss> <slash:comments>60</slash:comments> </item> <item><title>MySQL: INSERT IF NOT EXISTS syntax</title><link>https://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html</link> <comments>https://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html#comments</comments> <pubDate>Thu, 18 Oct 2007 13:20:21 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[database]]></category> <category><![CDATA[example]]></category> <category><![CDATA[examples]]></category> <category><![CDATA[exists]]></category> <category><![CDATA[insert]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[problem]]></category> <category><![CDATA[syntax]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html</guid> <description><![CDATA[To start: as of the latest MySQL, syntax presented in the title is not possible. But there are several very easy ways to accomplish what is expected using existing functionality. There are 3 possible solutions: using INSERT IGNORE, REPLACE, or INSERT &#8230; ON DUPLICATE KEY UPDATE. Imagine we have a table: CREATE TABLE `transcripts` &#40; [&#8230;]]]></description> <content:encoded><![CDATA[<p>To start: as of the latest MySQL, syntax presented in the title is not possible. But there are several very easy ways to accomplish what is expected using existing functionality.</p><p>There are 3 possible solutions: using INSERT IGNORE, REPLACE, or INSERT &#8230; ON DUPLICATE KEY UPDATE.</p><p>Imagine we have a table:</p><div
id="ig-sh-2" class="syntax_hilite"><div
class="code"><ol
class="sql" style="font-family:monospace;"><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #ff0000;">`transcripts`</span> <span
style="color: #66cc66;">&#40;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;<span
style="color: #ff0000;">`ensembl_transcript_id`</span> <span
style="color: #993333; font-weight: bold;">varchar</span><span
style="color: #66cc66;">&#40;</span><span
style="color: #cc66cc;">20</span><span
style="color: #66cc66;">&#41;</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">NULL</span><span
style="color: #66cc66;">,</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;<span
style="color: #ff0000;">`transcript_chrom_start`</span> <span
style="color: #993333; font-weight: bold;">int</span><span
style="color: #66cc66;">&#40;</span><span
style="color: #cc66cc;">10</span><span
style="color: #66cc66;">&#41;</span> <span
style="color: #993333; font-weight: bold;">unsigned</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">NULL</span><span
style="color: #66cc66;">,</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;<span
style="color: #ff0000;">`transcript_chrom_end`</span> <span
style="color: #993333; font-weight: bold;">int</span><span
style="color: #66cc66;">&#40;</span><span
style="color: #cc66cc;">10</span><span
style="color: #66cc66;">&#41;</span> <span
style="color: #993333; font-weight: bold;">unsigned</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">NULL</span><span
style="color: #66cc66;">,</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;<span
style="color: #993333; font-weight: bold;">PRIMARY</span> <span
style="color: #993333; font-weight: bold;">KEY</span> &nbsp;<span
style="color: #66cc66;">&#40;</span><span
style="color: #ff0000;">`ensembl_transcript_id`</span><span
style="color: #66cc66;">&#41;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #66cc66;">&#41;</span> ENGINE<span
style="color: #66cc66;">=</span>InnoDB <span
style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span
style="color: #66cc66;">=</span>latin1;</div></li></ol></div></div><p>Now imagine that we have an automatic pipeline importing transcripts meta-data from Ensembl, and that due to various reasons the pipeline might be broken at any step of execution. Thus, we need to ensure two things: 1) repeated executions of the pipeline will not destroy our database, and 2) repeated executions will not die due to &#8216;duplicate primary key&#8217; errors.</p><p>Method 1: using REPLACE<br
/> <span
id="more-238"></span><br
/> It&#8217;s very simple:</p><div
id="ig-sh-3" class="syntax_hilite"><div
class="code"><ol
class="sql" style="font-family:monospace;"><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #993333; font-weight: bold;">REPLACE</span> <span
style="color: #993333; font-weight: bold;">INTO</span> <span
style="color: #ff0000;">`transcripts`</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #993333; font-weight: bold;">SET</span> <span
style="color: #ff0000;">`ensembl_transcript_id`</span> <span
style="color: #66cc66;">=</span> <span
style="color: #ff0000;">'ENSORGT00000000001'</span><span
style="color: #66cc66;">,</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff0000;">`transcript_chrom_start`</span> <span
style="color: #66cc66;">=</span> <span
style="color: #cc66cc;">12345</span><span
style="color: #66cc66;">,</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff0000;">`transcript_chrom_end`</span> <span
style="color: #66cc66;">=</span> <span
style="color: #cc66cc;">12678</span>;</div></li></ol></div></div><p>If the record exists, it will be overwritten; if it does not yet exist, it will be created.<br
/> However, using this method isn&#8217;t efficient for our case: we do not need to overwrite existing records, it&#8217;s fine just to skip them.</p><p>Method 2: using INSERT IGNORE<br
/> Also very simple:</p><div
id="ig-sh-4" class="syntax_hilite"><div
class="code"><ol
class="sql" style="font-family:monospace;"><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #993333; font-weight: bold;">INSERT</span> <span
style="color: #993333; font-weight: bold;">IGNORE</span> <span
style="color: #993333; font-weight: bold;">INTO</span> <span
style="color: #ff0000;">`transcripts`</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #993333; font-weight: bold;">SET</span> <span
style="color: #ff0000;">`ensembl_transcript_id`</span> <span
style="color: #66cc66;">=</span> <span
style="color: #ff0000;">'ENSORGT00000000001'</span><span
style="color: #66cc66;">,</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff0000;">`transcript_chrom_start`</span> <span
style="color: #66cc66;">=</span> <span
style="color: #cc66cc;">12345</span><span
style="color: #66cc66;">,</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff0000;">`transcript_chrom_end`</span> <span
style="color: #66cc66;">=</span> <span
style="color: #cc66cc;">12678</span>;</div></li></ol></div></div><p>Here, if the &#8216;ensembl_transcript_id&#8217; is already present in the database, it will be silently skipped (ignored). (To be more precise, here&#8217;s a quote from MySQL reference manual: &#8220;If you use the IGNORE keyword, errors that occur while executing the INSERT statement are treated as warnings instead. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted.&#8221;.) If the record doesn&#8217;t yet exist, it will be created.</p><p>This second method has several potential weaknesses, including non-abortion of the query in case any other problem occurs (<a
href="http://dev.mysql.com/doc/refman/5.0/en/insert.html" class="broken_link" rel="nofollow">see the manual</a>). Thus it should be used if previously tested without the IGNORE keyword.</p><p>There is one more option: to use <a
href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html" class="broken_link" rel="nofollow">INSERT &#8230; ON DUPLICATE KEY UPDATE syntax</a>, and in the UPDATE part just <del
datetime="2008-08-30T14:13:11+00:00">do nothing</del> do some meaningless (empty) operation, like calculating 0+0 (<a
href="http://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html#comment-80275">Geoffray</a> <ins
datetime="2008-08-30T14:13:11+00:00">suggests doing the id=id assignment for the MySQL optimization engine to ignore this operation</ins>). Advantage of this method is that it only ignores duplicate key events, and still aborts on other errors.</p><p>As a final notice: this post was inspired by <a
href="http://www.xaprb.com/blog/2005/09/25/insert-if-not-exists-queries-in-mysql/">Xaprb</a>. I&#8217;d also advise to consult his other <a
href="http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/">post on writing flexible SQL queries</a>.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F10%2F18%2Fmysql-insert-if-not-exists-syntax.html&amp;linkname=MySQL%3A%20INSERT%20IF%20NOT%20EXISTS%20syntax" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F10%2F18%2Fmysql-insert-if-not-exists-syntax.html&amp;linkname=MySQL%3A%20INSERT%20IF%20NOT%20EXISTS%20syntax" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F10%2F18%2Fmysql-insert-if-not-exists-syntax.html&amp;linkname=MySQL%3A%20INSERT%20IF%20NOT%20EXISTS%20syntax" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F10%2F18%2Fmysql-insert-if-not-exists-syntax.html&amp;linkname=MySQL%3A%20INSERT%20IF%20NOT%20EXISTS%20syntax" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F10%2F18%2Fmysql-insert-if-not-exists-syntax.html&amp;linkname=MySQL%3A%20INSERT%20IF%20NOT%20EXISTS%20syntax" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2007%2F10%2F18%2Fmysql-insert-if-not-exists-syntax.html&#038;title=MySQL%3A%20INSERT%20IF%20NOT%20EXISTS%20syntax" data-a2a-url="https://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html" data-a2a-title="MySQL: INSERT IF NOT EXISTS syntax"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html/feed</wfw:commentRss> <slash:comments>46</slash:comments> </item> <item><title>MySQL &#8211; Python: good MySQLdb tutorial (examples)</title><link>https://bogdan.org.ua/2007/09/07/mysql-python-good-mysqldb-tutorial-examples.html</link> <comments>https://bogdan.org.ua/2007/09/07/mysql-python-good-mysqldb-tutorial-examples.html#comments</comments> <pubDate>Fri, 07 Sep 2007 12:32:25 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[Notepad]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[examples]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[mysqldb]]></category> <category><![CDATA[tutorial]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/09/07/mysql-python-good-mysqldb-tutorial-examples.html</guid> <description><![CDATA[Andy Dustman (used to blog at dustman.net) gave a presentation on Python and MySQL at the MySQL Users Conference 2005, Santa Clara, CA. The presentation is an excellent collection of examples for those who use the MySQLdb Python module. For the purpose of maintaining a personal archive of that excellent presentation, I created a PDF [&#8230;]]]></description> <content:encoded><![CDATA[<p>Andy Dustman (used to blog at dustman.net) gave a presentation on Python and MySQL at the MySQL Users Conference 2005, Santa Clara, CA. The presentation is an excellent collection of examples for those who use the MySQLdb Python module.<br
/> <span
id="more-220"></span><br
/> For the purpose of maintaining a personal archive of that excellent presentation, I created a <a
href="http://bogdan.org.ua/wp-content/uploads/2007/09/python-and-mysql.pdf">PDF version</a> of it. All copyrights belong to Andy Dustman.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F09%2F07%2Fmysql-python-good-mysqldb-tutorial-examples.html&amp;linkname=MySQL%20%E2%80%93%20Python%3A%20good%20MySQLdb%20tutorial%20%28examples%29" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F09%2F07%2Fmysql-python-good-mysqldb-tutorial-examples.html&amp;linkname=MySQL%20%E2%80%93%20Python%3A%20good%20MySQLdb%20tutorial%20%28examples%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F09%2F07%2Fmysql-python-good-mysqldb-tutorial-examples.html&amp;linkname=MySQL%20%E2%80%93%20Python%3A%20good%20MySQLdb%20tutorial%20%28examples%29" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F09%2F07%2Fmysql-python-good-mysqldb-tutorial-examples.html&amp;linkname=MySQL%20%E2%80%93%20Python%3A%20good%20MySQLdb%20tutorial%20%28examples%29" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F09%2F07%2Fmysql-python-good-mysqldb-tutorial-examples.html&amp;linkname=MySQL%20%E2%80%93%20Python%3A%20good%20MySQLdb%20tutorial%20%28examples%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2007%2F09%2F07%2Fmysql-python-good-mysqldb-tutorial-examples.html&#038;title=MySQL%20%E2%80%93%20Python%3A%20good%20MySQLdb%20tutorial%20%28examples%29" data-a2a-url="https://bogdan.org.ua/2007/09/07/mysql-python-good-mysqldb-tutorial-examples.html" data-a2a-title="MySQL – Python: good MySQLdb tutorial (examples)"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2007/09/07/mysql-python-good-mysqldb-tutorial-examples.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>