解决网站设计中MySQL经常停止导致网站打不开
发表日期:2019-09-30 07:00:03   文章编辑:admin    浏览次数:374
 

解决MySQL经常停止运行的问题

 

记一次解决MySQL经常停止运行的问题

问题背景

在多个月之前,也就是服务器刚刚搭建的时候,标题中的MySQL问题就出现了,很是奇怪,博客过一段时间就毫无征兆的挂掉了,提示连接数据库失败,然后重新启动一下MySQL服务就又可以正常运行了。但是这个问题总是像莫名其妙的发生,时不时的给我来一点小惊喜,小意外,我每次重启MySQL服务之后就又可以正常运行了,所以就没去怎么解决这个问题。但是最近真的是忍无可忍了,决定解决了它。

先说一下我的服务器情况:

服务器:CentOS Linux 7.2.1511 (Core)

MySQL版本:5.6.37

找到MySQL错误日志文件位置

解决问题当然是要看问题出在哪里,好在MySQL有自己的错误日志可以供我们分析。那么错误日志在那里呢? 我们可以用下面的方法找到这个文件的位置:

因为装了宝塔面板,所以直接在宝塔面板中mysql软件单击出来,左边菜单有个慢日志。就可以看到里面的详情介绍。

查看并分析MySQL错误日志

错误日志已经找到了,我们打开看一下,通过我的分析,我的这个MySQL运行出错有多处,但是直接导致MySQL宕机的只有一处。日志内容如下:

2019-07-13 10:33:25 24659 [Note] Plugin 'FEDERATED' is disabled.
2019-07-13 10:33:25 24659 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-07-13 10:33:25 24659 [Note] InnoDB: The InnoDB memory heap is disabled
2019-07-13 10:33:25 24659 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-13 10:33:25 24659 [Note] InnoDB: Memory barrier is not used
2019-07-13 10:33:25 24659 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-07-13 10:33:25 24659 [Note] InnoDB: Using Linux native AIO
2019-07-13 10:33:25 24659 [Note] InnoDB: Using CPU crc32 instructions
2019-07-13 10:33:25 24659 [Note] InnoDB: Initializing buffer pool, size = 16.0M
2019-07-13 10:33:25 24659 [Note] InnoDB: Completed initialization of buffer pool
2019-07-13 10:33:25 24659 [Note] InnoDB: Highest supported file format is Barracuda.
2019-07-13 10:33:25 24659 [Note] InnoDB: The log sequence numbers 265520552 and 265520552 in ibdata files do not match the log sequence number 340993584 in the ib_logfiles!
2019-07-13 10:33:25 24659 [Note] InnoDB: Database was not shutdown normally!
2019-07-13 10:33:25 24659 [Note] InnoDB: Starting crash recovery.
2019-07-13 10:33:25 24659 [Note] InnoDB: Reading tablespace information from the .ibd files...
2019-07-13 10:33:25 24659 [Note] InnoDB: Restoring possible half-written data pages 
2019-07-13 10:33:25 24659 [Note] InnoDB: from the doublewrite buffer...
InnoDB: Last MySQL binlog file position 0 7521, file name mysql-bin.000096
2019-07-13 10:33:25 24659 [Note] InnoDB: 128 rollback segment(s) are active.
2019-07-13 10:33:25 24659 [Note] InnoDB: Waiting for purge to start
2019-07-13 10:33:26 24659 [Note] InnoDB: 5.6.37 started; log sequence number 340993584
2019-07-13 10:33:26 24659 [Note] Server hostname (bind-address): '*'; port: 3306
2019-07-13 10:33:26 24659 [Note] IPv6 is available.
2019-07-13 10:33:26 24659 [Note]   - '::' resolves to '::';
2019-07-13 10:33:26 24659 [Note] Server socket created on IP: '::'.
2019-07-13 10:33:26 24659 [Note] Event Scheduler: Loaded 0 events

上面的错误日志是MySQL运行停止的最近一次错误提示。

分析得知,The InnoDB memory heap is disabled这个错误导致,这句话的大概意思就是InnoDB内存堆是禁用的。

通过查阅资料发现,MySQL默认的配置使用了操作系统的内存分配器,禁用了InnoDB的内置内存分配器所至。默认的innodb_use_sys_malloc配置是决定内存的分配器,当配置为1时是使用操作系统内存的分配器,当配置为1时使用InnoDB的默认分配器。所以我们只要将这个配置修改为0即可。

解决方案

找到MySQL的配置文件修改innodb_use_sys_malloc配置项为0.

一般的MySQL配置文件位置在/etc/my.cnf

查看配置文件中的配置后发现了一个尴尬的问题,竟然没有找到这个innodb_use_sys_malloc配置项。原来MySQL在版本升级的时候曾经取消了这个配置。但是人工添加上也是可以生效的。

我们直接在[mysqld]下面直接添加innodb_use_sys_malloc=0即可。

然后重启MySQL服务,再次查看日志。

