1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Unhappy mysql error ( Can't connect to local MySql server through socket (2)

Discussion in 'Plesk for Linux - 8.x and Older' started by blackhowling, Dec 7, 2005.

  1. blackhowling

    blackhowling Guest

    0
     
    Hii all , i am a newbie on linux, i have a problem now . when i use mysql command on chrooted bash, an error come up and it said "Can't connect to local MySql server through socket (2)" . Can anybody please help me...
     
  2. cmaxwell

    cmaxwell Regular Pleskian

    25
    73%
    Joined:
    Aug 1, 2001
    Messages:
    150
    Likes Received:
    1
    Hello,

    Make a backup of your current MySQL configuration file:

    cp /etc/my.cnf /etc/my.cnf.bak

    Then edit it eg:

    pico /etc/my.cnf

    I use pico but you can use whatever text editor you prefer.

    Look for the [client] section in this file, if it is not there then add this to the file:

    [client]
    socket=/var/lib/mysql/mysql.sock

    If there is a [client] section then just add the second socket line above to the section.

    Save the file and it should now work.

    - Chris
     
  3. Dmitry Frantsev

    Dmitry Frantsev Golden Pleskian

    28
    57%
    Joined:
    Sep 19, 2005
    Messages:
    1,911
    Likes Received:
    0
    It seems that mysql service is not running on your server. Take a look at the examples below:

    $mysql -uadmin -p`cat /etc/psa/.psa.shadow`
    ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    $/etc/init.d/mysqld start
    Starting MySQL: [ ОК ]

    $mysql -uadmin -p`cat /etc/psa/.psa.shadow`
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 1 to server version: 3.23.58

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

    mysql>

    When mysql service is not started there is no /var/lib/mysql/mysql.sock file created. Also, previous reply was also correct. So don't forget to check if following line persists in /etc/my.cnf file:

    socket=/var/lib/mysql/mysql.sock
     
  4. blackhowling

    blackhowling Guest

    0
     
    Thanx for all your answer . I already try it, but it still don't work . When i add

    [client]
    socket=/var/lib/mysql/mysql.sock

    and i restart mysql, it said "mysql locked, bla... bla.. " . :( :( :(

    I already check that mysql server is running . because when i login as root, i can connect to mysql server . but when i login as user i can't connect mysql server .
     
  5. cmaxwell

    cmaxwell Regular Pleskian

    25
    73%
    Joined:
    Aug 1, 2001
    Messages:
    150
    Likes Received:
    1
    What's the command you're using on the command line? This command should work:

    mysql -uadmin -p`cat /etc/psa/.psa.shadow`
     
  6. blackhowling

    blackhowling Guest

    0
     
    when i login as root use
    "mysql -uadmin -p `cat /etc/psa/.psa_shadow` . but when i login as normail user which use chrooted as it shell, and i use "mysql" it already show error "Can't connect through socket bla.. bla.. (2)" .
     
  7. cmaxwell

    cmaxwell Regular Pleskian

    25
    73%
    Joined:
    Aug 1, 2001
    Messages:
    150
    Likes Received:
    1
    If the user is chrooted then it is not going to have access to the system files for MySQL.

    The point of chrooting someone is to increase security on the system, and as a result they will not have access to stuff like the mysql.sock file which causes this error.

    A standard system user which is not chrooted will be able to access MySQL.
     
  8. cmaxwell

    cmaxwell Regular Pleskian

    25
    73%
    Joined:
    Aug 1, 2001
    Messages:
    150
    Likes Received:
    1
    I also find it interesting that a chrooted user can successfully use the mysql command even if it doesn't connect.

    The Plesk standard "bin" folder does not include the mysql binary. I would treat that as a security risk if you allow your users to use the mysql command line client - after all you don't really want them trying to access the psa database for instance do you? Just my thoughts...

    In saying that, if you know your users intimately, eg you're all part of the same company, then it is less of a risk but in a web hosting environment i'd say it's a big no no.
     
  9. blackhowling

    blackhowling Guest

    0
     
    actually, i just curious about this problem . At first, i want to give my client mysql command, but now i already told them that i can't allow them to connect mysql throught ssh . can't you please give a suggestion about this problem ? :D :D
     
  10. cmaxwell

    cmaxwell Regular Pleskian

    25
    73%
    Joined:
    Aug 1, 2001
    Messages:
    150
    Likes Received:
    1
    I understand. But as you have chrooted the users into their own home directories then they have no access to anything above their directory root.

    As far as a chrooted user is concerned, /home/httpd/vhosts/<domain> is the root directory and they cannot go any higher.

    To allow them to have access to files outside the chrooted environment you would need to change their shell so that it is not a chrooted shell, and I would highly recommend against that for security reasons unless you know and trust everyone on the server.

    Hope this helps.
     
  11. servertune

    servertune Guest

    0
     
    To take this even further, unless you really know your clients, I wouldn't give any client(s) access to shell, for security purposes. There are Linux savvy clients who can can get through chroot to the root level.
     
  12. cmaxwell

    cmaxwell Regular Pleskian

    25
    73%
    Joined:
    Aug 1, 2001
    Messages:
    150
    Likes Received:
    1
    Indeed. We wouldn't grant SSH access to users unless it was on a Virtuozzo-type VDS system, but hopefully blackhowling knows and trusts his users enough because it only takes one to try and break in and then you have a compromised system... :rolleyes:

    Still, it is useful on a corporate server, for example, when everyone is from the same organization and it is a bit more secure than giving everyone root access :)
     
  13. blackhowling

    blackhowling Guest

    0
     
    hehehe, ok i understand now :D . Thank you very much for all your answer :D :D .
     
Loading...