Import data from Access database to MySQL

2023/7/1 Update: For View, I can't find a good way... I can only do it manually, add it

------------------------------------------------------------------------------------------

I have developed a small tool before, using the Acesss database, and now I need to migrate it to the MySQL database on the cloud.

It seems to be a simple matter, but it took a bit of trouble, so I recorded it as a memo.

Use DBeaver

I tossed a lot of methods, and almost used a paid tool, but finally gave up. The final decision was to create it manually.

Because I have been using DBeaver as the data manager, I suddenly had a flash of inspiration, and searched DBeaver to migrate from Acess to MySQL, and found that there is really a way. Refer to the following articles:

(215 messages) Use Dbeaver to import tables in access to mysql_weixin_35695688's Blog-CSDN Blog

Although it is not perfect, it needs one table and one table, but it has saved a lot of work (more fields)

Well, not so nice...

Some problems were found during the actual operation, and they were solved one by one:

  • Problem with brackets around fields

For the SQL generated from the Access database, square brackets will be added on both sides of the field

When executing in MySQL, an error will be reported

 The solution is very simple. After pasting, use the replace all function to replace all left and right brackets with blanks.

This is also a good example of how important it is to be short and without spaces when defining field names!

  • field type problem

In the Access database, the Number type is NUMERIC(100,7) in the generated SQL, which is far beyond the 65 bits of MySQL. In fact, it is of course impossible to have such a large number. As far as my application is concerned, the tax is stored, and 9 digits are 100 million. NUMERIC (10,4) can accommodate 9.9 billion, which is enough. So if you encounter a prompt, change it according to the actual situation.

In addition, the Date/Time in ACCESS is TIMESTAMP in the generated SQL. Unless you really need a timestamp, you need to change it according to the actual situation. Otherwise, they are all accurate to milliseconds, which may cause problems in future queries.

  • Index and primary key definition issues (SQL execution order issues)

If the primary key and index are set in the original table, the corresponding SQL will be generated. When pasting it into MySQL for execution, you must first execute the part of creating the table, and then execute the corresponding statements of the primary key and index one by one. You cannot execute them all at once, otherwise an error will be reported.

  • View Migration

A lot of business logic is implemented through the view in Access, and it is found that DBeaver cannot correctly identify the SQL in the Access view

 

 I couldn't find a better way, so I could only copy SQL from ACCESS, and use the CREAT VIEW statement to create it in DBeaver.

 It didn't take too much trouble.

There are some differences between the SQL of ACCESS and MySQL, for example, the IIF() function in ACCESS, and the IF() function in MySQL; the field names temporarily defined in ACCESS SQL are allowed to be used immediately later, but not in MySQL. For example, the following paragraph of SQL defines the Payment field and the Invoice field, and then immediately quotes them, which is feasible in ACCESS, but in MySQL, the original field name can only be honestly written once: 

SELECT T3_ComYM_FullList.COMPANY, T3_ComYM_FullList.YM, T1_PaymentByYM.AmountOfSum AS Payment, T2_InvoiceByYM.TaxAmtOfSum AS Invoice, IIF(ISNULL([Payment]),0,[Payment]) - IIF(ISNULL([Invoice]),0,[Invoice]) AS Gap

Others, such as the fact that there are no square brackets on both sides of the field name, are the same as before.

Skill summary:

After copying out the SQL, do not rush to execute it. First, paste all the SQL in the original table to the script page on the MySQL side at one time, then replace and remove left and right brackets in batches, change TIMESTAMP in batches, and then execute the SQL in sequence.

for future research

After the tables are created, importing data needs to be processed table by table. Is there a batch command in DBeaver? Let's study it in the future.

Guess you like

Origin blog.csdn.net/m0_54284125/article/details/131484437