连接到MySQL数据库并在Julia中获取数据 [英] Connect to MySQL database and fetch data in Julia

查看:730
本文介绍了连接到MySQL数据库并在Julia中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Julia中从MySQL数据库中获取数据?

How can I fetch data from MySQL database in Julia?

看起来此程序包提供了用于连接任何数据库(包括MySQL)的工具.但是,看起来好像我必须先设置ODBC DSN才能连接到它(尽管我已经使用MySQL两年了,但我不知道它到底是什么).因此,我尝试通过阅读此内容进行配置页(位于MySQL文档中...),但立即陷入困境.

It looks like this package provides tools for connecting to any database, including MySQL. However, it looks like assuming I have to first setup ODBC DSN to connect to it (I don't know what it is in the first place, although I've used MySQL for two years). So I tried to configure it by reading this page at MySQL documentation... but hit the wall immediately.

一个,我在OS X 10.8.5中找不到名为myodbc-installer的命令.第二,没有这样的应用程序叫做ODBC Administrator,而是我的系统中有ODBC manager-所以我认为文档太过时了...对吧?

One, I can't find a command named myodbc-installer in my OS X 10.8.5. Two, there is no such application called ODBC Administrator, and instead there is ODBC manager in my system - So I think that documentation is too outdated... right?

此外,即使我打开ODBC manager并尝试单击User DSN选项卡上的Add,在屏幕上也没有检测到driver.那么如何在Julia中配置ODBC DSN并使用MySQL?

Also, even when I opened ODBC manager and tried to click on Add on User DSN tab, there are no driver detected on the screen. So how can I configure ODBC DSN and make use of MySQL in Julia?

此外,我是否必须处理这样繁琐的设置过程?我想使用一个软件包,如果有的话,它和R中的RMySQL软件包一样直观且易于使用,这不会迫使我关心DSN-Julia中的任何此类软件包吗?

Also, do I have to deal with such a tedious setup process? I'd like to use a package, if any, that is as intuitive and easy to use as RMySQL package in R, which doesn't force me to care about DSN - any such package in Julia?

我在Julia中的0.2.0-rc上,并且已经通过Pkg.add("ODBC")安装了该软件包. MySQL版本是5.3.6,并通过MAMP安装.

I'm on 0.2.0-rc in Julia and already installed the package through Pkg.add("ODBC"). MySQL version is 5.3.6 and installed via MAMP.

谢谢.

推荐答案

Jacob Quinn,这里是Julia的ODBC软件包的软件包维护者.

Jacob Quinn here, package maintainer for the ODBC package for Julia.

一些可以帮助您了解该过程如何工作的事情:

A few things to help you understand how the process works:

-ODBC是最初由Microsoft开发的API中间层,用于在DB系统和应用程序之间创建公共接口.这很有用,因为随着数据库系统数量的不同,很难可靠地连接到任何数据库的应用程序.

-ODBC is an API middle layer originally developed by Microsoft to create a common interface between DB systems and applications. This was useful because with the number of different DB systems, it would be hard to have applications that could reliably connect to any DB.

-ODBC已通过2个主要项目移植到Linux/Unix/OSX系统:iodbc(主要是OSX)和unixODBC(Linux)

-ODBC has been ported to Linux/Unix/OSX systems through 2 main projects: iodbc (mainly OSX) and unixODBC (Linux)

-API的基本组件是ODBC管理器,它是中间层,数据库系统,应用程序和ODBC 驱动程序,后者是特定于DB的并且实际上实现了通信在application-ODBC Manager和ODBC Manager-DB系统之间.

-The basic components of the API are the ODBC Manager, which is the middle layer, the DB system, the application, and the ODBC driver, which is DB-specific and actually implements the communication between application-ODBC Manager and ODBC Manager-DB system.

-对于RMySQL,只有MySQL驱动程序已使用R包装器功能实现,该功能允许连接到MySQL DB系统.

-In the case of RMySQL, only the MySQL driver has been implemented with R wrapper functions which allow the connection to MySQL DB systems

-对于ODBC.jl(以及R对应的RODBC),采用更通用的方法,其中提供了ODBC管理器的包装函数,该包装函数允许与 any 数据库系统连接,前提是用户安装了正确的数据库驱动程序和连接字符串

-In the case of ODBC.jl (and the corresponding RODBC for R), a more generalized approach is taken where wrapper functions of the ODBC Manager are provided, which allow connection with any DB system, provided the user has the correct DB driver installed and connection string

希望可以帮助您更好地了解ODBC进程.

Hopefully that helps understand the ODBC process a little better.

因此,对于您而言,您似乎未安装MySQL驱动程序,因为它未显示在ODBC管理器中.您可以在此处找到驱动程序.

So for your case, it looks like you don't have the MySQL driver installed since it didn't show up in your ODBC Manager. You can find the driver here.

一旦安装了驱动程序,设置DSN应该非常简单(遵循MySQL文档或出色的connectionstrings.com,

Once you have the driver installed, it should be pretty simple to set up a DSN (following either MySQL documentation or the excellent connectionstrings.com, MySQL Section).

然后您应该可以在julia中开始使用ODBC:

You should then be able to start using ODBC in julia:

Pkg.add("ODBC")
using ODBC
ODBC.connect(dsn)
query("select * from customers")

如果您遇到其他任何问题或无法进行设置或安装的麻烦,请随时打开一个问题在这里,我非常乐于帮助您解决设置问题,以帮助您继续前进.

If you run into any other issues or troubles getting things setup or installed, feel free to open an issue here and I'm more than willing to help troubleshoot the setup to get you going.

这篇关于连接到MySQL数据库并在Julia中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