


How to fix 'Failed to start mysql.service: Unit mysql.service not found'
Jun 28, 2025 am 01:54 AMI encountered the problem of "Failed to start mysql.service: Unit mysql.service not found", which means that the system cannot find the MySQL service unit file, usually due to incorrect installation or the service name is incorrect. 1. First check whether MySQL is installed, use mysql --version to confirm, and reinstall if not installed; 2. Check whether the service name is mysqld or other variant, use the systemctl list-units or ls command to find it; 3. Confirm whether MariaDB is installed instead of MySQL, and check the mariadb service status; 4. Advanced users can try to manually create the mysql.service file and overload the systemd service. Following the above steps to check generally solves the problem.
If you encounter the problem "Failed to start mysql.service: Unit mysql.service not found", it means that the system cannot find the service unit file for MySQL, which usually means that MySQL is not installed correctly, or the service name is incorrect.

1. Confirm whether MySQL is actually installed
The most common reason for this problem is that MySQL is not installed successfully at all . You can check it by:

mysql --version
If command not found
is prompted, it means that MySQL is not installed. At this time, you need to reinstall the MySQL server. Take Ubuntu as an example:
sudo apt update sudo apt install mysql-server
After the installation is complete, try to start the service:

sudo systemctl start mysql
2. Confirm whether the service name is correct
Sometimes the service name is not what you expected. For example, in some Linux distributions, the service name of MySQL may be:
-
mysqld
(common in CentOS, RHEL) -
mysql@bootstrap
(if you are building a cluster or using group replication)
You can use the following command to find out which MySQL-related services are available in the system:
systemctl list-units | grep -i mysql
Or more thoroughly:
ls /etc/systemd/system/multi-user.target.wants/ | grep mysql
After finding the correct service name, replace the original command and start it, such as:
sudo systemctl start mysqld
3. Check whether MariaDB is installed instead of MySQL
Some distributions install MariaDB by default, rather than Oracle's official MySQL. MariaDB is a fork of MySQL, with good compatibility, but its service name is usually:
mariadb
If you find that the system prompts that mysql.service
cannot be found after installation, but it has indeed performed similar installation operations, you can try to check whether MariaDB is installed:
sudo systemctl status mariadb
If this is the case, you can enable and start the service in the following ways:
sudo systemctl enable mariadb sudo systemctl start mariadb
4. Manually create service files (advanced users)
If you are sure that MySQL has been installed but still cannot find the service, it may be that the service file is corrupt or missing. You can create a simple .service
file manually, for example:
sudo nano /etc/systemd/system/mysql.service
Then add the following content (adjust according to your actual path):
[Unit] Description=MySQL Database Server After=network.target [Service] User=mysql ExecStart=/usr/sbin/mysqld Restart=always [Install] WantedBy=multi-user.target
Reload systemd after saving:
sudo systemctl daemon-reexec sudo systemctl daemon-reload sudo systemctl enable mysql sudo systemctl start mysql
However, this step is recommended only if you understand the system structure, otherwise you should reinstall MySQL first.
Basically that's it. Although the problem seems scary, most of the cases are that the installation is incomplete or the service name is wrong. You can basically solve it by checking it in the above steps.
The above is the detailed content of How to fix 'Failed to start mysql.service: Unit mysql.service not found'. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To reset the root password of MySQL, please follow the following steps: 1. Stop the MySQL server, use sudosystemctlstopmysql or sudosystemctlstopmysqld; 2. Start MySQL in --skip-grant-tables mode, execute sudomysqld-skip-grant-tables&; 3. Log in to MySQL and execute the corresponding SQL command to modify the password according to the version, such as FLUSHPRIVILEGES;ALTERUSER'root'@'localhost'IDENTIFIEDBY'your_new

mysqldump is a common tool for performing logical backups of MySQL databases. It generates SQL files containing CREATE and INSERT statements to rebuild the database. 1. It does not back up the original file, but converts the database structure and content into portable SQL commands; 2. It is suitable for small databases or selective recovery, and is not suitable for fast recovery of TB-level data; 3. Common options include --single-transaction, --databases, --all-databases, --routines, etc.; 4. Use mysql command to import during recovery, and can turn off foreign key checks to improve speed; 5. It is recommended to test backup regularly, use compression, and automatic adjustment.

When handling NULL values ??in MySQL, please note: 1. When designing the table, the key fields are set to NOTNULL, and optional fields are allowed NULL; 2. ISNULL or ISNOTNULL must be used with = or !=; 3. IFNULL or COALESCE functions can be used to replace the display default values; 4. Be cautious when using NULL values ??directly when inserting or updating, and pay attention to the data source and ORM framework processing methods. NULL represents an unknown value and does not equal any value, including itself. Therefore, be careful when querying, counting, and connecting tables to avoid missing data or logical errors. Rational use of functions and constraints can effectively reduce interference caused by NULL.

Turn on MySQL slow query logs and analyze locationable performance issues. 1. Edit the configuration file or dynamically set slow_query_log and long_query_time; 2. The log contains key fields such as Query_time, Lock_time, Rows_examined to assist in judging efficiency bottlenecks; 3. Use mysqldumpslow or pt-query-digest tools to efficiently analyze logs; 4. Optimization suggestions include adding indexes, avoiding SELECT*, splitting complex queries, etc. For example, adding an index to user_id can significantly reduce the number of scanned rows and improve query efficiency.

TosecurelyconnecttoaremoteMySQLserver,useSSHtunneling,configureMySQLforremoteaccess,setfirewallrules,andconsiderSSLencryption.First,establishanSSHtunnelwithssh-L3307:localhost:3306user@remote-server-Nandconnectviamysql-h127.0.0.1-P3307.Second,editMyS

GROUPBY is used to group data by field and perform aggregation operations, and HAVING is used to filter the results after grouping. For example, using GROUPBYcustomer_id can calculate the total consumption amount of each customer; using HAVING can filter out customers with a total consumption of more than 1,000. The non-aggregated fields after SELECT must appear in GROUPBY, and HAVING can be conditionally filtered using an alias or original expressions. Common techniques include counting the number of each group, grouping multiple fields, and filtering with multiple conditions.

MySQL transactions and lock mechanisms are key to concurrent control and performance tuning. 1. When using transactions, be sure to explicitly turn on and keep the transactions short to avoid resource occupation and undolog bloating due to long transactions; 2. Locking operations include shared locks and exclusive locks, SELECT...FORUPDATE plus X locks, SELECT...LOCKINSHAREMODE plus S locks, write operations automatically locks, and indexes should be used to reduce the lock granularity; 3. The isolation level is repetitively readable by default, suitable for most scenarios, and modifications should be cautious; 4. Deadlock inspection can analyze the details of the latest deadlock through the SHOWENGINEINNODBSTATUS command, and the optimization methods include unified execution order, increase indexes, and introduce queue systems.

MySQL paging is commonly implemented using LIMIT and OFFSET, but its performance is poor under large data volume. 1. LIMIT controls the number of each page, OFFSET controls the starting position, and the syntax is LIMITNOFFSETM; 2. Performance problems are caused by excessive records and discarding OFFSET scans, resulting in low efficiency; 3. Optimization suggestions include using cursor paging, index acceleration, and lazy loading; 4. Cursor paging locates the starting point of the next page through the unique value of the last record of the previous page, avoiding OFFSET, which is suitable for "next page" operation, and is not suitable for random jumps.
