Skip to content
Prev 190 / 1559 Next

R, RMySQL and OSX

I've got at least a partial resolution and workaround to my issue.

The default unix.socket parameter on the dbConnect call is "/opt/ 
local/var/run/mysql5/mysqld.sock" if unix.sock is not specified. I'm  
not sure where this unix.socket is coming from, but it doesn't work  
for me.

The correct unix.sock parameter for my case is  "/tmp/mysql.sock".

This works:

con <- dbConnect(dbDriver("MySQL"), username="myuser",  
host="localhost", dbname="mydb", password="secret", unix.sock="/tmp/ 
mysql.sock")

This does not:

con <- dbConnect(dbDriver("MySQL"), username="myuser",  
host="localhost", dbname="mydb", password="secret")

I also have a patch to RS-MySQL.c to display the error message  
returned by MySQL on a connect error. What should I do with this? Who  
is the current maintainer for this code?

The bit around the "my_sql_real_connect" should read something like:

   if(!mysql_real_connect(my_connection, host, user, passwd, dbname,
		       port, unix_socket, client_flags)){
     char buf[2048];
     sprintf(buf, "could not connect %s@%s on dbname \"%s\"\nError:%s 
\n",
	    user, host, dbname, mysql_error(my_connection));
     RS_DBI_errorMessage(buf, RS_DBI_ERROR);
   }

The current version clobbers "my_connection" on a failed connection  
rendering any call to "mysql_error(my_connection)" useless. My hacked  
RS-MySQL.c returns:

Error in mysqlNewConnection(drv, ...) : RS-DBI driver: (could not  
connect myuser at localhost on dbname "mydb"
Error:Can't connect to local MySQL server through socket '/opt/local/ 
var/run/mysql5/mysqld.sock' (2)

for the error I was having, returning an informative mysql error  
message on the failed connection.


Lou
On Jun 7, 2006, at 9:58 PM, Louis Springer wrote: