Databases Reference
In-Depth Information
Importing CSV files
In this section, we will examine how to import CSV files. There are two possible
methods— CSV and CSV using LOAD DATA . The first method is implemented
internally by phpMyAdmin and is the recommended one for its simplicity. With
the second method, phpMyAdmin receives the file to be loaded, and passes it to
MySQL. In theory, this method should be faster. However, it has more requirements
due to MySQL itself (refer to the Requirements sub-section of the CSV using LOAD
DATA section).
Differences between SQL and CSV formats
Usually, the SQL format contains both structure and data. The CSV file format
contains data only, so if we import in Table view, we must already have an existing
table in place. This table does not need to have the same structure as the original
table (from which the data comes); the Column names dialog enables us to choose
which columns are affected in the target table.
Since version 3.4, we can also import a CSV file in Database view. In this case,
phpMyAdmin examines the CSV data and generates a table structure to hold this
data (with generic column names such as COL 1 , COL 2 and a table name such as
TABLE 24 ).
Exporting a test file
Before trying an import, let us generate an author.csv export file from the author
table. We use the default values in the CSV export options. We can then use the
Empty option to empty the author table—we should avoid dropping this table as we
still need the table structure. The procedure to empty a table is covered in Chapter 5 ,
in the Deleting all of the rows in a table section.
CSV
From the author table menu, we select Import and then CSV .
 
Search WWH ::




Custom Search