<?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>Bo Wu&#039;s IT Lab &#187; MySQL</title>
	<atom:link href="http://www.bowu.org/category/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bowu.org</link>
	<description>If winter comes, can spring be far behind?</description>
	<lastBuildDate>Thu, 29 Dec 2011 18:09:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL</title>
		<link>http://www.bowu.org/mysql/exists-left-join-null.html</link>
		<comments>http://www.bowu.org/mysql/exists-left-join-null.html#comments</comments>
		<pubDate>Thu, 29 Dec 2011 18:09:17 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bowu.org/?p=601</guid>
		<description><![CDATA[NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL Which method is best to select values present in one table but missing in another one? This: SELECT &#160;l.* FROM &#160; &#160;t_left l LEFT JOIN &#160; &#160; &#160; &#160; t_right r ON &#160; &#160; &#160;r.value = l.value WHERE &#160; r.value IS NULL ,this: SELECT [...]]]></description>
			<content:encoded><![CDATA[<p>NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL</p>
<p>Which method is best to select values present in one table but missing in another one?</p>
<p>This:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT &nbsp;l.*<br />
FROM &nbsp; &nbsp;t_left l<br />
LEFT JOIN<br />
&nbsp; &nbsp; &nbsp; &nbsp; t_right r<br />
ON &nbsp; &nbsp; &nbsp;r.value = l.value<br />
WHERE &nbsp; r.value IS NULL</div></div>
<p>,this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT &nbsp;l.*<br />
FROM &nbsp; &nbsp;t_left l<br />
WHERE &nbsp; l.value NOT IN<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;value<br />
&nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; &nbsp;t_right r<br />
&nbsp; &nbsp; &nbsp; &nbsp; )</div></div>
<p>or this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT &nbsp;l.*<br />
FROM &nbsp; &nbsp;t_left l<br />
WHERE &nbsp; NOT EXISTS<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;NULL<br />
&nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; &nbsp;t_right r<br />
&nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; r.value = l.value<br />
&nbsp; &nbsp; &nbsp; &nbsp; )</div></div>
<p><strong>Differences between the methods</strong></p>
<p>These methods are quite different.</p>
<p>First of all, LEFT JOIN / IS NULL and NOT EXISTS are semantically equivalent, while NOT IN is not. These method differ in how they handle NULL values in t_right</p>
<p>LEFT JOIN is guaranteed to return every row from t_left, and then filtering is applied to the values returned from t_right. If for some row in t_left there is no corresponding row in t_right (which means no row with that exact value is present in t_right), the row from t_left will be returned once, and the NULL values will be substituted instead of t_right‘s actual values.</p>
<p>Since NULL values can never satisfy an equality JOIN condition, the NULL values returned by the query are guaranteed to be substituted by the LEFT JOIN, not fetched out of the actual t_right‘s row. This means that LEFT JOIN / IS NULL is guaranteed to return at most one row from t_left, and these row’s value is not equal to one of those in t_right.</p>
<p>The same holds for NOT EXISTS. Since it’s a predicate, not a JOIN condition, the rows from t_left can only be returned at most once too. EXISTS always returns TRUE or FALSE and it will return TRUE as soon as it finds only a single matching row in t_right, or FALSE, if it find none.</p>
<p>NOT EXISTS, therefore, will return TRUE only if no row satisfying the equality condition is found in t_right (same as for LEFT JOIN / IS NULL).</p>
<p>Note that NULL values do not safisfy the equality conditions, so both LEFT JOIN / IS NULL and NOT EXISTS will always return rows from t_left that have value set to NULL, even is there are rows with value IS NULL in t_right.</p>
<p>NOT IN, however, behaves differently.</p>
<p>IN predicate (unlike EXISTS) is trivalent, i. e. it can return TRUE, FALSE or NULL:</p>
<ul>
<li> TRUE is returned when the non-NULL value in question is found in the list
<li>FALSE is returned when the non-NULL value is not found in the list and the list does not contain NULL values
<li>NULL is returned when the value is NULL, or the non-NULL value is not found in the list and the list contains at least one NULL </li>
<p>value</ul>
<p>IN predicate does not give a definitive answer to whether or not the expression is contained in the list as long as there are NULL values on either side of the expression, returning NULL instead.</p>
<p>This of course makes no difference when using the positive form of NULL: predicates returning NULL are filtered out by the WHERE clause as well as those returning FALSE.</p>
<p>However, NOT IN is different, since negation of NULL is NULL as well.</p>
<p>That’s why NOT IN condition will never hold for any list with a NULL value in it.</p>
<ul>
<li>If a row is found in the list, IN will return TRUE and NOT IN, therefore, will return FALSE
<li>If a row is not found in the list, IN will return NULL, and NOT IN on its turn will also return NULL</ul>
<p>Both conditions will of course be filtered out by the WHERE clause.</p>
<p><strong>Summary</strong></p>
<p>In SQL Server, NOT EXISTS and NOT IN predicates are the best way to search for missing values, as long as both columns in question are NOT NULL. They produce the safe efficient plans with some kind of an Anti Join.</p>
<p>LEFT JOIN / IS NULL is less efficient, since it makes no attempt to skip the already matched values in the right table, returning all results and filtering them out instead.</p>
<hr />
The original posting URL: http://explainextended.com/2009/09/15/not-in-vs-not-exists-vs-left-join-is-null-sql-server/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bowu.org/mysql/exists-left-join-null.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resetting a forgotten MySQL root password</title>
		<link>http://www.bowu.org/mysql/resetting-forgotten-mysql-root-password.html</link>
		<comments>http://www.bowu.org/mysql/resetting-forgotten-mysql-root-password.html#comments</comments>
		<pubDate>Tue, 22 Feb 2011 01:58:11 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bowu.org/?p=558</guid>
		<description><![CDATA[Resetting the root password of a MySQL database is trivial if you know the current password if you don&#8217;t it is a little tricker. Thankfully it isn&#8217;t too difficult to fix, and here we&#8217;ll show one possible way of doing so. If you&#8217;ve got access to the root account already, because you know the password, [...]]]></description>
			<content:encoded><![CDATA[<p><img alt=" Resetting a forgotten MySQL root password" src="http://t3.gstatic.com/images?q=tbn:ANd9GcR8i7cZJXJtaFwcGYjH8xnmfLucnhZhodWqfO4cbAl6DH9OtBVljA&#038;t=1" title="MySQL" class="alignnone" width="211" height="239" /></p>
<p>Resetting the root password of a MySQL database is trivial if you know the current password if you don&#8217;t it is a little tricker. Thankfully it isn&#8217;t too difficult to fix, and here we&#8217;ll show one possible way of doing so.</p>
<p>If you&#8217;ve got access to the root account already, because you know the password, you can change it easily:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">steve@steve:~$ mysql --user=root --pass mysql<br />
Enter password:<br />
<br />
mysql&gt; update user set Password=PASSWORD('new-password-here') WHERE User='root';<br />
Query OK, 2 rows affected (0.04 sec)<br />
Rows matched: 2 &nbsp;Changed: 2 &nbsp;Warnings: 0<br />
<br />
mysql&gt; flush privileges;<br />
Query OK, 0 rows affected (0.02 sec)<br />
<br />
mysql&gt; exit<br />
Bye</div></div>
<p>However if you don&#8217;t know the current password this approach will not work &#8211; you need to login to run any commands and without the password you&#8217;ll not be able to login!</p>
<p>Thankfully there is a simple solution to this problem, we just need to start MySQL with a flag to tell it to ignore any username/password restrictions which might be in place. Once that is done you can successfully update the stored details.</p>
<p>First of all you will need to ensure that your database is stopped:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root@steve:~# /etc/init.d/mysqld stop</div></div>
<p>Now you should start up the database in the background, via the mysqld_safe command:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root@steve:~# /usr/bin/mysqld_safe --skip-grant-tables &amp;<br />
[1] 6702<br />
Starting mysqld daemon with databases from /var/lib/mysql<br />
mysqld_safe[6763]: started</div></div>
<p>Here you can see the new job (number &#8220;1&#8243;) has started and the server is running with the process ID (PID) of 6702.</p>
<p>Now that the server is running with the &#8211;skip-grant-tables flag you can connect to it without a password and complete the job:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root@steve:~$ mysql --user=root mysql<br />
Enter password:<br />
<br />
mysql&gt; update user set Password=PASSWORD('new-password-here') WHERE User='root';<br />
Query OK, 2 rows affected (0.04 sec)<br />
Rows matched: 2 &nbsp;Changed: 2 &nbsp;Warnings: 0<br />
<br />
mysql&gt; flush privileges;<br />
Query OK, 0 rows affected (0.02 sec)<br />
<br />
mysql&gt; exit<br />
Bye</div></div>
<p>Now that you&#8217;ve done that you just need to stop the server, so that you can go back to running a secure MySQL server with password restrictions in place. First of all bring the server you started into the foreground by typing &#8220;fg&#8221;, then kill it by pressing &#8220;Ctrl+c&#8221; afterwards.</p>
<p>This will now allow you to start the server:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root@steve:~# /etc/init.d/mysqld start<br />
Starting MySQL database server: mysqld.<br />
Checking for corrupt, not cleanly closed and upgrade needing tables..</div></div>
<p>Now everything should be done and you should have regained access to your MySQL database(s); you should verify this by connecting with your new password:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root@steve:~# mysql --user=root --pass=new-password-here<br />
Welcome to the MySQL monitor. &nbsp;Commands end with ; or \g.<br />
Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log<br />
<br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
<br />
mysql&gt; exit<br />
Bye</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bowu.org/mysql/resetting-forgotten-mysql-root-password.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Enable Remote Access to MySQL Database Server</title>
		<link>http://www.bowu.org/mysql/enable-remote-access-to-mysql-database-server.html</link>
		<comments>http://www.bowu.org/mysql/enable-remote-access-to-mysql-database-server.html#comments</comments>
		<pubDate>Sat, 03 Apr 2010 19:41:51 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bowu.org/?p=194</guid>
		<description><![CDATA[By default remote access to MySQL database server is disabled for security reasons. However, some time you need to provide remote access to database server from home or a web server. You need type the following commands which will allow remote connections. Once connected you need to edit the MySQL server configuration file my.cnf. * [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" title="MySQL" src="http://media.brajeshwar.com/i/linux/mysql.png" alt="mysql Enable Remote Access to MySQL Database Server" width="314" height="318" /></p>
<p>By default remote access to MySQL database server is disabled for security reasons. However, some time you need to provide remote access to database server from home or a web server.</p>
<p>You need type the following commands which will allow remote connections.</p>
<p>Once connected you need to edit the MySQL server configuration file my.cnf.</p>
<p>* If you are using Debian Linux file is located at /etc/mysql/my.cnf location<br />
* If you are using Red Hat Linux/Fedora/Centos Linux file is located at /etc/my.cnf location<br />
* If you are using FreeBSD you need to create a file /var/db/mysql/my.cnf</p>
<p># vi /etc/my.cnf</p>
<p>For example, if your MySQL server IP is 192.168.1.100 then entire block should be look like as follows:</p>
<p>[mysqld]<br />
user            = mysql<br />
pid-file        = /var/run/mysqld/mysqld.pid<br />
socket          = /var/run/mysqld/mysqld.sock<br />
port            = 3306<br />
basedir         = /usr<br />
datadir         = /var/lib/mysql<br />
tmpdir          = /tmp<br />
language        = /usr/share/mysql/English<br />
bind-address    = 192.168.1.100</p>
<p>* bind-address : IP address to bind to.<br />
* skip-networking : Don</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bowu.org/mysql/enable-remote-access-to-mysql-database-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
