MySQL: log in to remote host from command line

For reference:

To log into a remote host using the MySQL command line, use:

./mysql db_name --user=username --password=password
--host=remote_host

NB: this assumes you are in the same directory as the mysql executable is located.

This can be written shorthand as:

./mysql db_name -u username -p -h remote_host

This way you will be prompted for your password.

You can also import a MySQL dump by adding "< dump_file.sql" to the end of this.

Published on 26 September 2011