EJDF 2022-06-27 13:29 采纳率: 66.7%
浏览 113
已结题

centos8安装mysql.7 无法开机启动

问题遇到的现象和发生背景

centos8中安装mysql后,使用命令service mysqld start可以启动数据库,但是通过配置开机启动如下:
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
系统重启无法启动数据库

操作环境、软件版本等信息

操作系统为centos8,数据库为mysql-5.7.38-linux-glibc2.12-x86_64

尝试过的解决方法

关闭selinux之后,mysql可以启动,问题解决。
重新打开selinux;重启系统,数据库依然可以启动。
很懵--到底啥子问题啊,求各位给看下啊

我想要达到的结果

关闭selinux是我从网上找了很多之后实在没有办法下的尝试,我想要能够看到mysql无法启动的具体原因,学习下如何能够快速定位问题。
各位朋友,能帮我看下吗,还有能给推荐点比较好的一些运维知识吗,关于centos和mysql的

附上截图:
运行service mysqld start后,系统正常运行:

img

reboot系统重启后,mysql数据库无法开机启动,但是通过启动命令可以启动:

[root@localhost bin]# reboot
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(10.3.27.1) at 11:42:46.

Type `help' to learn how to use Xshell prompt.
[D:\~]$ reconnect


Connecting to 10.3.27.1:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Mon Jun 27 11:33:13 2022 from 10.3.27.21
[root@localhost ~]# ps -ef|grep mysql
root        1617    1580  0 11:43 pts/0    00:00:00 grep --color=auto mysql
[root@localhost ~]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
   Active: active (exited) since Mon 2022-06-27 11:43:28 CST; 22s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1245 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)

Jun 27 11:43:28 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
Jun 27 11:43:28 localhost.localdomain mysqld[1245]: /etc/rc.d/init.d/mysqld: line 239: /usr/local/mysql/bin/my_print_defaults: Permi>
Jun 27 11:43:28 localhost.localdomain mysqld[1245]: Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_sa>
Jun 27 11:43:28 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.


将selinux关闭后,mysql数据库可开机启动:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
#将SELINUX关闭保存后重启
[root@localhost ~]# reboot
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(10.3.27.1) at 11:47:35.

Type `help' to learn how to use Xshell prompt.
[D:\~]$ reconnect


Connecting to 10.3.27.1:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Mon Jun 27 11:43:36 2022 from 10.3.27.21
[root@localhost ~]# ps -ef|grep mysql
root        1272       1  0 11:48 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/3306/data --pid-file=/data/mysql/3306/log/mysql.pid
mysql       2142    1272  2 11:48 ?        00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/3306/log/error.log --pid-file=/data/mysql/3306/log/mysql.pid --socket=/data/mysql/3306/tmp/mysql.sock --port=3306
root        2313    2277  0 11:48 pts/0    00:00:00 grep --color=auto mysql
[root@localhost ~]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
   Active: active (running) since Mon 2022-06-27 11:48:18 CST; 23s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1238 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
    Tasks: 28 (limit: 23364)
   Memory: 201.6M
   CGroup: /system.slice/mysqld.service
           ├─1272 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/3306/data --pid-file=/data/mysql/3306/log/mysql.pid
           └─2142 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --plugin-dir=/usr/local/mys>

Jun 27 11:48:15 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
Jun 27 11:48:18 localhost.localdomain mysqld[1238]: Starting MySQL... SUCCESS!
Jun 27 11:48:18 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.

将selinux开启后,mysql数据库依然可以开机启动:

[root@localhost ~]# reboot
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(10.3.27.1) at 11:51:03.

