在新安装mysql后进行启动发现报错

mysql启动服务命令

systemctl start mysqld@3306

Starting mysqld (via systemctl):  Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld3306.service" and "journalctl -xe" for details.

按照错误提示信息进行排查

systemctl status mysqld3306.service

journalctl -xe



尝试连接mysql报错查看sock文件夹发现sock文件丢失

[root@cdh03 mysqldata3309]# mysql -uroot -S /data/mysqldata3309/sock/mysql.sock -p"Ygadb(vw<6ae"

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysqldata3309/sock/mysql.sock' (2)

使用命令journalctl -xe查看报错具体原因,发现红色找字体的日志:SELinux is preventing mysqld from getattr access on the file /var/lib/mysql/ibdata1. For complete SELinux messages run: sealert -l

发现是selinux限制导致mysql服务启动失败

解决办法

1. 查看SELinux状态

1.1 getenforce

getenforce 命令是单词get(获取)和enforce(执行)连写,可查看selinux状态,与setenforce命令相反。

setenforce 命令则是单词set(设置)和enforce(执行)连写,用于设置selinux防火墙状态,如: setenforce 0用于关闭selinux防火墙,但重启后失效

[root@cdh03 ~]# getenforce

Enforcing

1.2 /usr/sbin/sestatus

Current mode表示当前selinux防火墙的安全策略

[root@cdh03 ~]# /usr/sbin/sestatus

SELinux status: enabled

SELinuxfs mount: /sys/fs/selinux

SELinux root directory: /etc/selinux

Loaded policy name: targeted

Current mode: enforcing

Mode from config file: enforcing

Policy MLS status: enabled

Policy deny_unknown status: allowed

Max kernel policy version: 28

SELinux status:selinux防火墙的状态,enabled表示启用selinux防火墙

Current mode: selinux防火墙当前的安全策略,enforcing 表示强

2. 关闭SELinux

2.1 临时关闭

setenforce 0 :用于关闭selinux防火墙,但重启后失效。

[root@cdh03 ~]# setenforce 0

[root@cdh03 ~]# /usr/sbin/sestatus

SELinux status: enabled

SELinuxfs mount: /sys/fs/selinux

SELinux root directory: /etc/selinux

Loaded policy name: targeted

Current mode: permissive

Mode from config file: enforcing

Policy MLS status: enabled

Policy deny_unknown status: allowed

Max kernel policy version: 28

2.1 永久关闭

修改selinux的配置文件,重启后生效。

打开 selinux 配置文件

[root@cdh03 ~]# vim /etc/selinux/config

修改 selinux 配置文件

将SELINUX=enforcing改为SELINUX=disabled,保存后退出

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=enforcing

SELINUXTYPE= can take one of three two values:

targeted - Targeted processes are protected,

minimum - Modification of targeted policy. Only selected processes are protected.

mls - Multi Level Security protection.

SELINUXTYPE=targeted

此时获取当前selinux防火墙的安全策略仍为Enforcing,配置文件并未生效。

[root@cdh03 ~]# getenforce

Enforcing

重启

[root@cdh03 ~]# reboot

验证

[root@cdh03 ~]# /usr/sbin/sestatus

SELinux status: disabled

[root@cdh03 ~]# getenforce

Disabled

然后重启MYSQL服务,连接正常

