Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.
之后查看mysql日志
2018-09-13T02:45:55.234888Z 0 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file
'/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file
or directory)
2018-09-13T02:45:55.234901Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory
[root@izwz9i6slp0lyfpq28b2xoz local]# more /var/log/mysqld.log
上面的指令可以使用less命令。
如果提示报错
2019-07-09T01:23:01.770839Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2019-07-09T01:23:01.770856Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2019-07-09T01:23:01.770866Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-07-09T01:23:01.770880Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-07-09T01:23:01.770887Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-07-09T01:23:01.782124Z 0 [ERROR] Failed to initialize builtin plugins.
2019-07-09T01:23:01.782151Z 0 [ERROR] Aborting
根据一段一段错误信息查找问题时,网上基本上都是修改my.cnf配置文件,如修改innodb_buffer_pool_size的大小之类的,但是都没有作用。后面复制整段错误信息查找,找到了正确的解决方法。free指令查看内存:
可以使用free查看自己的swap内存是否足够
[root@VM_0_7_centos /]# free
total used free shared buff/cache available
Mem: 1016516 722544 70124 108428 223848 37380
Swap: 0 0 0
明显因为swap分区内存空间不够
$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 #增加1G的SWAP进去
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
$ free
total used free shared buffers cached
Mem: 608476 601432 7044 0 824 88752
-/+ buffers/cache: 511856 96620
Swap: 1048572 0 1048572
然后重启mysql,完美解决。