I have an R script where I want to pull some data from a MySQL database, then from a PostgreSQL database. However, loading the MySQL driver from RMySQL prevents me from loading the PostgreSQL driver from PostgreSQL.
I can load the Postgres driver fine on its own:
> RPostgreSQL::PostgreSQL()
<PostgreSQLDriver:(58810)>
Then I can load the RMySQL driver:
> RMySQL::MySQL()
<MySQLDriver>
However, if I load the MySQL driver first, the PostgreSQL driver fails to load:
> RMySQL::MySQL()
<MySQLDriver>
> RPostgreSQL::PostgreSQL()
Error in as.integer(from) :
cannot coerce type 'S4' to vector of type 'integer'
This seems a little magical to me: RMySQL shouldn't be altering functions in RPostgreSQL's namespace.
Does anyone have any idea what might be causing this problem and how I can solve it? I've replicated the problem on 2 different machines, with the exact same results.
Machine 1: Mac OS 10.9.5:
Machine R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] DBI_0.3.1 RMySQL_0.10 RPostgreSQL_0.41
Machine 2: Fedora release 20 (Heisenbug):
R version 3.1.1 (2014-07-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] DBI_0.3.1 RMySQL_0.10 RPostgreSQL_0.4
/edit: Furthermore, even if I load the Postgres driver first, merely loading the MySQL driver completely borks the Postgres driver:
library(DBI)
dr1 <- RPostgreSQL::PostgreSQL()
dr2 <- RMySQL::MySQL()
> dbConnect(dr1, host = "me", port = "1234", dbname = "me", user="me", password="me")
Error in as.integer(from) :
cannot coerce type 'S4' to vector of type 'integer'
/edit 2: This is a bug in RMySQL 0.10; the above code works fine in RMySQL 0.9.3. Judging from this 20-month old question, a similar bug crops up from time to time in RMySQL.
Related
Recently my R on Windows 10 breaks down when trying to connect to a MySQL database using RMariaDB. The same error occurs when using RMySQL drivers as well. The error just appeared. The exact same code worked flawlessly about a year ago.
I am using the following code:
mydb <- DBI::dbConnect(drv = RMariaDB::MariaDB(),
default.file = "path/rds-combined-ca-bundle.pem",
username = "some_username",
password = "some_password",
host = "some_host",
port = 3306)
The second I run the dbConnect command, R crashes with the following error:
RSession Aborted
R encountered a fatal error.
The session was terminated.
My sessionInfo before executing the command is as follows:
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.12.8 RMariaDB_1.0.9
loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 zeallot_0.1.0 crayon_1.3.4 checkpoint_0.4.7 DBI_1.1.0 backports_1.1.5
[7] pillar_1.4.3 rlang_0.4.2 vctrs_0.2.1 tools_3.6.1 bit64_0.9-7 bit_1.1-15.2
[13] hms_0.5.2 compiler_3.6.1 pkgconfig_2.0.3 tibble_2.1.3
My RStudio diagnostics file shows the following issue:
17 Jul 2020 22:27:28 [rsession-XXX] ERROR system error 10053 (An established connection was aborted by the software in your host machine) [request-uri=/events/get_events]; OCCURRED AT: void __cdecl rstudio::session::HttpConnectionImpl<class rstudio_boost::asio::ip::tcp>::sendResponse(const class rstudio::core::http::Response &) c:\jenkins\workspace\ide\windows-v1.2\src\cpp\session\http\SessionHttpConnectionImpl.hpp:111; LOGGED FROM: void __cdecl rstudio::session::HttpConnectionImpl<class rstudio_boost::asio::ip::tcp>::sendResponse(const class rstudio::core::http::Response &) c:\jenkins\workspace\ide\windows-v1.2\src\cpp\session\http\SessionHttpConnectionImpl.hpp:116
So it would seem that there is some issue outside of R, potentially with a firewall or anti-virus software. Consequently, I have added RStudio and all RSessions in the list to the Windows Defender "Allowed Apps" list and tried disabling both Windows Defender and Symantec Endpoint Protection. However, the error keeps occurring. Any advice would be much appreciated.
default.file is a configuration file, not a certificate.
Our shop just upgraded to Matlab 2019a, and I'm bumbling around the import of MySQL/MariaDB data (*.frm files). I found myself to the sqlread tutorial. I have yet to fully plumb the machinations behind the database command to set up a connection, but in messing around, I seem to have discovered that I don't have an sqlread function. This is odd, as I have the Database Toolbox:
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.6.0.1072779 (R2019a)
MATLAB License Number: ______
Operating System: Microsoft Windows 7 Enterprise Version 6.1 (Build 7601: Service Pack 1)
Java Version: Java 1.8.0_181-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.6 (R2019a)
Database Toolbox Version 9.1 (R2019a)
<...snip...>
>> help sqlread
--- sqlread not found. Showing help for stlread instead. ---
<...snip...>
>> which database
C:\Program Files\MATLAB\R2019a\toolbox\database\database\database.m
>> which sqlread
'sqlread' not found.
Why would this not be available?
TMW investigated and reported that sqlread becomes available after setting up a data source.
Unfortunately, the next road block that I'm confronting is setting up the data source.
My question about a simpler alternative to import MySQL data into Matlab still stands.
Thanks.
I have a project with a connection that was working properly on the same device. I suddenly got the error below. And I could connect from the same device through MySQL workbench.
What could be the reason?
library(RMySQL)
con <- dbConnect(RMySQL::MySQL(),
host = "xxx",
dbname="yyy",
user = "zzz",
password = "############")
Error in .local(drv, ...) :
Failed to connect to database: Error: Lost connection to MySQL server at 'reading authorization packet', system error: 10060
And here's the session info
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RMySQL_0.10.10 DBI_0.4-1
loaded via a namespace (and not attached):
[1] tools_3.3.1
My code started having this exact problem after doing a system wide package update on 3/29/2017 for the first time since 2/1/2017.
Looking at the versioning for RMySQL,
RMySQL_0.10.9.tar.gz published 2016-05-08 15:39
RMySQL_0.10.10.tar.gz published 2017-03-21 07:50
I reverted my version to 0.10.9 and the problem went away:
require(devtools)
install_version("RMySQL", version = "0.10.9", repos = "http://cran.us.r-project.org")
I posted your issue to the RMySQL bug page, so we'll see if they address it
I checked another latest version of RMySQL package recently, RMySQL_0.10.11.zip
The problem exists in that too.
Apologies, cant comment as not allowed currently, hence wanted to update about the version where the problem is still being seen.
Additional Info
Connection to MySQL on my system is working from
1) Cmdline
2) MySQL Workbench
3) Tableau
4) Excel
It is just not working on R.
I checked following
link1
link2
link3
SHOW GLOBAL STATUS like 'Aborted%clients%';
And every time connection is dropped from R, the value of above variable goes +1.
Even doing
SET GLOBAL connect_timeout = 10;
has not helped.
UPDATE
Is there a dependency/requirement for PERL to be installed for usage of RMySQL?
As of now, my system does not have PERL. if this requirement is indeed true, then that might be 1 of the reason and may be the latest version has the problem fixed. Please let me know about the PERL dependency?
I was able to fix this issue on my PC using R 3.4 by following #Page's advice to look into the package versioning. However, not only did I need to install an earlier version of RMySQL (reverting from 0.10.11 to 0.10.9), I also needed to change versions on its dependancy package DBI (reverting from 0.6-1 to 0.5), using the following command:
require(devtools)
install_version("DBI", version = "0.5", repos = "http://cran.us.r-project.org")
install_version("RMySQL", version = "0.10.9", repos = "http://cran.us.r-project.org")
I was trying to build my app on linux using mysql c api, and got this error at link stage, it's working fine on windows. Please help, thanks!
error message:
/bin/ld: myapp.so : version node not found for symbol mysql_select_db#libmysqlclient_16
/bin/ld: failed to set dynamic section sizes: Bad value
OS: CentOS 7, 64-bit, (VM on virtual box)
Mysql: 5.6.24 (community edition, installed via yum)
.bashrc file
export LIBMYSQL_INCLUDE_DIR=/usr/include/mysql
export LIBMYSQL_LIBRARY=/usr/lib64/mysql
export LD_LIBRARY_PATH=/usr/lib64/mysql:$LD_LIBRARY_PATH
cmake file: (variables are set according to environment variables)
FILE(GLOB SRC_MYAPP myapp/*.c myapp/*.h)
INCLUDE_DIRECTORIES(${LIBMYSQL_INCLUDE_DIR})
ADD_LIBRARY(myapp ${SRC_MYAPP})
IF (MSVC_IDE)
TARGET_LINK_LIBRARIES(myapp ${LIBMYSQL_LIBRARY}/libmysql)
ELSE ()
TARGET_LINK_LIBRARIES(myapp ${LIBMYSQL_LIBRARY}/libmysqlclient_r.a)
ENDIF ()
Put #hank 's comment as answer
I suppose you should add link_directories(/usr/lib64/mysql) before add_library and then target_link_libraries(myapp mysqlclient_r) – hank May 12 at 12:50
RMySQL library works at R-64bit version.
but still it doesn't work with the 32bit R version
because I'm using statconn tools(DCOM, rcom) which only work with the 32 version R,
I need to access MySQL DB with R-32bit Version.
below are thing i've done till now.
install latest Rtools
install 64-bit MySQL Client( 32bit version doens't work)
C:\Program Files\R\R-2.12.1\etc\Renviron.site and add line like MYSQL_HOME=C:/mysql (path to your mysql files)
copy libmysql.lib to (mysql/lib/opt, R_HOME\bin, windows\system32)
install.packages('RMySQL',type='source')
set R_HOME, MYSQL_HOME to enviroment variables properly
add R_HOME, MYSQL_HOME, Rtools to path.
error messages :
RS-MySQL.o:RS-MySQL.c:(.text+0x2f23): undefined reference to `mysql_get_client_version#0'
RS-MySQL.o:RS-MySQL.c:(.text+0x2f44): undefined reference to `mysql_get_client_info#0'
RS-MySQL.o:RS-MySQL.c:(.text+0x2f71): undefined reference to `mysql_server_end#0'
collect2: ld returned 1 exit status
ERROR: compilation failed for package 'RMySQL'
* removing 'C:/Program Files/R/R-2.15.1/library/RMySQL'
how can i use 32bit R version with 64bit MySQL?
For your information.
"RODBC" library works with 64 bit R version, but 32 bit R version