关于 MySQL 每次开机后需要很长时间才能启动的问题
来源:http://www.tudoupe.com时间:2022-02-02
现象,
通过查看 日志,
220201 13:
48:56 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
220201 13:58:54 mysqld_safe Logging to ‘/var/log/mysqld.log’.
可以看到,这里经过了10分钟,MySQL才进行了第二次尝试启动,
在这里卡了10分钟之久,
查看,/etc/my.cnf
[root@bogon ~]#cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
是否支持符号链接,即数据库或表可以存储在my.cnf中指定datadir之外的分区或目录,为0不开启
“STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER”
sql_mode 模式,定义了你MySQL应该支持的sql语法,对数据的校验等等,限制一些所谓的‘不合法’的操作
对于STRICT_TRANS_TABLES,MySQL将非法值转换为最接近该列的合法值并插入调整后的值。
“NO_ENGINE_SUBSTITUTION”,表示不进行引擎替换.
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION
这两货,在网上查了一下,似乎对MySQL启动并没有什么关系,
只是在使用 mysql的时候会有影响
但,神奇的是,我把这两货删除之后,重启服务器,MySQL秒启动,一点也不卡了.
回过头,咱们再来研究日志,
2022-02-01
14:01:485660 [Note] /usr/sbin/mysqld:Normal shutdown2022-02-01
14:01:485660 [Note] Giving 0 client threads a chance to die gracefully
这是我重启服务器的日志描述,normal shutdown 正常关闭MySQL
…
2022-02-01
14:02:040[Warning]TIMESTAMP with implicit DEFAULT
value is deprecated. Please use --explicit_defaults_for_timestamp
server option (see documentation for more details). 2022-02-01
14:02:04 0 [Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process
1789 … 2022-02-0114:02:041789[Warning]Buffered warning:
Changed limits: max_open_files: 1024 (requested 5000)2022-02-01
14:02:041789[Warning]Buffered warning: Changed limits:
table_open_cache: 431 (requested 2000)
到这里,出现了[Warning]但不是ERROR,所以忽略继续往下看
2022-02-01
14:02:041789[ERROR]Can’t start server: Bind on TCP/IP port: Address already in use
2022-02-0114:02:041789[ERROR]Do you
already have another mysqld server running on port: 3306 ? 2022-02-0114:02:041789[ERROR]Aborting
到这里,出了3个ERROR, 但没卡住,还在继续往下走,
2022-02-01 14:02:06 1789 [Note] /usr/sbin/mysqld: Shutdown complete
220201 14:
02:06 mysqld_safe mysqld from pid file
/var/run/mysqld/mysqld.pid ended
220201 14:12:04 mysqld_safe Logging
to ‘/var/log/mysqld.log’.
注意这里,02到12,卡了10分钟,
然后没停顿继续往下走,
220201 14:12:04 mysqld_safe Starting mysqld daemon with databases from
/var/lib/mysql 2022-02-0114:12:050 [Warning] TIMESTAMP with implicit
DEFAULT value is deprecated. Please use
–explicit_defaults_for_timestamp server option (see documentation for more details). 2022-02-01 14:12:05 0 [Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process 5836 … 2022-02-0114:12:055836 [Warning] Buffered warning: Changed limits: max_open_files: 1024
(requested 5000)2022-02-01
14:12:055836 [Warning] Buffered warning: Changed limits:
table_open_cache: 431 (requested 2000)
虽然这里又出了3个 [Warning] ,但没卡继续往下走
2022-02-01
14:12:055836 [Note] /usr/sbin/mysqld:ready for
connections. Version: ‘5.6.51’ socket: ‘/var/lib/mysql/mysql.sock’
port: 3306 MySQL Community Server (GPL)
直接启动成功,
这里拦一下
一个循环结束
接着分析
下面的日志
这里,在下一个循环开始之前,
手工到
/etc/my.cnf里把
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION
这两个东西删了,保存退出,然后,开始下一个循环 ,重启服务器,
2022-02-01 15:
03:00 5836 [Note] /usr/sbin/mysqld:Normal shutdown2022-02-01 15:
03:00 5836 [Note] Giving 0 client threads a chance to die gracefully
一个新的重启,
2022-02-01 15:
03:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server
option (see documentation for more details). 2022-02-01 15:03:17 0
[Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process 1660 …
2022-02-01 15:03:17 1660 [Warning] Buffered warning: Changed limits:
max_open_files: 1024 (requested 5000)2022-02-01 15:
03:17 1660 [Warning] Buffered warning: Changed limits:
table_open_cache: 431 (requested 2000)
又出现了3个 [Warning] ,但没卡,继续往下走,
2022-02-01 15:
03:17 1660 [Note] /usr/sbin/mysqld:ready for
connections. Version: ‘5.6.51’ socket: ‘/var/lib/mysql/mysql.sock’
port: 3306 MySQL Community Server (GPL)
一点也没卡,直接秒起,
第二个循环的 服务器重启时间是:15:03:00,数据库就位的时间是: 15:03:17,时间采用了170毫秒,
和刚才的 10分钟比起来,天差地别.
这就是 /etc/my.cnf 文件影响的MySQL 启动
February the 01st 2022 tuesday
补充,
重启服务器没问题,但是关闭服务器等半小时再开机,
就又出现了之前的问题,卡在
mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
这里,然后过了10分钟才又开始执行下面的语句
mysqld_safe Logging to '/var/log/mysqld.log'.
卡在它俩中间了,
于是,继续研究,
去看 交给 chkconfig 管理的 mysqld 的内容,
[root@bogon ~]#cd /etc/rc.d/init.d
[root@bogon init.d]#ll
总用量 44
-rw-r–r--. 1 root root 17500 5月 3 2017 functions
-rwxr-xr-x. 1 root root 1141 2月 1 13:58mysqld
-rwxr-xr-x. 1 root root 4334 5月 3 2017 netconsole
-rwxr-xr-x. 1 root root 7293 5月 3 2017 network
-rw-r–r--. 1 root root 1160 8月 5 2017 README
[root@bogon init.d]#cat mysqld
# chkconfig: 2345
320
# description:February the 01st tuesday 2022[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target
我设置的 mysqld 的启动顺位是3,
但, [Unit] 写明了,要在 network 之后启动,
所以还要去看一下 network 的启动顺位是多少,
[root@bogon init.d]#cat network
# chkconfig: 2345
1090
# description: Activates/Deactivates all network interfaces configured
可以看到,network 的启动顺位是 10,
所以,需要将 mysqld 的启动顺位调整到 network 之后,
[root@bogon init.d]#vi mysqld
# chkconfig: 2345
1191
# description:February the 01st tuesday 2022
调整完毕,保存退出,
再关机等待一段时间后,开启服务器,看结果,
还是不行,
去查看
MySQL 当前状态
[root@bogon ~]#systemctl status mysqld
● mysqld.service - MySQL Community Server
Loaded:loaded(/usr/lib/systemd/system/mysqld.service; enabled; vendor preset:
disabled)
可以看出,MySQL 启动的时候,是要去load/usr/lib/systemd/system/mysqld.service它的,
去看看它里面都有啥,
[root@bogon ~]#cd /usr/lib/systemd/system/
[root@bogon system]#ll |grep mysql
-rwxr-xr–. 1 root root 1073 1月 5 2021
mysqld.service
打开看看
[root@bogon system]#cat mysqld.service
TimeoutSec=600
有一行这个,600秒不就是10分钟嘛,不正好是卡住的时间长度么(mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended),
既然我不知道问题出在哪里,
要不我就给这个时间减少点,这样会不会能快点启动呢?
着手实验,
[root@bogon system]#vi mysqld.service
TimeoutSec=
6
改成 6 秒,保存退出,关机 等待一段时间,再开机,看看效果.
可以了,
不用等10分钟以上了.
但不知道,问题是不是彻底解决了,
需要在以后的使用中验证,
February the 01st 2022 tuesday
下一篇:Golang——深浅拷贝
相关新闻
- 2023-04-16 2台电脑怎么共享(2台电脑怎么共享
- 2023-04-16 主板检测卡代码(电脑主板检测卡代
- 2023-04-16 dnf未响应(dnf未响应老是上不去)
- 2023-04-16 ppoe(pppoe拨号上网)
- 2023-04-16 网速不稳定(网速不稳定是路由器的
- 2023-04-16 wds状态(Wds状态成功)
- 2023-04-16 光标键(光标键不动了怎么办)
- 2023-04-16 电脑提速(电脑提速100倍的方法)
- 2023-04-16 切换用户(切换用户怎么切换回来
- 2023-04-16 数据包是什么(产品数据包是什么
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
