I'm trying to use RODBC to connect to a MySQL db on my computer (I'm assuming it's localhost). I've read the package reference manual and can't figure out how to do anything (connect, set default driver, open channel, etc). Any suggestions?
EDIT:
> install.packages("RMySQL", type="source")
Installing package(s) into ‘C:/Users/backupSam/Documents/R/win-library/2.13’
(as ‘lib’ is unspecified)
trying URL 'http://lib.stat.cmu.edu/R/CRAN/src/contrib/RMySQL_0.8-0.tar.gz'
Content type 'application/x-gzip' length 160735 bytes (156 Kb)
opened URL
downloaded 156 Kb
* installing *source* package 'RMySQL' ...
ERROR: configuration failed for package 'RMySQL'
* removing 'C:/Users/backupSam/Documents/R/win-library/2.13/RMySQL'
* restoring previous 'C:/Users/backupSam/Documents/R/win-library/2.13/RMySQL'
The downloaded packages are in
‘C:\Users\backupSam\AppData\Local\Temp\RtmpitXEFu\downloaded_packages’
Warning messages:
1: running command 'C:/PROGRA~1/R/R-213~1.2/bin/x64/R CMD INSTALL -l "C:/Users/backupSam/Documents/R/win-library/2.13" C:\Users\BACKUP~1\AppData\Local\Temp\RtmpitXEFu/downloaded_packages/RMySQL_0.8-0.tar.gz' had status 1
2: In install.packages("RMySQL", type = "source") :
installation of package 'RMySQL' had non-zero exit status
First set up a connection.
1) For me I had to download a driver on MySql's website, which will vary by system and version, I used this page:
Windows ODBC Drivers
2) Once this is downloaded run the setup utility.
3) Next setup up the DSN. Instructions for windows are here: MySQL ODBC DSN Setup
4) Important: Remember the name of the DSN as it is used when you create the channel in RODBC to connect to your database.
5) Finally, once this is setup you install and load the RODBC package.
6) To connect to your database use something like this:
channel <- odbcConnect("mysql 2", uid="root")
where 'mysql 2' is the name of your DSN connection, NOT the name of the database.
7) Finally you can send a query like this:
result1 <- sqlQuery(channel, paste("SELECT * from db1"))
Related
I am attempting to use clsql-mysql on the Windows platform. I am using 32 bit Clozure CL with the 32 bit MySQL Connector library (from Oracle) to provide the external library.
I added the path of the connector to %path% so that clsql could find the connector library, and connecting to the database with
(clsql:connect '("host" "db" "user" "pw"))
Which goes without a hitch and returns a <MYSQL_DATABASE> object.
When I attempt to do a simple SQL query, however, I get the following error:
;; Query
(clsql:query "select * from logentry where id = 3346;")
;; Error:
`Can't resolve foreign symbol "clsql_mysql_field_flags"`
Could this be something to do with the way that the mysql connector is compiled? from the INFO_BIN file supplied with the MySQL Connector:
===== Information about the build process: =====
Build was run at Thu 07/13/2017 on host 'VITRO50'
Build was done on Windows-6.2 using AMD64
Build was done using cmake 3.2.3
===== Compiler / generator used: =====
Visual Studio 14 2015
Pointer size: 4
===== Feature flags used: =====
-- Cache values
CANDLE_EXECUTABLE:FILEPATH=C:/Program Files (x86)/WiX Toolset v3.10/candle.exe
CMAKE_CONFIGURATION_TYPES:STRING=DebugReleaseMinSizeRelRelWithDebInfo
CMAKE_INSTALL_PREFIX:PATH=C:/Program Files (x86)/LibMySQL
COMMUNITY_BUILD:BOOL=ON
DEBUG_EXTNAME:BOOL=ON
ENABLED_PROFILING:BOOL=ON
ENABLE_DEBUG_SYNC:BOOL=ON
ENABLE_GCOV:BOOL=OFF
ENABLE_GPROF:BOOL=OFF
EXTRA_INSTALL:BOOL=G:\ade\build\sb_0-24199034-1499945748.28/mysql-connector-c-6.1.11-vs12-win32/lib/mysqlclient.liblib/vs12DevelopmentG:\ade\build\sb_0-24199034-1499945748.28/mysql-connector-c-6.1.11-vs12-win32/lib/debug/mysqlclient.liblib/vs12/debugDebugBinariesG:\ade\build\sb_0-24199034-1499945748.28/mysql-connector-c-6.1.11-vs14-win32/lib/mysqlclient.liblib/vs14DevelopmentG:\ade\build\sb_0-24199034-1499945748.28/mysql-connector-c-6.1.11-vs14-win32/lib/debug/mysqlclient.liblib/vs14/debugDebugBinaries
FEATURE_SET:STRING=community
HEAT_EXECUTABLE:FILEPATH=C:/Program Files (x86)/WiX Toolset v3.10/heat.exe
INSTALL_LAYOUT:STRING=STANDALONE
LIGHT_EXECUTABLE:FILEPATH=C:/Program Files (x86)/WiX Toolset v3.10/light.exe
MYSQL_DATADIR:PATH=C:/Program Files/MySQL/MySQL Server 6.1/data
MYSQL_KEYRINGDIR:PATH=C:/Program Files/MySQL/MySQL Server 6.1/keyring
MYSQL_MAINTAINER_MODE:BOOL=OFF
PKG_INSTALL_PREFIX:PATH=C:/Program Files (x86)/LibMySQL
TMPDIR:PATH=
WIN_DEBUG_NO_INLINE:BOOL=OFF
WITH_ARCHIVE_STORAGE_ENGINE:BOOL=ON
WITH_ASAN:BOOL=OFF
WITH_BLACKHOLE_STORAGE_ENGINE:BOOL=ON
WITH_CLIENT_PROTOCOL_TRACING:BOOL=ON
WITH_DEBUG:BOOL=OFF
WITH_DEFAULT_COMPILER_OPTIONS:BOOL=ON
WITH_DEFAULT_FEATURE_SET:BOOL=ON
WITH_EMBEDDED_SERVER:BOOL=ON
WITH_EXTRA_CHARSETS:STRING=all
WITH_FEDERATED_STORAGE_ENGINE:BOOL=ON
WITH_INNOBASE_STORAGE_ENGINE:BOOL=ON
WITH_MSAN:BOOL=OFF
WITH_MSCRT_DEBUG:BOOL=OFF
WITH_NUMA:BOOL=ON
WITH_PARTITION_STORAGE_ENGINE:BOOL=ON
WITH_SSL:STRING=bundled
WITH_TEST_TRACE_PLUGIN:BOOL=OFF
WITH_UBSAN:BOOL=OFF
WITH_UNIT_TESTS:BOOL=OFF
WITH_ZLIB:STRING=bundled
WIX_DIR:PATH=C:/Program Files (x86)/WiX Toolset v3.10
===== EOF =====
The only hits I could find when searching for this error were ones that relate to a similar issue on Ubuntu.
How do I start to debug this error, or how do I fix this error so that the SQL query completes without error?
I've been forced to try to port to PySide2 from PySide because I'm developing code (on Windows 7) used inside Maya and Maya 2017 has moved to PySide2.
PySide2 ships with Maya but only comes with the driver to talk to sqlite DBs. So I need to tell Qt about a new DIR that contains the MySql driver, like this:
from PySide2 import QtWidgets
QtWidgets.QApplication.addLibraryPath("C:\temp\plugins")
This DIR contains a sub sqldrivers DIR which contains the driver. This works- when I call QtSql.QSqlDatabase.drivers() the new one is there so I've got the right driver and it's being picked up.
However when I create a new DB and call open:
db = QtSql.QSqlDatabase.addDatabase("QMYSQL3")
db.setDatabaseName("my_db")
db.setHostName("host")
db.setUserName("user")
db.setPassword("password")
db.open()
the open command returns False and the DB is not accessible. I call:
db.lastError()
and get:
# Result: <PySide2.QtSql.QSqlError("", "Driver not loaded", "Driver not loaded") at 0x0000000075410C08> #
NB: we successfully did the exact same thing with the previous PySide version.
Other threads mention similar things and it turned out to be missing the actual libmysql.dll, which is the actual MySql DLL and can result in the same error if missing. However I definitely have this on my system and it's definitely in the PATH. It's actually the same file that is being successfully picked up through PySide. But the PySide2 driver just wont open a connection to the DB.
I suspect maybe a dodgy driver but wondered if anyone has any experience with this or any advice?
I had the same error, but with postgres.
I solved by placing the libpq.dll connector library next to my script.py.
Then for mysql it would be libmysql.dll.
In my case I had to build the libpq.dll from the source of postgres 9.6
It seems that with PySide2 it is not necessary to use:
QtWidgets.QApplication.addLibraryPath ("C: \ path_to\ plugins")
using:
print (PySide2.QtCore.QLibraryInfo.location (PySide2.QtCore.QLibraryInfo.PluginsPath)), I could see that the path was correct.
a greeting
I want to create a database within a pipeline script to be used by the deployed app. But first I started testing the connection. I got this problem:
java.sql.SQLException: No suitable driver found for jdbc:mysql://mysql:3306/test_db
I have the database plugin and the MySQL database plugin installed.
How do I get the JDBC driver?
import groovy.sql.Sql
node{
def sql = Sql.newInstance("jdbc:mysql://mysql:3306/test_db", "user","passwd", "com.mysql.jdbc.Driver")
def rows = sql.execute "select count(*) from test_table;"
echo rows.dump()
}
Update after albciff answer:
My versions of:
Jenkins = 2.19.1
Database plugin = 1.5
Mysql database plugin = 1.1
The latest test script.
import groovy.sql.Sql
Class.forName("com.mysql.jdbc.Driver")
Which throws:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
From the MySQL DataBase Plugin documentation you can see that jdbc drivers for MySQL are included:
Note that MySQL JDBC driver is under GPLv2 with FOSS exception. This
plugin by itself qualifies under the FOSS exception, but if you are
redistributing this plugin, please do check the license terms.
Drizzle(+MySQL) Database Plugin is available as an alternative to this
plugin, and that one is under the BSD license.
More concretely the actual last version (1.1) for this plugin contains connector version 5.1.38:
Version 1.1 (May 21, 2016) mysql-connector version 5.1.38
So probably in order to have the driver available you have to force the driver to be registered.
To do so use Class.forName("com.mysql.jdbc.Driver") before instantiate the connection in your code:
import groovy.sql.Sql
node{
Class.forName("com.mysql.jdbc.Driver")
def sql = Sql.newInstance("jdbc:mysql://mysql:3306/test_db", "user","passwd", "com.mysql.jdbc.Driver")
def rows = sql.execute "select count(*) from test_table;"
echo rows.dump()
}
UPDATE:
In order to has the JDBC connector classes available in the Jenkins pipeline groovy scripts you need to update the DataBase plugin to last currently version:
Version 1.5 (May 30, 2016) Pipeline Support
You can simply add the java connector in the java class path.
If jenkins is running java < 9 you probably will find the right place inside something like that:
<java_home>/jre/lib/ext
If jenkins is running java >= 9 you probably will find the right place inside something like that:
/usr/share/jenkins/jenkins.war
To find your paths you can check:
http://your.jenkins.host/systemInfo (or navigate system info path by GUI) and search for java.ext.dirs or java.class.path
http://your.jenkins.host/script (running console script such as System.getProperty("java.ext.dirs") or System.getProperty("java.class.path"))
This snippet can help you with the jenkins.war thing when running inside docker:
#adding extra jars to default jenkins java classpath (/usr/share/jenkins/jenkins.war)
RUN sudo mkdir -p /usr/share/jenkins/WEB-INF/lib/
RUN whereis jar #just to find full jar command classpath to use with sudo
COPY ./jar-ext/groovy/mysql-connector-java-8.0.21.jar /usr/share/jenkins/WEB-INF/lib/
RUN cd /usr/share/jenkins && sudo /opt/java/openjdk/bin/jar -uvf jenkins.war ./WEB-INF/lib/mysql-connector-java-8.0.21.jar
For Jenkins running on Java >= 9 add the jdbc drivers under ${JENKINS_HOME}/war/WEB-INF/lib and under the --webroot directory.
I am using a Windows 7 64-bit computer, trying to connect to an ODBC driver directly with R. I tried downloading the RMySQL package as a source, but for some reason it won't install and just leaves error messages like this:
* installing *source* package 'RMySQL' ...
** package 'RMySQL' successfully unpacked and MD5 sums checked
Warning: running command 'sh ./configure.win' had status 127
ERROR: configuration failed for package 'RMySQL'
* removing 'C:/Users/jizzard/Documents/R/win-library/3.1/RMySQL'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-31~1.1/bin/x64/R" CMD INSTALL -l "C:\Users\jizzard\Documents\R\win-library\3.1" C:\Users\jizzard\AppData\Local\Temp\Rtmp8qnScH/downloaded_packages/RMySQL_0.9-3.tar.gz' had status 1
Warning in install.packages :
installation of package ‘RMySQL’ had non-zero exit status
So I'm trying to use the RODBC package instead. I've got my database as an ODBC driver shortcut (Verizon DMP)
but when I try to type con = odbcConnect("Verizon Fios") in R, no connection is established. What is going wrong?
odbcConnect() requires your username (uid) and password (pwd):
odbcConnect(dsn, uid, pwd, ...)
After manually upgrading PHP and MySQL on my Cent OS box then logging in to my Plesk administration panel, I'm receiving the following error when attempting to carry out numerous tasks. PHP and MySQL are functioning correctly in their own right.
New files of configuration for Apache web server were not built due to errors in configuration templates: Template processing failed: file = /usr/local/psa/admin/conf/templates/default/domainVhost.php, error = [unixODBC][Driver Manager]Can't open lib '/usr/lib64/libmyodbc3.so' : /usr/lib64/libmyodbc3.so: cannot open shared object file: No such file or directory. The detailed error message was e-mailed to you, so please check the e-mail, fix the errors, and click here to retry generating broken configuration or click here to retry generating of all configurations.
I have located the ODBC configuration details in the following file:
/etc/odbcinst.ini
The contents of which are as follows:
# Driver from the MyODBC package
# Setup from the unixODBC package
[MySQL]
Description = MySQL driver for Plesk
Driver = /usr/lib64/libmyodbc3.so
Setup =
FileUsage = 1
Driver64 = /usr/lib64/libmyodbc3.so
Setup64 =
UsageCount = 1
I expect that the Driver & Driver64 parameters must be updated to reflect the changes that occurred when MySQL was upgraded however I am unable to locate the path to the appropriate driver and am out of my depth now. Any advice greatly welcomed.
UPDATE: a '# locate libmyodbc3' returns no results.
Turns out the ODBC and mysql-connector-odbc packages were missing.
They were installed using YUM as follows:
# yum install unixODBC
# yum mysql-connector-odbc packages