Connect MySQL Workbench on WSL MySQL?

青春壹個敷衍的年華 提交于 2020-08-10 22:08:07

问题


I have installed MySQL on WSL2 with the following

$ 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

Then I've tried to connect:

$ 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>

In the meantime I've created the user laravel and tried to connect from WSL with mysql -ularavel -p.

Eventually I tried to connect from Windows:

Why is this not working?


回答1:


I bet you need to GRANT access. I added a new user and GRANTed access.

mysql> CREATE USER 'newguy'@'localhost' IDENTIFIED BY 'ratfink';
Query OK, 0 rows affected (0.02 sec)

mysql> GRANT ALL ON mysql.* TO 'newguy'@'localhost';
Query OK, 0 rows affected (0.01 sec)

Check the examples down the page here.

Then try connecting with user: newguy and password: ratfink from MySQL Workbench.



来源:https://stackoverflow.com/questions/60902050/connect-mysql-workbench-on-wsl-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!