UK Webmaster Talk - Online Marketing - SEO


 

How to import Microsoft Excel data to MySQL

This is a discussion on How to import Microsoft Excel data to MySQL within the Php and MySQL forums, part of the Programming / Scripting / Coding category; How to import Microsoft Excel data to MySQL Introduction I was recently approached with a question relating to import data ...


Go Back   UK Webmaster Talk - Online Marketing - SEO > Website Design & Development > Programming / Scripting / Coding > Php and MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Notices

Reply

 

LinkBack Thread Tools Display Modes
Old 01-12-2005, 13:44   #1 (permalink)
Super Moderator
 
Join Date: Mar 2005
Location: Herts, UK
Posts: 1,030
iTrader: 1 / 100%
monaghan is a jewel in the rough
Default How to import Microsoft Excel data to MySQL

How to import Microsoft Excel data to MySQL

Introduction

I was recently approached with a question relating to import data from an Excel spreadsheet into a MySQL database.

My initial response was to use LOAD DATA INFILE, however this was failing with an error.

The Problem

On further investigation the source data was requested and reviewed. The data in the final column contained text data. This text data was however punctuated and contained many "," As the data was being exported as CSV from Excel this created a CSV file with differing numbers of columns per row and was therefore not able to be imported with LOAD DATA INFILE.

The Solution

Export the Excel file, Tab Separated Text is the ideal option in this case given the actual data.

Copy the file to a location where MySQL can read the file (/tmp in my case)

Create a table (MyTable) in my database

Import the data, this was my SQL command

load data infile '/tmp/MyFile.txt' into table MyTable
fields terminated by '\t'
lines terminated by '\r\n'

Each field was separated by a tab (\t)

As the file originated on a PC and was moved to my test box via Samba the file was DOS format, so line termination was CR/LF (\r\n), the line termination obviously needs to reflect your actual data file.

Conclusion

MySQL is complex database system, it is essential that you spend a bit of time getting to understand the basics of how the system operates. Most issues can be resolved with a simple understanding of what goes on underneath the GUI.

About the Author

Alex Monaghan is a Certified MySQL Professional and was the 2nd UK listed person on the MySQL Listing of Certified MySQL Professionals (there are a number of UK listings now). Alex runs an IT consultancy Monaghan Consultants Ltd and Web Hosting via DIY Hosting

This article is published at Monaghan Consultants MySQL Tips page and may not be republished without permission.
monaghan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
data, excel, import, microsoft, mysql

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Using excel for maths! robertall Programming Articles 7 01-08-2005 08:16
Microsoft name new O.S Vista kprhosting Domain Names 11 22-07-2005 17:31
What gave microsoft there bad repuation robertall General Webmaster Discussion 16 12-05-2005 14:08
phpbb to vbulletin DB Import Wistow Comments / Suggestions 3 09-04-2005 16:06


All times are GMT +1. The time now is 18:22.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
UK Webmaster Forum © WebmasterTalk.co.uk | Design by Forbairt

Ad Management by RedTyger

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41