# Connect  Windows (XAMPP) MySQL from WSL2 Ubuntu

Install MySQL client on WSL Ubuntu.

```bash
sudo apt install mysql-client-core-8.0
```

Back yo Windows, run:

```bash
mysql -u root -p
```

Enter this command to enable root account for any host:

```bash
> CREATE USER 'root'@'%' IDENTIFIED BY 'root'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
> FLUSH PRIVILEGES;
> exit;
```

Next, on Wsl2, run:

```bash
mysql -u root -p -h "$(hostname).local"
```

This should works.

If still shows:

```bash
ERROR 2003 (HY000): Can't connect to MySQL server on xxx
```

Try install `libnss-mdns`

```bash
sudo apt install libnss-mdns
```

Now you may want to enter the hostname to `.env` file, just type:

```bash
echo $(hostname).local
```

And copy the result to your `.env` file.
