My Experience with MySql and MS Access
(retrieved from stronglytyped v1)
I have been pondering the idea of using MySql as a database backend with Microsoft Access. I thought that if it worked well it would make a great match. Some friends asked why not just use Microsoft SQL or the desktop version. My question to that was why not use MySql? We would need some tests to prove feasiblilty and heres what I found:
NOTE: Ive been using a product called DBTools - DBManager Professional . Its an awesome product and can connect to a variety of databases including MySql (Brasillians Rock!!).
After getting MySql installed youll need the MySql ODBC driver. Access connected and worked very well from the start with the combination although there are a few things you need to keep in mind.
First MySql supports types that Access doesnt. For example MySql can use BigInt. Access doesnt support that and if you open a table with an unsupported type youll get #error in the grid view. Also if you make any changes to the tables youll have to delete and recreate the linked tables.
The second thing I found that helps a great deal is to include a timestamp field in each table. MySql supports this and will update the field with a date/time value of when the record was updated. My guess is Access uses this for concurrency management.
The next thing I did was started logging how Access talks with the database. The results were interesting:
Access doesnt open a connection to the database until it needs to which is good. When I opened my app it didnt connect until I opened the form. The connection isnt closed until Access is shutdown not when the MDB is closed.
For reference Im using this table:
CREATE TABLE `todos` (
`id` int(11) NOT NULL auto_increment,
`description` varchar(100) NOT NULL default ,
`done` tinyint(4) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
The MyISAM database engine seemed most appropriate because of its goal as a general purpose engine.
When I first opened the form I found a series of queries that came through:
1> 45 Connect root@localhost on todo
2> 45 Query SELECT Config, nValue FROM MSysConf
3> 45 Query SELECT `todos`.`id` FROM `todos`
4> 45 Query SELECT `id`,`description`,`done` FROM `todos` WHERE `id` = 1
The query to MSysConf was unfamiliar to me. I found that if the table exists it help control Access with optimizing its connection:
http://office.microsoft.com/en-us/assistance/HP051876211033.aspx
The next two queries look familiar. The #3 looks like its grabbing a list of primary keys and #4 is pulling the record which is being displayed
Heres what I found after an update. As soon as I started the edit Access pulled the latest record:
SELECT `id`,`description`,`done` FROM `todos` WHERE `id` = 1
Im assuming its pulling the latest record for concurrency checking.
Heres what it did after I committed the record:
SET AUTOCOMMIT=0
UPDATE `todos` SET `description`=Upgrade to python 2.9′ WHERE `id` = 1 AND `description` = Upgrade to python 2.8′ AND `done` = 1
COMMIT
SET AUTOCOMMIT=1
So far everything makes sense and seems reasonable. MySql should be more than capable of handling this type of interaction.
Heres what happened when I committed a new record:
SET AUTOCOMMIT=0
INSERT INTO `todos` (`description`,`done`) VALUES (Buy more books,0)
SELECT `id`,`description`,`done`,`sys_timestamp` FROM `todos` WHERE `id` IS NULL
COMMIT
SET AUTOCOMMIT=1
SELECT `id`,`description`,`done`,`sys_timestamp` FROM `todos` WHERE `id` IS NULL
SELECT `todos`.`id` FROM `todos` WHERE `description` = Buy more books AND `done` = 0
SELECT `id`,`description`,`done`,`sys_timestamp` FROM `todos` WHERE `id` = 5
SELECT `id`,`description`,`done`,`sys_timestamp` FROM `todos` WHERE `id` = 5 OR `id` = 5 OR `id` = 5 OR `id` = 5 OR `id` = 5 OR `id` = 5 OR `id` = 5 OR `id` = 5 OR `id` = 5 OR `id` = 5
Im not sure what Access is doing with the 4 select queries. I think the second one is to refresh the form to take into account of any default data produced by the database.
The one with multiple id = 5 just confuses me. I also noticed that if the timestamp field doesnt exist youll get #deleted text in the fields if you go back to the record in Access.
Ive been testing Access and MySql with several databases with 100K+ records and it seems to hum pretty well. I havent found any show stoppers.
Currently were porting a medium sized Access application to a MySql back end. We had to rename many fields and tables (i.e. Balance$ had to be changed to BalanceAmt) and made sure primary keys existed. Besides that its working quite well.
