Fil
Fil

Reputation: 8863

mysql: unrecognized service

I followed the instruction here to install mariadb on WSL after following the steps. and I run this

sudo service mysql start

I got

mysql: unrecognized service

Any idea how to solve this?

Upvotes: 8

Views: 40100

Answers (2)

Fil
Fil

Reputation: 8863

It's just a simple problem as you see but it takes me 24 hours to diagnose the problem.

Solution: I uninstall mariadb with this command

sudo apt-get remove --auto-remove mariadb-server

and install sudo apt install mysql-server instead but it leads to a more problems

Successfully install mysql but can't start

dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          
Errors were encountered while processing:
mysql-server-5.7
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

so by removing mariadb's deb sources and purging mysql-common and then reinstalling it.

do: sudo apt edit-sources

and look for anything containing mariadb like: deb [arch=amd64,arm64,ppc64el] http://ftp.nluug.nl/db/mariadb/repo/10.3/ubuntu bionic main

comment it out by putting a # in front of it. then run

sudo apt update
sudo apt purge mysql-common
sudo apt install mysql-common

after that you can installed mysql-server properly via sudo apt install mysql-server, then do:

sudo apt purge mysql-server mysql-server-5.7
sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-5.7 mysql-client-core-5.7


sudo rm -rfv /etc/mysql /var/lib/mysql

sudo apt autoremove

sudo apt autoclean

Finally:

sudo apt update    
sudo apt install mysql-server mysql-client --fix-broken --fix-missing

References: https://askubuntu.com/questions/980314/cannot-install-mysql-server-in-ubuntu16-0-4 https://askubuntu.com/questions/763534/cannot-reinstall-mysql-server-after-its-purge

Upvotes: 9

Akshay Anurag
Akshay Anurag

Reputation: 744

Which Linux distribution are you using on your WSL?

First, try the following:

systemctl {start|stop|restart|status} mysql

OR

service mysql {start|stop|restart|status}

to manage the MySQL service.

The reasons can be the following:

  1. Wrong service name:

    On some Linux distributions, the service is named as mysqld instead of mysql.

    To check: Run chkconfig --list on your WSL and identify the correct service name.

  2. File permission issues:

    Please ensure that the files in /var/lib/mysql have 770 permissions and ownership set to mysql user.

    To fix:

    chmod -R 770 /var/lib/mysql
    chgrp -R mysql /var/lib/mysql
    

    In addition to that, ensure that the /etc/rc.d/init.d/mysqld script has executable permissions to modify mysqld.

    To fix:

    chmod 755 /etc/rc.d/init.d/mysqld
    
  3. Missing/Corrupted MySQL server package:

    Reinstall MySQL!

Upvotes: 5

Related Questions