How to move CSV file to MySQL easily

database schema 1895779

CSV stands for Comma-separated values. It contains data in tabular form and csv files are saved with .csv extensions and are in plain text, which means it can be edited in any text editor.
As they are in tabular form, similar to tables in MySQL or cells in a spreadsheet software. You may find a need to move your csv file to MySQL database.

Here’s how to do it.

In this tutorial, we’ll move the csv file which is IP.csv to our MySQL database in movies table.

Step 1:- create a table, name the fields and specify the constraints which are required.

In this case, we have table movies.

mysql table

Step 2:- Make a csv file if you haven’t already with fields similar in MySQL

In this case, we’ll use IP.csv. Here’s what a csv file looks like.

example of csv file

Step 3:- Open MySQL Workbench which comes with MySQL client

open MySQL workbench

workbench

Click on local instance, it may ask for your password. Then a New window will appear.

mysql workbench

Step 4:- Open your table which in which you’d like to move your csv file

Enter the commands and click on run button run. As you haven’t entered any data, so the table content will show null.

MYsql wordbench

Empty table:-

null tables

Step 5:- click on import button to import csv or json datafiles

import button

Proceed to complete the wizard as shown in the picture.

sql wizard

As we’re using our existing table structure, click on use existing table option. Also don’t forget to choose the correct table name, in this case it is movies.
It is mentioned sy.movies which means movies table inside the database name sy.

sql wizard

Make sure to import all the fields by checking the check marks.

check marks

All Done! Now, your csv file is importing in your MySQL database. It may take few seconds depending on the size of csv.

importing

Now run the commands again. This timetable will be displayed in place of null cells.

MySQL table

Tried this but still facing problems let me know in comments 🙂

Do you know how to check real-time data usage in Linux?

Related Posts

Leave a Reply

Your email address will not be published.