not able to connect to mysql

Discussion in 'Perl Misc' started by HP, Jan 6, 2006.

  1. HP

    HP Guest

    Hi All

    this is my code:

    $db = DBI->connect($dbpath, $dbuser , $dbpass) || die "cannot connect
    to database".$DBI::errstr;

    i am trying to connect to mysql database.when i am running as perl
    -cgi script on command line its working fine.
    but when i am running it through browser its giving me this error .

    Can't connect to local MySQL server through socket
    '/var/lib/mysql/mysql.sock'

    do anyone know the reason?
     
    HP, Jan 6, 2006
    #1
    1. Advertising

  2. HP

    Brian Wakem Guest

    HP wrote:
    > Hi All
    >
    > this is my code:
    >
    > $db = DBI->connect($dbpath, $dbuser , $dbpass) || die "cannot connect
    > to database".$DBI::errstr;
    >
    > i am trying to connect to mysql database.when i am running as perl
    > -cgi script on command line its working fine.
    > but when i am running it through browser its giving me this error .
    >
    > Can't connect to local MySQL server through socket
    > '/var/lib/mysql/mysql.sock'
    >
    > do anyone know the reason?
    >




    Probably a permissions issue. You missed the all important number off
    the end of that error message.



    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Jan 6, 2006
    #2
    1. Advertising

  3. HP

    HP Guest

    the whole error message is-


    Can't connect to local MySQL server through socket
    '/var/lib/mysql/mysql.sock' (13)

    >Probably a permissions issue

    i am writing cgi script as a root user and giving the file
    chmod 755.
    what can be the reason
     
    HP, Jan 6, 2006
    #3
  4. HP

    HP Guest

    the whole error string is-

    Can't connect to local MySQL server through socket
    '/var/lib/mysql/mysql.sock' (13)

    >Probably a permissions issue


    i am creating the file with root permission, changing the mode of file
    chmod 755

    do you think anything wrong here?
     
    HP, Jan 6, 2006
    #4
  5. HP

    Brian Wakem Guest

    HP wrote:

    > the whole error string is-
    >
    > Can't connect to local MySQL server through socket
    > '/var/lib/mysql/mysql.sock' (13)
    >
    >>Probably a permissions issue

    >
    > i am creating the file with root permission, changing the mode of file
    > chmod 755
    >
    > do you think anything wrong here?



    Yes mysql needs to own the file and have permission to write to it. Also
    you need to check that mysql is actually running and that the path to the
    sock file is correct in the first place.


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Jan 6, 2006
    #5
  6. HP

    HP Guest

    i have chenged the permission to write but the problem still occuring.
    mysql is running fine.i am able to run this scriot from command line.
    even path of mysql.sock is right

    help me out please
     
    HP, Jan 6, 2006
    #6
  7. HP

    HP Guest

    i have changed the permission to write but the problem still occuring.
    mysql is running fine.i am able to run this scriot from command line.
    even path of mysql.sock is right

    help me out please
     
    HP, Jan 6, 2006
    #7
  8. HP

    HP Guest

    >Yes mysql needs to own the file and have permission to write to it

    i have changed the permission to write but problem is still thete.

    > you need to check that mysql is actually running


    mysql is running fine. my script is running fine from the command line.

    >the path to the sock file is correct in the first place.

    place of mysql.sock is right.

    help me out please
     
    HP, Jan 6, 2006
    #8
  9. HP

    HP Guest

    >mysql needs to own the file and have permission to write to it

    i have changed the permission to write the problem is still there
    > you need to check that mysql is actually running


    mysql is running fine,since i am able to run this script fron=m the
    command line mode

    >the path to thesock file is correct in the first place.

    the path of sockfile is correct.
     
    HP, Jan 6, 2006
    #9
  10. HP

    Brian Wakem Guest

    HP wrote:

    >>mysql needs to own the file and have permission to write to it

    >
    > i have changed the permission to write the problem is still there
    >> you need to check that mysql is actually running

    >
    > mysql is running fine,since i am able to run this script fron=m the
    > command line mode
    >
    >>the path to thesock file is correct in the first place.

    > the path of sockfile is correct.



    It must be a permissions problem then.

    First do this:

    mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 105 to server version: 4.1.11

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

    mysql> status
    --------------
    mysql Ver 14.7 Distrib 4.1.11, for mandrake-linux-gnu (i586)

    Connection id: 105
    Current database:
    Current user: root@localhost
    SSL: Not in use
    Current pager: stdout
    Using outfile: ''
    Using delimiter: ;
    Server version: 4.1.11
    Protocol version: 10
    Connection: Localhost via UNIX socket
    Server characterset: latin1
    Db characterset: latin1
    Client characterset: latin1
    Conn. characterset: latin1
    UNIX socket: /var/lib/mysql/mysql.sock

    And make sure the UNIX socket line definitely says /var/lib/mysql/mysql.sock
    and not /tmp/mysql.sock

    Now chown and chgrp the socket file to the user mysql runs under (probably
    mysql). Then, and this is the bit that can stump some people, the mysql
    user needs permission to enter the directory the socket file is in, so
    chown and chgrp /var/lib/mysql.

    Now this is nothing to do with perl so you should post any further questions
    to a mysql group.


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Jan 7, 2006
    #10
  11. HP <> wrote:

    > i am writing cgi script as a root user



    Why?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 7, 2006
    #11
  12. HP

    HP Guest

    Hi All

    i wana give you more information regarding my database.
    mysql database is managed by phpmyadmin.
    and my database is created by phpmyadmin.
    while as a user i have all the priviledge
    do you think it can be problem from connecting to database through
    perl cgi script.
     
    HP, Jan 9, 2006
    #12
  13. HP

    HP Guest

    Hi All
    Common help me someone
     
    HP, Jan 9, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yoshitha

    not able to connect to sqlserver

    yoshitha, Jan 5, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    438
    yoshitha
    Jan 5, 2006
  2. sed_y
    Replies:
    0
    Views:
    1,049
    sed_y
    Feb 15, 2012
  3. Allen Marshall
    Replies:
    1
    Views:
    210
    Gunnar Hjalmarsson
    Jan 24, 2004
  4. Replies:
    5
    Views:
    269
  5. Replies:
    6
    Views:
    153
    Uri Guttman
    Aug 18, 2006
Loading...

Share This Page