title: Connect to mysql on Amazon EC2 from a remote server - ERROR 2003
body: <p>cant get it to work. this is what i've done so far:</p>
  
  <pre><code>mysql&gt; CREATE USER 'admin'@'localhost' IDENTIFIED BY 'xxxxxx';
  mysql&gt; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
  mysql&gt; CREATE USER 'admin'@'%' IDENTIFIED BY 'xxxxxx';
  mysql&gt; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
  </code></pre>
  
  <p>in AWS Console -> EC2 -> Network &amp; Security -> Security Groups -> quick-start-1 -> Inbound tab -> Choose 'MYSQL' from drop down -> Add Rule -> apply</p>
  
  <p>edit <code>/etc/my.cnf</code> and added <code>bind-address</code>, then</p>
  
  <pre><code>sudo /etc/init.d/mysqld restart
  
  sudo /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
  sudo service iptables save
  </code></pre>
  
  <p>and finally from my computer:</p>
  
  <pre><code>[nir@dhcppc4 ~]$ mysql -h xxx.xxx.xxx.xxx -u admin -p 
  Enter password: 
  ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (113)
  </code></pre>
  
  <p><strong>EDIT:</strong>
  running <code>netstat -lp | grep mysql</code> (I dont see port number in the output):</p>
  
  <pre><code>tcp        0      0 *:mysql                     *:*                         LISTEN      -                
  
  unix  2      [ ACC ]     STREAM     LISTENING     16003  -                   /var/lib/mysql/mysql.sock
  </code></pre>
  
  <p>added in <code>/etc/my.cnf</code></p>
  
  <pre><code>port=3306
  </code></pre>
  
  <p>and now <code>netstat -lp | grep mysql</code> is</p>
  
  <pre><code>tcp        0      0 *:mysql                     *:*                         LISTEN      -                   
  unix  2      [ ACC ]     STREAM     LISTENING     37757  -                   /var/lib/mysql/mysql.sock
  </code></pre>
  
  <p><code>/etc/my.cnf</code> file:</p>
  
  <pre><code>[mysqld]
  datadir=/var/lib/mysql
  socket=/var/lib/mysql/mysql.sock
  user=mysql
  port=3306
  bind-address = 0.0.0.0
  #skip-networking
  # Disabling symbolic-links is recommended to prevent assorted security risks
  symbolic-links=0
  
  [mysqld_safe]
  log-error=/var/log/mysqld.log
  pid-file=/var/run/mysqld/mysqld.pid
  </code></pre>
  
  <p>plus i tried to connect through other computer and i could not connect, so i guess its not a problem on the connecting computer</p>
  
  <p>and i got access denied my telnet:</p>
  
  <pre><code>[nir@dhcppc4 ~]$ telnet xxx.xxx.xxx.xxx 3306
  Trying xxx.xxx.xxx.xxx...
  telnet: connect to address xxx.xxx.xxx.xxx: No route to host
  </code></pre>
  
  <p>** i'm also trying to solve it in <a href="https://forums.aws.amazon.com/thread.jspa?messageID=471681&amp;#471681" rel="nofollow">amazon ec2 forum</a></p>