在Mathematica中使用MySQL数据库[英] Using MySQL databases in Mathematica

本文是小编为大家收集整理的关于在Mathematica中使用MySQL数据库的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我已经看到,可以使用Input Needs["DatabaseLink"]和conn = OpenSQLConnection[JDBC["MySQL(Connector/J)", "yourserver/yourdatabase"], "Username" -> "yourusername", "Password" -> "yourpassword"]在Mathematica和MySQL数据库之间建立连接(如果任何人都想尝试一下).DataBaselink的文档在这里,顺便说一句.

有人以这种方式有使用Mathematica的经验,可能是为了分析数据库中包含的数据吗?是否有明显的缺点(速度,需要的内存等)?

推荐答案

我最近使用数据库加快了Manipulate[]块.

没有数据库,在内存中需要来自150 MB ASCII文件的基本数据才能访问.结果,Manipulate[]块减慢了. PackedArray[]可能会有所帮助.我没有调查.

使用数据库,单个数据集的访问速度比Select[]块稍慢,但是内存足迹的下降速度接近10倍.

我会说去.

其他推荐答案

我尚未与MySQL一起使用DatabaseLink`,但是我已经与Oracle,SQL Server和HSQLDB一起使用了它.我的大多数DatabaseLink`用法都在Windows上的Mathematica版本6到8上.我已经将其用于阅读和写作,有时还具有很大的数据集.我的经验是,该设施按预期工作.我没有遇到任何涉及性能或记忆的异常情况.我希望您发现Mathematica中的SQL访问与您在其他语言中的经历相媲美.特别是,它的性能非常类似于使用Java-大概是因为Mathematica在内部使用Java来完成所有繁重的举动.

我会提到,在Mathematica中执行查询的"明显"方法, sqlexecute ,将读取整个结果设置为内存.如果您想在不耗尽内存的情况下使用大型结果集合,请查看结果集功能 sqlresultSetopen等..

有关在Mathematica中使用SQL的非常基本的示例(使用HSQLDB),请参阅我对使用内存构建功能的最佳方法.

本文地址:https://www.itbaoku.cn/post/597728.html

问题描述

I've seen it's possible to make a connection between Mathematica and MySQL databases using Input Needs["DatabaseLink"] and conn = OpenSQLConnection[JDBC["MySQL(Connector/J)", "yourserver/yourdatabase"], "Username" -> "yourusername", "Password" -> "yourpassword"] (in case anyone wants to give it a try). Documentation of DatabaseLink here, by the way.

Does anyone have experience using Mathematica in this way, probably to analyze data contained in the database? Are there obvious drawbacks (speed, memory needed, etc.)?

推荐答案

I recently used databases to speed up a Manipulate[] block.

Without the database, essential data from a 150 MB ASCII file were required in memory for access. As a result, the Manipulate[] block slowed down. It's possible that PackedArray[] would have helped. I didn't investigate this.

With the database, the speed of access of individual datasets is slightly slower than a Select[] block, but the memory footprint is down by a factor of nearly 10.

I'd say go for it.

其他推荐答案

I have not used DatabaseLink` with MySQL, but I have used it extensively with Oracle, SQL Server and HSQLDB. Most of my DatabaseLink` usage has been on Mathematica versions 6 through 8, on Windows. I have used it for both reading and writing, sometimes with very large data sets. My experience has been that the facility works as expected. I did not run into any unusual situations involving performance or memory. I would expect you to find SQL access in Mathematica to be comparable to what you have experienced in other languages. In particular, it performs very much like using Java -- presumably because Mathematica uses Java internally to do all of the heavy lifting.

I will mention that the "obvious" way to execute queries in Mathematica, SQLExecute, will read the entire result set into memory. If you want work with large result sets without running out of memory, take a look at the result set functions SQLResultSetOpen et al.

For a very basic example of SQL use in Mathematica (using HSQLDB), see my response to The best way to construct a function with memory.