为什么我有,com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链路故障

为什么我有,com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链路故障,mysql,scala,jdbc,mariadb,Mysql,Scala,Jdbc,Mariadb,我正在尝试使用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 Th

我正在尝试使用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)
我尝试过这个,在端口上找到侦听器

 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")

我应该如何指定我的根目录,问题出在哪里?

MySQL的可能副本没有运行,或者至少它没有在localhost:3306上运行。有关详细信息,请参阅链接副本。@MarkrotVeel,请查看我的编辑,我是mysql新手。看起来您只有在unix域套接字上运行mysql;MySQL JDBC驱动程序不能使用这个功能:它只能通过TCP/IP连接;更改MySQL配置,使其侦听127.0.0.1:3306。另请参阅链接副本上的已接受答案。@MarkRotteveel我已尝试更改配置,请查看我的最新编辑!MySQL的可能副本没有运行,或者至少它没有在localhost:3306上运行。有关详细信息,请参阅链接副本。@MarkrotVeel,请查看我的编辑,我是mysql新手。看起来您只有在unix域套接字上运行mysql;MySQL JDBC驱动程序不能使用这个功能:它只能通过TCP/IP连接;更改MySQL配置,使其侦听127.0.0.1:3306。另请参阅链接副本上的已接受答案。@MarkRotteveel我已尝试更改配置,请查看我的最新编辑!
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")