Thursday, November 21, 2024
HomeHow ToImporting Data by Mask

Importing Data by Mask

Introduction

In this article, we will show how to perform routine data export from multiple files by a certain mask with help of the Data Import functionality of dbForge Studio for MySQL and how to schedule the recurring execution of the import with Microsoft Task Scheduler.

Scenario

Suppose, we need to simultaneously import multiple daily report files in the .csv format stored in a folder:

A set of daily report files in the .csv format

To complete the task we are going to do the following:

  1. Create a project file with the Data Import Wizard.
  2. Create an executable file on the basis of the created data import project.
  3. Schedule a daily recurring task with help of Windows Task Scheduler

Creating Data Import Project

1. In dbForge Studio for MySQL, click Import data in the Database menu to open the Data Import wizard.

Select Import data from the dropdown list

2. On the Source file tab of the wizard, specify the CSV file format and provide a file path to any of the required files.

Pick the CSV format on the Source file tab

Click Next.

3. On the Destination tab of the wizard, we need to specify the target connection, database, and a table. In our case, we are going to import data into the already existing Report_DAILY table.

Specify the target connection, database and a table

Click Next.

4. Switch to the Modes tab of the wizard to specify the data import mode. We are going to repopulate the table with the imported data and use the bulk insert option that reduces the quantity of statements and speeds up the import operation.

Choose the data import mode

5. Click the Save button and select Save Template from the shortcut menu.

Creating Executable File

Now, when we have our data import template, we can proceed to the creation of the bat file.

For this, open a text editor like notepad and insert the following code:

@ECHO OFF
for %%f in ("D:\Daily_Report\*_DAILY.csv") do (
  "C:\Program Files\Devart\dbForge Studio for MySQL\dbforgemysql.com" /dataimport /templatefile:"D:\Report.dit" /inputfile:"%%f"
  )

Where:

  • D:\Daily_Report\ is the directory where all our files are stored.
  • *_DAILY.csv is a mask for importing all files which names contain _DAILY.csv in the end.

Save the file as a .bat file.

As a result, we have an executable file, that we can run whenever we need to simultaneously import our CSV files. But we can simplify our work a bit more and automate the data import process.

Scheduling Data Import

To schedule data import on the daily basis, we are going to use Windows Task Scheduler.

So, to schedule data import:

1. Open Windows Task Scheduler and click Create Basic Task in the Actions section.

To schedule data import, first open Create Basic Task wizard

2. Set the task schedule. We want to perform data import on the daily basis, so we select Daily and set the start date.

Set up a convenient trigger

3. Select the created .bat file in the wizard.

Select the .bat file in the wizard

So, that’s it! Now we can forget about manual daily import and switch to more important tasks.

Conclusion

In this article, we described how to import data from bulk files by a predefined mask and optimize the data import daily routines with help of dbForge Studio for MySQL and Windows Task Scheduler. dbForge Studio can help you with many other tasks and simplify your daily routines in a number of different ways. Give it a try and see for yourself!

RELATED ARTICLES

Whitepaper

Social

Topics

Products