简体   繁体   English

使用OBDC将.sql导入MS Access

[英]Importing .sql into MS Access using OBDC

I currently have a database in MySQL, which I'd like to import in MS Access. 我目前在MySQL中有一个数据库,我想在MS Access中导入该数据库。

Is it possible to do this while keeping all relationships intact (ie without exporting to .csv, or by using ODBC)? 是否可以在保持所有关系不变的情况下执行此操作(即,无需导出到.csv或使用ODBC)?

I'm a noob in this area so any help is greatly appreciated. 我是这个领域的菜鸟,所以对您的帮助非常感谢。

Thanks. 谢谢。

Do you mean SQL Server? 你是说SQL Server吗? A good starting point might be to check out SQL Server Integration Services (SSIS), which can be used for transferring data around like that. 一个不错的起点可能是检查SQL Server Integration Services(SSIS),该服务可用于像这样传输数据。

Google will also be helpful, check out the first result: Google也会提供帮助,请查看第一个结果:

http://support.microsoft.com/kb/237980 http://support.microsoft.com/kb/237980

By the way, you said ".sql" in your question: a .SQL file is a script file, which could do anything from create a database, insert data, drop table, delete data, or given the right permissions, call system procedures and reboot a machine, format a drive, send an email.. Just for ref, .SQL files aren't the storage format used by SQL Server. 顺便说一句,您在问题中说“ .sql”:.SQL文件是一个脚本文件,它可以执行任何操作,包括创建数据库,插入数据,删除表,删除数据或获得正确的权限,然后调用系统过程并重新启动计算机,格式化驱动器,发送电子邮件。。仅供参考,.SQL文件不是SQL Server使用的存储格式。

You need to solve two different problems: 您需要解决两个不同的问题:

  1. Creating an empty MS Access database with a structure that matches the MySQL database structure. 使用与MySQL数据库结构匹配的结构创建一个空的MS Access数据库。

  2. Extracting the data from MySQL and loading it into MS Access. 从MySQL中提取数据并将其加载到MS Access中。

This is not easy because different SQL databases offer different structural features, different datatypes, and so on. 这是不容易的,因为不同的SQL数据库提供不同的结构特征,不同的数据类型等等。 The more complex your use of MySQL is the more likely you'll run into some show-stopper during the conversion (for instance, Access doesn't support triggers at all). 您对MySQL的使用越复杂,在转换过程中就越有可能遇到一些麻烦(例如,Access根本不支持触发器)。 Conversely if you're using MySQL as a simple data store you may find the conversion fairly easy. 相反,如果将MySQL用作简单的数据存储,则转换可能会很容易。

To get an MS Access database with the same structure as your MySQL database, your best bet is to find a database definition / diagramming tool that offers reverse engineering and supports both MySQL and MS Access. 为了获得与MySQL数据库具有相同结构的MS Access数据库,最好的选择是找到一个提供逆向工程并同时支持MySQL和MS Access的数据库定义/图表工具。 Use it to reverse engineer your MySQL database into a database diagram, then change the underlying database to MS Access and use the tool to generate a database. 使用它可以将MySQL数据库反向工程为数据库图,然后将基础数据库更改为MS Access并使用该工具生成数据库。

Check out Dezign For Databases which (on paper, anyway) offers the features you would need to do this. 查看Dezign For Databases (无论如何,在纸上)提供您需要执行此操作的功能。

To pump the data across, there are any number of tools. 要泵送数据,可以使用许多工具。 This kind of operation is generically referred to as ETL (Extract, Translate, Load). 这种操作通常称为ETL(提取,翻译,加载)。

You can try using this: Converting MS Access to MySQL with relationships 您可以尝试使用以下方法: 通过关系将MS Access转换为MySQL

Works fine and export all relationships. 正常工作并导出所有关系。

While you can script your database's schema into script files via something like SQLyog, you will find that the syntax varies enough from database to database (MySQL to Access, in your case) that you can't directly apply the scripts. 虽然您可以通过SQLyog之类的代码将数据库的模式编写为脚本文件,但您会发现语法在数据库之间差异很大(在您的情况下是MySQL到Access),您不能直接应用这些脚本。

With much effort a conversion script could be created by editing the script (perhaps automated with a program, depending on the resulting script size). 可以通过编辑脚本来创建转换脚本(可以通过程序自动完成,具体取决于生成的脚本大小)。 I think you would be better served using ODBC to copy the tables (and data) and then extracting and re-applying the relationships from the generated script by hand. 我认为使用ODBC复制表(和数据),然后从生成的脚本中手动提取并重新应用关系会更好。 Time consuming, but also a one time operation I would hope. 我希望这很耗时,而且也是一次性操作。

When both systems are the same database, there are tools that can do the comparison and script generation (TOAD for MySQL and RedGate Compare for Microsoft SQL), but they don't do cross database work (at least not the ones I am aware of). 当两个系统是同一个数据库时,有一些工具可以进行比较和脚本生成(MySQL为TOAD,Microsoft SQL为RedGate Compare),但它们不能跨数据库工作(至少不是我所知道的) )。

If you create a ODBC DSN, you can use TransferDatabase to import from your MySQL database. 如果创建ODBC DSN,则可以使用TransferDatabase从MySQL数据库导入。 You can do it manually with the GET EXTERNAL DATA command (or whatever it is in A2007/A2010) and see how well it works. 您可以使用GET EXTERNAL DATA命令(或A2007 / A2010中的任何命令)手动进行操作,并查看其效果如何。 It won't get all data types exactly right, but you could do some massaging and likely get it closer to what will work best. 它不会使所有数据类型都完全正确,但是您可以进行一些按摩,并使其更接近最有效的数据类型。

Is there some reason you can't just link to the MySQL tables and use them directly? 您是否有某些原因不能仅仅链接到MySQL表并直接使用它们? That is, why do you need to import into Access at all? 也就是说,为什么您需要完全导入Access?

Access: run query. 访问:运行查询。 Just make sure to adapt the SQL code since every RDMS has its own sintaxis (despite SQL being an ANSI standard). 只需确保修改SQL代码即可,因为每个RDMS都有其自身的特征(尽管SQL是ANSI标准)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM