Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entering data from an excel spreadsheet into database?

Tags:

mysql

excel

I'm looking for a clever way to extract 500 plus lines of data from an excel spreadsheet and enter is into my database.

The spreadsheet is like this

My table 'tbl_foot_teams' is set out as

id | name | rating

Quite simply, I need to enter get the two columns from the spreadsheet into the database fields name and rating.

Is there any efficient way to achieve this? Individually, it will take me a ridiculous amount of time!

Thanks

like image 969
sark9012 Avatar asked Feb 09 '26 22:02

sark9012


1 Answers

Save Excel file as CSV and use LOAD DATA INFILE command to import data.

Your excel file has no id field. Make id field in the table as AUTO_INCREMENT, and use command like this -

LOAD DATA INFILE 'file_name.csv' INTO TABLE tbl_foot_teams
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
-- IGNORE 1 LINES -- if csv file has column headers
(name, rating)
SET id = NULL; -- this will set unique value for each row

Also, have a look at GUI Data Import tool (Excel or CSV format) in dbForge Studio for MySQL.

like image 143
Devart Avatar answered Feb 12 '26 14:02

Devart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!