SQL Data Import Methods

by George Ionescu.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on databases  

You are here: Categories » Computers and technology » Databases

This article presents the most common ways of importing data to MySQL.

Importing from a Text File

To create a text file that contains several records to be added to our playerdata table, simply denote each column with a tab and each row by a new line. Here is a screen shot of five lines of data to be added to the database in Windows Notepad:

Note how we use \N to specify a field that contains NULL and an extra tab is required after each row of data to signify the end of that row. We have saved this file in the MySQL bin directory (i.e., c:\mysql\bin) with the filename import.txt.

Now go to the MySQL console client and type the following:

mysql> LOAD DATA LOCAL INFILE 'import.txt' INTO TABLE playerdata;

The console will inform us that five rows have been affected or, in this case added to our database.

If we now select all the information from the playerdata table, we can see that our five rows of data have been imported correctly into the database.

Importing from a Native Source

Another method available to use for importing data is using the Microsoft Excel spreadsheet program or any other application that can export data as tab-delimited data.

For this example, however, we will use Microsoft Excel. Let's enter another five rows of data that we wish to add to our playerdata table in Excel. Once this is done, it should look similar to the figure below:

Once our data is entered, we need to save the data in a format that MySQL can understand. In this case, we will use tab-delimited values and save them in a text file called excel.txt in the MySQL bin directory.

Now the process is the same as importing a text file, as we did in the last section.

Leave a comment or ask a question
Total comments: 0

Databases Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
Introduction to SQL - SQL is an acronym for Structured Query Language and is the standard language for interaction with databases. SQL is both an ISO (International Organization for Standardization) and ANSI (Americ (more...)
What Is a Database - A database is simply an organized collection of information. It allows many different types of data to be stored and retrieved in a highly efficient manner. Information within a database (more...)
Installing MySQL Server - Installing MySQL is relatively painless. First, you need the installation program for MySQL, which is available on the companion CD. You can also download the latest version from (more...)
Basic SQL syntax: Creating and Modifying tables and databases - This tutorial shows basic syntax and commands and of the SQL language. Creating and Dropping Databases First, let's see what databases already exist in the MySQL server. We (more...)
Joining SQL Tables - When accessing information within database tables, we may sometimes need to look at data from two or more different tables, as we saw in the previous example. There is another useful way to acc (more...)
Relational SQL Databases - Think of a database that related the players in a game to one another (for example, to determine who was a friend of each player and who was an enemy of each player). First let's create (more...)
SQL Data Manipulation: Select Insert Delete and Modify SQL data - This tutoriald focuses on how to add, modify, and remove data from tables in the database using SQL Data Manipulation Language. Without this knowledge, we would not really have any use for a (more...)
Setting the Color of a Movie Clip - You want to control the color of a movie clip dynamically (at runtime, rather than during authoring). Create a Color object that targets the desired movie clip, and then use the Color.setRGB( ) met (more...)
SQL Server 2005`s Design Goals - SQL Server 2005 faces a much different challenge today than it did in the eighties when SQL Server was first announced. Back then ease-of-use was a priority and having a database scaled to (more...)
A Brief History of Microsoft SQL Server - SQL Server 2005 is the latest version of a database server product that has been evolving since the late 1980s. Microsoft SQL Server originated as Sybase SQL Server in 1987. In 1988, Micro (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.