Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

How to start MariaDB (or MySQL) server on a WSL using systemctl?

+1
−0

When I try to start MariaDB server (same problem with MySQL) on a fresh Debian 11 install in a Windows Subsystem Linux (WSL) I got the following error:

$ sudo systemctl start mariadb
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

However the following command to enable MariaDB seems to work:

$ sudo systemctl enable mariadb
Synchronizing state of mariadb.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mariadb

I've tried some things like adding [boot] systemd=true to /etc/wsl.conf (find here) but the error persists.

Set up

I've tested with a fresh install of Debian WSL1 installed from the Microsoft Store (Debian GNU/Linux 11 bullseye) on a Windows 10 Professionnel (version 22H2) host and MariaDB installed with sudo apt install mariadb-server.

I have exactly the same problem on a Ubuntu 22.04.2 LTS WSL1 and Fedora Linux 38 (Container Image) WSL1 (with MySQL), with both installed from the Microsoft Store.

Context

I try to "set up a new (development) instance of Codidact/QPixel" on a WSL following this workflow.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

2 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+3
−0

As the error says, WSL doesn't boot using systemd in the same way a native Debian install does, so you can't use systemctl either. The answer is simply to use service instead, which doesn't rely on systemd:

sudo service mysql start
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Follow-up error: start failed (1 comment)
+1
−0

systemctl is a tool for controlling systemd, the "new" Linux init system (actually it's been widely used for 10 years now). Systemd is the first process that runs at boot, which then brings up all the rest of the OS. It also handles various background processes like system services.

WSL does not boot the way a normal Linux would, so it does not have a working systemd. That's why systemctl will not work.

Since you are on Windows, it is possible to instead set up the MariaDB on Windows directly, using Windows services. A basic set up normally results in MariaDB listening on localhost, and you should then be able to connect to it from inside WSL. Of course, Windows's CLI is quite different from Linux/Unix.

I would recommend running a Dockerized instance of it. You'll have to install Docker first, but that's well documented and MariaDB (and any other container) will be easy afterwards. With containers:

  • It's all set up for you already and you don't have to deal with configuring
  • If you do want to create your own DIY container, the Dockerfile makes it much easier to develop & troubleshoot because it's deterministic and reproducible
  • Systemd doesn't run normally in Docker either, but it's much better documented how to deal with issues like this (plus the official MariaDB image for example has already taken care of that for you, so you don't even need to care)
  • If you decide to deploy your app to a real server later, you can use the same Docker image as is instead of having to set up and configure the DB again
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Dockerized instance on Windows? (2 comments)

Sign up to answer this question »