簡體   English   中英

在 WSL MySQL 上連接 MySQL Workbench?

[英]Connect MySQL Workbench on WSL MySQL?

我已經使用以下內容在 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> 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)

此處查看頁面下方的示例

然后嘗試使用 MySQL Workbench 中的用戶: newguy和密碼: ratfink進行連接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM