記一次令人絕望的mysql啟動報錯

weixin_34236869發表於2018-11-06

簡述:

今天在做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

開心~~

相關文章