1. 程式人生 > >[ 轉載 ] Centos 安裝mysql後啟動失敗 出現 ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

[ 轉載 ] Centos 安裝mysql後啟動失敗 出現 ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

details .sh fail oot The trac mysql csdn mks

MySQL Daemon failed to start

Mysql出問題一定要學會查看log

https://blog.csdn.net/shuai825644975/article/details/79473236

mysql突然掛了,重啟提示:MySQL Daemon failed to start

用mysql -root -p登錄,提示[mysql]ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)

查了下日誌(var/log/mysqld.log)

2018-03-07T08:02:15.926378Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2018-03-07T08:02:15.926392Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2018-03-07T08:02:15.926401Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2018-03-07T08:02:15.926410Z 0 [ERROR] Plugin ‘InnoDB‘ init function returned error.
2018-03-07T08:02:15.926415Z 0 [ERROR] Plugin ‘InnoDB‘ registration as a STORAGE ENGINE failed.
2018-03-07T08:02:15.926421Z 0 [ERROR] Failed to initialize plugins.
2018-03-07T08:02:15.926426Z 0 [ERROR] Aborting

從日誌看,在分配內存的時候出錯了

查看內存,swap是0

技術分享圖片

適當增加swap

1、給swap分配2G物理內存:dd if=/dev/zero of=/var/swap bs=1024 count=2048000

2、將文件變成swap分區:mkswap /var/swap

3、開啟swap:swapon /var/swap

技術分享圖片

設置好後,再啟動mysql,成功

參考:https://www.cnblogs.com/olinux/p/5144205.html

參考:http://www.k2zone.cn/?p=1182

[ 轉載 ] Centos 安裝mysql後啟動失敗 出現 ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’