MySQL Import Data From EXCEL (csv file)

mysql logo

1. Save as excel document in CSV format. (found as CSV Comma Delimited file)

2. Connect to Mysql through command line
Start Cmd
cd c:\mysql\bin\ (or wherever the mysql directory is installed…)

3. Connect to MySQL command console
use
[sourcecode lang=”sql”]mysql -u root[/sourcecode]
to connect as root user to be able to do changes to your db

4. Remember to Save the CSV File in the mysql\bin directory

5. Enter the following commands
SELECT THE DATABASE TO USE
[sourcecode lang=”sql”]use yourdbname;[/sourcecode]
ENTER THE INSERT COMMAND
[sourcecode lang=”sql”]
LOAD DATA LOCAL INFILE ‘/yourCSVfilename.csv’
INTO TABLE test_table
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
(field1, filed2, field3); [/sourcecode]

For Greek or non-unicode Remember 3 Things
1.  mysql> set character_set_database =utf8;
2. CSV File saved as UTF8 encoding
3. database Table character set to greek_unicode_ci;

Leave a Reply

Your email address will not be published.