programing

com.myql.jdbc.exceptions.jdbc4가 있는 이유는 무엇입니까?커뮤니케이션예외:통신 링크 고장

lastmoon 2023. 9. 4. 20:36
반응형

com.myql.jdbc.exceptions.jdbc4가 있는 이유는 무엇입니까?커뮤니케이션예외:통신 링크 고장

SCALA를 사용하여 데이터베이스 서버에 연결하려고 합니다.

scala> val connection = DriverManager.getConnection(
     | "jdbc:mysql://127.0.0.1:3306/test",
     | "milenko",
     | "nilton")

이건 내가 할게.

com.mysql.jdbc.exceptions.jdbc4.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.
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
  at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1038)
  at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338)
  at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2237)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2270)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2069)
  at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
  at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
  at java.sql.DriverManager.getConnection(DriverManager.java:664)
  at java.sql.DriverManager.getConnection(DriverManager.java:247)
  ... 49 elided
Caused by: java.net.ConnectException: Connection refused (Connection refused)

저는 SQL에 대한 기본 지식이 있습니다. scala 튜토리얼에서 이 예제를 실행하려고 합니다.

scala> val connection = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/test",
"root", // username when connecting
"" // password
)
java.sql.Connection = com.mysql.jdbc.JDBC4Connection@12e78a69

포트에서 청취자를 찾기 위해 시도했습니다.

 netstat -tln

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:31416           0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN  

이에 따라 연결은 변경되었지만 연결은 변경되었습니다.데이터베이스를 검색합니다.

milenko@milenko-desktop:~$ netstat -an | grep -i mysql
unix  2      [ ACC ]     STREAM     LISTENING     404688   /var/run/mysqld/mysqld.sock
milenko@milenko-desktop:~$ sudo su
[sudo] password for milenko: 
root@milenko-desktop:/home/milenko# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.0.29-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

프로토콜을 변경하려는 경우

root@milenko-desktop:/home/milenko# mysql --protocol=TCP/IP
Unknown option to protocol: TCP/IP
Alternatives are: 'TCP','SOCKET','PIPE','MEMORY'
root@milenko-desktop:/home/milenko# mysql --protocol=TCP
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111 "Connection refused")

루트를 어떻게 지정해야 합니까, 어디에 문제가 있습니까?

언급URL : https://stackoverflow.com/questions/42345516/why-do-i-have-com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communica

반응형