ERROR 2002 (HY000): Can’t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock’的解决办法,看一下/var/log/mysql.log 看到ERROR详细的错误部分是这样的
2019-08-27T15:48:56.150027Z 0 [ERROR] [MY-012681] [InnoDB] mmap(137363456 bytes) failed; errno 12
2019-08-27T15:48:56.150073Z 1 [ERROR] [MY-012956] [InnoDB] Cannot allocate memory for the buffer pool
2019-08-27T15:48:56.154201Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
2019-08-27T15:48:56.164877Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2019-08-27T15:48:56.170728Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
根据个人经验错误原因是swap空间不够了
dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon /swapfile
free
service mysql restart
service mysqld restart
然后重启数据库,并登录
service mysqld restart
mysql -uroot -p
之后我就能正常登录了
如果还是不行,那请多看看/var/log/mysql.log里面是如何报错的,然后把详细报错放百度里找一般都能找到的