You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7执行systemctl start MySQL报错:Failed to start mysql.service: Unit not found

Fixing "Failed to start mysql.service: Unit not found" on CentOS 7

Hey there, let's work through this error step by step. This issue usually boils down to a missing installation, incorrect service name, or incomplete setup. Here's what to check:

1. Verify if MySQL is actually installed

First, confirm you have MySQL (or its drop-in replacement MariaDB) installed on your system. Run either of these commands:

rpm -qa | grep mysql
# OR
yum list installed | grep mysql

If you get no output, MySQL isn't installed. Since CentOS 7's default repos don't include MySQL (they ship with MariaDB instead), you'll need to add the official MySQL YUM repository first:

# Download the MySQL repo package for CentOS 7
sudo wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
# Install the repo
sudo rpm -ivh mysql80-community-release-el7-3.noarch.rpm
# Install MySQL Server
sudo yum install mysql-community-server

Once installed, note that the service name might be mysqld instead of mysql—try starting it with:

sudo systemctl start mysqld

2. Check if you're using the correct service name

CentOS 7 defaults to MariaDB, which uses the mariadb service name instead of mysql. To check which service units exist on your system:

systemctl list-unit-files | grep -E '(mysql|mariadb)'

If you see mariadb.service listed, use this command to start it instead:

sudo systemctl start mariadb

3. Repair incomplete MySQL installation

If you confirmed MySQL is installed but the service unit is missing, your installation might be corrupted. Try reinstalling the MySQL server package:

sudo yum reinstall mysql-community-server

After reinstalling, reload systemd to pick up any new service files:

sudo systemctl daemon-reload

Then try starting the service again.

4. Manual service file for manually compiled MySQL

If you installed MySQL from source (not via YUM), systemd won't have a pre-configured service file. You'll need to create one manually:

  1. Create the service file at /etc/systemd/system/mysql.service with the following content (adjust paths to match your installation):
[Unit]
Description=MySQL Server
After=network.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
Restart=always

[Install]
WantedBy=multi-user.target
  1. Reload systemd to recognize the new service:
sudo systemctl daemon-reload
  1. Now you can start MySQL with:
sudo systemctl start mysql

Verify the fix

After starting the service, check its status to confirm it's running:

sudo systemctl status mysqld  # or mysql/mariadb depending on your setup

You can also test connecting to MySQL with:

mysql -u root -p

内容的提问来源于stack exchange,提问作者Chao Liang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 07:03:19