sudo apt update && sudo apt upgrade

Install MySQL

sudo apt install mysql-server
mysql --version
sudo /etc/init.d/mysql start

If you want to secure MySQL by setting up the user pass, you can also run sudo mysql_secure_installation

Allow remote access

Allow remote access from autside WSL

Allow the root user to assess the database using basic username and password authentication (no certificate required).

Src: SO – Cannot connect to MySQL database (running on WSL2) from Windows Desktop Application “MySQL Workbench”

From the MySQL prompt run:

ALTER
USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

Change default port:

sudo vim /etc/mysql/my.cnf

Add line

[mysqld]
port = 33061
sudo service mysql restart

Autostart MySQL in WSL

In WSL terminal run

sudo update-rc.d mysql defaults

Now, every time WSL is started, MySQL will start.

MySQL Reset root PASS

Install MariaDB

sudo apt install mariadb-server

Src: https://pen-y-fan.github.io/2021/08/08/How-to-install-MySQL-on-WSL-2-Ubuntu/

0
Would love your thoughts, please comment.x
()
x