0

When I run

library(RMySQL)
mydb = dbConnect(MySQL(), user = "XX", password = "XX", dbname = "XX", host = "XX")

on the R console it works,

however when I put save it as a yy.R file and run it as R CMD BATCH yy.R, or as source("yy.R") it says

Error in mysqlNewConnection(drv, ...) : RS-DBI driver: (Failed to connect to database: Error: Can't connect to MySQL server on 'XX' (111) ) Calls: dbConnect -> dbConnect -> mysqlNewConnection -> .Call Execution halted

could I check if RMySQL only runs on the console? Thanks!

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
user3847136
  • 47
  • 1
  • 6

1 Answers1

1

Perhaps you can specify the driver with RMySQL::MySQL(), this works for me in scripts.

Lee
  • 405
  • 2
  • 10
  • Sorry, I can't reproduce the problem. I think MySQL error 111 is for host-related connection problems. When I set host to 'localhost' the connection works at console and in script. MySQL is running locally. However, when I set it to '192.168.1.0', it fails at console and in script. This must be because MySQL is only configured to accept connections from localhost (or 127.0.0.1). Doesn't explain what you are experiencing but hope it helps point in right direction to find solution. [link](https://stackoverflow.com/questions/1420839/cant-connect-to-mysql-server-error-111) – Lee Jun 13 '16 at 13:34