In some of these examples, particularly the remote server I’ve included usernames and passwords, but you might not need it locally, depending on your mysql permissions setup.
Run and save results of sql statement against a remote mysql server
mysql -h remote_server_ip -u your_username --password=your_password database_name -N -e 'select * from your_table' > results.txt
Run file of sql commands against a remote mysql server
mysqldump -u your_username --password=your_password -h 10.1.2.1 database_name < /tmp/your-file-with-sql-statements.sql
Run file of sql commands against a local mysql server
mysql database_name < /tmp/your-file-with-sql-statements.sql