Import CSV into MySQL

It happens (often to me) that as an external (consultant) member, for company policies I cannot have even read access to production DB tables.

This will come to be very unproductive when I have to test for the integrity of some records or for the motivation of the behavior of an application.

The solution I’ve found every time is to create on my local MySQL database the same table structure of the production environment and then ask to someone who has access to DB tables to make me an export in order to import it in my tables.

Generally this export come out as CSV file but with semicolon (;) as field separator.

MySQL offer a very cool command for import large amount of data into table: load data statement.

Starting from the point that your user has privileges for doing this operation, the command is like the following

load data local infile ‘path/to/your/file.txt‘ into table your_table fields terminated by ‘;’;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s