将数据框写入 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
Writing the data frame to MySql DB table
提问by pandhale
How to write the data frame in R
into 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 MySQL
DB table.
I have used RMySql
package 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
回答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 yourtable
to the database named yourTableInMySQL
.
使用下面的命令对我有用。请注意,这会将行附加yourtable
到名为yourTableInMySQL
.
library(RMySQL)
dbWriteTable(con, "yourTableinMySQL", yourtable, append = TRUE)