<?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>Blonko! &#187; yaml</title>
	<atom:link href="http://www.wonko.be/tag/yaml/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wonko.be</link>
	<description>Blog + Wonko = Blonko!</description>
	<lastBuildDate>Mon, 16 Aug 2010 18:03:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>all-number passwords in database.yml</title>
		<link>http://www.wonko.be/2007/11/30/all-number-passwords-in-databaseyml</link>
		<comments>http://www.wonko.be/2007/11/30/all-number-passwords-in-databaseyml#comments</comments>
		<pubDate>Fri, 30 Nov 2007 18:55:08 +0000</pubDate>
		<dc:creator>blonko</dc:creator>
				<category><![CDATA[blonko]]></category>
		<category><![CDATA[connection problem]]></category>
		<category><![CDATA[database.yml]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://www.wonko.be/2007/11/30/all-number-passwords-in-databaseyml/</guid>
		<description><![CDATA[A small posting in english, as it might help a lot of people. When using Ruby on Rails, if you keep getting a &#8220;could not connect to database&#8221; while you are 100% sure the username and password you entered in your database.yml is correct, and you can&#8217;t find what is causing it&#8230; observe Database.yml: production: [...]]]></description>
			<content:encoded><![CDATA[<p>A small posting in english, as it might help a lot of people.</p>
<p>When using Ruby on Rails, if you keep getting a &#8220;could not connect to database&#8221; while you are 100% sure the username and password you entered in your database.yml is correct, and you can&#8217;t find what is causing it&#8230; observe</p>
<p>Database.yml:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">production:
  username: dontcare
  password: 0123456
  host: localhost
  ...</pre></div></div>

<p>When we connect to the database using the RoR console, we get the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ RAILS_ENV=production script<span style="color:#006600; font-weight:bold;">/</span>console 
Loading production environment.
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">establish_connection</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;activerecord ::Base::ConnectionSpecification:0x40b0c0a4 @adapter_method=&quot;mysql_connection&quot;, </span>
<span style="color:#0066ff; font-weight:bold;">@config</span>=<span style="color:#006600; font-weight:bold;">&#123;</span>:host<span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;localhost&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:username</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;dontcare&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:database</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;foobar&quot;</span>, 
<span style="color:#ff3333; font-weight:bold;">:adapter</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;mysql&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:password</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">42798</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;/</span>activerecord<span style="color:#006600; font-weight:bold;">&gt;</span></pre></div></div>

<p><small>(wrapped the output so it would be readable)</small></p>
<p>Take a close look to the last field in the output, the password has changed from &#8220;0123456&#8243; to &#8220;42798&#8243;. This is, however, expected behavior, as a leading zero is interpreted as the sign the number following the zero is a octal representation of a number. This has even nothing to do with rails, this is default ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ irb
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:001:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> a = 0123
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">83</span></pre></div></div>

<p>The solution is to quote your password:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">production:
  username: dontcare
  password: '0123456'
  host: localhost
  ...</pre></div></div>

<p>By the way, remember these two lines, they help you test the database connection; you can even omit the first one, but then you won&#8217;t see the actual connection parameters, which helped me discover the cause of this problem.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">establish_connection</span>
<span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">select_all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'SHOW TABLES'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Just start a console, and use these to test your database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wonko.be/2007/11/30/all-number-passwords-in-databaseyml/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!--f0c25b539901624b460e129d15264305-->
