Transferring an R data frame to a MySQL (MariaDB) database table, I get the following error: Lost connection to MySQL server during query
Example data can be loaded in R with this command
cntxt <- read.delim("http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&file=comext%2FCOMEXT_METADATA%2FCLASSIFICATIONS_AND_RELATIONS%2FENGLISH%2FCN.txt", header = FALSE, quote = "", stringsAsFactors = FALSE)
I use the RMySQL
package to transfer the data frame to the the database:
con <- RMySQL::dbConnect(RMySQL::MySQL(), dbname = "test")
RMySQL::dbWriteTable(con, "cntxt", cntxt, row.names = FALSE, overwrite = TRUE)
The database write operation works fine on my laptop for tables of any size. But on a server it returns an error. The error only appears for sufficiently large tables (above 1000 rows):
dbWriteTable()
succeeds for 1000 lines of data
RMySQL::dbWriteTable(con, "cntxt", head(cntxt,1000), row.names = FALSE, overwrite = TRUE)
# [1] TRUE
dbWriteTable()
fails for 2000 lines of data
RMySQL::dbWriteTable(con, "cntxt", head(cntxt,2000), row.names = FALSE, overwrite = TRUE)
# Error in .local(conn, statement, ...) :
# could not run statement: Lost connection to MySQL server during query
Based on related questions, I have checked the value of max_allowed_packet:
mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
| max_allowed_packet | 16777216 |
16Mb should be more than enough for 2000 lines of data.
Where is the error coming from?
There is nothing visible in mysql the error log /var/log/mysql/error.log
.
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1