fastest/secure way for export mysql tables into ms Access table
i'm searching for a way to export some MySql ta开发者_C百科bles into other tables of a MsAccess DB (I'm talking about a million records table...)
the only two way that I thought about are:
export from myadmin or toad a csv file and then import it into the access DB.
making directly from Toad the "Access Database Export"
I'm getting that the first is more fast but less secure for the data integrity, while the second is perfect for the data integrity but very slow ... someone knows other ways?
Thanks A.
step by step guide to running Access frontend application with MySQL database on webserver (you dont need to IMPORT the tables, you can use your msaccess application WITH them on the webserver):
If you are running MsAccess, i suppose that you are using windows
- Install MySQL ODBC 5.1 Driver (connector) http://dev.mysql.com/downloads/connector/odbc/
- Open CONTROL PANEL on win machine
- ADMINISTRATIVE TOOLS (if Vista or Seven, search ODBC)
- SET UP DATA SOURCES ODBC
- SYSTEM DSN
- ADD
depending on your server, you might have some difficulty finding the server name or IP, look for SSH Database connection (or something like that). as an example, read NetSol's FAQ: http://www.networksolutions.com/support/how-to-back-up-the-mysql-database-using-ssh/
once you have done that, in MsAccess: 1. FILES 2. EXTERNAL DATA SOURCE 3. LINK TABLES
if you want to EXPORT to MySQL from MsAccess, you can create a FORM in access, put a button on it, and in VBA create this sub for the OnClick() event:
Dim sTblNm As String
Dim sTypExprt As String
Dim sCnxnStr As String, vStTime As Variant
Dim db As Database, tbldef As DAO.TableDef
On Error GoTo ExportTbls_Error
sTypExprt = "ODBC Database"
sCnxnStr = "ODBC;DSN=DSNname;UID=userOnServer;PWD=pwdOnServer"
vStTime = Timer
Application.Echo False, "Visual Basic code is executing."
Set db = CurrentDb()
For Each tbldef In db.TableDefs
Debug.Print tbldef.Name
sTblNm = tbldef.Name
DoCmd.TransferDatabase acExport, sTypExprt, sCnxnStr, acTable, sTblNm, sTblNm
Next tbldef
MsgBox "Done!"
On Error GoTo 0
SmoothExit_ExportTbls:
Set db = Nothing
Application.Echo True
Exit Sub
ExportTbls_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExportTblsODST"
Resume SmoothExit_ExportTbls
sometimes, while running non-english windows you might get error 2507, change "ODBC Database" for "ODBC" (works with French).
If you have ODBC access to MySQL, and your server is on your network, you can import its tables from within Access. I think the menu selections are "File | Get external data | Import".
For "Files of type", select "ODBC Databases". You might need to create a new DSN name.
I can't recall whether ODBC drivers are generally an installation default, or whether they're a separate install. I think they're installed by default, but I could be wrong.
Thanks tony for that awesome time-saving script. Since I name my tables with the prefix "tbl", I modified the code so it will only export those tables (not the weird looking ones):
Private Sub Command0_Click()
Dim sTblNm As String
Dim sTypExprt As String
Dim sCnxnStr As String, vStTime As Variant
Dim db As Database, tbldef As DAO.TableDef
Dim str As String
On Error GoTo ExportTbls_Error
sTypExprt = "ODBC Database"
sCnxnStr = "ODBC;DSN=proxmox decaoriginal;UID=matantan;PWD=majadero5"
vStTime = Timer
Application.Echo False, "Visual Basic code is executing."
str = "tbl"
Set db = CurrentDb()
For Each tbldef In db.TableDefs
Debug.Print tbldef.Name
If Left(tbldef.Name, 3) = str Then
sTblNm = tbldef.Name
DoCmd.TransferDatabase acExport, sTypExprt, sCnxnStr, acTable, sTblNm, sTblNm
Else
End If
Next tbldef
MsgBox "Done!"
On Error GoTo 0
SmoothExit_ExportTbls:
Set db = Nothing
Application.Echo True
Exit Sub
ExportTbls_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExportTblsODST"
Resume SmoothExit_ExportTbls
End Sub
精彩评论