title: RDS MySQL ERROR 1045 (28000): Access denied for user when connecting to db from EC2
body: <p>I have an EC2 instance that I am trying to connect to an RDS (mySQL) instance.</p>
  
  <p>I created an RDS mySQL instance with the name: <code>mydbinstance</code>, user: <code>mysuperuser</code> and a generic 8 character (<code>mypassword</code>) just for testing purpose.</p>
  
  <blockquote>
    <p>Virtual Private Cloud: <strong>default</strong>
    (same as where the EC2 is located)</p>
    
    <p>Subnet group: <strong>default</strong></p>
    
    <p>Public accessibility: <strong>No</strong> (<em>DB instance will not have a public IP
    address assigned. No EC2 instance or devices outside of the VPC will
    be able to connect.</em>)</p>
    
    <p>Availability zone: <strong>No preference</strong></p>
    
    <p>VPC security groups: <strong>Create new VPC security group</strong></p>
    
    <p>IAM DB authentication: Disabled</p>
  </blockquote>
  
  <p>I added the RDS instance to the same VPC as the EC2 instance, so it's in the same zone.</p>
  
  <p>The dbinstance is using a new security group:</p>
  
  <blockquote>
    <p>Type: Custom TCP Rule Protocol: TCP Port: 3306 CIDR: 174.62.127.135/32</p>
  </blockquote>
  
  <p>Where does this IP address comes from? I didn't specify anything at instantiation...</p>
  
  <p>Next, I ssh to my EC2 instance (the one located in the same VPC), and try:</p>
  
  <pre><code>$ mysql -h mydbinstance.$(RDS_INSTANCE).us-west-2.rds.amazonaws.com -P 3306 -u mymasteruser -p
  </code></pre>
  
  <p>I entered <code>mypassword</code> (the one I specified earlier) at the prompt and I get:</p>
  
  <blockquote>
    <p>ERROR 1045 (28000): Access denied for user 'mymasteruser'@'localhost'
    (using password: YES)</p>
  </blockquote>
  
  <p>I tried getting the IP address of the EC2 box with <code>ifconfig</code>, and updated the security group IP address (the one I was wondering about above) used by RDS with it. Same result, no luck connecting. I've been googling for an answer since then.</p>
  
  <p>What are my other options to debug this? I would appreciate any suggestions.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I was able to run this from my laptop (by changing the DB <code>Public Access</code> to <code>YES</code>):</p>
  
  <pre><code>mysql -h mydbinstance.$(RDS_INSTANCE).us-west-2.rds.amazonaws.com -P 3306 -u mymasteruser -p
  </code></pre>
  
  <blockquote>
    <p>found 0 associations found 1 connections:</p>
  </blockquote>
  
  <pre><code>found 0 associations
  found 1 connections:
       1: flags=82&lt;CONNECTED,PREFERRED&gt;
      outif en3
      src 192.168.86.33 port 55863
      dst xx.xxx.xxx.xxx port 3306
      rank info not available
      TCP aux info available
  </code></pre>
  
  <p>But I am unable to get any output from my EC2 instance. It hangs! Same why I run netcat (nc) command. Why is this not working on my EC2 instance?</p>