Install mysql database in ubuntu in WSL

Install mysql database in ubuntu in WSL

Excerpt

The installation is mainly divided into the following steps. The main difference between wsl and ordinary ubuntu installation is that an error will be reported when starting mysql. Ordinary ubuntu's mysql will also run automatically after the installation is completed. 1. Delete the previously installed mysql. If it is not installed, you can skip
sudo apt-get remove --purge mysql
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get re…


The installation is mainly divided into the following steps.
The main difference between wsl and ordinary ubuntu installation is that an error will be reported when starting mysql. Ordinary ubuntu's mysql will also run automatically after the installation is completed.


No installation can be skipped

sudo apt-get remove --purge *mysql*
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get remove --purge *mariadb*

2. Update source


sudo apt update
sudo apt upgrade

3. Install mysql server


sudo apt install mysql-server

4. Start mysql


sudo service mysql start

1. Start mysql:

Method one: sudo /etc/init.d/mysql start
Method two:sudo service mysql start

2. Stop mysql:

Method one: sudo /etc/init.d/mysql stop
Method two:sudo service mysql stop

3. Restart mysql:

Method one: sudo/etc/init.d/mysql restart
Method two:sudo service mysql restart

Note: If it cannot be started cat /var/log/mysql/error.log, check the error log and find that the port is occupied , so it cannot be started. It is found that Ubuntu and Windows of wsl have public ports, so use the command under cmd netstat -ano| findstr 3306to check the pid and remember (the last column), and open the task Manager, open details, close that pid and restart mysql, success. (This is a problem unique to wsl)

5. Set the username and password (if set during the installation process, you can skip the following)


Take a look at the account and password given by the system by default, and use them to log in to mysql.

sudo cat /etc/mysql/debian.cnf
mysql -u默认用户名 -p默认密码

Please add image description
Reset username and password

use mysql;  
update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost'; 
update user set  plugin="mysql_native_password";     
flush privileges;      
quit;     

Note: Use the following code to set the password for mysql80

use mysql;    
alter user 'root'@'localhost' identified with mysql_native_password by '123456';   
flush privileges; 

test:
Insert image description here

Guess you like

Origin blog.csdn.net/feichangyanse/article/details/132848640