虚拟机关机后第二天mysql起不来,回想一下我关机前和关机后的操作发现:关机前没关闭mysqld服务就直接init 0了,关机后将虚拟机内存由1G降到724M。笔者保证再也做过别的骚操作了。

-- ::  [Note] Plugin 'FEDERATED' is disabled.
-- :: [Note] InnoDB: Using atomics to ref count buffer pool pages
-- :: [Note] InnoDB: The InnoDB memory heap is disabled
-- :: [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
-- :: [Note] InnoDB: Memory barrier is not used
-- :: [Note] InnoDB: Compressed tables use zlib 1.2.
-- :: [Note] InnoDB: Using CPU crc32 instructions
-- :: [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap( bytes) failed; errno
-- :: [ERROR] InnoDB: Cannot allocate memory for the buffer pool
-- :: [ERROR] Plugin 'InnoDB' init function returned error.
-- :: [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
-- :: [ERROR] Unknown/unsupported storage engine: InnoDB
-- :: [ERROR] Aborting -- :: [Note] Binlog end
-- :: [Note] Shutting down plugin 'partition'
-- :: [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
-- :: [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
-- :: [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
-- :: [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
-- :: [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
-- :: [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
-- :: [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
-- :: [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
-- :: [Note] Shutting down plugin 'INNODB_SYS_TABLES'
-- :: [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
-- :: [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
-- :: [Note] Shutting down plugin 'INNODB_FT_CONFIG'
-- :: [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
-- :: [Note] Shutting down plugin 'INNODB_FT_DELETED'
-- :: [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
-- :: [Note] Shutting down plugin 'INNODB_METRICS'
-- :: [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
-- :: [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
-- :: [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
-- :: [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
-- :: [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
-- :: [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
-- :: [Note] Shutting down plugin 'INNODB_CMPMEM'
-- :: [Note] Shutting down plugin 'INNODB_CMP_RESET'
-- :: [Note] Shutting down plugin 'INNODB_CMP'
-- :: [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
-- :: [Note] Shutting down plugin 'INNODB_LOCKS'
-- :: [Note] Shutting down plugin 'INNODB_TRX'
-- :: [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
-- :: [Note] Shutting down plugin 'ARCHIVE'
-- :: [Note] Shutting down plugin 'BLACKHOLE'
-- :: [Note] Shutting down plugin 'MyISAM'
-- :: [Note] Shutting down plugin 'MRG_MYISAM'
-- :: [Note] Shutting down plugin 'CSV'
-- :: [Note] Shutting down plugin 'MEMORY'
-- :: [Note] Shutting down plugin 'sha256_password'
-- :: [Note] Shutting down plugin 'mysql_old_password'
-- :: [Note] Shutting down plugin 'mysql_native_password'
-- :: [Note] Shutting down plugin 'binlog'
-- :: [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

日志

2017-09-05 09:19:21 1940 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2017-09-05 09:19:21 1940 [ERROR] Plugin 'InnoDB' init function returned error.
2017-09-05 09:19:21 1940 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2017-09-05 09:19:21 1940 [ERROR] Unknown/unsupported storage engine: InnoDB
2017-09-05 09:19:21 1940 [ERROR] Aborting

貌似是innodb引擎错误,还有就是分配内存失败,内存分配失败会导致innodb错误吗,还是断电导致的?不得而知!!!

mysql 启动到底需要多少内存?

官网是这什么回答的:

How MySQL Uses Memory?

MySQL allocates buffers and caches to improve performance of database operations. The default configuration is designed to permit a MySQL server to start on a virtual machine that has approximately512MB of RAM. You can improve MySQL performance by increasing the values of certain cache and buffer-related system variables. You can also modify the default configuration to run MySQL on systems with limited memory.

于是,那么有什么办法可以小内存启动 mysql 吗?

vim /etc/my.cnf

performance_schema_max_table_instances=
table_definition_cache=
table_open_cache=

增大虚拟机内存或调整mysql参数

百度答案花样百出,最后试着在/etc/my.cnf中加入下列一行再重启

tmp_table_size=500M

***************************************

PS:下列谷歌出来的方法笔者没试过,可以一试:

主要是innodb日志大小不对造成的
innodb_buffer_pool_size=512M
innodb_log_file_size=128M
把以上几个参数调大点,然后把ibdata1,ib_logfile0,ib_logfile1这三个文件删除后,再重启服务就好了。
如果还是不行,在my.ini文件里还需要加入tmpdir="usr/tmp"这样的路径,因为innodb还需要一个临时的文件缓存区。

没试过的方法

****************************************

事实证明没用,该句只是用来设置内部(内存中)临时表的最大大小

重启后仍然报错,网上解决方法一般是:

问题描述:

非正常关闭mysql,同时更改了my.cnf 导致启动时不支持innodb,出现如下错误:

[ERROR] Plugin ‘InnoDB’ init function returned error.

[ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.

[ERROR] Unknown/unsupported table type: InnoDB

[ERROR] Aborting

解决办法:

删除log文件和data的初始化文件  

重新运行mysql_install_db
再启动

网上某解决方案

笔者并没有删除文件,只是将/data/dbdata下的三个文件移动到/tmp下备份了,万一以后用得着呢?

三个文件:ibdata1、ib_logfile0、ib_logfile1

再用mysql-install-db初始化

但是这一系列操作后mysqld仍然启动不了,直接关机,将虚拟机内存调回1G,没想到居然好了,可以成功启动mysqld服务啦!

##########

但是这还不够,进入数据库后出现了奇怪的一幕:数据库和表都在,却打不开,什么鬼

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| binlog |
| log |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
rows in set (0.00 sec) mysql> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| groups |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| httpstep |
| httpstepitem |
| httptest |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| items |
| items_applications |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_url |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| task |
| task_close_problem |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
+----------------------------+
rows in set (0.00 sec) mysql> desc valuemaps;
ERROR (42S02): Table 'zabbix.valuemaps' doesn't exist
mysql> desc usrgrp;
ERROR (42S02): Table 'zabbix.usrgrp' doesn't exist
mysql> select * from users;
ERROR (42S02): Table 'zabbix.users' doesn't exist
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
row in set (0.00 sec) mysql>

数据库操作

日志文件中大量报错:

-- ::  [Warning] InnoDB: Cannot open table zabbix/dbversion from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table zabbix/dbversion from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table zabbix/dbversion from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table mysql/innodb_index_stats from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table mysql/innodb_table_stats from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table mysql/slave_master_info from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table mysql/slave_relay_log_info from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table mysql/slave_worker_info from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table zabbix/dbversion from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
-- :: [Warning] InnoDB: Cannot open table zabbix/dbversion from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.

cannot open file

各种表都不能访问,包括下列五个表:

innodb_table_stats
innodb_index_stats
slave_master_info
slave_relay_log_info
slave_worker_info 

之前备份过旧的ibdata1文件
虽然重新初始化之后,数据库会自动创建一个ibdata1文件,但是上述系统表也是innodb引擎,所以不能访问了.

关闭mysql服务后,尝试着将之前备份的ibdata1恢复。结果很神奇的解决了这个问题!数据库能成功读写了,但查看日志文件后发现还是有问题:

虽然这个问题暂时不影响对数据库的操作,但日志文件中如此多的警告强迫症怎么受得了

谷歌后发现两个不错的博文:http://blog.cuicc.com/blog/2015/10/12/mysql-can-not-startup-after-loss-power/

https://boknowsit.wordpress.com/2012/12/22/mysql-log-is-in-the-future/

依葫芦画瓢,但数据导入出错。。。无奈只能重新初始化再倒入数据,导入数据后需要重新刷新用户权限mysql.user表中设置的密码才会生效。

=============

理解以上错误需要重点理解innodb的表空间文件ibdata1和两个重做日志文件ib_logfile0 && ib_logfile1

https://m.aliyun.com/yunqi/articles/174339?spm=5176.mtagdetail.0.0.iTtVMO

  

记一次mysql事故---纪念逝去的一上午的更多相关文章

  1. 记一次 mysql 启动没反应

    记一次 mysql 启动没反应 ,重启linux又可以启动 vim /var/log/mysqld.log 2018-02-04 13:22:49 28507 [ERROR] InnoDB: Cann ...

  2. 记一次MySQL表分区操作

    最近一次日常迭代中,业务线需要对一张大表进行联合查询,查询性能可想而知,测试过程中服务接口直接响应超时,导致服务不可用,最后临时对该表进行分区操作,暂时缓解性能问题.由于是第一次操作表分区,姑且记录一 ...

  3. 记一次mysql数据库被勒索(中)

    背景在上一篇文章里面已经提过了. 现在面临的问题是nextcloud没有mysql数据库,用不起来了. 因为文件没丢,一种方法是启动新的mysql数据库,把文件重新提交一次. 为了程序员的面子,没有选 ...

  4. 记一次mysql数据库被勒索(下)

    背景: nextcloud的mysql数据库被黑,删库勒索.参考:记一次mysql数据库被勒索(上) mysql数据库恢复成功,nextcloud还是无法连接.参考:记一次mysql数据库被勒索(中) ...

  5. 记一次mysql事务未提交导致锁未释放的问题

    记一次mysql事务未提交导致锁未释放的问题 ## 查看未提交的事务(3秒内未操作的事务) SELECT p.ID AS conn_id, P.USER AS login_user, P.HOST A ...

  6. 【踩坑记录】记一次MySQL主从复制延迟的坑

    最近开发中遇到的一个MySQL主从延迟的坑,记录并总结,避免再次犯同样的错误. 情景 一个活动信息需要审批,审批之后才能生效.因为之后活动要编辑,编辑后也可能触发审批,审批中展示的是编辑前的活动内容, ...

  7. 记一次生产事故的排查与优化——Java服务假死

    一.现象 在服务器上通过curl命令调用一个Java服务的查询接口,半天没有任何响应.关于该服务的基本功能如下: 1.该服务是一个后台刷新指示器的服务,即该服务会将用户需要的指示器数据提前计算好,放入 ...

  8. 从史上八大MySQL事故中学到的经验

    本文列举了史上八大MySQL宕机事件原因.影响以及人们从中学到的经验,文中用地震级数来类比宕机事件的严重性和后果,排在最严重层级前两位的是由于亚马逊AWS宕机故障(相当于地震十级和九级). 一.Per ...

  9. 【夯实Mysql基础】记一次mysql语句的优化过程

    1. [事件起因] 今天在做项目的时候,发现提供给客户端的接口时间很慢,达到了2秒多,我第一时间,抓了接口,看了运行的sql,发现就是 2个sql慢,分别占了1秒多. 一个sql是 链接了5个表同时使 ...

随机推荐

  1. MySQL遇到Deadlock found when trying to get lock,解决方案

    最近遇到一个MYSQL update语句出现Deadlock found when trying to get lock的问题,分析一下原因. 什么情况下会出现Deadlock found when ...

  2. [转]MPP架构

    数据库构架设计中主要有Shared Everthting.Shared Nothing.和Shared Disk: Shared Everthting:一般是针对单个主机,完全透明共享CPU/MEMO ...

  3. Machine Learning第十一周笔记:photo OCR

    博客已经迁移至Marcovaldo's blog (http://marcovaldong.github.io/) 刚刚完毕了Cousera上Machine Learning的最后一周课程.这周介绍了 ...

  4. QT信号/槽

    在我的理解中,QT和Android都是类似的开发框架,都是由开发团队封装了各式各样的接口和数据结构.将一些问题的解决方法简单化比如QT中将线程封装为QThread,派生类通过重写run方法来将代码投入 ...

  5. plsql 通过修改配置文件的方式实现数据库的连接

    查看oracle的安装位置: XP系统: 开始>>所有程序>>>Oracle-OraDb10g_home1>>>配置和移植工具>>>右 ...

  6. permutohedral lattice理解

    [完结]saliency filters精读之permutohedral lattice 2012年09月28日 22:40:08 工长山 阅读数:12432    版权声明:本文为博主原创文章,未经 ...

  7. Swagger UI 传入对象类型参数

    Swagger要传送对象作为参数,只需添加@ModelAttribute或@RequestBody @RestController @RequestMapping("/api/json/re ...

  8. mysql like 查不到结果 中文 查询优化

    [参考]mysql like %keyword%不走索引替代方法 在使用msyql进行模糊查询的时候,很自然的会用到like语句,通常情况下,在数据量小的时候,不容易看出查询的效率,但在数据量达到百万 ...

  9. jquery中Get方法请求接口

    $.ajax( { url: apiUrl + '/api/Code/GetCodeProductInfo', type: 'GET', //Header头部添加Token参数 beforeSend: ...

  10. SQL in、not in、exists和not exists的区别:

    来自:http://blog.sina.com.cn/s/blog_8a0c4f130100zaw2.html 先谈谈in和exists的区别: exists:存在,后面一般都是子查询,当子查询返回行 ...