Results 1 to 4 of 4

Thread: Remote MySQL query

  1. #1
    Join Date
    Jul 2007
    Location
    Luleå, Sweden
    Beans
    572
    Distro
    Ubuntu 9.10 Karmic Koala

    Remote MySQL query

    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.

  2. #2
    Join Date
    Sep 2009
    Beans
    72

    Re: Remote MySQL query

    That mysql server could work on sockets, it could work on different port or it could allow communication only with local users.
    You could use:
    wget http://that_server.com/path/get_data.php > outfile

  3. #3
    Join Date
    Apr 2006
    Location
    Timisoara, Romania
    Beans
    132
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Remote MySQL query

    Hi.

    Did you set properly the variables ($HOST, etc) before running the script?
    Try to inspect them before running the script:
    echo $HOST

    Cheers

  4. #4
    Join Date
    Jul 2007
    Location
    Luleå, Sweden
    Beans
    572
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Remote MySQL query

    The command worked beautifully when I ran it from my web hotel (not the same server as the MySQL server), so I guess there's something that I haven't configured correctly on my own computer.

    Anyway, it works, so I'm happy.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •