Wednesday, February 20, 2008

Few Info for Mysql

If you need to dump a table from database, use a simple command is.
mysqldump -uUSERNAME -pPASSWORD DATABASE_NAME TABLE_NAME > myBackup.sql

Someone may require only get the table structure, not the data. For those,
mysqldump -uUSERNAME -pPASSWORD DATABASE_NAME -d TABLE_NAME > myBackup.sql

Again someone may require only the data, not the table, simple, just use -t
mysqldump -uUSERNAME -pPASSWORD DATABASE_NAME -t TABLE_NAME > myBackup.sql

Sometimes it requires to dump from mysql database using where clause. It is simple to write one of them.
mysqldump -uUSERNAME -pPASSWORD DATABASE_NAME TABLE_NAME --where='id >= 10 and id <20'> myBackup.sql

Now you know how to dump of etc. Time to import the dumps into mysql again. When importing, you find some of the data already exist into your table. what should be done? There is a simple but effective way at latter version of mysql. You have an option to Update while duplicate found.
INSERT INTO TABLE_NAME ... ON DUPLICATE KEY UPDATE SET field=field_value;

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...