描述
服务器很久没使用,突然有人告诉我说,我服务器进不去,说实话,啥都忘记了。只能各种找回账号密码,辛苦登上了阿里云,先启动Spring服务,再去启动mysql数据,搞了两个小多时,终于完成。记录下,解决问题的过程,希望看文章的,能受到些启发。
步骤
1. 启动mysql
运行命令: service mysqld start
报错:
[root@iZwwejhwng6juuZ etc]# service mysqld start
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
看到这个,别慌。先看日志。
2.查看日志
我的日志在路径:/var/log/mysqld.log
运行命令:vim /var/log/mysqld.log
关键来了,日志显示如下:
2020-03-31 16:10:11 26919 [Warning] Buffered warning: Performance schema disabled (reason: init failed).
2020-03-31 16:10:11 26919 [Note] Plugin 'FEDERATED' is disabled.
2020-03-31 16:10:11 26919 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-03-31 16:10:11 26919 [Note] InnoDB: The InnoDB memory heap is disabled
2020-03-31 16:10:11 26919 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-03-31 16:10:11 26919 [Note] InnoDB: Memory barrier is not used
2020-03-31 16:10:11 26919 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-03-31 16:10:11 26919 [Note] InnoDB: Using Linux native AIO
2020-03-31 16:10:11 26919 [Note] InnoDB: Not using CPU crc32 instructions
2020-03-31 16:10:11 26919 [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(136019968 bytes) failed; errno 12
2020-03-31 16:10:11 26919 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2020-03-31 16:10:11 26919 [ERROR] Plugin 'InnoDB' init function returned error.
2020-03-31 16:10:11 26919 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-03-31 16:10:11 26919 [ERROR] /usr/sbin/mysqld: unknown variable 'nnodb_buffer_pool_size=128M'
2020-03-31 16:10:11 26919 [ERROR] Aborting
标记:InnoDB: Cannot allocate memory for the buffer pool
这个bug,网上说的比较多的是,修改配置,我改了,但是不行(后面附上分享命令找配置的办法)。
再标记:InnoDB: mmap(136019968 bytes) failed; errno 12是关键的错误信息。
分析说是swap分区为0导致的此错误,使用free -m命令查看系统内存,发现swap确实为0。使用如下命令建立一个临时的swap分区:(解决方案来自:https://blog.csdn.net/sxyandapp/article/details/77091007)
[root@iZwwejhwng6juuZ etc]# free -m
total used free shared buffers cached
Mem: 1893 1836 56 0 10 82
-/+ buffers/cache: 1743 149
Swap: 0 0 0
[root@iZwwejhwng6juuZ etc]# dd if=/dev/zero of=/swap bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 4.68474 s, 115 MB/s
[root@iZwwejhwng6juuZ etc]# mkswap /swap
mkswap: /swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=747d2cdb-4fbe-45f4-b2cc-7c65b6f493e0
[root@iZwwejhwng6juuZ etc]# swapon /swap
[root@iZwwejhwng6juuZ etc]# free -m
total used free shared buffers cached
Mem: 1893 1838 54 0 2 92
-/+ buffers/cache: 1743 149
Swap: 511 0 511
总结下命令:
free -m
dd if=/dev/zero of=/swap bs=1M count=512 //创建一个swap文件,大小为512M
mkswap /swap //将swap文件变为swap分区文件
swapon /swap //将其映射为swap分区
free -m
最后再运行启动命令
service mysqld start
很失望,还是失败了。莫慌,打开日志查看
2020-03-31 16:15:37 27261 [Note] Plugin 'FEDERATED' is disabled.
2020-03-31 16:15:37 27261 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-03-31 16:15:37 27261 [Note] InnoDB: The InnoDB memory heap is disabled
2020-03-31 16:15:37 27261 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-03-31 16:15:37 27261 [Note] InnoDB: Memory barrier is not used
2020-03-31 16:15:37 27261 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-03-31 16:15:37 27261 [Note] InnoDB: Using Linux native AIO
2020-03-31 16:15:37 27261 [Note] InnoDB: Not using CPU crc32 instructions
2020-03-31 16:15:37 27261 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-03-31 16:15:37 27261 [Note] InnoDB: Completed initialization of buffer pool
2020-03-31 16:15:38 27261 [Note] InnoDB: Highest supported file format is Barracuda.
2020-03-31 16:15:38 27261 [Note] InnoDB: The log sequence numbers 1625997 and 1625997 in ibdata files do not match the log sequence number 2560229 in the ib_logfiles!
2020-03-31 16:15:38 27261 [Note] InnoDB: Database was not shutdown normally!
2020-03-31 16:15:38 27261 [Note] InnoDB: Starting crash recovery.
2020-03-31 16:15:38 27261 [Note] InnoDB: Reading tablespace information from the .ibd files...
2020-03-31 16:15:39 27261 [Note] InnoDB: Restoring possible half-written data pages
2020-03-31 16:15:39 27261 [Note] InnoDB: from the doublewrite buffer...
2020-03-31 16:15:39 27261 [Note] InnoDB: 128 rollback segment(s) are active.
2020-03-31 16:15:39 27261 [Note] InnoDB: Waiting for purge to start
2020-03-31 16:15:39 27261 [Note] InnoDB: 5.6.43 started; log sequence number 2560229
2020-03-31 16:15:39 27261 [ERROR] /usr/sbin/mysqld: unknown variable 'nnodb_buffer_pool_size=128M'
2020-03-31 16:15:39 27261 [ERROR] Aborting
看日志显示的是 /usr/sbin/mysqld: unknown variable ‘nnodb_buffer_pool_size=128M’
想起之前有网友说改配置文件,没改回来导致的。回到配置文件里修改掉就好。最后启动mysql,搞定。
分享linux下查看mysql的配置文件的方法
which mysql
显示出目录比如我的是下面这个
/usr/bin/mysql
接下来就可以针对这个目录通过一些命令查看配置文件在哪了,如下
/usr/bin/mysql --verbose --help | grep -A 1 ‘Default options’
然后在下面会出现一些信息比如我的
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
这个信息的意思是:
服务器首先读取的是/etc/mysql/my.cnf文件,如果前一个文件不存在则继续读/etc/my.cnf文件,如若还不存在便会去读~/.my.cnf文件
原文链接:https://blog.csdn.net/tribalElders/article/details/53895982