SoFunction
Updated on 2025-03-02

MySQL service cannot be started: failed to restart : unit not found

Preface

When using MySQL databases on a daily basis, you may sometimes encounter the problem that the service cannot start normally. This type of problem usually occurs after system updates or service configuration files change. This article fails to start MySQL service, promptfailed to restart : unit not foundError message, providing solutions to help readers quickly troubleshoot problems and solve them.

1. Problem description

On a MySQL database server that has been running stably for a long time, after software updates and restarting the server, when trying to restart the MySQL service, the system prompts the following error message:

failed to restart : unit not found

By searching for relevant information, I found that the service name of MySQL is fromTurned into, and this service file is usually located in/lib/systemd/system/In the directory. If there are multiple MySQL-related service files in this directory, it may cause the system to fail to find the correct file when starting the service, resulting in an error.

2. Problem analysis

The MySQL service starts a service unit file that relies on systemd management, which is usually located in/lib/systemd/system/In the directory. MySQL's service unit file can beor. In some cases, such as system updates or package changes, it may cause:

  • Files are deleted or replaced.
  • There are multiple MySQL-related service files in the system, such asand[email protected]

To ensure that the service starts normally, it should be ensured that only the latest version of the service files are retained and expired or duplicate files are cleaned.

3. Solution steps

3.1 Check MySQL service files

First, check/lib/systemd/system/Whether there are MySQL-related service files in the directory. You can use the following command to list all MySQL-related files:

ll /lib/systemd/system/*mysql*

This command will return an output similar to the following:

-rw-r--r-- 1 root root 1234 Sep 29 10:00 /lib/systemd/system/
-rw-r--r-- 1 root root 1234 Sep 29 10:00 /lib/systemd/system/[email protected]
-rw-r--r-- 1 root root 1234 Sep 29 09:00 /lib/systemd/system/

Here you can see multiple MySQL-related service files, includingand

3.2 Backup old service files

In order to prevent the system from confusing selecting old versions of service files, it is recommended to convert the old onesBackup the files. Rename it to

mv /lib/systemd/system/ /lib/systemd/system/

3.3 Start MySQL Service

After backing up old service files, the system will use the latestFile to start MySQL. Next, try restarting the MySQL service:

systemctl daemon-reload
systemctl start mysqld

If you need to set the MySQL service to power on, you can use the following command:

systemctl enable mysqld

3.4 Verify service status

Finally, use the following command to check the running status of the MySQL service to make sure it has started normally:

systemctl status mysqld

Under normal circumstances, the output is similar to the following:

●  - MySQL Server
   Loaded: loaded (/lib/systemd/system/; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2024-09-29 10:00:00 UTC; 1h 45min ago

4. Summary

Through the above steps, we resolved the issue where the MySQL service cannot be started. The root of the problem lies in the old versionFiles and latestA file conflict occurred, causing the system to not find the correct service unit file when starting MySQL. The problem was solved smoothly by backing up old files and restarting the service.

Conclusion

The proper operation of MySQL services is crucial to the stability of database applications. When encountering a service startup exception, first check whether the service unit file exists and whether it is configured correctly. At the same time, regular updates and backups of related service files can help reduce the occurrence of such problems.

This is the article about MySQL service not being started: failed to restart : unit not found. For more related content related to MySQL service not being started, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!