Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Import a CSV File Through the Command Line

DZone's Guide to

How to Import a CSV File Through the Command Line

Learn how dbForge Studio for MySQL makes it much easier to import data via the command line.

· Database Zone ·
Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

In this post, we are going to explore 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.

1. Creating a Data Import Template Based on the CSV File

In Database Explorer, right-click a required database.

In the shortcut menu, point to Tools and click Import Data…

Image title

The Data Import wizard opens. In the Source file tab, select the CSV data format and add the file name by clicking Browse…

Image title

Open the previously created CSV file and click Next.

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.

Image title

The Options and Data formats tabs allow you to customize your table by specifying the properties and adjusting the data format you need.

Image title

The Mapping tab allows you to map the file content to table columns.

Image title

You can handle errors by setting a particular option. Additionally, you can write a report to a log file.

Image title

To complete the process of creating the template, click Save Template in the Data Import wizard.

2. Creating a BAT File

Open the template file in any third-party text editor; for example, Notepad++.

Remove everything from the tag <ColumnMappings> along with the tag itself.

Create BAT file with the following content; for example, where D:\template.dit is your template file:

@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%

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 and the table name to be created when importing.

Image title

Once the data import process is successfully completed, go to dbForge Studio for the 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.

Do you pay to use your database? What if your database paid you? Learn more with RavenDB.

Topics:
mysql ,database ,csv ,data import ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}