title: MySQL remote connection [not as usual]
body: <p>I'm not getting to get access to mysql externally.
  I think it's mysql or firewall stuff or some privilege within the mysql.</p>
  
  <p>I already tried doing steps that are on internet. I'll put the process step-by-step to exemplify what I'm doing and to serve as a tutorial for another people that has this same problem:</p>
  
  <p>I'm using:</p>
  
  <pre><code>-ubuntu server 12.04 
  -mysql-server5.5
  -there is NO hardware firewall just software one
  </code></pre>
  
  <p><strong>1- First I installed mysql with:</strong></p>
  
  <pre><code>sudo apt-get install mysql-server
  </code></pre>
  
  <p><strong>2- I changed the root password by:</strong></p>
  
  <pre><code>sudo /etc/init.d/mysql stop
  sudo mysqld --skip-grant-tables &amp;
  mysql -u root mysql
  UPDATE user SET Password=PASSWORD('MYPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
  </code></pre>
  
  <p><strong>3- I give ALL PRIVILEGES to root to any ip:</strong></p>
  
  <pre><code>mysql&gt; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
  mysql&gt; FLUSH PRIVILEGES;
  </code></pre>
  
  <p><strong>4- After I edited the my.cnf</strong></p>
  
  <pre><code>sudo nano /etc/mysql/my.cnf
  </code></pre>
  
  <p>I commented the lines, as bellow:</p>
  
  <pre><code>#skip-external-locking 
  #bind-address           = 127.0.0.1
  </code></pre>
  
  <p><strong>5- I edited the iptables to allow MySql 3306:</strong></p>
  
  <pre><code>iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
  </code></pre>
  
  <p>now typing netstat -ant:</p>
  
  <pre><code>Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State
  tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN
  tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN
  tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN
  tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN
  tcp        0      0 66.123.173.170:53       0.0.0.0:*               LISTEN
  tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN
  tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
  tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN
  tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN
  tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN
  tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN
  tcp        0      0 66.123.173.170:22       189.32.2.232:49167      ESTABLISHED
  tcp        0    336 66.123.173.170:22       189.32.2.232:49654      ESTABLISHED
  tcp6       0      0 :::110                  :::*                    LISTEN
  tcp6       0      0 :::143                  :::*                    LISTEN
  tcp6       0      0 :::8080                 :::*                    LISTEN
  tcp6       0      0 :::21                   :::*                    LISTEN
  tcp6       0      0 :::53                   :::*                    LISTEN
  tcp6       0      0 :::22                   :::*                    LISTEN
  tcp6       0      0 ::1:953                 :::*                    LISTEN
  tcp6       0      0 :::25                   :::*                    LISTEN
  tcp6       0      0 :::993                  :::*                    LISTEN
  tcp6       0      0 :::995                  :::*                    LISTEN
  tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN
  </code></pre>
  
  <p>See that port 3306 is open! Am I right?</p>
  
  <p><strong>6- I restarted the mysql:</strong></p>
  
  <pre><code>sudo service mysql start
  </code></pre>
  
  <p>I typed:</p>
  
  <pre><code>service mysql status
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>mysql start/running, process 20757
  </code></pre>
  
  <p><strong>7- I tried to connect to the server:</strong></p>
  
  <pre><code>mysql -h 66.123.173.170 -u root -p
  </code></pre>
  
  <p>I got this error:</p>
  
  <blockquote>
    <p>ERROR 2003 (HY000): Can't connect to MySQL server on '66.123.173.170' (111)</p>
  </blockquote>
  
  <p>When I do:</p>
  
  <pre><code>mysql -h 127.0.0.1 -u root -p
  </code></pre>
  
  <p>It works opened MySQL> terminal</p>
  
  <p><strong>8- DOUBT: Do you see anything wrong with this process?</strong></p>
  
  <p>OBS: on step 4, I also tried to put the bind address to 
  bid-address = 0.0.0.0 
  but it didn't solve the problem.</p>
  
  <p><strong>9- DOUBT: If I turn off the MySQL with: <code>service mysql stop</code> then, can I access the firewall locally with mysql -h 127.0.0.1 -u root -p ?</strong></p>
  
  <p>I did it and I could connect even with mysql stopped/waiting (this was the status given after stop and retrieveing status of MySQL).</p>