MySQL commands in text files and mysqldump for Linux and Windows

Here you will see how to execute SQL syntax is in a file in the command line and how to launch mysqldump with options

Date: 27 may 2009

If your SQL syntax is in a file, you can execute it like this:
In Linux:

shell> mysql -uUserName -p db_name < text_file

In Windows:

source {pathToFile}/myfolder/mysqlfile.sql;

In Windows (From the command line with force (-f) option, continue executing even with sql errors,
in this example mysql is installed with Wamp)

C:\wamp\bin\mysql\mysql5.0.51b\bin\mysql -uUSERNAME -pPASSWORD database_name -f < D:\SqlFiles\DB.sql

Mysqldump with options
shell> mysqldump -uroot -p -f -t --insert-ignore my_database_name table1 table2 table3 > my_dump_file.sql

The options are explained here:

-uroot: user for login to the database

-p: asking for a password

-f: force, continue even if we get an sql error.

-t: don't write table creation info

--insert-ignore: Insert rows with INSERT IGNORE (will only insert if row doesn't exist, which will avoid duplicate row problems)

table1, table2, table3: will only dump these tables, remove this if you want to dump the whole database

These are useful little tips