Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Dung Do Tien Apr 01 2021 285

Hello,

I created a project with PHP7 and Apache server. I also install MySQL database in my VPS (Linux Ubuntu 18.0.4)

But when I publish this project into VPS and run mysql -u root -p command I got an error:  Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Please help if you knew any reason.

Have 2 answer(s) found.
  • จักรพงษ์ รักษาศรี Apr 01 2021

    Maybe the MySql service is not active.  To check the status you can use the command below:

    sudo service mysql status

    If your MySql is not active, you can active it by command below:

    sudo service mysql start

    To restart service:

    sudo service mysql restart

    To stop service:

    sudo service mysql stop

    I hope it useful for you.

  • M

    MSIIIXI Apr 01 2021

    I got the same error, you have to reload apparmor setting. You can run commands as below:

    sudo service mysql stop 
    sudo /etc/init.d/apparmor reload
    sudo service mysql start

    Run line by line command, and finally run mysql -u root -p command to access to MySql CLI. If you can access it, your issue is resolved.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close