MySQL 因控制进程退出并显示错误代码而失败

MySQL 因控制进程退出并显示错误代码而失败

当我尝试启动 MySQL 服务时,出现错误代码。

systemctl 状态 mysql.service

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Wed 2019-07-31 15:53:02 EDT; 25s ago
  Process: 4527 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 4519 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 4527 (code=exited, status=1/FAILURE);         : 4528 (mysql-systemd-s)
    Tasks: 2
   Memory: 312.0K
      CPU: 132ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─4528 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─4581 sleep 1

journalctl-xe

Jul 31 15:53:32 localhost mysql-systemd-start[4597]: my_print_defaults: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 22!
Jul 31 15:53:32 localhost mysql-systemd-start[4597]: my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Jul 31 15:53:32 localhost mysqld[4605]: mysqld: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 22!
Jul 31 15:53:32 localhost mysqld[4605]: mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
Jul 31 15:53:32 localhost systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Jul 31 15:53:58 localhost sudo[4665]: username : TTY=pts/0 ; PWD=/home/username ; USER=root ; COMMAND=/bin/journalctl -xe
Jul 31 15:53:58 localhost sudo[4665]: pam_unix(sudo:session): session opened for user root by username(uid=0)

tail -30 /var/log/mysql/error.log

2019-07-31T19:32:21.755618Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2019-07-31T19:32:21.755622Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2019-07-31T19:32:21.755626Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2019-07-31T19:32:21.755629Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2019-07-31T19:32:21.755633Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2019-07-31T19:32:21.755637Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2019-07-31T19:32:21.755640Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2019-07-31T19:32:21.755644Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2019-07-31T19:32:21.755647Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2019-07-31T19:32:21.755651Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2019-07-31T19:32:21.755655Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2019-07-31T19:32:21.755658Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2019-07-31T19:32:21.755662Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2019-07-31T19:32:21.755666Z 0 [Note] Shutting down plugin 'InnoDB'
2019-07-31T19:32:21.755717Z 0 [Note] InnoDB: FTS optimize thread exiting.
2019-07-31T19:32:21.755825Z 0 [Note] InnoDB: Starting shutdown...
2019-07-31T19:32:21.856374Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2019-07-31T19:32:21.857042Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 190731 15:32:21
2019-07-31T19:32:22.970442Z 0 [Note] InnoDB: Shutdown completed; log sequence number 3106693
2019-07-31T19:32:22.972650Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-07-31T19:32:22.972676Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2019-07-31T19:32:22.972683Z 0 [Note] Shutting down plugin 'MEMORY'
2019-07-31T19:32:22.972687Z 0 [Note] Shutting down plugin 'CSV'
2019-07-31T19:32:22.972693Z 0 [Note] Shutting down plugin 'MyISAM'
2019-07-31T19:32:22.972700Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2019-07-31T19:32:22.972735Z 0 [Note] Shutting down plugin 'sha256_password'
2019-07-31T19:32:22.972739Z 0 [Note] Shutting down plugin 'mysql_native_password'
2019-07-31T19:32:22.972931Z 0 [Note] Shutting down plugin 'binlog'
2019-07-31T19:32:22.973293Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

答案1

关键错误消息是这样的:

mysqld: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 22!

这意味着你的 mysql 配置文件的第 22 行有错误。我怀疑你那里有一个不存在的选项,或者你有一个用于不同部分的选项(即用于[client]下面的选项[mysqld],反之亦然) 以下是 my.cnf 文件的文档

以下是一个例子:

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=128M

[mysqldump]
quick

相关内容