将数据框写入 MySql DB 表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12186839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:41:45  来源:igfitidea点击:

Writing the data frame to MySql DB table

mysqlr

提问by pandhale

How to write the data frame in Rinto MySQL?

如何将数据框R写入MySQL

dateTime            host    authId     sessionId      status                    action 
2012-08-22 14:58:23 foo.com 221501398 2c10b368ae23ba3        questions#instant_answers
2012-08-22 14:58:23 foo.com 221501398 22c10b368ae23                      questions#new
2012-08-22 14:58:23 foo.com 221501398 01a36f64bd3f80c                     sessions#new

I want to write the dataframe all at once to the MySQLDB table. I have used RMySqlpackage to connect and establish the connection.

我想一次将数据帧写入MySQL数据库表。我已经使用RMySql包来连接并建立连接。

Thanks

谢谢

回答by MadSeb

Use the dbWriteTable function. It looks like this :

使用 dbWriteTable 函数。它看起来像这样:

dbWriteTable(connection, value = data.frame, name = "MyTable", append = TRUE ) 

The function is well documented.

该功能有据可查。

P.S Also look at: RMySQL dbWriteTable with field.types

PS另看: RMySQL dbWriteTable with field.types

回答by Dirk Eddelbuettel

See help(dbSendQuery)for generic update ...statements in SQL, and help(dbWriteTable)to write an entire data frame to a new table.

请参阅SQL 中的help(dbSendQuery)通用update ...语句,并将help(dbWriteTable)整个数据框写入新表。

回答by vinit kumar singh

It worked for me using the command below. Note that this will append the rows in yourtableto the database named yourTableInMySQL.

使用下面的命令对我有用。请注意,这会将行附加yourtable到名为yourTableInMySQL.

library(RMySQL)
dbWriteTable(con, "yourTableinMySQL", yourtable, append = TRUE)