Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing mysql on /etc/init.d/ directory

I've been trying to install mysql using WSL and I've followed the steps indicated in this guide https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-database. I tried running mysql --version and it worked (prompted mysql Ver 8.0.23 for Linux on x86_64 (MySQL Community Server - GPL)). But as I try the next command sudo /etc/init.d/mysql start, it says sudo: /etc/init.d/mysql: command not found. I've also tried checking the contents of /etc/init.d/ directory and there is no existing mysql file/folder there. What should I do next to proceed with my mysql installation?

Thanks!

like image 392
Adriell de Guzman Avatar asked Jun 25 '26 04:06

Adriell de Guzman


1 Answers

There is a great blog post on this problem, with explanations of the issue and detailed solutions. https://www.58bits.com/blog/2020/05/03/installing-mysql-80-under-wsl-2-and-ubuntu

From the post:

One solution is to download the mysql.server.sh script from here - https://github.com/mysql/mysql-server/tree/8.0/support-files - and then copy and rename the script to /etc/init.d/mysql (make sure that it's also executable - chmod +x mysql)

You'll then need to set the default values for basdir, datadir and pid file locations.

Here's an excerpt with the top portion of the file and the settings that worked for me...

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/usr
datadir=/var/lib/mysql

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

# The following variables are only set for letting mysql.server find things.

# Set some defaults
mysqld_pid_file_path=/var/run/mysqld/mysqld.pid
if test -z "$basedir"

After this you should be able to start and stop MySQL as follows:

sudo service mysql start
sudo service mysql stop

As he mentions later, you also need to create /var/run/mysqld/ and set permissions:

sudo mkdir /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
like image 141
Dovev Hefetz Avatar answered Jun 26 '26 19:06

Dovev Hefetz