启动MySQL时抛出:

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

提示说使用journalctl -xe查看详细日志

[linga@localhost ~]$ journalctl -xe

-- Subject: Unit mysqld.service has begun start-up

-- Defined-By: systemd

-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

--

-- Unit mysqld.service has begun starting up.

Aug 30 04:32:12 localhost.localdomain mysqld[2312]: Initialization of mysqld failed: 0

Aug 30 04:32:12 localhost.localdomain systemd[1]: mysqld.service: control process exited, code=exited status=1

Aug 30 04:32:14 localhost.localdomain systemd[1]: Failed to start MySQL Server.

-- Subject: Unit mysqld.service has failed

-- Defined-By: systemd

-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

--

-- Unit mysqld.service has failed.

--

-- The result is failed.

Aug 30 04:32:14 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.

Aug 30 04:32:14 localhost.localdomain systemd[1]: mysqld.service failed.

Aug 30 04:32:14 localhost.localdomain systemd[1]: mysqld.service holdoff time over, scheduling restart.

Aug 30 04:32:14 localhost.localdomain systemd[1]: Starting MySQL Server...

-- Subject: Unit mysqld.service has begun start-up

-- Defined-By: systemd

-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

--

-- Unit mysqld.service has begun starting up.

Aug 30 04:32:14 localhost.localdomain mysqld[2359]: Initialization of mysqld failed: 0

Aug 30 04:32:14 localhost.localdomain systemd[1]: mysqld.service: control process exited, code=exited status=1

Aug 30 04:32:16 localhost.localdomain systemd[1]: Failed to start MySQL Server.

-- Subject: Unit mysqld.service has failed

-- Defined-By: systemd

-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

--

-- Unit mysqld.service has failed.

--

-- The result is failed.

Aug 30 04:32:16 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.

Aug 30 04:32:16 localhost.localdomain systemd[1]: mysqld.service failed.

发现时进程已经存在了,MySQL的进程pid是3306,于是想着杀掉该进程:

kill 3306

发现报错了,于是在cat /etc/my.cfg中查看配置

最后发现设置字体编码时弄错配置了,导致启动失败的;

[linga@localhost ~]$ kill 3306

-bash: kill: (3306) - No such process

[linga@localhost ~]$ cat /etc/my.cnf

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]

#

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

#

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

#

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

datadir=/var/lib/mysql

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

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

# Add UTF-8

character_set=utf8

init_connect='SET NAMES utf8'

[linga@localhost ~]$ sudo vim /etc/my.cnf

[sudo] password for linga:

[linga@localhost ~]$ sudo systemctl start mysqld

[linga@localhost ~]$ sudo systemctl status mysqld

● mysqld.service - MySQL Server

Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

Active: active (running) since Thu 2018-08-30 04:41:33 EDT; 12s ago

Docs: man:mysqld(8)

http://dev.mysql.com/doc/refman/en/using-systemd.html

Process: 14018 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)

Process: 14001 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

Main PID: 14021 (mysqld)

CGroup: /system.slice/mysqld.service

└─14021 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Aug 30 04:41:32 localhost.localdomain systemd[1]: mysqld.service holdoff time over, scheduling restart.

Aug 30 04:41:32 localhost.localdomain systemd[1]: Starting MySQL Server...

Aug 30 04:41:33 localhost.localdomain systemd[1]: Started MySQL Server.

启动失败大多都是由于配置文件配置出错了才启动不起来,一定要提前备份好配置文件

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