服务器一直都没啥大毛病,可是最近这几天数据库一直异常,网页不能正常显示并报错,同时还伴有CPU占用异常,疯狂给我发来邮件,连上服务器,看了下日志,大概是这样的:

2018-02-06 00:49:26 32762 [Note] Plugin ‘FEDERATED’ is disabled.
2018-02-06 00:49:26 32762 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-02-06 00:49:26 32762 [Note] InnoDB: The InnoDB memory heap is disabled
2018-02-06 00:49:26 32762 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-02-06 00:49:26 32762 [Note] InnoDB: Memory barrier is not used
2018-02-06 00:49:26 32762 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-02-06 00:49:26 32762 [Note] InnoDB: Using Linux native AIO
2018-02-06 00:49:26 32762 [Note] InnoDB: Using CPU crc32 instructions
2018-02-06 00:49:26 32762 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-02-06 00:49:26 32762 [Note] InnoDB: Completed initialization of buffer pool
2018-02-06 00:49:26 32762 [Note] InnoDB: Highest supported file format is Barracuda.
2018-02-06 00:49:26 32762 [Note] InnoDB: The log sequence numbers 8671802 and 8671802 in ibdata files do not match the log sequence number 9616217 in the ib_logfiles!
2018-02-06 00:49:26 32762 [Note] InnoDB: Database was not shutdown normally!
2018-02-06 00:49:26 32762 [Note] InnoDB: Starting crash recovery.
2018-02-06 00:49:26 32762 [Note] InnoDB: Reading tablespace information from the .ibd files…
2018-02-06 00:49:26 32762 [Note] InnoDB: Restoring possible half-written data pages
2018-02-06 00:49:26 32762 [Note] InnoDB: from the doublewrite buffer…
2018-02-06 00:49:32 32762 [Note] InnoDB: 128 rollback segment(s) are active.
180206 00:49:32 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
180206 00:59:26 mysqld_safe Logging to ‘/var/log/mysqld.log’.
180206 00:59:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

好的,阅读之后发现:

[Note] InnoDB: Initializing buffer pool, size = 128.0M

[Note] InnoDB: Completed initialization of buffer pool

原因大概是,内存不够造成的mysql异常,而`mysql.sock`是一个临时文件,在mysql启动时会自动生成,我的服务器未启动,自然就没有mysql.sock文件。同时,看了下mysql服务的状态,并不是running

于是,我想到了以下解决方式

  1. 增加内存
  2. 增加swap
  3. 减少InnoDB buffer pool的内存占用。

最终我采取了第二种方式,下面是操作步骤:

  • 创建一个大小为256M的文件 
    dd if=/dev/zero of=/swapfile bs=1024 count=262144
  • 把这个文件变成swap文件 
    mkswap /swapfile
  • 启用这个swap文件 
    swapon /swapfile
  • 找到并编辑/etc/fstab文件,使在每次开机时自动加载swap文件: 
    /swapfile    swap    swap    default   0 0

然后就好了,弄完之后,现在内存多了一个这个:

‘ Swap: 255M         36K         255M’

当然之前也看到了什么创建软连接

`ln -s /var/lib/mysql/mysql.sock   /tmp/mysql.sock` 

和更改用户组,对我来说并没什么效果….hhhh

现在修好了很开心hua

分类: 小记

发表评论

电子邮件地址不会被公开。 必填项已用*标注