我已经在WSL2上安装了MySQL,如下所示
$ sudo apt remove --purge *mysql*
$ sudo rm -rf /var/lib/mysql
$ sudo apt install -y mysql-server mysql-client
invoke-rc.d: could not determine current runlevel
...
* Stopping MySQL database server mysqld [ OK ]
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
invoke-rc.d: could not determine current runlevel
Setting up mysql-server (5.7.29-0ubuntu0.18.04.1) ...
Processing triggers for systemd (237-3ubuntu10.39) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
$ sudo service mysql start
* Starting MySQL database server mysqld No directory, logging in with HOME=/
mkdir: cannot create directory ‘//.cache’: Permission denied
-su: 19: /etc/profile.d/wsl-integration.sh:
cannot create //.cache/wslu/integration: Directory nonexistent
然后我试着联系:
$ sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
...
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
同时,我创建了用户laravel
,并尝试使用mysql -ularavel -p
从WSL连接。
最后我尝试从Windows连接:
为什么这行不通?
2条答案
按热度按时间omqzjyyz1#
我敢打赌你需要授权访问。我添加了一个新用户和授权访问。
检查here.页下的示例
然后尝试连接用户:newguy和密码:ratfink从MySQL工作台。
mtb9vblg2#
以前的答案似乎已经过时了。下面的命令帮助我解决了这个问题。
UPDATE mysql.user SET plugin='mysql_native_password', password=PASSWORD('your_password') WHERE user='your_username' AND host='localhost';
然后运行
FLUSH PRIVILEGES;
祝你今天愉快!