Closing active connections using RMySQL

前端 未结 6 843
时光说笑
时光说笑 2020-12-28 18:49

As per my question earlier today, I suspect I have an issue with unclosed connections that is blocking data from being injected into my MySQL database. Data is being allowed

6条回答
  •  庸人自扰
    2020-12-28 19:03

    Closing a connection

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

        all_cons <- dbListConnections(MySQL())
        for(con in all_cons) 
          dbDisconnect(con)
    

    Check all connections have been closed

        dbListConnections(MySQL())
    

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

        dbGetQuery(mydb, "show processlist")
    

    Where mydb is..

        mydb = dbConnect(MySQL(), user='user_id', password='password', 
                          dbname='db_name', host='host')
    

    Close a particular connection

        dbGetQuery(mydb, "kill 2")
        dbGetQuery(mydb, "kill 5")
    

提交回复
热议问题