kgui
kgui

Reputation: 4165

Load csv into MySQL, using a new table

I am using phpMyAdmin to load a CSV file into a MySQL table but, does the table have to be created before the load?

I have read that if the workbench is used ( Import a CSV file into MySQL workbench into a new table dynamically ) the latest version creates the table on the fly but, is this possible with phpMyAdmin. Here is the code that doesn't work

load data local infile '/Users/...'
into table skin_cutaneous_melanoma
fields terminated by ','
lines terminated by '\n'

Error is:

#1146 - Table hospital.skin_cutaneous_melanoma' doesn't exist 

Upvotes: 0

Views: 1107

Answers (1)

Isaac Bennetch
Isaac Bennetch

Reputation: 12422

Sure, phpMyAdmin can do this.

From the main page, look for the Import tab. This is, of course, how you expect to import any file including if you already have the database and table created, but if not phpMyAdmin creates a temporary database and table for you using generic names and best guesses as to the data types for your columns. Note that this is probably not the ideal structure, but is the best guess based on the existing data in your database. For best results, you'll probably want to put the desired column names at the top of your CSV file and select the corresponding option during import, or rename them after import (likewise with the database and table names) -- but it is absolutely possible to do the import to a new table.

Upvotes: 2

Related Questions