背景: 华为云服务器错误关机,导致之前创建的文件丢失
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 ]