这里完全按照WSL官网安装MySQL
To install MySQL on WSL (Ubuntu 18.04):
- Open your WSL terminal (ie. Ubuntu 18.04).
- Update your Ubuntu packages:
sudo apt update
- Once the packages have updated, install MySQL with:
sudo apt install mysql-server
- Confirm installation and get the version number:
mysql --version
You may also want to run the included security script. This changes some of the less secure default options for things like remote root logins and sample users. To run the security script:
- Start a MySQL server:
sudo /etc/init.d/mysql start
- Start the security script prompts:
sudo mysql_secure_installation
- The first prompt will ask whether you’d like to set up the Validate Password Plugin, which can be used to test the strength of your MySQL password. You will then set a password for the MySQL root user, decide whether or not to remove anonymous users, decide whether to allow the root user to login both locally and remotely, decide whether to remove the test database, and, lastly, decide whether to reload the privilege tables immediately.
To open the MySQL prompt, enter: sudo mysql
To see what databases you have available, in the MySQL prompt, enter: SHOW DATABASES;
To create a new database, enter: CREATE DATABASE database_name;
To delete a database, enter: DROP DATABASE database_name;
For more about working with MySQL databases, see the MySQL docs.
To work with with MySQL databases in VS Code, try the MySQL extension.
安装Bug: cannot create directory ‘//.cache’: Permission denied
然而,在执行sudo mysql
这一步时,出现下面错误:
* Starting MySQL database server mysqld No directory, logging in with HOME=/
-su