关于mysql关闭之后,重启失败的原因探究

前提:

linux系统的mysql安装好之后,能够成功启动,但是关闭之后启动报错

在这里插入图片描述

解决思路:

查看报错日志 /var/log/mysqld.log

[root@oracle etc]# cat /var/log/mysqld.log 
2019-04-15T16:09:49.697123Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.15) starting as process 10034
2019-04-15T16:09:49.810549Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
2019-04-15T16:09:49.811278Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-04-15T16:09:49.811386Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-04-15T16:09:49.816195Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.15)  MySQL Community Server - GPL.
2019-04-15T16:10:09.444996Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.15) starting as process 10288
2019-04-15T16:10:09.475011Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
2019-04-15T16:10:09.475288Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-04-15T16:10:09.475426Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-04-15T16:10:09.476849Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.15)  MySQL Community Server - GPL.
2019-04-15T16:10:48.788585Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.15) starting as process 10522
2019-04-15T16:10:48.800683Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
2019-04-15T16:10:48.800819Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-04-15T16:10:48.800913Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-04-15T16:10:48.801883Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.15)  MySQL Community Server - GPL.
2019-04-15T16:11:49.459309Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.15) initializing of server in progress as process 10581
2019-04-15T16:11:54.467934Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dKqjsy*i/0w.
2019-04-15T16:11:58.217859Z 5 [ERROR] [MY-010455] [Server] Failed to open the bootstrap file /var/lib/mysql-files/install-validate-password-plugin.JtGFdP.sql
2019-04-15T16:11:58.217888Z 5 [ERROR] [MY-000061] [Server] 1105  Bootstrap file error, return code (0). Nearest query: 'LSE SET @sys.tmp.table_exists.SQL = CONCAT('SELECT COUNT(*) FROM `', in_db, '`.`', in_table, '`'); PREPARE stmt_select FROM @sys.tmp.table_exists.SQL; IF (NOT v_error) THEN DEALLOCATE PREPARE stmt_select; SET out_exists = 'TEMPORARY'; END IF; END IF; END;
'.
2019-04-15T16:11:58.219236Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/lib/mysql/ is unusable. You can safely remove it.
2019-04-15T16:11:58.219254Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-04-15T16:11:59.780188Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.15)  MySQL Community Server - GPL.
2019-04-15T16:13:08.002248Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.15) starting as process 10854

可能原因:

**

1.位于/etc/my.cnf的MySQL数据库的配置文件权限有问题

配置文件my.cnf权限问题,默认是不存在执行权限的

[root@oracle etc]# ll my.cnf
-rw-r--r--. 1 root root 1245 Jun 12 23:38 my.cnf

改变权限 chmod 777 my.cnf

[root@oracle etc]# ll my.cnf
-rw-r--r--. 1 root root 1245 Jun 12 23:38 my.cnf
[root@oracle etc]# chmod 777 my.cnf

重新启动,成功!

[root@oracle etc]# service mysqld start
my_print_defaults: [Warning] World-writable config file '/etc/my.cnf' is ignored.
my_print_defaults: [Warning] World-writable config file '/etc/my.cnf' is ignored.
my_print_defaults: [Warning] World-writable config file '/etc/my.cnf' is ignored.
my_print_defaults: [Warning] World-writable config file '/etc/my.cnf' is ignored.
my_print_defaults: [Warning] World-writable config file '/etc/my.cnf' is ignored.
my_print_defaults: [Warning] World-writable config file '/etc/my.cnf' is ignored.
Starting mysqld:                                           [  OK  ]

** 可以看到my.cnf的权限改成777之后,虽然能够成功启动,但是有很多警告信息,因为人以用户都能对my.cnf进行操作,权限太大,因此建议改成644,chmod 644 my.cnf,重启发现警告消失。***

2.mysql数据库的my.cnf的内容有问题

之前在搭建mysql主从复制的时候,配置文件里面的server-id=136拼写错误,导致启动失败

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-bin=mysql-bin
server-id=136

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

3.Selinux开启的原因,关闭即可

在这里插入图片描述
由于生产环境一般是不会重启服务器的,所以选择利用setenforce=0来让selinux临时生效变成permissive状态,同时修改配置文件,使得下次服务器重启直接关闭selinux。可以用getenforce来查看状态。

[root@zookeeper2 selinux]# setenforce 1
[root@zookeeper2 selinux]# getenforce  
Enforcing
[root@zookeeper2 selinux]# setenforce 0
[root@zookeeper2 selinux]# getenforce  
Permissive
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值