How to Create Table From CSV in MySQL

Preet Sanghavi Feb 02, 2024
How to Create Table From CSV in MySQL

In this tutorial, we aim at understanding how to create a table from CSV in the MySQL database.

Businesses and organizations must generate tables rapidly from large amounts of data. These organizations generally have large amounts of CSV files with loads of data spread evenly across the file in multiple fields to get this done.

Sometimes, it becomes necessary for analysts to create tables directly from such CSV files. In this tutorial, let us get our hands around this concept.

Let us collect some data in a CSV file to understand this better.

We can name this file dummy_data. A look into our CSV file can be illustrated as follows.

mysql create trable from csv 1

Now that we have our data set up in the CSV file, let us learn how to convert this data into a table in MySQL.

Use MySQL Workbench to Create Table From CSV in MySQL

We can perform this operation in MySQL Workbench by right-clicking our database’s Tables tab. It would show us the tab Table Data Import Wizard.

It can be illustrated as shown in the figure below.

mysql create trable from csv 2

Once we click on the tab, we can choose the path of our CSV file and click Next, as shown below.

mysql create trable from csv 3

We keep clicking next until our task has been executed. Once all the tabs are run successfully, you can see the table created in the left-hand side tab on your MySQL Workbench.

The name of the newly created table will be the same as the file’s name, whose path was given before.

Alternatively, we can look up the data from this table to ensure that this table has been created. We can use the query below to get this operation done.

SELECT * from dummy_data;

The query loops through our entire table and fetches values. The output of the query can be illustrated as follows.

Client 	Job Name						Fees Paid		Taxes Paid     Total Billed 	Your Earnings
b	pay per project						-7.6			-0.38			38				30.02
A	How-To Style Article Writers Needed	-26.1			-1.31			130.5			103.09
C 	Consultancy	Technical writers for 	-19.8			-0.99			99				78.21
d	Developing a Machine Learning model	-5				-0.25			25				19.75

We have the alias Jobs with the AS keyword in MySQL to increase the program’s readability in the output block.

Therefore, with the help of the queries and methods, we can create a new table from CSV entries efficiently and quickly in MySQL.

Preet Sanghavi avatar Preet Sanghavi avatar

Preet writes his thoughts about programming in a simplified manner to help others learn better. With thorough research, his articles offer descriptive and easy to understand solutions.

LinkedIn GitHub

Related Article - MySQL CSV

Related Article - MySQL Table