Hello @kartik,
You need to use the -p flag to send a password. And it's tricky because you must have no space between -p and the password.
$ mysql -h "server-name" -u "root" "-pXXXXXXXX" "database-name" < "filename.sql"
If you use a space after -p it makes the mysql client prompt you interactively for the password, and then it interprets the next command argument as a database-name:
$ mysql -h "server-name" -u "root" -p "XXXXXXXX" "database-name" < "filename.sql"
Enter password: <you type it in here>
ERROR 1049 (42000): Unknown database 'XXXXXXXX'
Actually, I prefer to store the user and password in ~/.my.cnf so I don't have to put it on the command-line at all:
[client]
user = root
password = XXXXXXXX
Then:
$ mysql -h "server-name" "database-name" < "filename.sql"
Hope it helps!!
Thank you!!