解决Linux-Centos7启动Mysql服务失败丢失mysql.sock问题的更多相关文章

  1. centos7启动httpd服务失败:Job for httpd.service failed because the control process exited with error code.

    centos7启动httpd命令有两个可以用 service httpd start    systemctl start httpd.service 如果出现如下报错 Job for httpd.s ...

  2. mysql服务突然丢失解决方案

    mysql服务突然丢失解决方案 今天系统从win7更新到win10之后,mysql突然没了,使用navicat连接提示如下: 看到这个,以为自己的mysql服务没启动,于是打开服务找mysql服务,发 ...

  3. Linux下启动Oracle服务和监听程序步骤

    Linux下启动Oracle服务和监听程序启动和关闭步骤整理如下: 1.安装oracle: 2.创建oracle系统用户: 3./home/oracle下面的.bash_profile添加几个环境变量 ...

  4. linux centos7 安装常用软件java,node,mysql,Seafile

    linux centos7 安装常用软件java,node,mysql,Seafile 安装压缩解压缩软件 yum install -y unzip zip 安装git yum install -y ...

  5. (转) Linux安装启动FTP服务

    Linux安装启动FTP服务 Linux服务器默认是没有开启FTP服务的.也没有FTP服务器,为了文件的传输需要用到FTP服务器,以典型的vsftpd为例.vsftpd作为FTP服务器,在Linux系 ...

  6. 解决Linux下启动Tomcat遇到Neither the JAVA_HOME ...报错

    解决Linux下启动Tomcat遇到Neither the JAVA_HOME ...报错 Neither the JAVA_HOME nor the JRE_HOME environment var ...

  7. CentOS7启动SSH服务报:Job for ssh.service failed because the control process exited with error code

    CentOS7启动SSH服务报:Job for ssh.service failed because the control process exited with error code....... ...

  8. Linux服务器启动jstatd服务

    Linux服务器启动jstatd服务 1.查找jdk所在目录 2.在jdk的bin目录下创建文件jstatd.all.policy touch jstatd.all.policy 3.写入安全配置 g ...

  9. 如何重启MySQL服务,正确重启mysql

    RedHat Linux (Fedora Core/Cent OS) 1.启动:/etc/init.d/mysqld start 2.停止:/etc/init.d/mysqld stop 3.重启:/ ...

随机推荐

  1. 多NX如何共存

    在安装NX时,本机已经装了NX其他版本,只能修改当前程序,无法安装,那么多NX如何共存? 如图:先安装了32位NX8.5,后安装64位NX 8.5时弹的框. 解决办法有两种: 1)将已经安装的NX目录 ...

  2. 基于redis的分布式锁的实现与框架解决方案

    利用切面实现redis分布式锁:https://www.cnblogs.com/xiaoxiongcanguan/p/10718202.html 细节分析redis实现分布式锁的前因后果:https: ...

  3. 手对手的教你用canvas画一个简单的海报

    啦啦啦,首先说下需求,产品想让用户在我们app内,分享一张图片到微信.qq等平台.图片中包含用户的姓名.头像.和带着自己信息的二维码.然后,如何生成这张海报呢~~~首先我们老大告诉我有一个插件叫htm ...

  4. linux上部署springboot项目

    1.安装jdk,请参考个人博客linux安装jdk 2.安装mysql,请参考个人博客 linux安装mysql 3.项目打包(使用idea) 打开项目,点击idea右边Maven Projects菜 ...

  5. P2783 有机化学之神偶尔也会作弊 题解

    题面 前言 这道题以前还是道(水)黑题,现在怎么降紫了???? 前置芝士 tarjain 缩点 倍增求LCA或树剖求LCA 脑子... 题意 给你一个无向图,要求你把所有的环缩成一个点.在新得到的图上 ...

  6. 从远程库github.com克隆代码时遇到了如下的问题:

    Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hos ...

  7. JVM垃圾回收的基础知识

    什么是垃圾? 没有任何引用指向的对象,就是垃圾 如何找到垃圾?(2 种方法) 过程:先找到正在使用的对象,然后把没有正在使用的对象进行回收 1.引用数-Reference-Count 被引用数为 0 ...

  8. sql注入里关键字绕过的发现

    网上大量文章,甚至<黑客攻防技术实战宝典-WEB实战篇>里面都说一些关键字如 select 等绕过可以用注释符/**/. 例如: select,union.可以用 ,se/**/lect, ...

  9. Mybatis中进行批量更新(updateBatch)

    更新多条数据,每条数据都不一样 背景描述:通常如果需要一次更新多条数据有两个方式,(1)在业务代码中循环遍历逐条更新.(2)一次性更新所有数据(更准确的说是一条sql语句来更新所有数据,逐条更新的操作 ...

  10. Docker学习:(一)初识Docker

    Docker(容器虚拟化技术)要点(秒级启动) Docker的WWH公式学习 What[是什么]. Why[为什么要用它]. How[怎么用] 1.Docker简介 (1)问题:为什么会有docker ...