[Original] CentOS7 MySQL fails to start

Description of the environment:
CentOS Linux release 7.3.1611 (Core) 64-bit
mysql Ver 14.14 Distrib 5.7.19

Phenomenon:
After installing Wordpress and DB, the default article is deleted in Wordpress, and then suddenly inexplicable prompts that the DB cannot be connected. (I may have done some other DB operations and modifications before, I can't remember a little)

Reason investigation:
The first thing I found is that, for some reason, MySQL was stopped, and the following error was prompted:
# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since 五 2017-10-20 09:13:16 CST; 633ms ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 10382 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 10365 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

10月 20 09:13:16 67-216-220-130 systemd[1]: Failed to start MySQL Server.
10月 20 09:13:16 67-216-220-130 systemd[1]: Unit mysqld.service entered failed state.
10月 20 09:13:16 67-216-220-130 systemd[1]: mysqld.service failed.
10月 20 09:13:16 67-216-220-130 systemd[1]: mysqld.service holdoff time over, scheduling restart.
10月 20 09:13:16 67-216-220-130 systemd[1]: start request repeated too quickly for mysqld.service
10月 20 09:13:16 67-216-220-130 systemd[1]: Failed to start MySQL Server.
10月 20 09:13:16 67-216-220-130 systemd[1]: Unit mysqld.service entered failed state.
10月 20 09:13:16 67-216-220-130 systemd[1]: mysqld.service failed.

Then check the MySQL log:
# tail -n 100 /var/log/mysqld.log
......
2017-10-20T01:09:48.647161Z 0 [Note] InnoDB: Buffer pool(s) load completed at 171020  9:09:48
2017-10-20T01:09:48.647236Z 0 [Note] InnoDB: Starting shutdown...
2017-10-20T01:09:48.747574Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2017-10-20T01:09:48.747891Z 0 [ERROR] InnoDB: Cannot open '/var/lib/mysql/ib_buffer_pool.incomplete' for writing: Permission denied
2017-10-20T01:09:50.258312Z 0 [Note] InnoDB: Shutdown completed; log sequence number 4076122
2017-10-20T01:09:50.258371Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2017-10-20T01:09:50.258378Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
......

The log shows that '/var/lib/mysql/ib_buffer_pool.incomplete' does not have write permission. It seems to be a permissions issue. So execute the following command to view the owner and current permissions:
# ls -ld /var/lib/mysql
drwxr-x--x 6 mysql mysql 4096 10月 20 09:17 /var/lib/mysql

It seems that the owner is ok, so try changing the owner for its subdirectories and files:
# chown mysql:mysql -R /var/lib/mysql

After that, restart the MySQL service:
# systemctl restart mysqld

MySQL can be started normally.

===================================================== =========
If you look at the MySQL Log prompt, the error is as follows:
# tail -n 100 /var/log/mysqld.log
......
2017-10-20T02:58:09.562816Z 0 [Note] InnoDB: Initializing buffer pool, total size = 96M, instances = 1, chunk size = 96M
2017-10-20T02:58:09.562860Z 0 [ERROR] InnoDB: mmap(103071744 bytes) failed; errno 12
2017-10-20T02:58:09.562867Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2017-10-20T02:58:09.562872Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2017-10-20T02:58:09.562878Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2017-10-20T02:58:09.562882Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2017-10-20T02:58:09.562886Z 0 [ERROR] Failed to initialize plugins.
2017-10-20T02:58:09.562889Z 0 [ERROR] Aborting

2017-10-20T02:58:09.562907Z 0 [Note] Binlog end
......

It means that the cache size initialized when MySQL starts is too large (that is to say, it may be caused by your VPS being too small). The default cache size is 128M, but I have changed it to 96M and still get an error, indicating that the setting is still too large (my VPS has only 512M of memory, but there are many services running on it, so the available memory is insufficient).

So go ahead and shrink the cache size:
# vim /etc/my.cnf

Modify the following value innodb_buffer_pool_size = 64M (set to a suitable size)

and restart MySQL after that.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326111229&siteId=291194637