[R] Disconnect all MySQL connections

David James dj at research.bell-labs.com
Mon Mar 6 15:52:02 CET 2006


mailto-nik at bluemail.ch wrote:
> Hi
> 
> I've got the error "cannot allocate a new connection -- maximum of 16 connections
> already opened" after I tried to create a new connection to a database. However,
> the reason ist, that i did not disconnect previous connections....
> 
> I don't know the name of this connections. How can I disconnect this "unknown"
> connections and drivers? if I delete all objects, the error still occurs.
> Exists a function which i don't know?

You can use dbDisconnect() together with dbListConnections() to
disconnect those connections RMySQL is managing:

   > all_cons <- dbListConnections(MySQL())
   > for(con in cons)
   +  dbDisconnect(con)

   ## check all connections have been closed
   > dbListConnections(MySQL())
   > list()

You could also kill any connection you're allowed to (not just those
managed by RMySQL):

   > dbGetQuery(con, "show processlist")
       Id      User       Host       db   Command Time
   1 2366 celnet_do gaia:47944 wireless Connect     19
   2 2367 celnet_do gaia:47946 wireless Connect     15
   3 2368 celnet_do gaia:47948 wireless   Query      0

   > dbGetQuery(con, "kill 2366")
   > dbGetQuery(con, "kill 2367")
   ....

HTH,

-- 
David 

> 
> Thanks a lot for your help.
> Regards
> Nik
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list