Professional Documents
Culture Documents
Jay Krishnaswamy | July 2009 | PHP Most businesses use a software mix in their IT arsenal that makes business sense to them. Because of this, often they have to migrate a part, or whole of their data from one software program to another. In this article by Dr. Jay Krishnaswamy, the built-in method of exporting tables in Microsoft Access is explored to take a table in Microsoft over to MySQL, the open source database product that changed hands recently. This article steps you through the process with a number of screen shots to guide you along the way.
Introduction
It is assumed that you have a working copy of MySQL which you can use to work with this article. The MySQL version used in this article came with the XAMPP download. XAMPP is an easy to install (and use) Apache distribution containing MySQL, PHP, and Perl. The distribution used in this article is XAMPP for Windows. You can find documentation here. Here is a screen shot of the XAMPP control panel where you can turn the services on and off and carry out other administrative tasks.
You need to follow the steps indicated here: 1. Create a database in MySQL to which you will export a table from Microsoft Access 2003 2. Create a ODBC DSN that helps you connecting Microsoft Access to MySQL
+--------------------+ | Database | +--------------------+ | information_schema | | cdcol | | expacc | | mengerie | | mydb | | mysql | | phpmyadmin | | test | | testdemo | | testmove | | webauth | +--------------------+ 11 rows in set (0.00 sec) mysql>
The login detail that works error free is shown. The preference for host name is localhost v/s either the Machine Name (in this case Hodentek2) or the IP address. The first 'Show Databases' command does not display the TestMove we created which you can see in response to the 2nd Show Databases command. In windows the commands are not case sensitive.
Click the Add... button to open the Create New Data Source window as shown.
Scroll down and choose MySQL ODBC 5.1 Driver as the driver and click Finish. The MySQL Connector/ODBC Data Source Configuration window shows up.
You will have to provide a Data Source Name (DSN) and a description. The server is the localhost. You must have your User Name/Password information to proceed further. The database is the name of the database you created earlier (TestMove) and this should show up in the drop-down list if the rest of the information is correct. Accept the default port. If all
Click and test the connection using the Test button. You should get a response as shown.
Click the OK button on the Test Result window. Click OK on the MySQL Connector/ODBC Data Source Configuration window. There are a number of other flags that you can set up using the 'Details' button. The defaults are acceptable for this article.
You have successfully created a System DSN 'AccMySQL' as shown in the next window. Click OK.
Open the Northwind.mdb (or any other mdb file) file as shown in the next figure.
Highlight the Employees table and make a right click to bring up a drop-down menu as
shown.
Click on Export to open the Export Table 'Employees' To... window. Click on the Save as type drop-down to reveal the various file types that you can export to as shown.
Click OK. This opens the Select Data Source window. Click on the Machine Data Source tab to show the various available DSN's. You will notice the AccMySQL created earlier.
Choose AccMySql and click OK. The program returns you to MS Access's Northwind database without giving you an indication about the success/failure of the export. If there is an error it however gives a error message.
Now you can see that the Employees table has entered the TestMove database in MySql. Probe a little further by entering a select statement to see how much of the data has come in.
mysql> use testmove Database changed mysql> show tables; +--------------------+ | Tables_in_testmove | +--------------------+ | employees | +--------------------+ 1 row in set (0.00 sec) mysql> Select * from Employees; +------------+-----------+-----------+-------------------------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------+-----------+ | EmployeeID | LastName | FirstName | Title | TitleOfCourtesy | BirthD ate | HireDate | Address | City | Region | PostalCode | Country | HomePhone | Extension | Photo | Notes | ReportsTo | +------------+-----------+-----------+-------------------------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------+-----------+ | 1 | Davolio | Nancy | Sales Representative | Ms. | 1968-1 2-08 00:00:00 | 1992-05-01 00:00:00 | 507 - 20th Ave. E. Apt. 2A | Seattle | WA | 98122 | USA | (206) 555-9857 | 5467 | EmpID 1.bmp | Education includes a BA in psychology from Colorado State University. She also co mpleted "The Art of the Cold Call." Nancy is a member of Toastmasters International.| 2 | | 2 | Fuller | Andrew | Vice President, Sales | Dr. | 1952-0 2-19 00:00:00 | 1992-08-14 00:00:00 | 908 W. Capital Way | Tacoma | WA | 98401 | USA | (206) 555-9482 | 3457 | EmpID2.bmp | Andrew received his BTS commercial and a Ph.D. in international marketing from the University of Dallas. He is fluent in French and Italian and reads German. He joined the company as a sales representative, was promoted to sales manager and was then named vice president of sales. Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association. | NULL | | 3 | Buchanan | Steven | Sales Manager | Mr. | 1955-0 3-04 00:00:00 | 1993-10-17 00:00:00 | 14 Garrett Hill | London | NULL |
SW1 8JR | UK | (71) 555-4848 | 3453 | EmpID5.bmp | Steven Buchanan graduate d from St. Andrews University, Scotland, with a BSC degree. Upon joining the company as a sales representative, he spent 6 months in an orientation program at the Seattle office a nd then returned to his permanent post in London, where he was promoted to sales manager. Mr. Buchanan has completed the courses "Successful Telemarketing" and "International Sale s Management." He is fluent in French. | 2 | | 4 | Suyama | Michael | Sales Representative | Mr. | 1963-0 7-02 00:00:00 | 1993-10-17 00:00:00 | Coventry House Miner Rd. | London | NULL | EC2 7JR | UK | (71) 555-7773 | 428 | E mpID6.bmp | Michael is a graduate of Sussex University (MA, economics) and the University of California at Los Angeles (MBA, marketing). He has also taken the courses "Multi-Cultural Selling" and "Time Management for the Sales Professional." He is fluent in Japanese and can read and write French, Portuguese, and Spanish.| 3 | +------------+-----------+-----------+-------------------------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------+-----------+ 4 rows in set (0.00 sec) mysql>
The output is not particularly pretty but you can see that the data has come in. The next figure shows the same query run in MySQL Workbench a graphic tool used in querying and modeling MySql databases.
Summary
The article described the procedure to create an ODBC DSN for connecting to a MySQL Database. The article also described the process of copying data in an MS Access database to MySQL.
Migration Issues
According to a recent survey, over 20% of MySQL users plan to migrate a Microsoft Access applications to MySQL over the next 12 months. However there are few documents available that describe best practices for performing such a migration. This document summarizes discussion from the MS Access Migration session at the 2007 MySQL User Group meeting in California. That session brought together a number of MySQL users with a goal of identifying key success factors for moving MS Access applications to MySQL. Because MS Access applications were often created in an ad hoc fashion, migration can pose particular challenges. MySQL Users reported two common migration problems: Data migration issues: MS Access data conversion is often complicated by poor schema design and even low data quality. Application migration issues: MS Access applications often
contain logic or design errors in their forms and reports, making them impossible to convert automatically. The group consensus was that a successful migration path has three fundamental tasks: 1. Rebuild the schema: create a new schema in MySQL that reflects SQL best practices rather than trying to simply recreate the Access schema in MySQL 2. Clean the data: extract the data from the Access database, cleanse the data, then import the data into the new MySQL schema 3. Rewrite the application: rebuild the Access application using web development tools like php or ActiveGrid
Low data quality: Access applications often have out-of-date corporate data or corrupt data based on poorly defined schemas Poor security: Access applications do not integrate with corporate security and do not allow advanced security such as role-based access controls Limited manageability: Access applications can not be centrally managed by IT No web-based distribution: Access applications cannot be accessed over the web SOX compliance: Access applications are often identified in corporate audits as a significant source of risk.
Access data is not clean: in part because the tables were not defined rigorously, the data in Access databases is often corrupt. One MySQL user reported finding text strings in fields which were meant to be date fields for geotechnical data.
Quality issues: given that the original MS Access app was written by a nonprogrammer, I dont even want the logic moved I dont trust it. Desire to make application web-based: most MySQL users would prefer to migrate legacy MS Access applications to more robust web architectures Security requirements: MySQL users often want to add enterprise security features like Siteminder/LDAP authentication and role-based access controls
Although there are tools available that automate the conversion of a MS Access application to Java, MySQL users reported little success with automated conversion. Instead, the preferred approach is to port MS Access applications using a coding language like PHP or a web 2.0 visual builder like ActiveGrid.
1. Define the model. The model defines the data used in the application, including database tables and relationships between tables. The developer specifies this information by importing an existing database schema or using a visual data editor. 2. Create the views. The view describes the web pages displayed by the application. ActiveGrid can create default Ajax web pages based on the database schema, or the developer can create new web pages using a visual screen builder. 3. Build the controller(s). The controllers manage actions within the application, including navigation between pages and invoking data, security and web services. The developer can define new actions using a visual action editor that call web services or custom code modules written in Java or Python.
1. Import MySQL data schema into visual builder tool such as ActiveGrid 2. Create new web pages that provide graphical interface for application using the ActiveGrid page editor 3. Define actions that provide needed functionality for application using the ActiveGrid action editor, custom Java or Python code, or web services. In summary, best practices for Access to MySQL migration require careful migration of data to a new schema along with a requirements-driven rebuilding of the application forms and reports using web-based development tools. MySQL is an increasingly attractive database solution for companies trying to improve the security and data quality of their departmental applications. However a successful migration from Access requires pairing MySQL with a web development tool.
Other resources
There are a number of additional resources on the web describing MS Access to MySQL migrations: Dual-Master MySQL 5 Replication Done Right MySQL replication is the most flexible way to deal with scalability. If not done right, however, replication can result in disaster. The most common problem with replication is primary key collision. Primary key collision involves two MySQL servers creating table rows containing different data, but the same primary key. When this happens replication stops. With replication stopped, the difference between the data on the servers grows. At some point the weirdness gets noticed. Then begins the painful process of recovery, of trying to weave masses of conflicting data into a whole. In this tutorial, we'll outline, step-by-step, how to avert disaster by creating a dual master MySQL replication setup configured to avoid primary key collision. We'll call the two MySQL servers Server A and Server B. In a dual master setup each server functions as both a master and a slave to the other server. If you run into any problems, feel free to visit our forum and share details! Problems? Neo Code Software Can Help! What's 10 - 3? First Name Last Name Email
master-user = <slave user> master-password = <slave password> master-connect-retry = 60 replicate-do-db = <database name> log-bin = C:\mysql\log\log-bin.log # change this to a path/name appropriate to your system binlog-do-db = <database name> Below is what needs to be added to the configuration for Server B: server-id = 2 replicate-same-server-id = 0 auto-increment-increment = 2 auto-increment-offset = 2 master-host = <IP address of Server A> master-user = <slave user> master-password = <slave password> master-connect-retry = 60 replicate-do-db = <database name> log-bin= C:\mysql\log\log-bin.log # change this to a path/name appropriate to your system binlog-do-db = <database name> After making the changes to your configuration, restart the two servers. Check your MySQL error logs for any problems. A warning message will likely recommend that you specify the name of your relay log in your server configuration. To avoid future problems, do this! A relay log, for those that are wondering, is simply a local echo of data read from the master's log. Note: The two MySQL configuration variables that prevent key collisions are autoincrement-increment and auto-increment-offset. The value of auto-increment-increment should be set to N, where N is equal to the number of servers in the replication setup (in this case two). The auto-increment-offset and server-id configuration variables should be set as consecutive integers (in this case 1 and 2).
Next, on each server enter the command below into the MySQL command line of each server: Server MySQL command line> CHANGE MASTER TO MASTER_HOST='<master's IP>', MASTER_USER='<slave user>', MASTER_PASSWORD='<slave password>', MASTER_LOG_FILE='<master's log file name>', MASTER_LOG_POS=<master's log file position>; Once you've entered the above command, issue the "start slave" command on both servers. Replication should now be working! To confirm that replication is working, first issue the "show slave status" command on both servers. Both "Slave_IO_Running" and "Slave_SQL_Running" should be "YES". If both aren't "YES", you'll need to reset replication.
Resetting Replication
It doesn't take much for replication to go out of sync. A simple network interruption to one server can effectively halt two-way replication if data gets written during the interruption. It makes sense to learn how to reset replication before something goes wrong. A network outage can be simulated by unplugging one of the MySQL servers from the network. While one server is unplugged, try inserting rows to both. This will generally disrupt replication even though, after restoring network connectivity, the slave status of each server may look normal. To reset replication, shut down both servers, delete their relay logs, and synchronize the servers (as outlined in the previous section). Deleting the relay logs will cause each server to re-read from their master.
Testing
Before putting a replication setup into production, be sure to thoroughly test it. Primary keys generated on Server A should always be odd numbers, while those generated on Server B should always be even. Have fun!