1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can't connect to MySQL

Discussion in 'Server Configuration and Hosting' started by Sheratan, Mar 9, 2014.

  1. Sheratan

    Sheratan Well-Known Member

    I can't connect to mysql using
    Code:
    mysql -u root -p
    But I can login into phpmyadmin and my forum are running without problem! o_O

    Code:
    [mysql]
    
    # CLIENT #
    port                           = 3306
    socket                         = /var/lib/mysql/mysql.sock
    
    [mysqld]
    
    # GENERAL #
    user                           = mysql
    default_storage_engine         = InnoDB
    pid_file                       = /var/lib/mysql/mysql.pid
    ....
    
    It's Percona 5.6 in Debian 7.

    Any thought?
     
  2. MattW

    MattW Well-Known Member

    what permissions show for root via phpMyAdmin then?

    upload_2014-3-9_15-55-28.png
     
  3. Sheratan

    Sheratan Well-Known Member

    All Privileges. As usual.
     
  4. MattW

    MattW Well-Known Member

    Does it give an error when trying to log in, or just time out?
     
  5. Sheratan

    Sheratan Well-Known Member

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
     
  6. Tracy Perry

    Tracy Perry Well-Known Member

    First thing.. check your disk space. How much free space do you have.
    Second, try logging in with mysql -u root -p -h 127.0.0.1 and see if it works.
    Third, make sure the /var/lib/mysql/mysql.sock exists and restart the msyql server and try again.
     
    Sheratan likes this.
  7. Sheratan

    Sheratan Well-Known Member

    Free space is good. Lots of it. (15GB+)

    mysql -u root -p -h 127.0.0.1 did the trick! (y) Care to explain?
     
  8. Tracy Perry

    Tracy Perry Well-Known Member

    Indicates problems communicating with the socket itself. Did you check to see if it exists at the location you specified in your my.cnf?
    By using the localhost IP you are bypassing the socket entirely.

    This is what I have defined in mine
    Code:
    [client]
    socket          = /var/run/mysqld/mysqld.sock
    [mysqld_safe]
    socket          = /var/run/mysqld/mysqld.sock
    
    [mysqld]
    pid-file        = /var/run/mysqld/mysqld.pid
    socket          = /var/run/mysqld/mysqld.sock
    Make sure the socket is defined for client, mysqld and mysqld_safe. I'm running the latest Percona on Debian Wheezy on all my servers and I have the above in their my.cnf.
     
    Sheratan likes this.
  9. Sheratan

    Sheratan Well-Known Member

    The socket is there (/var/lib) but somehow the permission is wrong (root:root) not mysqld:mysqld so it cant connect.
     
  10. Tracy Perry

    Tracy Perry Well-Known Member

    Change the permission appropriately to the user that mysql runs under. Should work then.
     

Share This Page