How to Import a Data File into MySQL via phpMyAdmin

Sometimes we have a need to read data into an existing database. Knowing how to import a data file into an established table can save you a lot of time.

First, we’ll be working with MySQL and to make things easier we’ll use phpMyAdmin to speak to the database.

Second, obtain a delimited text file, which is basically a listing of table columns where each column of data is separated by, or marked off by, or delimited by a character. Common delimiting characters are the comma, semi-colon and quote marks, but any character may be used as long as you indicate what the delimiters are.

Example character separated values or CSV file.

In this example the tilde (~) encloses each field of text and the carat (^) denotes the end of the fields.

In phpMyAdmin select your database and table into which you want to import data and click on the Import tab.

The Import tab of phpMyAdmin.

Browse to the location of your delimited text file and select the character set of the file if the default is not correct.

The Import page in phpMyAdmin.

Under “Format of imported file”, click CSV, which stands for comma separated values file or character separated values file. An options form will open when CSV is chosen, but if SQL is checked the options form remains hidden.

Select the CSV button to open this part of the import page.

Under “Options” you can tick off the boxes for ‘Replace table data with file’ and ‘Ignore duplicate rows’ if either function is desired.

Enter the characters that are appropriate for your CSV under ‘Fields terminated by’ and ‘Fields enclosed by’. In the example file above ‘^’ was used for the field termination character and ‘~’ for the field enclosure character.

Characters for escaping fields or terminating lines can be input here, too. Also, if you want to add column names enter the names separated by commas in the blank provided. When ready, hit “Go”.

If successful, you’ll get a message that X number of queries were executed, which means that X number of records were imported into your table. If not successful, check the number of columns and the characters that you’ve input for the CSV and try again.

Your system may limit the size of file that can be imported. If so, check out this LOAD FILE post for a little help.

As always, verify that the data was read into the database correctly. Check that the data for each column of the table matches up with the source delimited text file.

This entry was posted in mysql, php. Bookmark the permalink.

7 Responses to How to Import a Data File into MySQL via phpMyAdmin

  1. Pingback: Format of Numerical Values Matters to Your MySQL Database | computeraxe.com

  2. Alana says:

    Thank you so much for this info!!! Saved me.

  3. angela such says:

    the phpmyadmin that I am using ONLY shows SQL as the ‘format of inported file’.. why? and how can I get around this if I have a .csv file.

    THANKS for your assistance.
    Angela

  4. LizzyFin says:

    Hi Angela,

    When you log in to phpmyadmin, select your database, and click on the Import tab, you will see SQL as the only choice under “Format of imported file”.

    You need to click on the table name that you want to import data into in order to see CSV as a choice for the format of your imported file.

    Good luck!

  5. Angela says:

    THANKS! I see it now!

  6. Yopie says:

    Trying to figure out why I cant import classified ads through phpmyadmin and to get the pictures as well, this is scraped data

  7. LizzyFin says:

    Yopie,
    Perhaps the real authors have some voo-doo protection of their data going on. Can’t blame them, and we can’t help you if you can’t help yourself! Instead of scraping content, take time to make your own content and you’ll get a lot further in life.

    Pitiful. This teacher gives you an F for plagiarism!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>