How to Fix “mysqld: unrecognized service” Error on CentOS – MySQL Service Recovery Guide


8 views

When your MySQL service suddenly becomes unrecognized on CentOS, it's typically one of these scenarios:

  • The MySQL package was accidentally removed or corrupted
  • The service name changed between MySQL versions (mysqld vs mysql)
  • Systemd vs init.d configuration issues
  • MySQL was never properly installed as a service

Before trying solutions, verify these key points:

# Check if MySQL binaries still exist
which mysqld
ls -la /usr/sbin/mysqld

# Check installed packages
rpm -qa | grep -i mysql
yum list installed | grep -i mysql

# Alternative service names to try
systemctl list-unit-files | grep -i mysql

Case 1: MySQL Package Exists But Service Missing

Reinstall just the server package:

sudo yum reinstall mysql-server
sudo systemctl enable mysqld
sudo systemctl start mysqld

Case 2: Different Service Name

Modern CentOS often uses 'mysql' instead of 'mysqld':

sudo systemctl status mysql
sudo service mysql start

Case 3: Manual Service Registration

For custom installations, create a systemd service file at /etc/systemd/system/mysqld.service:

[Unit]
Description=MySQL Server
After=network.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Restart=on-failure

[Install]
WantedBy=multi-user.target

Then reload systemd:

sudo systemctl daemon-reload
sudo systemctl enable mysqld

For production servers, consider:

  • Setting up monitoring for critical services
  • Regularly verifying backups
  • Using configuration management tools like Ansible

Example monitoring cron job:

*/5 * * * * pgrep mysqld || systemctl restart mysql && echo "MySQL restarted" | mail -s "MySQL Alert" admin@example.com

When encountering the "mysqld: unrecognized service" error on CentOS, it typically indicates one of these situations:

  • The MySQL service isn't installed properly
  • The service name differs between MySQL versions (mysqld vs mysql)
  • The init script is missing or relocated
  • Systemd vs SysV init compatibility issues

Before attempting fixes, verify MySQL's actual status:

# Check if MySQL is running despite the error
ps aux | grep mysql

# Modern systemd approach
systemctl status mysqld
systemctl status mysql

# Alternative method using service name variants
service mysql status
service mysqld status

Case 1: Different service name in newer MySQL versions

# For MySQL 5.7+ or MariaDB installations
sudo systemctl start mariadb
sudo systemctl start mysql

Case 2: Missing init scripts

# Reinstall MySQL server while preserving data
sudo yum reinstall mysql-server

# For MariaDB systems
sudo yum reinstall mariadb-server

If standard solutions fail, try these approaches:

# Manual service registration (SysV systems)
sudo chkconfig --add mysqld
sudo service mysqld start

# Systemd service file creation (if missing)
sudo cp /usr/lib/systemd/system/mysqld.service /etc/systemd/system/
sudo systemctl daemon-reload

After applying any solution, confirm successful recovery:

mysqladmin -u root -p version
systemctl is-active mysqld
netstat -tulnp | grep 3306
  • Regularly back up your my.cnf configuration
  • Document your exact MySQL installation method
  • Consider using configuration management tools
  • Monitor critical services with tools like Monit