mysql - 如何安装和配置 RMySQL 以连接到远程 MySQL 数据库 (AWS RDS)?

标签 mysql r amazon-web-services ssh rmysql

与我的问题相关的系统信息:

AWS RDS DB Instance
Instance Class - db.m1.small
Engine - MySQL 5.6.13

AWS EC2 Linux AMI
https://aws.amazon.com/amazon-linux-ami/2014.03-release-notes/

R version 3.0.2
i686-redhat-linux-gnu (32-bit)

Linux MySQL packages installed:
mysql.noarch            5.5-1.6.amzn1        @amzn-main   
mysql-server.noarch     5.5-1.6.amzn1        @amzn-main   
mysql55.i686            5.5.37-1.46.amzn1    @amzn-updates
mysql55-common.i686     5.5.37-1.46.amzn1    @amzn-updates
mysql55-libs.i686       5.5.37-1.46.amzn1    @amzn-updates
mysql55-server.i686     5.5.37-1.46.amzn1    @amzn-updates

我在上述 AWS Linux AMI 上安装了 R。我正在尝试将数据从运行 MySQL 的 RDS 实例提取到 R 数据帧中。

就目前情况而言,我已将 DBI 包安装到 R 中,但安装 RMySQL 失败并出现以下错误:

$> R CMD INSTALL RMySQL_0.9-3.tar.gz
* installing to library ‘/usr/lib/R/library’
* installing *source* package ‘RMySQL’ ...
** package ‘RMySQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for compress in -lz... yes
checking for getopt_long in -lc... yes
checking for mysql_init in -lmysqlclient... no
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking mysql.h usability... no
checking mysql.h presence... no
checking for mysql.h... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking /usr/local/include/mysql/mysql.h usability... no
checking /usr/local/include/mysql/mysql.h presence... no
checking for /usr/local/include/mysql/mysql.h... no
checking /usr/include/mysql/mysql.h usability... no
checking /usr/include/mysql/mysql.h presence... no
checking for /usr/include/mysql/mysql.h... no
checking /usr/local/mysql/include/mysql/mysql.h usability... no
checking /usr/local/mysql/include/mysql/mysql.h presence... no
checking for /usr/local/mysql/include/mysql/mysql.h... no
checking /opt/include/mysql/mysql.h usability... no
checking /opt/include/mysql/mysql.h presence... no
checking for /opt/include/mysql/mysql.h... no
checking /include/mysql/mysql.h usability... no
checking /include/mysql/mysql.h presence... no
checking for /include/mysql/mysql.h... no

Configuration error:
  could not find the MySQL installation include and/or library
  directories.  Manually specify the location of the MySQL
  libraries and the header files and re-run R CMD INSTALL.

INSTRUCTIONS:

1. Define and export the 2 shell variables PKG_CPPFLAGS and
   PKG_LIBS to include the directory for header files (*.h)
   and libraries, for example (using Bourne shell syntax):

      export PKG_CPPFLAGS="-I<MySQL-include-dir>"
      export PKG_LIBS="-L<MySQL-lib-dir> -lmysqlclient"

   Re-run the R INSTALL command:

      R CMD INSTALL RMySQL_<version>.tar.gz

2. Alternatively, you may pass the configure arguments
      --with-mysql-dir=<base-dir> (distribution directory)
   or
      --with-mysql-inc=<base-inc> (where MySQL header files reside)
      --with-mysql-lib=<base-lib> (where MySQL libraries reside)
   in the call to R INSTALL --configure-args='...' 

   R CMD INSTALL --configure-args='--with-mysql-dir=DIR' RMySQL_<version>.tar.gz

ERROR: configuration failed for package ‘RMySQL’
* removing ‘/usr/lib/R/library/RMySQL’

很明显,我需要将安装定向到 MySQL 的安装位置,但我不知道从哪里开始找到正确的目录。我做了以下尝试环顾四周:

$> find / -name mysql
/usr/share/mysql
/usr/lib/perl5/vendor_perl/auto/DBD/mysql
/usr/lib/perl5/vendor_perl/DBD/mysql
/usr/lib/mysql
/usr/bin/mysql
/var/lib/mysql
/var/lib/mysql/mysql

所以我的 AWS Linux 实例上有很多不同的 MySQL 目录。我在安装路径中使用哪一个?我应该反复试验吗?

我的另一个问题是(假设我正确安装了 RMySQL),MySQL 服务器是否必须在安装了 R 的同一台物理(虚拟?)机器上运行才能使 RMySQL 正常工作?

其他研究表明,必须创建 SSH 隧道才能使 RMySQL 与 MySQL 数据库的连接正常工作。这是真的?如果我没记错的话,AWS RDS 不允许 SSH 隧道。

还有其他建议吗?

最佳答案

您错过了配置输出中最重要的一行:

checking for mysql.h... no

您已安装 MySQL 的运行时软件包。您现在需要开发包

在 Debian/Ubuntu 下,我们强加了这些构建依赖(我刚刚编辑了最低版本要求):

Build-Depends: debhelper, cdbs, r-base-dev, libmysqlclient-dev, r-cran-dbi

前两个是 Debian 内部封装,第三个是 R,第四个是 MySQL,您需要将其映射到 RH/FC 的名称,最后一个是 R 的 DBI。

关于mysql - 如何安装和配置 RMySQL 以连接到远程 MySQL 数据库 (AWS RDS)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23447862/

相关文章:

Mysql - 数据库中的表情符号字符

mysql - sql查询是否正确?

r - 在 ggplot 上添加回归线

r - 创建分层网络

ruby-on-rails - Rails 的 AWS CodeBuild 进程无法安装 pg gem

php - 对查询结果使用 foreach() 而不是 while()

mysql - 有没有办法对 MySQL 数据库进行地理编码,然后在 Google map 上显示结果?

r - 计算两个非零数字之间的零,然后通过 R 中的数字数组继续执行此操作

java - 创建实例时可用区无效

c# - 是什么导致 UWP Release模式下出现此亚马逊构建错误?