Skip to content

R, RMySQL and OSX

2 messages · Louis Springer, Brian Ripley

#
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:

            

  
  
#
Please (as we ask) consult the R posting guide at

http://www.r-project.org/posting-guide.html

and

0) Do not send HTML mail.
1) Do not post to multiple lists.
2) Contact the maintainer first as it asks you to there. (It also tells 
you how to find out the maintainer and other relevant information.)
On Wed, 7 Jun 2006, Louis Springer wrote: