File Content Extract

May 14, 2008 by simanta

If you want to extract content from a large file then use the following command from shell

$ sed -n ‘/start string/’,'/end string/p’ database.sql > usertable.sql

The above command will extract the inner content from the SQL file between ’start string’ and ‘end string’.

CSV Import to Using MySQL

May 14, 2008 by simanta

Use the below query in MySQL to import csv data to populate a table.

LOAD DATA LOCAL INFILE ‘path/to/csv/file’ INTO TABLE `tablename` FIELDS TERMINATED BY ‘;’ ENCLOSED BY ‘”‘ ESCAPED BY ‘\\’ LINES TERMINATED BY ‘\r\n’(`id`,`name`,`value`,`isactive`);

Welcome to MySQL World

May 13, 2008 by simanta

To make a database backup using the MySQL command-line utilities, execute the following command:

$ mysqldump -u root -p dbname > dump.sql

If you need to restore your database, you can do so like this:

$ mysql -u username -p dbname < dump.sql