title: How to connect to mysql localhost on opensuse?
body: <p>first the details of the configuration:</p>
  
  <ol>
  <li>openSUSE 11.3 with Parallels Plesk Panel 10 (64-bit) Server</li>
  <li>MySQL installed and running (no "skip-networking")</li>
  <li>java 1.6.0_24 (Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode))</li>
  </ol>
  
  <p>The mysql server listens on 0.0.0.0:3306 <br></p>
  
  <pre><code>netstat -lnp | grep mysql
  tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      3499/mysqld         
  unix  2      [ ACC ]     STREAM     LISTENING     10916  3499/mysqld         /var/run/mysql/mysql.sock
  </code></pre>
  
  <p>Now the problem.
  I can not connect to the mysql from localhost with jdbc (mysql-connector-java-5.1.17-bin.jar) using this class:</p>
  
  <pre><code>public class Connect {
      public static void main(String[] args) {
          Connection conn = null;
  
          try {
              String userName = "user";
              String password = "password";
              // This also doesn't work with "localhost" in the connect string.
              String url = "jdbc:mysql://127.0.0.1:3306/database";
  
              System.out.println("URL: " + url);
  
              Class.forName("com.mysql.jdbc.Driver").newInstance();
              conn = DriverManager.getConnection(url, userName, password);
              System.out.println("Database connection established");
          } catch (Exception e) {
              e.printStackTrace();
              System.err.println("Cannot connect to database server");
          } finally {
              if (conn != null) {
                  try {
                      conn.close();
                      System.out.println("Database connection terminated");
                  } catch (Exception e) { /* ignore close errors */
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>More details:</p>
  
  <p>telnet gives time out</p>
  
  <pre><code>telnet localhost 3306
  Trying 127.0.0.1...
  telnet: connect to address 127.0.0.1: Connection timed out
  </code></pre>
  
  <p>nmap shows the port 3306 is filtered on localhost</p>
  
  <pre><code>nmap -p 3306 localhost
  Starting Nmap 5.00 ( http://nmap.org ) at 2011-08-30 19:21 CEST
  Interesting ports on localhost (127.0.0.1):
  PORT     STATE    SERVICE
  3306/tcp filtered mysql
  
  Nmap done: 1 IP address (1 host up) scanned in 2.31 seconds
  </code></pre>
  
  <p>If I connect from outside to the servers 3306 port with the Connect class, everything works fine.</p>
  
  <p>As I think this is something with the firewall. This is the automatically generated firewall from the plesk configuration center.</p>
  
  <pre><code>iptables -nvL
  Chain INPUT (policy DROP 0 packets, 0 bytes)
  target     prot opt in     out     source               destination         
  ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
  REJECT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:!0x17/0x02 reject-with tcp-reset 
  DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID 
  ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:10000 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:4306 
  DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:12443 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:11443 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:11444 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8447 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8443 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8880 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:80 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:443 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:21 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:587 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:25 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:465 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:110 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:995 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:143 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:993 
  DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:106 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:3306 
  ACCEPT     tcp  --  *      *       127.0.0.1            0.0.0.0/0           tcp dpt:5432 
  DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:5432 
  ACCEPT     tcp  --  *      *       127.0.0.1            0.0.0.0/0           tcp dpt:9008 
  ACCEPT     tcp  --  *      *       127.0.0.1            0.0.0.0/0           tcp dpt:9080 
  DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:9008 
  DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:9080 
  DROP       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:137 
  DROP       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:138 
  DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:139 
  DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:445 
  DROP       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:1194 
  ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:53 
  ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:53 
  DROP       icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8 code 0 
  DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           
  
  Chain FORWARD (policy DROP 0 packets, 0 bytes)
  target     prot opt in     out     source               destination         
  ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
  REJECT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:!0x17/0x02 reject-with tcp-reset 
  DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID 
  ACCEPT     all  --  lo     lo      0.0.0.0/0            0.0.0.0/0           
  DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           
  
  Chain OUTPUT (policy DROP 0 packets, 0 bytes)
  target     prot opt in     out     source               destination         
  ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
  REJECT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:!0x17/0x02 reject-with tcp-reset 
  DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID 
  ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0           
  ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0
  </code></pre>
  
  <p>Furthermore I can connect with perl to the local mysql.</p>
  
  <pre><code>$dsn = "dbi:mysql:$database:localhost:3306";
  $connect = DBI-&gt;connect($dsn, $user, $pw);
  </code></pre>
  
  <p>I would be regretful for any hint to the solution of this.
  Martin</p>