$ mysql -p$pass -u$user -h$otherhost $db < dumpfile
dumpfile is text from
mysqldump, containing raw SQL statements.
It is important that there be no space between
-p and the password. (I assume you want automatic login.) If the password does not immediately follow the
mysql interprets the option as meaning it should ask interactively for the password, and treats the separate password argument as the DB name.
For this to work,
$user must have permission to log in, drop a table, create a table, and insert rows into that table, all as a remote user. MySQL keeps separate remote and local permissions for users, so this is an easy trap to fall into. Because allowing a remote user this much power is a security risk, you may want to use SSL (
--ssl* options) with
mysql. Otherwise, I don't know that I would allow a remote user to do such things.