数据库启动:Starting MySQL. ERROR! The server quit without updating PID file

1、启动报错

[root@temp ~]# service mysql start
Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/temp.pid).
  • 该报错主要是表面的报错,我们要找到问题的根源,今天记录的是我遇到的一种,数据库是安装没有几天的,前几天运行正常,后面就出现问题链接不上,登录数据库会报以下错误:
mysql -proot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
  • 然后:ps -ef | grep mysql 查询mysql是否有启动
[root@temp ~]# ps -ef | grep mysql
root     16236 15991  0 09:49 pts/2    00:00:00 grep mysql
  • 发现没有启动,然后启动:service mysql start(有的不定是这个指令)报上面的错误

2、查找问题

  • 查看mysql的日志 vim /var/log/mysqld.log
2019-09-04T01:54:38.461302Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-09-04T01:54:38.461333Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2019-09-04T01:54:38.461342Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2019-09-04T01:54:38.461354Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-09-04T01:54:38.461358Z 0 [ERROR] Failed to initialize builtin plugins.
2019-09-04T01:54:38.461367Z 0 [ERROR] Aborting
  • 可以看到MySql启动报错: [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12,这个时候我们用free查看内存的使用情况
[root@temp ~]# free
             total       used       free     shared    buffers     cached
Mem:        501856     495784       6072        168       1156     154768
-/+ buffers/cache:     339860     161996
Swap:            0          0          0
  • 上面就可以发现Swap为0,就是这个出现了问题,那么现在我们增加Swap的内存。

3、解决问题

  • 增加Swap的内存:sudo dd if=/dev/zero of=/swapfile bs=1M count=256(可以根据需求设置)
[root@temp ~]# sudo dd if=/dev/zero of=/swapfile bs=1M count=256
256+0 records in
256+0 records out
268435456 bytes (268 MB) copied, 2.38453 s, 113 MB/s
[root@temp ~]# sudo mkswap /swapfile
mkswap: /swapfile: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 262140 KiB
no label, UUID=c7a8c2ef-26c4-40da-b203-9bd7048b09c3
[root@temp ~]# sudo swapon /swapfile
[root@temp ~]# free
             total       used       free     shared    buffers     cached
Mem:        501856     495620       6236        168       1328     154280
-/+ buffers/cache:     340012     161844
Swap:       262140          0     262140
  • 按照上面的操作执行,添加Swapd的内存,启动MySql:
[root@iZbp18jikiib7cnql70judZ ~]# service mysql start
Starting MySQL.... SUCCESS! 

说明:以上为我解决该问题的方法,你也可能遇到的是其他情况,在此我做个记录方便以后处理问题!

你可能感兴趣的:(数据库启动:Starting MySQL. ERROR! The server quit without updating PID file)