Mysql启动失败,报PID错误

背景: 华为云服务器错误关机,导致之前创建的文件丢失

1.启动mysql
[root@ecs-8c16g ~]# service mysqld start
/etc/init.d/mysqld: line 47: /usr/local/mysql/data: Is a directory
Starting MySQL.The server quit without updating PID file (/[FAILED]mysqld/mysqld.pid).

2.查看mysql错误日志
  • 找到日志位置 log-file
[root@ecs-8c16g ~]# cat /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
default_character_set=utf8
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#不区分大小写
lower_case_table_names = 1

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

max_connections=5000


#replication
server-id       = 2
log_bin         = mysql-bin.log
replicate-do-db = hm_advertise #只复制某个库
replicate-do-db = hm_common
replicate-do-db = hm_num
replicate-do-db = hm_order
replicate-do-db = hm_user
#replicate-ignore-db=mysql #不复制某个库

  • 查看错误日志。发现有如下错误
[root@ecs-8c16g ~]# tail -100  /var/log/mysqld.log
2019-11-22T08:02:28.498265Z 0 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2019-11-22T08:02:28.498275Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory

是因为/var/run/mysqld/mysqld.pid文件不存在。

3.解决
  • 创建目录[root@ecs-8c16g ~]# mkdir -p /var/run/mysqld
  • 授权mysql用户组 [root@ecs-8c16g ~]# chown mysql.mysql /var/run/mysqld
  • 创建mysqld.pid文件 [root@ecs-8c16g ~]# touch /var/run/mysqld/mysqld.pid
  • 授权[root@ecs-8c16g ~]# chown mysql.mysql /var/run/mysqld/mysqld.pid
  • 启动mysql [root@ecs-8c16g ~]# service mysqld start

启动成功:

[root@ecs-8c16g ~]# service mysqld start
/etc/init.d/mysqld: line 47: /usr/local/mysql/data: Is a directory
Starting MySQL.                                            [  OK  ]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值