Next activation : never
2019-07-13 14:46:49 5649 [Note] /www/server/mysql/bin/mysqld: Normal shutdown
2019-07-13 14:46:49 5649 [Note] Giving 0 client threads a chance to die gracefully
2019-07-13 14:46:49 5649 [Note] Event Scheduler: Purging the queue. 0 events
2019-07-13 14:46:49 5649 [Note] Shutting down slave threads
2019-07-13 14:46:49 5649 [Note] Forcefully disconnecting 0 remaining clients
2019-07-13 14:46:49 5649 [Note] Binlog end
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'partition'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_METRICS'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_CMPMEM'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_CMP'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_LOCKS'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'INNODB_TRX'
2019-07-13 14:46:49 5649 [Note] Shutting down plugin 'InnoDB'
2019-07-13 14:46:49 5649 [Note] InnoDB: FTS optimize thread exiting.
2019-07-13 14:46:49 5649 [Note] InnoDB: Starting shutdown...
2019-07-13 14:46:50 5649 [Note] InnoDB: Shutdown completed; log sequence number 341778147
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'BLACKHOLE'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'ARCHIVE'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'MRG_MYISAM'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'MyISAM'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'MEMORY'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'CSV'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'sha256_password'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'mysql_old_password'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'mysql_native_password'
2019-07-13 14:46:50 5649 [Note] Shutting down plugin 'binlog'
2019-07-13 14:46:50 5649 [Note] /www/server/mysql/bin/mysqld: Shutdown complete
 
2019-07-13 14:46:51 9424 [Note] Plugin 'FEDERATED' is disabled.
2019-07-13 14:46:51 2ae7df6e3f00 InnoDB: Warning: Setting innodb_use_sys_malloc to FALSE is DEPRECATED. This option may be removed in future releases, together with the InnoDB's internal memory allocator.
2019-07-13 14:46:51 9424 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-07-13 14:46:51 9424 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-13 14:46:51 9424 [Note] InnoDB: Memory barrier is not used
2019-07-13 14:46:51 9424 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-07-13 14:46:51 9424 [Note] InnoDB: Using Linux native AIO
2019-07-13 14:46:51 9424 [Note] InnoDB: Using CPU crc32 instructions
2019-07-13 14:46:51 9424 [Note] InnoDB: Initializing buffer pool, size = 16.0M
2019-07-13 14:46:51 9424 [Note] InnoDB: Completed initialization of buffer pool
2019-07-13 14:46:51 9424 [Note] InnoDB: Highest supported file format is Barracuda.
2019-07-13 14:46:51 9424 [Note] InnoDB: 128 rollback segment(s) are active.
2019-07-13 14:46:51 9424 [Note] InnoDB: Waiting for purge to start
2019-07-13 14:46:52 9424 [Note] InnoDB: 5.6.37 started; log sequence number 341778147
2019-07-13 14:46:52 9424 [Note] Server hostname (bind-address): '*'; port: 3306
2019-07-13 14:46:52 9424 [Note] IPv6 is available.
2019-07-13 14:46:52 9424 [Note]   - '::' resolves to '::';
2019-07-13 14:46:52 9424 [Note] Server socket created on IP: '::'.
2019-07-13 14:46:52 9424 [Note] Event Scheduler: Loaded 0 events
2019-07-13 14:46:52 9424 [Note] /www/server/mysql/bin/mysqld: ready for connections.
Version: '5.6.37-log'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution

如没特殊注明,文章均为宜兴博路网络原创,转载请注明来自https://www.boroad.net/news/changjianwenti/2019/0713/194.html
相关文章推荐
欢迎访问豪峰建设集团官网:www.hfgroup.net.cn,由宜兴网络公司博路网络定制设计完成。 ...
用过PS软件设计的朋友们都知道,如果新建的图层不多的时候,或者没有文件夹图标的时候可以用ctrl+鼠标左键可以快速选中自动想要的图标,非常方便,但是如果你网站在设计版面的时候,网站··· ...
宜兴网站定制,宜兴网站设计,宜兴网站案例 谈青窑艺官网 谈青窑艺简介: 谈青窑艺是由江苏非物质文化遗产宜兴青瓷制作技艺省级代表性传承人谈志坚大师继承传统,以陶都特有的紫砂五色土入 ...
1、下载之后,解压,使用编辑器打开,修改第9行代码,将代码中 src 后的链接修改为自己要验证的js地址链接。<scripttype="text/javascrip··· ...
欢迎访问豪峰建设集团官网:www.hfgroup.net.cn,由宜兴网络公司博路网络定制设计完成。 豪峰建设集团有限公司(以下简称“公司”)成立于2010年,注册资本金5.06亿··· ...
博路网络中秋同欢喜,网站优惠送不停 活动时间:2021年9月18日--2021年10月31日 花好月圆人团圆,盛隆送礼,礼不停。 博路网络,借此中秋,与合作伙伴共度佳节! 此次活动··· ...