IT Information Technology

Error

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

FIX

sudo apt-get install mysql-server
  1. Stop mysql
    sudo /etc/init.d/mysql stop
    

    Or for other distribution versions:

    sudo /etc/init.d/mysqld stop
    
  2. Start MySQL in safe mode
    sudo mysqld_safe --skip-grant-tables &
    
  3. Log into MySQL using root
    mysql -u root
    
  4. Select the MySQL database to use
    use mysql;
    
  5. Reset the password
    Explain
    -- MySQL version < 5.7
    update user set password=PASSWORD("mynewpassword") where User='root';
    
    -- MySQL 5.7, mysql.user table "password" field -> "authentication_string"
    
    update user set authentication_string=password('mynewpassword') where user='root';
    
  6. Flush the privileges
    flush privileges;
    
  7. Restart the server
    quit
    
  8. Stop and start the server again

    Ubuntu and Debian:

    sudo /etc/init.d/mysql stop
    ...
    sudo /etc/init.d/mysql start
    

On CentOS, Fedora, and RHEL:

    sudo /etc/init.d/mysqld stop
    ...
    sudo /etc/init.d/mysqld start
  1. Login with a new password
    mysql -u root -p
    
  2. Type the new password and enjoy your server again like nothing happened

 

Error

su: warning: cannot change directory to /nonexistent: No such file or directory

 

Fix

sudo service mysql stop
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start
en_USEnglish
👁
🚀 تنقل سريع
IT IT