MySQL启动报错Starting MySQL. ERROR! The server quit without updating PID file

修改innodb_buffer_pool_size 或者加大swap分区空间

查看错误日志err:

  1.  
    2019-01-16 10:22:48 39795 [Note] Plugin 'FEDERATED' is disabled.
  2.  
    2019-01-16 10:22:48 39795 [Note] InnoDB: Using atomics to ref count buffer pool pages
  3.  
    2019-01-16 10:22:48 39795 [Note] InnoDB: The InnoDB memory heap is disabled
  4.  
    2019-01-16 10:22:48 39795 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
  5.  
    2019-01-16 10:22:48 39795 [Note] InnoDB: Memory barrier is not used
  6.  
    2019-01-16 10:22:48 39795 [Note] InnoDB: Compressed tables use zlib 1.2.11
  7.  
    2019-01-16 10:22:48 39795 [Note] InnoDB: Using Linux native AIO
  8.  
    2019-01-16 10:22:48 39795 [Note] InnoDB: Using CPU crc32 instructions
  9.  
    2019-01-16 10:22:48 39795 [Note] InnoDB: Initializing buffer pool, size = 128.0M
  10.  
    InnoDB: mmap(137363456 bytes) failed; errno 12
  11.  
    2019-01-16 10:22:48 39795 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
  12.  
    2019-01-16 10:22:48 39795 [ERROR] Plugin 'InnoDB' init function returned error.
  13.  
    2019-01-16 10:22:48 39795 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
  14.  
    2019-01-16 10:22:48 39795 [ERROR] Unknown/unsupported storage engine: InnoDB
  15.  
    2019-01-16 10:22:48 39795 [ERROR] Aborting

解决方式一:

innodb_buffer_pool_size = 8M (安装MySQL5.6到小于1G内存服务器上,启动MySQL会失败,报内存分配失败的错误,此时,需要修改my.cnf的内存大小从标准128M设置到8M或者64M)

解决方式二:

增加swap缓存,查看free -m或者free -h

  1.  
    ##创建大小为1024M的文件
  2.  
    dd if=/dev/zero of=/swapfile bs=1M count=1024
  3.  
    ##将该文件变为swap
  4.  
    mkswap /swapfile
  5.  
    ##启用swap文件
  6.  
    swapon /swapfile

 执行结果打印:

  1.  
    [root@instance-zq6zwn1b ~]# dd if=/dev/zero of=/swapfile bs=1M count=1024
  2.  
    1024+0 records in
  3.  
    1024+0 records out
  4.  
    1073741824 bytes (1.1 GB) copied, 15.5654 s, 69.0 MB/s
  5.  
    [root@instance-zq6zwn1b ~]# mkswap /swapfile
  6.  
    Setting up swapspace version 1, size = 1048572 KiB
  7.  
    no label, UUID=4bccb9aa-6e83-442c-97eb-a9c8c1ddd1e6
  8.  
    [root@instance-zq6zwn1b ~]# swapon /swapfile
  9.  
    ##挂载时会报一个权限错误,建议将swapfile文件的权限修改为600
  10.  
    swapon: /swapfile: insecure permissions 0644, 0600 suggested.
  11.  
    [root@instance-zq6zwn1b ~]# free
  12.  
    total used free shared buff/cache available
  13.  
    Mem: 995548 245408 72700 19724 677440 564924
  14.  
    Swap: 1048572 0 1048572

此时没有写到/etc/fstab,重启需要手动挂载,写到了/etc.rc.local

写入/etc/fstab,以后不用手动挂载。

  1.  
    vi /etc/fstab
  2.  
    ##末尾添加
  3.  
    /swapfile swap swap defaults 0 0

===============取消swap分区===================

查看swap:cat /proc/swaps

取消激活:swapoff /swapfile

删除配置的信息:进入 vi /etc/fstab 删除配置的信息

删除文件:rm -f /swapfile

查看swap使用情况:swapon -s

显示分区信息:sfdisk -l


swap分区一般为内存的2倍,但最大不超过2G

一般来说可以按照如下规则设置swap大小:

4G以内的物理内存,SWAP 设置为内存的2倍。

4-8G的物理内存,SWAP 等于内存大小。

8-64G 的物理内存,SWAP 设置为8G。

64-256G物理内存,SWAP 设置为16G。

系统在什么情况下才会使用SWAP?

实际上,并不是等所有的物理内存都消耗完毕之后,才去使用swap的空间,什么时候使用是由swappiness 参数值控制。

cat /proc/sys/vm/swappiness

swappiness=0的时候表示最大限度使用物理内存,然后才是 swap空间,

swappiness=100的时候表示积极的使用swap分区,并且把内存上的数据及时的搬运到swap空间里面。

现在一般都尽可能设置小写。

永久修改:

在/etc/sysctl.conf 文件里添加如下参数:

vm.swappiness=10

然后reboot now

posted on 2020-09-27 15:18  小贤爱编程  阅读(225)  评论(0编辑  收藏  举报

导航