我有这段代码,想要读取数据框中的所有数据并将其插入到mysql中,但是我收到了这个错误:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘dbWriteTable’ for signature ‘"MySQLConnection", "character", "tbl_myr"’
我的数据库已启动并正在运行,df1是我要插入的数据。 有什么我做错了吗?
> mydb = dbConnect(MySQL(), user='test', password='passwd', dbname='test_db', host='192.168.1.77')
> dbWriteTable(mydb, value =df1, name ="test_db.myr" , row.names = F , append = T , overwrite = F )
感谢您的协助。
答案 0 :(得分:0)
问题是您正在将数据作为名为mydata的数据框读取。因此,将数据导入sql的代码应为:
mydb = dbConnect(MySQL(), user='test', password='passwd', dbname='test_db', host='192.168.1.77')
# NOTICE that value = df1 CHANGED to value = mydata since your data frame is actually named mydata.
dbWriteTable(mydb, value = mydata, name ="test_db.myr" , row.names = F , append = T , overwrite = F )
运行类(mydata)应该导致data.frame。