title: Why do I have,com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
body: <p>I am trying to connect to a database server with SCALA</p>
  
  <pre><code>scala&gt; val connection = DriverManager.getConnection(
       | "jdbc:mysql://127.0.0.1:3306/test",
       | "milenko",
       | "nilton")
  </code></pre>
  
  <p>I got this</p>
  
  <pre><code>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.&lt;init&gt;(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.&lt;init&gt;(ConnectionImpl.java:794)
    at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(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)
  </code></pre>
  
  <p>I have just basic knowledge of SQL,I am trying to run this example from scala tutorial</p>
  
  <pre><code>scala&gt; 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
  </code></pre>
  
  <p>I have tried this,to find listener on port</p>
  
  <pre><code> 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  
  </code></pre>
  
  <p>According to this,I have changed my connection but still get the same.
  I search for database</p>
  
  <pre><code>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)]&gt; show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | mysql              |
  | performance_schema |
  +--------------------+
  3 rows in set (0.00 sec)
  </code></pre>
  
  <p>If I try to change protocol</p>
  
  <pre><code>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")
  </code></pre>
  
  <p>How should I specify my root,where is the problem?</p>