在新安装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服务,连接正常

最新文章

  1. junit4进行单元测试
  2. sql server 数据库 日期格式转换
  3. ArcEngine:The XY domain on the spatial reference is not set or invalid错误
  4. 关于python3.X 报&quot;import urllib.request ImportError: No module named request&quot;错误,解决办法
  5. [算法]检测空间三角形相交算法(Devillers &amp; Guigue算法)
  6. Vsftpd 配置
  7. 【转】eclipse.ini内存设置
  8. 网络流转换为Byte数组
  9. 如何重启MySQL服务,正确重启mysql
  10. AssetBundle.CreateFromFile的有趣事情
  11. POI单元格添加公式以及读取公式结果的值
  12. Hibernate学习错误集锦-GenericJDBCException: could not execute statement
  13. Android重构篇——项目架构篇
  14. leetcode【67】-Bulb Switcher
  15. 安装需要的第三方库时,命令行输入pip提示不是内部或外部命令
  16. react_app 项目开发 (9)_数据可视化 ECharts
  17. redis cluster介绍
  18. [20180317]12c TABLE ACCESS BY INDEX ROWID BATCHED2.txt
  19. MySQL(二)MySQL的启动或链接失败
  20. LeetCode OJ 56. Merge Intervals

热门文章

  1. Java Web学习(七)HttpServletResponse(客户端响应)
  2. web自动化整理
  3. (转载)IO模型
  4. Java知识系统回顾整理01基础03变量08表达式
  5. 《C++primerplus》第12章练习题
  6. IntelliJ IDEA Commons IO环境搭建
  7. P2034 选择数字 / P2627 [USACO11OPEN]Mowing the Lawn G
  8. 解决FAT32格式U盘安装Windows 10时的报错(错误代码:0x8007000D)
  9. HttpReports 2.0 发布了 !!!
  10. ansible-playbook定义变量与使用