DEV Community

Cover image for Connect MySQL Workbench to MySQL Server in WSL using Node
Susan Githaiga
Susan Githaiga

Posted on

Connect MySQL Workbench to MySQL Server in WSL using Node

Windows Subsystem for Linux(WSL) is a Microsoft Windows feature that lets you run a Linux environment directly on your Windows machine without needing a separate virtual machine or dual booting your PC.

WSL uses your window's system IP address as it's own. However, the default MySQL workbench config only accepts requests and connections from 127.0.0.1

If you want to connect your NodeJS app to MySQL workbench, then you need to use the ip address of your host machine(PC). To do this, follow these steps:

  • Open your WSL terminal.

  • Run the following command in your WSL terminal to retrieve your host machine's(PC's) IP address:

ip route show | grep -i default | awk '{ print $3}'

Image description

  • On your .env file, change the DB_HOST(the variable which stores your host IP Address) to your host machine's IP Address

Image description

Now, your NodeJS server is running and ready for use:

Image description

To learn more about how to access your PC's network applications through WSL, read the following article on Microsoft learn: Accessing network applications with WSL

Top comments (0)