[mythtv-users] suddenly can't connect to database, SOLVED

Michael T. Dean mtdean at thirdcontact.com
Thu Mar 20 17:07:47 UTC 2008


On 03/20/2008 12:50 PM, Daniel Arfsten wrote:
>>> this morning all of a sudden it says I can't connect to the database mythconverg.
>>> mythtv is running and I even tried restarting it.
>> At a command line type ps ax|grep mysql to see if mysql is running.
>> If it isn't, do a /etc/init.d/mysql start
>> If it is running, I sometimes have to re-do permissions on Mysql.  go
>> to /usr/share/mythtv/sql and do a mysql mythconverg <mc.sql
> That was it, I noticed that mysql wasn't running a little bit after I sent the
> message out. What I find weird is that the mythtv-backend start script within
> etc/init.d/ in Ubuntu wouldn't check to make sure mysql is running before firing up
> mythtv-backend. Even if I did a restart, shouldn't it error out and tell me that
> mysql isn't running???? Anyway, thanks for responding.
>
>   

I'm using the following.  I'll leave it up to you how to get DBHostName 
to the script.  Note that this will not detect a situation where the 
mythtv user doesn't have permission to connect to the DB (i.e. if the 
mythtv user in MySQL hasn't been created, yet).  However, IMHO, that's 
not an issue as I create the mythtv user when I create the mythconverg 
database and, if the mythconverg database doesn't exist (or the mythtv 
MySQL user doesn't exist), I have /much/ bigger problems than just a 
database that isn't running.

You'll need to put the password in the MySQL options file (/etc/my.cnf 
or ~/.my.cnf) or add a "-pmythtv" (or whatever) to the mysqladmin 
command.  Oh, and I'm pretty sure the math I'm doing is a bashism (you 
need to have "#!/bin/bash" (no quotes) at the top of the script).

Mike

    # See if the DB is available
    ready=0
    count=1
    # Ping the DB if we found its hostname.  Otherwise, skip it, start
    # mythbackend, and hope for the best.
    if [ "x${DBHostName}" != "x" ]; then
      while [ $ready = 0 ]; do
        echo "Pinging Database (on host $DBHostName) (try $count)..."
        mysqladmin -h${DBHostName} -umythtv ping > /dev/null 2>&1
        if [ $? = 0 ]; then
          ready=1
        else
          count=$(( $count + 1))
          if [ $count -lt 60 ]; then
            sleep $count
          else
            sleep 60
          fi
        fi
      done
    fi



More information about the mythtv-users mailing list