<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
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/"
> <channel><title>Comments on: MySQL User Defined Variables</title> <atom:link href="http://www.mysqldiary.com/user-defined-variables/feed/" rel="self" type="application/rss+xml" /><link>http://www.mysqldiary.com/user-defined-variables/</link> <description>Exploring, Sharing and  Discussing MySQL practice</description> <lastBuildDate>Thu, 02 Feb 2012 09:16:49 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-5237</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Thu, 02 Feb 2012 09:16:49 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-5237</guid> <description>Try this:
SELECT PASSWORD FROM USER WHERE USER = ‘jon’ INTO @var;
CREATE USER ‘jane’@’127.0.0.1′;
SET PASSWORD FOR ‘jane’@’127.0.0.1′ = PASSWORD(@var);
Please note: when you write &#039;@var&#039; (with the apostrophes) it means a string with the letters &#039;@&#039;,&#039;v&#039;,&#039;a&#039;,&#039;r&#039;.</description> <content:encoded><![CDATA[<p>Try this:<br
/> SELECT PASSWORD FROM USER WHERE USER = ‘jon’ INTO @var;<br
/> CREATE USER ‘jane’@’127.0.0.1′;<br
/> SET PASSWORD FOR ‘jane’@’127.0.0.1′ = PASSWORD(@var);</p><p>Please note: when you write &#8216;@var&#8217; (with the apostrophes) it means a string with the letters &#8216;@&#8217;,'v&#8217;,'a&#8217;,'r&#8217;.</p> ]]></content:encoded> </item> <item><title>By: Larsen</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-5224</link> <dc:creator>Larsen</dc:creator> <pubDate>Wed, 01 Feb 2012 16:48:47 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-5224</guid> <description>Thanks for your reply.
The SELECT already returns the hashed value, so if I don´t use &quot;BY PASSWORD&quot;, MySQL sets the hashed value itself as the password:
SELECT PASSWORD FROM USER WHERE USER = &#039;jon&#039; INTO @var;
SELECT @var;   --&gt; *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B
CREATE USER &#039;jane&#039;@&#039;127.0.0.1&#039; IDENTIFIED BY &#039;@var&#039;;
SELECT PASSWORD FROM USER WHERE USER = &#039;jane&#039; ;   --&gt; *33EF0CD2D187BCD7DBFFDE2943960E094684DAE6
As you can see, the hash values of the two passwords differ, but they should be the same. Not using apostrophes with @var only gives a MySQL error...</description> <content:encoded><![CDATA[<p>Thanks for your reply.</p><p>The SELECT already returns the hashed value, so if I don´t use &#8220;BY PASSWORD&#8221;, MySQL sets the hashed value itself as the password:</p><p>SELECT PASSWORD FROM USER WHERE USER = &#8216;jon&#8217; INTO @var;<br
/> SELECT @var;   &#8211;&gt; *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B<br
/> CREATE USER &#8216;jane&#8217;@&#8217;127.0.0.1&#8242; IDENTIFIED BY &#8216;@var&#8217;;<br
/> SELECT PASSWORD FROM USER WHERE USER = &#8216;jane&#8217; ;   &#8211;&gt; *33EF0CD2D187BCD7DBFFDE2943960E094684DAE6</p><p>As you can see, the hash values of the two passwords differ, but they should be the same. Not using apostrophes with @var only gives a MySQL error&#8230;</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-5207</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Tue, 31 Jan 2012 19:31:28 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-5207</guid> <description>There is no problem with your first MySQL query.
However, your second one has syntax Error. From the &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/create-user.html&quot; title=&quot;Create User&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;MySQL CREATE USER Syntax&lt;/a&gt; page: &quot;to assign a password, use IDENTIFIED BY with the &lt;strong&gt;literal plaintext&lt;/strong&gt; password value&quot;.
Please try to use the solution suggested by &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/assigning-passwords.html&quot; title=&quot;MySQL assigning account passwords&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;MySQL Assigning Account Passwords&lt;/a&gt; page.</description> <content:encoded><![CDATA[<p>There is no problem with your first MySQL query.<br
/> However, your second one has syntax Error. From the <a
href="http://dev.mysql.com/doc/refman/5.1/en/create-user.html" title="Create User" target="_blank" rel="nofollow">MySQL CREATE USER Syntax</a> page: &#8220;to assign a password, use IDENTIFIED BY with the <strong>literal plaintext</strong> password value&#8221;.<br
/> Please try to use the solution suggested by <a
href="http://dev.mysql.com/doc/refman/5.1/en/assigning-passwords.html" title="MySQL assigning account passwords" target="_blank" rel="nofollow">MySQL Assigning Account Passwords</a> page.</p> ]]></content:encoded> </item> <item><title>By: Larsen</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-5205</link> <dc:creator>Larsen</dc:creator> <pubDate>Tue, 31 Jan 2012 17:10:19 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-5205</guid> <description>Hi,
I want to create a user with the password from another user like this:
SELECT PASSWORD FROM USER WHERE USER = &#039;jon&#039; INTO @var;
CREATE USER &#039;jane&#039;@&#039;localhost&#039; IDENTIFIED BY PASSWORD @var;
Unfortunately, this only gives me &quot;You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;@var&#039; at line 1&quot;.
I have tried other ways but didn´t succeed. Is what I´m trying to do even possible?
Lars</description> <content:encoded><![CDATA[<p>Hi,</p><p>I want to create a user with the password from another user like this:<br
/> SELECT PASSWORD FROM USER WHERE USER = &#8216;jon&#8217; INTO @var;<br
/> CREATE USER &#8216;jane&#8217;@'localhost&#8217; IDENTIFIED BY PASSWORD @var;</p><p>Unfortunately, this only gives me &#8220;You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#8216;@var&#8217; at line 1&#8243;.</p><p>I have tried other ways but didn´t succeed. Is what I´m trying to do even possible?</p><p>Lars</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-5070</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Sun, 22 Jan 2012 20:16:58 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-5070</guid> <description>There isn&#039;t such a case in example number 4. MySQL must evaluate the &quot;IF&quot; statement before assigning the value to the variable.</description> <content:encoded><![CDATA[<p>There isn&#8217;t such a case in example number 4. MySQL must evaluate the &#8220;IF&#8221; statement before assigning the value to the variable.</p> ]]></content:encoded> </item> <item><title>By: David Coppit</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-5069</link> <dc:creator>David Coppit</dc:creator> <pubDate>Sun, 22 Jan 2012 19:58:09 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-5069</guid> <description>Your Example #4 is buggy in the way it uses @same_value. Quoting the MySQL docs at http://dev.mysql.com/doc/refman/5.0/en/user-variables.html:
As a general rule, you should never assign a value to a user variable and read the value within the same statement. You might get the results you expect, but this is not guaranteed. The order of evaluation for expressions involving user variables is undefined and may change based on the elements contained within a given statement; in addition, this order is not guaranteed to be the same between releases of the MySQL Server. In SELECT @a, @a:=@a+1, ..., you might think that MySQL will evaluate @a first and then do an assignment second. However, changing the statement (for example, by adding a GROUP BY, HAVING, or ORDER BY clause) may cause MySQL to select an execution plan with a different order of evaluation.
Does anyone know a good way to fix this?</description> <content:encoded><![CDATA[<p>Your Example #4 is buggy in the way it uses @same_value. Quoting the MySQL docs at <a
href="http://dev.mysql.com/doc/refman/5.0/en/user-variables.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/user-variables.html</a>:</p><p>As a general rule, you should never assign a value to a user variable and read the value within the same statement. You might get the results you expect, but this is not guaranteed. The order of evaluation for expressions involving user variables is undefined and may change based on the elements contained within a given statement; in addition, this order is not guaranteed to be the same between releases of the MySQL Server. In SELECT @a, @a:=@a+1, &#8230;, you might think that MySQL will evaluate @a first and then do an assignment second. However, changing the statement (for example, by adding a GROUP BY, HAVING, or ORDER BY clause) may cause MySQL to select an execution plan with a different order of evaluation.</p><p>Does anyone know a good way to fix this?</p> ]]></content:encoded> </item> <item><title>By: Murali</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-4527</link> <dc:creator>Murali</dc:creator> <pubDate>Mon, 02 Jan 2012 13:10:40 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-4527</guid> <description>hi friends...i dont know how to apply this for java..
1.so how to insert variable in mysql using java..
for ex: int a=20
stmt.executeUpdate(&quot;SET @b:=a INSERT INTO product VALUES (b);&quot;);
it gives error...so how to insert..
2.Similarly how to retrieve and assign data from database to int , string variable and applet label in JAVA...&quot;</description> <content:encoded><![CDATA[<p>hi friends&#8230;i dont know how to apply this for java..</p><p>1.so how to insert variable in mysql using java..</p><p>for ex: int a=20</p><p>stmt.executeUpdate(&#8220;SET @b:=a INSERT INTO product VALUES (b);&#8221;);</p><p>it gives error&#8230;so how to insert..</p><p>2.Similarly how to retrieve and assign data from database to int , string variable and applet label in JAVA&#8230;&#8221;</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-3353</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Sun, 10 Apr 2011 06:55:55 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-3353</guid> <description>I have tried it right now and it is working fine. Maybe you have a typo.</description> <content:encoded><![CDATA[<p>I have tried it right now and it is working fine. Maybe you have a typo.</p> ]]></content:encoded> </item> <item><title>By: Jesse Donat</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-3350</link> <dc:creator>Jesse Donat</dc:creator> <pubDate>Thu, 07 Apr 2011 19:30:59 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-3350</guid> <description>Thank you very much! Used this to write a fairly epic query to sort my tags to display pretty :-)
SELECT *
FROM   (SELECT ( @counter := @counter + 1 ) &amp; 1 AS x,
w.*
FROM   (SELECT @counter := 0) v,
(SELECT tag, COUNT(*)AS c
FROM   categories_tags
INNER JOIN categories USING(categories_id)
WHERE  `status` AND `list`
GROUP  BY tag
ORDER  BY c)w)x
ORDER  BY x, IF(x, -c, c), IF(x, -CHAR_LENGTH(tag), CHAR_LENGTH(tag))</description> <content:encoded><![CDATA[<p>Thank you very much! Used this to write a fairly epic query to sort my tags to display pretty <img
src='http://www.mysqldiary.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><p>SELECT *<br
/> FROM   (SELECT ( @counter := @counter + 1 ) &amp; 1 AS x,<br
/> w.*<br
/> FROM   (SELECT @counter := 0) v,<br
/> (SELECT tag, COUNT(*)AS c<br
/> FROM   categories_tags<br
/> INNER JOIN categories USING(categories_id)<br
/> WHERE  `status` AND `list`<br
/> GROUP  BY tag<br
/> ORDER  BY c)w)x<br
/> ORDER  BY x, IF(x, -c, c), IF(x, -CHAR_LENGTH(tag), CHAR_LENGTH(tag))</p> ]]></content:encoded> </item> <item><title>By: Rich</title><link>http://www.mysqldiary.com/user-defined-variables/comment-page-1/#comment-3348</link> <dc:creator>Rich</dc:creator> <pubDate>Thu, 07 Apr 2011 09:46:42 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=7#comment-3348</guid> <description>lee,
To add to the answer Hazan provided, it&#039;s more of a phpmyadmin &#039;thing&#039; getting the [BLOB] response than MySQL itself. You can use type casting to get the desired results.
asjain01,
wrapping your select statement in brackets removes the error.
set @h = (select count(*) from reportx);</description> <content:encoded><![CDATA[<p>lee,</p><p>To add to the answer Hazan provided, it&#8217;s more of a phpmyadmin &#8216;thing&#8217; getting the [BLOB] response than MySQL itself. You can use type casting to get the desired results.</p><p>asjain01,<br
/> wrapping your select statement in brackets removes the error.</p><p>set @h = (select count(*) from reportx);</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Dynamic page generated in 0.296 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-06 00:46:59 -->
<!-- Compression = gzip -->
