Handy MySQL Commands

Sunday, April 25, 2010 - 6:30 pm
By Colin
To reset an auto_increment field to 1:

ALTER TABLE tbl_name AUTO_INCREMENT = 1;
To load a local csv file into an empty existing table:

LOAD DATA LOCAL INFILE ‘/completePathToLocalData.csv’ INTO TABLE tableName FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘\n’ IGNORE 1 LINES;

This assumes you’ve already created your empty table with the same number of fields that your csv file has.

To load mysql db dump into an existing empty database:

mysql -u userName -p -h localhost databaseName < /path/to/mysqldbdump.sql

You will have to enter your password on the next prompt.

Leave a Reply