【问题标题】:Connect MySQL Workbench on WSL MySQL?在 WSL MySQL 上连接 MySQL Workbench?
【发布时间】:2020-07-09 03:21:03
【问题描述】:

我已经在 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 并尝试从 WSL 连接到 mysql -ularavel -p

最终我尝试从 Windows 连接:

为什么这不起作用?

【问题讨论】:

  • 难道mysql-server 没有配置为服务网络连接? mysql-client 从命令行运行时,可能会通过本地套接字连接(请参阅stackoverflow.com/questions/3715925/…)。 sudo mysql -h 127.0.0.1 的输出是什么?

标签: mysql windows-subsystem-for-linux


【解决方案1】:

我打赌您需要授予访问权限。我添加了一个新用户并授予了访问权限。

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)

查看页面下方的示例here.

然后尝试从 MySQL Workbench 连接用户:newguy 和密码:ratfink

【讨论】:

  • 错误是关于连接到服务器,而不是权限被拒绝。
  • 是的,但未经许可,您将被拒绝连接访问。
  • 不幸的是,这对我不起作用。另见:stackoverflow.com/q/47524577/470749
猜你喜欢
  • 1970-01-01
  • 2015-01-19
  • 2015-08-18
  • 2015-12-17
  • 2013-11-03
  • 2018-03-29
  • 2015-02-15
  • 1970-01-01
  • 2011-10-30
相关资源
最近更新 更多