MySQL
Database Import
MySQL Workbench
Data Management
SQL Tools

How can I import data into mysql database via mysql workbench?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

MySQL Workbench can import data in more than one way, and the right method depends on what kind of file you have. A full SQL dump is usually imported through the Data Import screen, while CSV-style tabular data is often easier through the Table Data Import Wizard.

Importing a .sql Dump File

If your input is a SQL dump created by mysqldump or a similar tool, use the main Data Import workflow.

Typical steps in MySQL Workbench are:

  1. connect to the target MySQL server
  2. open Server and then Data Import
  3. choose Import from Self-Contained File
  4. browse to the .sql file
  5. select the target schema or create one first
  6. start the import

This method is best when the file already contains SQL statements such as CREATE TABLE, INSERT, and possibly index or constraint definitions.

If you prefer the SQL editor, you can also open the file and execute it directly:

sql
SOURCE /path/to/dump.sql;

That is conceptually simple, but the Data Import screen is usually easier for larger dump files and clearer for less command-line-oriented workflows.

Importing CSV Data into a Table

If the source is a CSV file rather than a SQL dump, Workbench usually expects you to import it into an existing or new table. The easiest route is the Table Data Import Wizard.

Typical workflow:

  1. create the target schema if needed
  2. create or select the destination table
  3. right-click the table in the schema browser
  4. choose Table Data Import Wizard
  5. select the CSV file
  6. map columns and review types
  7. complete the import

This is useful when the file is plain rows and columns rather than executable SQL.

For example, if your CSV looks like this:

text
id,name,email
1,Ada,[email protected]
2,Linus,[email protected]

Workbench can map each CSV column into the destination table columns during the wizard flow.

Prepare the Table First When Needed

CSV import works more smoothly when the destination table structure is already clear. For example:

sql
1CREATE TABLE users (
2    id INT PRIMARY KEY,
3    name VARCHAR(100) NOT NULL,
4    email VARCHAR(255) NOT NULL
5);

Then use the wizard to load the rows. This avoids guesswork around types and prevents the import from creating an unexpected schema.

When LOAD DATA INFILE Is Better

For larger datasets, Workbench may still be only the interface, while the actual best import mechanism is MySQL's LOAD DATA command.

sql
1LOAD DATA LOCAL INFILE '/path/to/users.csv'
2INTO TABLE users
3FIELDS TERMINATED BY ','
4LINES TERMINATED BY '\n'
5IGNORE 1 LINES
6(id, name, email);

Workbench can run this SQL in the query editor. This approach is often faster and more explicit than clicking through the wizard, especially when you are repeating the same import in multiple environments.

Validate After Import

Always inspect the imported data instead of assuming success because the dialog finished without errors.

Simple checks include:

sql
SELECT COUNT(*) FROM users;
SELECT * FROM users LIMIT 10;

If the row count is unexpectedly low, or if columns appear shifted, the delimiter, quoting, encoding, or table definition may not match the source file.

Common Pitfalls

  • Using the SQL dump import workflow for CSV files or the CSV wizard for full SQL dumps.
  • Importing into a table with the wrong column order or incompatible types.
  • Forgetting to create or select the intended target schema before importing.
  • Assuming a successful import dialog means the data was mapped correctly.
  • Ignoring file encoding, delimiters, or header-row settings when working with CSV data.

Summary

  • Use the Data Import screen for .sql dump files.
  • Use the Table Data Import Wizard for CSV-style tabular data.
  • Create the destination table explicitly when you want predictable column types.
  • For large repeated imports, LOAD DATA INFILE is often the clearer and faster option.
  • Always validate the imported row count and sample records after the import completes.

Course illustration
Course illustration

All Rights Reserved.