title: MariaDB: Could not connect: unexpected end of stream
body: <p>I have recently turned my Raspberry to a web server, which could be connected via SSH from either outside or inside the network. </p>
  
  <p>However, when I tried to connect to the database (MariaDB 10 + Apache2) by using DBCP (a MySQL connector): </p>
  
  <ul>
  <li><p>I can connect to the database if I'm inside the network </p></li>
  <li><p>I used to successfully connect to my server from outside network, but not
  anymore. </p></li>
  </ul>
  
  <p>Instead, I got an error:</p>
  
  <pre><code>Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to blabla.com:8080 : unexpected end of stream, read 0 bytes from 4 (socket was closed by server)
              at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:175)
              at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:110)
              at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1107)
              at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:502)
              at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:155)
              at org.mariadb.jdbc.Driver.connect(Driver.java:86)
              at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:53)
              at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:279)
              at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2343)
              at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2329)
              ... 14 more
  </code></pre>
  
  <p><strong>What I tried:</strong></p>
  
  <ol>
  <li>Set validation query to <code>SELECT 1</code></li>
  <li>Increase time out</li>
  <li>Completely remove Apche2+MariaDB and set them up again</li>
  </ol>
  
  <p>And finally, none of them worked.</p>
  
  <p>Thanks in advance.</p>