pandhale
pandhale

Reputation: 219

Writing the data frame to MySql DB table

How to write the data frame in R into 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.

Thanks

Upvotes: 16

Views: 29510

Answers (3)

vinit kumar singh
vinit kumar singh

Reputation: 21

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

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

Upvotes: 1

MadSeb
MadSeb

Reputation: 8234

Use the dbWriteTable function. It looks like this :

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

The function is well documented.

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

Upvotes: 30

Dirk is no longer here
Dirk is no longer here

Reputation: 368181

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

Upvotes: 7

Related Questions