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}'
Now, your NodeJS server is running and ready for use:
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
The above is the detailed content of Connect MySQL Workbench to MySQL Server in WSL using Node. For more information, please follow other related articles on the PHP Chinese website!