Once a day I need to update a plain text file with the result of an SQL query. The MySQL database is on another server, so I need to connect remotely. This should be pretty simple with bash.
Code:
echo "SELECT pname FROM applications WHERE status = 1" | /usr/bin/mysql -u$USERNAME -p$PASSWORD -h$HOST $DATABASE_NAME > outfile
Doing this locally (omitting the -h option) works just fine, but whenever I try to do it remotely I get:
Code:
ERROR 2005 (HY000): Unknown MySQL server host 'MY.MYSQL.SERVER.com' (1)
The server works fine, as all my websites make use of it, and they're OK. Am I doing something wrong, and if so, what?
If you have any other way of doing this via a script that can be run by a cronjob, please let me know. All I need is to get the result of the query in a plain text file with each result on its own line.
Bookmarks