Problem Solution Discussion Exchanging Data Between MySQL and Microsoft Access

File loaded with no warnings, no per-record tests performed I f you load t m p int o t he managers t able, no problem s should occur: mysql LOAD DATA LOCAL INFILE tmp INTO TABLE managers IGNORE 1 LINES; Query OK, 2841 rows affected 0.13 sec Records: 2841 Deleted: 0 Skipped: 0 Warnings: 0

10.39 Exchanging Data Between MySQL and Microsoft Access

10.39.1 Problem

You want t o exchange inform at ion bet ween MySQL and Access.

10.39.2 Solution

To use inform at ion st ored in MySQL, connect t o t he MySQL server direct ly from Access. To t ransfer inform at ion from Access t o MySQL, use a ut ilit y t hat can perform t he t ransfer direct ly, or else export t ables from Access int o files and im port t he files int o MySQL.

10.39.3 Discussion

MySQL and Access bot h underst and ODBC, so you can connect t o MySQL direct ly from Access. By m aking an ODBC connect ion, Access becom es a front end t hrough which you use MySQL dat abases. The m ysql.com MyODBC area cont ains a lot of useful inform at ion: ht t p: www.m ysql.com product s m yodbc An excellent descript ion of t he procedures for set t ing up ODBC and for connect ing from Access t o MySQL over ODBC m ay be found in W.J. Gilm ores art icle at t he DevShed web sit e: ht t p: www.devshed.com Server_Side MySQL ODBC I f your t ables current ly are in Access and you want t o m ove t hem int o MySQL, youll need t o creat e t ables in MySQL t o hold t he inform at ion and t hen im port t he Access dat a int o t hose t ables. A couple of good free t ools t hat can m ake t his easier are DBTools and MySQLFront . They can exam ine t he st ruct ure of t ables in an Access dat abase, creat e t he corresponding MySQL t ables for you, and copy t he dat a direct ly int o MySQL. You can also choose t o export Access t ables t o files and t hen im port t he files int o MySQL. This m ay be necessary, for exam ple, if your MySQL server is on a different m achine and doesnt allow connect ions from your Windows box. I f you elect t o go t his rout e, som e of t he issues youll need t o consider are t he file form at t o use, dat e form at conversion, and how t o creat e t he MySQL t ables for t he dat a if t he t ables dont already exist . Several of t he script s described earlier in t he chapt er such as cvt _file.pl, cvt _dat e.pl, and guess_t able.pl can provide assist ance in dealing wit h t hese issues. The procedure for im port ing an Access t able int o MySQL m ight go som et hing like t his: 1. Expor t t he t able fr om Access in som e t ext for m at , per haps including t he colum n labels. Should you need t o t r ansfor m t he file w it h ot her ut ilit ies t hat assum e t ab- delim it ed, linefeed- t er m inat ed input , it w ill be m ost useful t o expor t in t hat for m at . 2. I f t he t able cont ains dat es and you did not export t hem in I SO form at , it w ill be necessary t o convert t hem for MySQL. cvt _dat e.pl can be used for t his. 3. I f t he MySQL t able int o w hich you w ant t o im port t he Access dat a does not exist , creat e it . The guess_t able.pl ut ilit y m ight be helpful at t his point for gener at ing a CREATE TABLE st at em ent . 4. I m port t he dat afile int o MySQL w it h LOAD DATA or m ysqlim por t .

10.40 Exchanging Data Between MySQL and Microsoft Excel