Type `help' to learn how to use Xshell prompt.
[D:\~]$ reconnect


Connecting to 10.3.27.1:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Mon Jun 27 11:48:29 2022 from 10.3.27.21
[root@localhost ~]# ps -ef|grep mysqld
root        1255       1  0 11:54 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/3306/data --pid-file=/data/mysql/3306/log/mysql.pid
mysql       2141    1255  0 11:54 ?        00:00:06 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/3306/log/error.log --pid-file=/data/mysql/3306/log/mysql.pid --socket=/data/mysql/3306/tmp/mysql.sock --port=3306
root        2425    2388  0 13:22 pts/0    00:00:00 grep --color=auto mysqld

附上mysql配置文件:

[client]
port = 3306
socket = /data/mysql/3306/tmp/mysql.sock
 
[mysqld]
server-id = 1
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql/3306/data
tmpdir  = /data/mysql/3306/tmp
socket = /data/mysql/3306/tmp/mysql.sock
pid-file = /data/mysql/3306/log/mysql.pid
skip_name_resolve = 1
character-set-server = utf8mb4
transaction_isolation = READ-COMMITTED
collation-server = utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
lower_case_table_names = 1
max_connections = 400
max_connect_errors = 1000
explicit_defaults_for_timestamp = true
max_allowed_packet = 128M
interactive_timeout = 1800
wait_timeout = 1800
tmp_table_size = 16M
max_heap_table_size = 128M
query_cache_size = 0
query_cache_type = 0

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
binlog_cache_size = 1M 
back_log = 130
log_error = /data/mysql/3306/log/error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/3306/log/slow.log
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 5
min_examined_row_limit = 100
expire_logs_days = 5
 
log-bin = mysql-bin
binlog_format = ROW
binlog_row_image = minimal
 
# Innodb设置
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_log_buffer_size = 2M
innodb_flush_method = O_DIRECT
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_lock_wait_timeout = 120
innodb_log_file_size = 32M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

附上mysql安装过程:

[root@localhost ~]# mkdir /data
[root@localhost ~]# cd /data/
[root@localhost data]# mkdir software
[root@localhost data]# groupadd mysql
[root@localhost data]# useradd -g mysql mysql -d /data/mysql
[root@localhost data]# passwd mysql
Changing password for user mysql.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost data]# mkdir /data/mysql/3306/
[root@localhost data]# mkdir /data/mysql/3306/data
[root@localhost data]# mkdir /data/mysql/3306/log
[root@localhost data]# mkdir /data/mysql/3306/tmp
[root@localhost data]# cd /data/software/
[root@localhost software]# tar -zxf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz 
[root@localhost software]# mv mysql-5.7.38-linux-glibc2.12-x86_64 /usr/local/
[root@localhost software]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.38-linux-glibc2.12-x86_64 mysql
[root@localhost local]# chown -R mysql:mysql mysql/
[root@localhost local]# cd /etc/
[root@localhost etc]# chown -R mysql:mysql /data/mysql
[root@localhost etc]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysqld --initialize --user=mysql
[root@localhost bin]# vi /data/mysql/3306/log/error.log
[root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost bin]# chmod +x /etc/rc.d/init.d/mysqld
[root@localhost bin]# chkconfig --add mysqld
[root@localhost bin]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@localhost bin]# service mysqld start
Starting MySQL.. SUCCESS! 
[root@localhost bin]# ps -ef|grep mysql
root        5563       1  2 11:41 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/3306/data --pid-file=/data/mysql/3306/log/mysql.pid
mysql       6268    5563  8 11:41 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/3306/log/error.log --pid-file=/data/mysql/3306/log/mysql.pid --socket=/data/mysql/3306/tmp/mysql.sock --port=3306
root        6298    5323  0 11:41 pts/0    00:00:00 grep --color=auto mysql
[root@localhost bin]# 

  • 写回答

2条回答 默认 最新

  • 於黾 2022-06-27 13:57
    关注

    selinux是一个防火墙
    它针对的不是外部攻击,而是内部权限,禁止无权限的进程启动
    当你安装的程序不是用yum等工具自动安装,而是手动拷贝然后解压的
    那么很有可能某些文件的权限已经丢失了(因为windows下没有对应的权限系统)
    那么当自动启动时,selinux就会阻止(手动运行无碍)
    这个时候你需要先执行restorecon -Rv /你的安装目录
    会自动将目录下的文件权限恢复为默认值
    至于你先关闭selinux再打开,没这么搞过,但是大概可能效果跟执行restorecon一样吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月6日
  • 已采纳回答 6月28日
  • 创建了问题 6月27日

悬赏问题

  • ¥15 iscsi服务无法访问,如何解决?
  • ¥15 感应式传感器制作的感应式讯响器
  • ¥15 如何使用SC92F8003固件库解析私有协议数据?
  • ¥15 如何在音频中嵌入字符串(水印)信息进行传递
  • ¥30 plc怎么以设计说明书申请软著
  • ¥15 硬盘识别不了,需要初始化,可我的数据怎么办
  • ¥15 lvm2被mask了,怎么unmask都没用(标签-ubuntu|关键词-apt)
  • ¥15 交叉注意力机制的残差问题
  • ¥15 微信小程序:渲染收货地址时页面不显示
  • ¥20 win7 64位DirectShow提示初始化失败如何解决?