Wednesday, 6 August 2014

How to take backup and restore database through commandprompt

It is a good idea to backup your MySQL data occasionally as a precautionary measure. It is also a good idea to create a backup before making any major changes, in-case something goes wrong and you need to revert to the unmodified version. Database backups can also be used to transfer your database from one server to another if you change web hosts.

Open command prompt.



First go to MySQL bin folder.

Take Backup.
mysqldump -u username -ppassword databasename>databasename.sql

Eg:
mysqldump -u root -ppassword Test>c:\Test.sql

If it displays Access is denied.

Run cmd as Administrator

Start->cmd->Right click Run as Administrator.

                                                                     Restore.
mysql -u username -ppassword databasename<databasename.sql

Eg:
mysql -u root -ppassword Test<"c:\Test.sql"




Tuesday, 5 August 2014

Selecting duplicate IDs in mysql

select column_name,count(*) from table_name group by column_name having count(*)>1;

Example:

select consignment_id,count(*) from trip_sheet_trip group by consignment_id having count(*)>1;