MySQL/Swap

来自康健生活
Kangkk​(留言 | 贡献)2020年2月23日 (日) 08:38的版本 (创建页面,内容为“== error == <blockquote> Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'</blockquote> <syntaxhighlight lang="bash"> systemctl status m…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

error

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

systemctl status mysqld.serrvice

服务器启动不了,本质是交换内存(Swap)不足

Swap

swapon -s

没有返回任何内容,则摘要为空并且不存在交换文件。

df -h
free -m
              total        used        free      shared  buff/cache   available
Mem:         488704      160568       54248       21824      273888      293700
Swap:             0           0           0

创建交换文件

fallocate -l 4G /swapfile
ls -lh /swapfile
-rw-r--r--. 1 root root 4.0G Jan 19 06:41 /swapfile

启用交换文件

chmod 600 /swapfile
ls -lh /swapfile
-rw-------. 1 root root 4.0G Jan 19 06:41 /swapfile
mkswap /swapfile
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=441f052e-c359-40f5-a9c8-18442c4a7361

开始使用

swapon /swapfile

验证程序是否成功

swapon -s
Filename                                Type            Size    Used    Priority
/swapfile                               file            4194300 0       -2
free -m
              total        used        free      shared  buff/cache   available
Mem:            477         168          21          21         286         274
Swap:          4095           0        4095

交换文件永久化

vi /etc/fstab

在文件的底部,您需要添加一行来告诉操作系统自动使用您创建的交换文件

/swapfile   swap    swap    sw  0   0