记一次令人绝望的mysql启动报错

简述:

今天在做LNMP环境的时候,mysql启动失败,LNMP环境是用的oneinstack一键安装脚本安装的。

报错简述:

➜  sudo systemctl restart mysqld.service
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.

➜  sudo systemctl status mysqld.service 
● mysqld.service - LSB: start and stop MySQL
  Loaded: loaded (/etc/init.d/mysqld; generated)
  Active: failed (Result: exit-code) since Tue 2018-11-06 18:31:34 CST; 6s ago
  Docs: man:systemd-sysv-generator(8)
  Process: 22460 ExecStart=/etc/init.d/mysqld start (code=exited, status=1/FAILURE)

11月 06 18:31:33 ubuntu-kevin systemd[1]: Starting LSB: start and stop MySQL...
11月 06 18:31:33 ubuntu-kevin mysqld[22460]: Starting MySQL
11月 06 18:31:34 ubuntu-kevin mysqld[22460]: . * The server quit without updating PID file (/tmp/mysql.pid).
11月 06 18:31:34 ubuntu-kevin systemd[1]: mysqld.service: Control process exited, code=exited status=1
11月 06 18:31:34 ubuntu-kevin systemd[1]: mysqld.service: Failed with result 'exit-code'.
11月 06 18:31:34 ubuntu-kevin systemd[1]: Failed to start LSB: start and stop MySQL.

大致意思是因为/tmp目录缺少启动文件(mysql.pid)导致的,恩,于是参照网上提供的方法,修改/etc/my.cnf文件

#socket = /tmp/mysql.sock
socket = /var/lib/mysql/mysql.sock

修改pid文件的存放目录,然后chmod -R 777 /var/lib/mysql/
重新启动,恩?失败!!

➜  sudo systemctl status mysqld.service 
● mysqld.service - LSB: start and stop MySQL
  Loaded: loaded (/etc/init.d/mysqld; generated)
  Active: failed (Result: exit-code) since Tue 2018-11-06 18:31:34 CST; 6s ago
 Docs: man:systemd-sysv-generator(8)
  Process: 22460 ExecStart=/etc/init.d/mysqld start (code=exited, status=1/FAILURE)

11月 06 18:31:33 ubuntu-kevin systemd[1]: Starting LSB: start and stop MySQL...
11月 06 18:31:33 ubuntu-kevin mysqld[22460]: Starting MySQL
11月 06 18:31:34 ubuntu-kevin mysqld[22460]: . * The server quit without updating PID file (/var/lib/mysql/mysql.pid).
11月 06 18:31:34 ubuntu-kevin systemd[1]: mysqld.service: Control process exited, code=exited status=1
11月 06 18:31:34 ubuntu-kevin systemd[1]: mysqld.service: Failed with result 'exit-code'.
11月 06 18:31:34 ubuntu-kevin systemd[1]: Failed to start LSB: start and stop MySQL.

那继续,还有大佬说查看mysql报错日志

➜  vi /data/mysql/mysql-error.log
文件无法打开???权限不够?行吧,我sudo
➜  sudo vi /data/mysql/mysql-error.log

2018-11-04T11:47:38.194829Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 181104 19:47:38
2018-11-04T11:47:39.352071Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2592787
2018-11-04T11:47:39.353709Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2018-11-04T11:47:39.353718Z 0 [Note] Shutting down plugin 'MEMORY'
2018-11-04T11:47:39.353723Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2018-11-04T11:47:39.353726Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2018-11-04T11:47:39.353741Z 0 [Note] Shutting down plugin 'sha256_password'
2018-11-04T11:47:39.353743Z 0 [Note] Shutting down plugin 'mysql_native_password'
2018-11-04T11:47:39.353856Z 0 [Note] Shutting down plugin 'binlog'
2018-11-04T11:47:39.465526Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

等会,好像有什么不对啊,今天明明是11-06,你这个11-04什么鬼!!!!
绝望~
然后冷静下来,想到,刚刚查看日志文件为什么会显示权限不够,什么时候vi都要超级管理员权限了。
然后ll看了一下文件的所属

drwxr-x---  2 1002 1002     4096 11月  4 19:47 mysql

嗯哼,这个1002是什么鬼,顿时发现问题
####解决方法:
创建mysql用户和mysql组

➜  sudo useradd mysql -g mysql
➜  sudo groupadd mysql
➜  chown -R mysql:mysql /usr/local/mysql
➜  chown -R mysql:mysql /var/lib/mysql
➜  chown -R mysql:mysql /data/mysql

➜  sudo systemctl restart mysqld.service

nice启动成功了!!!

➜  mysql mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 
MySQL [(none)]> quit
Bye

开心~~

文章目录
  1. 1. 简述:
  2. 2. 报错简述: