Group Abstract Group Abstract

Message Boards Message Boards

JDBC::error when connecting to local MySQL database

GROUPS:
I will go right to the problem.

I have a localhost (XAMPP) installed on my computer (Mac). With this installation follows a MySQL server, and I would like to connect to it. But here is what happens:
Needs["DatabaseLink`"]

conn1 = OpenSQLConnection[JDBC["MySQL(Connector/J)", "127.0.0.1"],  "Username" -> "root", "Password" -> ""]
The result is get is:
JDBC::error: 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. >>

$Failed

I have checked the following:I am running out of ideas on what to do. This problem has always existed and I have never been able to solve it.

I would be really greatful if someone miraculously know tips and tricks to get it up and running.  
POSTED BY: Simon Pedersen
Answer
9 months ago
Hi,
That error is typical when the server does not exist or cannot be reached.  Can you mention what other clients (MySQL Workbench etc.) have been able to connect?

Also:  if your server is running on a non-standard port (i.e. not 3306), you will have to specify it in the connection URL.  The connection command would be something like this:
OpenSQLConnection[JDBC["MySQL(Connector/J)","127.0.0.1:1234/mydatabase"], "Username" -> "username", "Password" -> "$Prompt"]
... for port 1234 and database mydatabase.
POSTED BY: Dillon Tracy
Answer
9 months ago
A slightly silly suggestion but...
...is you MySQL server running?  

Go to a terminal and simply type

mysql

If your mysql server is not running then you will get an error message like 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

And indeed when my mysql server is not running I get the same Mathematica error as you do when attempting to open a connection using DatabaseLink
POSTED BY: David Reiss
Answer
9 months ago
Hello Dillon and David,

Thank you both for answering!

For some reason the MySQL server did not allow for external connections from other than 127.0.0.1, Restarting both Apache and MySQL Server, the computer prompted me to allow or deny external connections. Allowing this, made Mathematica able to connect!

Best Regards

Simon P.
POSTED BY: Simon Pedersen
Answer
9 months ago