SpringBoot with MariaDB: The driver has not received any packets from the server

Viewed 818

I have a MariaDB, when connecting with sequel Pro I use this credentials and I can connect

enter image description here

with SpringBoot I use

spring.datasource.url=jdbc:mysql://172.105.50.55:3306/pradera_db
spring.datasource.username=pradera_usr
spring.datasource.password=Mddejh847h$#@

but I have this error:

Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402)
    at java.base/java.net.Socket.connect(Socket.java:591)
    at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
    at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
    ... 81 common frames omitted
2020-05-31 12:30  [restartedMain] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2020-05-31 12:30  [restartedMain] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

this is the dependency in the pom.xml:

<dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
2 Answers

Try this as connection string :

spring.datasource.url=jdbc:mysql://172.105.50.55:3306/pradera_db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

pom.xml :

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

On the machine that's running your database add your ip as an allowed connection on the port 3306

Linux:

iptables -I INPUT -p tcp -s your.ip.address.here --dport 3306 -j ACCEPT

Windows: Open the start menu, write in the search bar: Windows firewall, open advanced settings on the left, select inbound rules, press new rule button on the right, Select port and press next, select tcp and specify the port 3306, press next, Allow the connection and after that just finish by selecting Domain, private, public and choosing a name for the rule itself.

Check if the service is running and enable/start it.

Linux:

sudo systemctl status mariadb
sudo systemctl enable mariadb
sudo systemctl start mariadb

Windows: Open the start menu, search for Services.msc, inside the services tab find your mariadb service and modify it's status by right clicking it.

Hope it helps.

Related