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.
Join the DZone community and get the full member experience.
Join For FreeIn 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…
The Data Import wizard opens. In the Source file tab, select the CSV data format and add the file name by clicking Browse…
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.
The Options and Data formats tabs allow you to customize your table by specifying the properties and adjusting the data format you need.
The Mapping tab allows you to map the file content to table columns.
You can handle errors by setting a particular option. Additionally, you can write a report to a log file.
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.
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.
Published at DZone with permission of Jordan Sanders. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Database Integration Tests With Spring Boot and Testcontainers
-
Observability Architecture: Financial Payments Introduction
-
Building a Flask Web Application With Docker: A Step-by-Step Guide
-
Reactive Programming
Comments