Thread: mysql configuration validation script

Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21
  1. Default mysql configuration validation script #1
    scotte is offline Cornerstone of the Community
    Join Date
    Jan 2007
    Location
    Diamond Springs, CA, USA
    Posts
    234
    MythTV Gallery
    0
    Are you having trouble with errors related to the mysql connection from 'mythtv-setup'? Give this script a try and see if it helps narrow down your problem.

    As I get feedback from others and think of additional tests, I'll revise this script as we go. My hope is this will help with some of the more basic and common mysql configuration issues. Clearly it's not the be-all-end-all configuration test, but it should help provide some clues!

    This script requires perl, bash, and mysql client to execute. Save this to a file, make it executable, and give it a try - running as the same user you plan to run 'mythtv-setup' as (this is important, the script will NOT WORK unless run as the same user you run 'mythtv-setup' as!)

    Have feedback or problems, please let me know. It's OK to pm me with suggestions or feedback related directly to the execution of this script, but please do NOT pm me for questions related with how to run the script or to fix problems identified by this, please go ahead and start a new topic to discuss instead. Thanks for your understanding, my goal is to help with some common+basic configuration issues.

    Code:
    #!/usr/bin/perl
    #
    # mythdb_validate.pl
    #
    # Do some basic validation for mythtv mysql configuration.
    #
    # 2007-02-13 - scotte - Created
    # 2007-02-14 - scotte - Updated - now batches errors, checks groups
    #
    
    $MROOT=$ENV{"HOME"}."/.mythtv";
    $MYCNF="$MROOT/mysql.txt";
    $USER=$ENV{"USER"};
    $BASH="/bin/bash";
    $MYSQL="/usr/bin/mysql";
    
    $failed=0;
    
    print "Directory being checked is '$MROOT'.\n";
    print "User running this script is '$USER'.\n";
    
    if ($USER eq "root") {
            print "\nAs a general rule it's a bad idea to configure and run mythtv as the root user.\n";
            print "This script will continue but the results will not be accurate.\n";
            print "Are you really sure you want to do everything as 'root'?\n";
    }
    
    print "Checking file and directory permissions.\n";
    
    -e $MROOT || fail2("$MROOT does not exist!");
    -o $MROOT || fail2("$MROOT is not owned by you!");
    -r $MROOT || fail2("$MROOT is not readable!");
    -w $MROOT || fail2("$MROOT is not writable!");
    -x $MROOT || fail2("$MROOT is not executable!");
    -e $MYCNF || fail2("$MYCNF does not exist!");
    -o $MYCNF || fail2("$MYCNF is not owned by you!");
    -r $MYCNF || fail2("$MYCNF is not readable!");
    -w $MYCNF || fail2("$MYCNF is not writable!");
    !$failed || fail();
    
    print "Checking '$MYCNF'\n";
    
    open (CONF, $MYCNF) || die ("Unable to open $MYCNF");
    while(<CONF>) {
            if (/^DBHostName=(.+)$/) {
                    $dbhost=$1;
            } elsif (/^DBUserName=(.+)$/) {
                    $dbuser=$1;
            } elsif (/^DBPassword=(.+)$/) {
                    $dbpass=$1;
            } elsif (/^DBName=(.+)$/) {
                    $dbname=$1;
            } elsif (/^DBType=(.+)$/) {
                    $dbtype=$1;
            }
    }
    close(CONF);
    
    $dbhost || fail2("DBHostName was not found in $MYCNF!");
    $dbuser || fail2("DBUserName was not found in $MYCNF!");
    $dbpass || fail2("DBPassword was not found in $MYCNF!");
    $dbname || fail2("DBName was not found in $MYCNF!");
    $dbtype || fail2("DBType was not found in $MYCNF!");
    !$failed || fail();
    
    $dbtype eq "QMYSQL3" || fail("DBType is '$dbtype' but we were expecting 'QMYSQL3'.\nThis script only supports mysql.");
    
    print "Trying to connect to mysql.\n";
    
    open(MYSQL, "$BASH -c 'echo exit|$MYSQL -vvv -u $dbuser --password=$dbpass -h $dbhost $dbname' 2>&1|") || die ("Unable to run mysql command");
    $worked=0;
    while(<MYSQL>) {
            if (/^Bye$/) {
                    $worked=1;
            } else {
                    $buffer=$buffer.$_;
            }
    }
    close(MYSQL);
    
    if (!$worked) {
            print "\nmysql test failed. Here's the results:\n\n";
            print "=====\n";
            print $buffer;
            print "=====\n";
            fail("mysql test reported the above error. Your mysql configuration is not correct!");
    }
    
    print "Checking group permissions.\n";
    
    @gids=split(/\s/,$();
    foreach $i (@gids) {
            $name=getgrgid($i);
            if ($name eq "audio") { $audio=1; }
            if ($name eq "video") { $video=1; }
    }
    
    $audio || fail2("You are not in the 'audio' group!");
    $video || fail2("You are not in the 'video' group!");
    !$failed || fail();
    
    print "\nOK, all tests detectable by this script have passed.\n";
    print "Please try running 'mythtv-setup' AS THE USER '$USER'.\n\n";
    print "If mythtv is still unable to connect to the database then it's a failure that\n";
    print "this script isn't smart enough to know about. Please report back to the\n";
    print "mythtvtalk forums.\n";
    
    sub fail2() {
            $failed || print "\n";
            print "STOP! $_[0]\n";
            $failed=1;
    }
    
    sub fail() {
            !$_[0] || print "\nSTOP! $_[0]\n";
            print "\nYour configuration is not correct!\n\n";
            print "Please check that '$MROOT' exists and that it, and everything\n";
            print "in it is owned by '$USER' and that you have write permission.\n";
            print "Please check '$MYCNF' is correct as well.\n";
            print "Have you followed the documentation to the letter?\n";
            print "This script is intentionally very picky about the formatting in\n";
            print "'$MYCNF'. Make sure there is no whitespace\n";
            print "in non-comment lines.\n";
            exit 1;
    }
    If everything is working properly the script should output something along the lines of:



    Directory being checked is '/home/mythtv/.mythtv'.
    User running this script is 'mythtv'.
    Checking file and directory permissions.
    Checking '/home/mythtv/.mythtv/mysql.txt'
    Trying to connect to mysql.
    Checking group permissions.

    OK, all tests detectable by this script have passed.
    Please try running 'mythtv-setup' AS THE USER 'mythtv'.

    If mythtv is still unable to connect to the database then it's a failure that
    this script isn't smart enough to know about. Please report back to the
    mythtvtalk forums.


    Edit by Coume: I made this post a sticky one, as it should help lots of users.
    Reply With Quote  

  2. Default #2
    scotte is offline Cornerstone of the Community
    Join Date
    Jan 2007
    Location
    Diamond Springs, CA, USA
    Posts
    234
    MythTV Gallery
    0
    A couple new additions to the script.

    It now checks that the user is a member of the audio and video groups. This seems to be another common problem.

    It also batches up errors related to the permissions checks.


    Reply With Quote  

  3. Default #3
    dknovick is offline Cornerstone of the Community
    Join Date
    Jan 2006
    Location
    Albuquerque, NM
    Posts
    1,382
    Distribution
    AMD64 F12
    MythTV Version
    0.22
    MythTV Gallery
    0
    Awesome! Hopefully this will help solve a lot of problems.


    Reply With Quote  

  4. Default Excellent!!! #4
    tallmtt is offline MythTV Rookie
    Join Date
    Feb 2007
    Posts
    1
    MythTV Gallery
    0
    Thank you for script - I was having issues with my MythTV after an update and I thought it had to do with the database server. I ran your script and thought it just didn't catch whatever the issue was - turns out - there was nothing to catch - I had to recompile the module for my tuner card!

    Anyways, for those of you who may not know how to use a script like this, save it to a text file, then type:

    chmod 777 your_filename

    then ./your_filename

    Thanks again for your script.


    Reply With Quote  

  5. Default #5
    chewiesw is offline MythTV Friend in Training
    Join Date
    Feb 2007
    Posts
    18
    MythTV Gallery
    0
    Thanks ran the script and it didn't catch anything, so back to the drawing board- might just start from scratch again.

    Anybody know how to cleanly uninstall mysql, mythtv so that I don't have to really start from the beginning with a clean install of edgy


    Reply With Quote  

  6. Default #6
    lonecrow is offline MythTV Rookie
    Join Date
    Oct 2007
    Posts
    4
    MythTV Gallery
    0
    Code:
    [matt@localhost Desktop]$ ./myth_script
    ": No such file or directory
    This is what I get when I try to run the script...


    Reply With Quote  

  7. Default #7
    dishbert is offline MythTV Friend in Training
    Join Date
    Nov 2007
    Posts
    8
    MythTV Gallery
    0
    I found this great script and I've been using it to diagnose and fix my problems. Now everything seems fine, and I can connect to mythtv-setup, as mythtv and password mythtv with no errors, but nothing I do is stored in the database.

    Earlier, I had to change file ownerships to 'chris' and now the script says:

    OK, all tests detectable by this script have passed.
    Please try running 'mythtv-setup' AS THE USER 'chris'.

    But when I change the ~/.mythtv/mysql.txt to user chris and my password, I again get the dreaded "Unable to connect" message.

    I thought the solution would be to change the file ownership to mythtv, but I get this message when I try:

    root@downstairs:/usr/src/mythtv# chown mythtv /home/chris/.mythtv
    chown: `mythtv': invalid user

    As a result of this mythtv-setup exits with a bunch of these:

    QMYSQL3: Unable to execute query
    Database error was:
    Table 'mythconverg.keybindings' doesn't exist

    And when I look using mythtv, password mythtv I get:

    chris@downstairs:/usr/src/mythtv$ mysql -u mythtv -p -Dmythconverg
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 21
    Server version: 5.0.45-Debian_1ubuntu3 Debian etch distribution

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql> show tables;
    Empty set (0.00 sec)

    mysql> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mythconverg |
    +--------------------+
    2 rows in set (0.01 sec

    Any help would be appreciated.

    dishbert


    Reply With Quote  

  8. Default Can not connect to DB #8
    wm_sorg is offline MythTV Rookie
    Join Date
    Jan 2009
    Posts
    1
    MythTV Gallery
    0
    Hi all,

    Tried to run the script and had no luck. Here are some results:

    mythtv@myth-master:~/.mythtv> mysql -u mythtv -p mythconverg
    Enter password: mythtv
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 99
    Server version: 5.0.67 SUSE MySQL RPM

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql>

    I can log into MySQL with the mythtv ID and it's credentials.

    When I run the validate script I get the following:
    ythtv@myth-master:~/.mythtv> /usr/bin/mythdb_validate.pl
    Directory being checked is '/home/mythtv/.mythtv'.
    User running this script is 'mythtv'.
    Checking file and directory permissions.
    Checking '/home/mythtv/.mythtv/mysql.txt'
    Trying to connect to mysql.

    mysql test failed. Here's the results:
    =====
    ERROR 1045 (28000): Access denied for user 'mythtv'@'myth-master' (using password: YES)
    =====
    STOP! mysql test reported the above error. Your mysql configuration is not correct!
    Your configuration is not correct!

    Here is the con tense of My SQL.txt:
    DBUserName=mythtv
    DBPassword=mythtv
    DBName=mythconverg
    DBType=QMYSQL3

    I also checked permissions and they appear to be OK. Any thoughts or suggestions will be greatly appreciated.

    Regards,
    BILL


    Reply With Quote  

  9. Default #9
    eric70x7 is offline MythTV Rookie
    Join Date
    May 2009
    Posts
    3
    MythTV Gallery
    0
    Thank you. A piece of code is worth a thousand words.


    Reply With Quote  

  10. Default #10
    PhilB is offline MythTV Helper
    Join Date
    Feb 2009
    Location
    South West London
    Posts
    186
    Distribution
    Mythbuntu 12.04
    MythTV Version
    0.25
    MythTV Gallery
    0
    I have an issue with not being a member of audio group. Please help this novice fix that.
    The group seems to exist:

    cat /etc/group|grep audio
    audio:29:mythtv

    [that's audio colon X - not a smiley!]

    But cannot be seen in system > users and groups

    Google suggest I use adduser but that isn't working either.

    Is it safe to jump in with big boots and gedit the file /etc/group?

    regards
    Phil


    Reply With Quote  

Page 1 of 3 1 2 3 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. HVR-1600 Configuration
    By KingofChaos in forum Installation Issues
    Replies: 0
    Last Post: 07-01-2008, 12:32 AM
  2. Running a python script / MySQL
    By julz in forum General
    Replies: 5
    Last Post: 02-25-2008, 08:33 AM
  3. best ati configuration
    By leespa in forum Installation Issues
    Replies: 0
    Last Post: 04-16-2007, 07:57 PM
  4. EPG configuration
    By CityZen in forum Installation Issues
    Replies: 5
    Last Post: 11-24-2006, 11:25 PM
  5. Dual Car Configuration
    By netwho in forum Installation Issues
    Replies: 0
    Last Post: 03-16-2005, 01:16 PM

Posting Permissions

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