MS Access 到 MySQL 转换帮助(巨型表)
因此,我在 MS Access (*.mdb) 中有一个巨大的表,包含大约 700 万条记录,我想将其转换为更可行的 MySQL 格式,并将其存储在我的网络服务器上。文件本身重 2GB。
问题是,由于表太大,它不会让我正常导出它(Access 说限制是 65,536 条记录。)
我尝试了一些 3rd 方软件,但无济于事。
谁能推荐一种干净的方法,而不损坏内部数据?
预先感谢您的任何帮助。
So I have this gigantic table, containing approx 7 million records, in MS Access (*.mdb), I want to transfer it into a much more workable MySQL format, and store it on my webserver. The file itself weighs 2GB.
The problem is, since the table is so large, it won't let me export it normally (Access says the limit is 65,536 records.)
I've tried some 3rd party software but to no avail.
Can anyone recommend a clean way of doing so, without damaging the data inside?
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您还没有 MySQL 的 ODBC 驱动程序,请安装该驱动程序。最新版本可在此处获取:下载 Connector/ODBC
为您的 MySQL 服务器创建 DSN(数据源名称)从 Windows ODBC 数据源管理器。
然后从 Access 2003 的“数据库”窗口中选择表,然后从 Access 的主菜单中选择“文件”->“导出”。在“将表'yourtablename'导出到...”对话框中,从“保存类型”下拉列表(位于对话框底部)中选择“ODBC Databases()”。下一个对话框允许您指定 MySQL 将用于导出表的名称,默认为 Access 表名称。单击“确定”后,您将看到另一个对话框“选择数据源”,您可以在其中选择 MySQL 的 DSN。在该对话框中单击“确定”后,您可能会再次收到一个询问您用户名和密码的对话框。提供它们,然后单击“确定”。
希望您的表能够顺利传输。不过,我从来没有用 MySQL 做过这样的操作。它对我来说很有效,可以将 ODBC 传输到 SQL Server 和 PostGreSQL。所以我不明白为什么它不能与 MySQL 一起工作。
而且我从来没有尝试过一次性导出 700 万条记录。如果它窒息了,我们就必须想出一个解决办法。
如果您使用的是 Access 2007 而不是 2003,请从功能区的“导出”部分开始查找类似的选项。
我建议采用这种方法,因为我的印象是此导出将是一次性交易,因此我认为 Access UI 导出方法是最简单的。但是,您可以使用 DoCmd.TransferDatabase 方法对 VBA 代码执行基本相同的操作 与您的 ODBC DSN。
另一种替代方法是在 MySQL 中创建兼容的表结构,在 Access 中创建到 MySQL 目标表的链接(再次使用您的 DSN),然后从 Access 运行“附加查询”:
附加查询方法在以下情况下可能很有用:出口受阻于 700 万张唱片。您可以添加 WHERE 子句将 SELECT 查询的输出记录集限制为可管理的块大小,然后使用不同的 WHERE 重复以指定另一个块。
Install an ODBC driver for MySQL, if you don't have one already. The latest version is available here: Download Connector/ODBC
Create a DSN (Data Source Name) for your MySQL server from the Windows ODBC Data Source Administrator.
Then from Access 2003, select your table in the Database Window, and choose File->Export from Access' main menu. In the "Export Table 'yourtablename' To ..." dialog, select "ODBC Databases()" from the "Save as type" drop-down list (at the bottom of the dialog). The next dialog allows you to specify the name MySQL will use for the exported table, and it defaults to the Access table name. After you click OK, you will get another dialog, "Select Data Source", where you can select your DSN for MySQL. After you click OK on that dialog, you will probably get one more asking you for user name and password. Supply them, and click OK.
Hopefully your table will then transfer without errors. However, I've never done that operation with MySQL. It has worked for me with ODBC transfers to SQL Server and PostGreSQL. So I don't see why it wouldn't work with MySQL, too.
Also I've never attempted to export 7 million records in one go. If it chokes, we'll have to figure out a work-around.
If you're using Access 2007 instead of 2003, look for a similar option starting with the Export section of the ribbon.
I suggested this approach because my impression is this export will be a one-time deal, so I think the Access UI export method would be easiest. However, you can do essentially the same operation with VBA code using the DoCmd.TransferDatabase Method with your ODBC DSN.
Yet another alternative would be to create a compatible table structure in MySQL, create a link in Access to the MySQL destination table (using your DSN again), then run an "append query" from Access:
The append query approach could be useful in case the export chokes on 7 million records. You could add a WHERE clause to limit the SELECT query's output record set to a manageable chunk size, and then repeat with a different WHERE to specify another chunk.
那700万是紧凑+修复后的价值吗?我的意思是,如果每张唱片的长度约为 120 个字符,那么 2 场演出可以容纳 3200 万张唱片。
另外,我不知道导出 65,000 条记录的限制,但仅限于 Excel。
因此,您可以/应该能够将数据导出到 csv,然后在 mySql 中使用批量文本导入来提取该数据。因此,请尝试将表导出为 csv。那应该有效。
我的意思是,如果您与 sql 服务器有良好的本地连接,您可以通过 odbc 链接表,但如果没有,那么我将导出到 csv (它非常快)。然后我会压缩该文件(它们压缩得很棒)。将文件上传到服务器,并解压缩,然后使用批量文本导入。因此,这样的压缩文件非常小,并且可以节省大量的传输时间。
您还可以考虑使用制表符分隔,因为 mySql 也可以导入它们,但简单的文本文件应该可以正常工作。
Is that 7 million value after a compact + repair? I mean, if each record is about 120 chars in length, you can fit 32 million records in 2 gigs.
Also, I not aware of a limit of exporting 65,000 records, but only in regards to Excel.
So, you can/should be able to export the data to a csv, and then use a bulk text import in mySql to pull that data in. So, try exporting the table as csv. That should work.
I mean, you could link a table via odbc if you have a good local connection to the sql server, but if not, then I would export to csv (it is VERY fast). I would then zip the file (they zip fantastic). Upload file to server, and un-zip, and then use bulk text import. So, such a zipped file is VERY small and will save huge amounts of transfer time.
You can also consider using tab delimited as mySql also can import those, but a simple text file should work just fine.
中所述使用 pyodbc
我将按照http://en.wikibooks.org/wiki/Python_Programming/Database_Programming< /a>
从下载 python 2.7
http://python.org/
下载
http://code.google.com/p/pyodbc/
修改以下代码进行设置myfile.mdb 和 MyTable 根据您的表和文件
将代码保存在文件中 translate.py
运行
python translate.py
I would use pyodbc as described in
http://en.wikibooks.org/wiki/Python_Programming/Database_Programming
download python 2.7 from
http://python.org/
download
http://code.google.com/p/pyodbc/
modify the following coede to set myfile.mdb and MyTable according to your table and file
save the code in a file translate.py
run
python translate.py
在您自己的系统上安装 MySQL 并升级到它,而不是尝试使用您的本地服务器。然后从 MySQL 向服务器实例运行追加查询。
Install MySQL on your own system and upsize to it rather than trying to use your local server. Then run an append query from your MySQL to the server instance.