Django - Отказ в подключении mysql на подсистеме ubuntu windows 10
Я использую xaamp для MySQL DB и запускаю свой сервер как на cmd, так и на подсистеме ubuntu, но мой ubuntu говорит
django.db.utils.OperationalError: (2003, 'Не удается подключиться к серверу MySQL на '127.0.0.1' (111 "Connection refused")')
Причина в том, что подсистема Ubuntu находится на другом сетевом уровне. Поэтому они не могут подключиться.
Connecting to Windows network applications/servers from Ubuntu in WSL2
WSL2 is actually running on a separate, virtualized, NAT'd network from your Windows host. As such, you need to determine the proper IP address to use for the Windows host in order to connect to it from the WSL2 network.
Assuming a default WSL/Ubuntu installation on a supported Windows release, mDNS is usually the best option.
The mDNS name of your Windows host that you can use from within Ubuntu will look like:
MyComputerName.local
As long as you haven't changed the DNS resolver from the WSL default, that will be the same as what you see when you run hostname in Ubuntu.
You can determine this programmatically by:
Obtaining the hostname in your programming language / environment
Appending .local
For instance, in Bash, to connect to a Windows MySQL server:
Install the MySQL client in Ubuntu:
sudo apt install mysql-client
Connect to Windows MySQL server via "$(hostname).local":
mysql --hostname=$(hostname).local --user=me -p mydb