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

前端 未结 30 1076
离开以前
离开以前 2020-11-22 02:25

I installed LAMP on Ubuntu 12.04 LTS (Precise Pangolin) and then set root password on phpMyAdmin. I forgot the password and now I am unable to login. When I try to chan

30条回答
  •  醉话见心
    2020-11-22 03:17

    In my case, It seems like I wasnt really able to kill the mysql process, when I run

    sudo service mysql stop
    ps -ef | grep mysql
    

    The mysql process was always there, it looks like it was blocking the socket file and new mysql process wasnt able to create it itself.

    so this helped

    cd /var/run
    sudo cp mysqld/ mysqld.bc -rf
    sudo chown mysql:mysql mysqld.bc/
    sudo service mysql stop
    sudo cp mysqld.bc/ mysqld -rf
    sudo chown mysql:mysql mysqld -R
    sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
    

    Now Im able to log in database using

    mysql -u root
    

    Then to update root password:

    UPDATE user SET authentication_string=password('YOURPASSWORDHERE') WHERE user='root';
    FLUSH PRIVILEGES;
    

    PS: I had trouble updating root passwod, seems like problem with "auth_socket" plugin, so I had to create new user with full privileges

    insert into user set `Host` = "localhost", `User` = "super", `plugin` = "mysql_native_password", `authentication_string` = NULL, `password_expired` = "N", `password_lifetime` = NULL, `account_locked` = "N", `Select_priv` = "Y",
    `Insert_priv` = "Y", `Update_priv` = "Y", `Delete_priv` = "Y", `Create_priv` = "Y", `Drop_priv` = "Y", `Reload_priv` = "Y", `Shutdown_priv` = "Y", `Process_priv` = "Y", `File_priv` = "Y",
    `Grant_priv` = "Y",  `References_priv` = "Y", `Index_priv` = "Y", `Alter_priv` = "Y", `Show_db_priv` = "Y", `Super_priv` = "Y", `Create_tmp_table_priv` = "Y", `Lock_tables_priv` = "Y",
    `Execute_priv` = "Y", `Repl_slave_priv` = "Y",  `Repl_client_priv` = "Y",  `Create_view_priv` = "Y", `Show_view_priv` = "Y", `Create_routine_priv` = "Y", `Alter_routine_priv` = "Y",
    `Create_user_priv` = "Y",  `Event_priv` = "Y", `Trigger_priv` = "Y", `Create_tablespace_priv` = "Y";
    

    This creates user "super" with no password and then you can connect with mysql -u super

提交回复
热议问题