Devart Blog

How To Import a .CSV file through the Command Line

Posted by on August 14th, 2017

In this post, we are going to explore the way of how to import a .csv file through the command line in dbForge Studio for MySQL.

You will not have to waste your valuable time on manually specifying properties each time you need to create a new MySQL table. With this option, you can forget about going through this process over and over again. Instead, you can import data by creating a template based on the .csv file fast and in a few clicks.

In the following example, we are going to demonstrate the process of importing a .csv file through the command line in dbForge Studio for MySQL.

Step 1. Creating a data import template based on the .CSV file

  1. In Database Explorer, right-click a required database.
  2. In the shortcut menu, point to Tools and click Import Data…step 1
  3. The Data Import wizard opens. In the Source file tab, select the .csv data format and add the file name by clicking Browse…screen 2
  4. Open the previously created .CSV file and click Next.
  5. On the Destination tab, you can select a connection from the drop-down list or create a new one. Also, you need to choose a database and specify a name for the new table.screen 3
  6. The Options and Data formats tabs allow you to customize your table by specifying the properties and adjusting the data format you need.options
  7. The Mapping tab allows you to map the file content to table columns.mapping
  8. You can handle errors by setting a particular option. Additionally, you can write a report to a log file.errors handling
  9. To complete the process of creating the template, click Save Template in the Data Import wizard.

Step 2. Creating a .bat file

  1. Open the template file in any third-party text editor, for example, Notepad++.
  2. Remove everything from the tag <ColumnMappings> along with the tag itself.
  3. Create .bat file with the following content, for example:
    @echo off
    set /P csv_file="Input csv file(full path): "
    set /P table_name="Input table for import: "
    set p=%ProgramFiles%\Devart\dbForge Studio for MySQL
    "%p%\dbforgemysql.com" /dataimport /inputfile:"%csv_file%" /templatefile:"D:\template.dit" /table:%table_name%
    

    where D:\template.dit is your template file.

Step 3. Importing a .CSV file through the command line

After successfully creating the .bat file, run it and then enter:

  • the full path to the .csv file
  • the table name to be created when importing
    screen 4

Once the data import process is successfully completed, go to dbForge Studio for MySQL table and click Refresh in Database Explorer.

Conclusion

To import data via the command line is much easier with dbForge Studio for MySQL. It simplifies the import process and saves much time on loading multiple .csv files in several clicks, efficiently and effortlessly.

Leave a Reply