Mac OS remotely logs in to the MySQL database of the Windows server through SSH

Due to some strange needs, the author needs to build MySQL on a Windows server. Here is how to use a relatively simple method to enable Navicat on the Mac to remotely log in to the MySQL database running on the Windows server through SSH . The software and hardware environment of the client is Macbook Air M2+macOS Vantura 13.4.1+Navicat Premium 16.0.7; the software environment of the server is Windows 11 Professional Edition+MySQL 8.0.27, and the network status is under the same LAN .

1. Modify MySQL remote login permissions

After installing MySQL on Windows, you need to modify the login authority of MySQL to set remote access.
Win+ ROpen the run box and type cmd to open a command prompt. enter

mysql -u root -p

Then enter the password to connect to the local MySQL service.
Please add a picture description
use command

use mysql

Database changed will be displayed, and then use the command

select host ,user from user;

Check whether remote login is enabled for the database, and find that the root corresponds to localhost, which only allows local login and needs to be modified.
insert image description here
use command

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

Modify the remote login permissions, then use

FLUSH PRIVILEGES;

Refresh the permissions just modified. use again

select host ,user from user;

Command to view the results and found that the modification was successful.
Please add a picture description
Finally, use the "exit" command to exit the MySQL service.

Second, configure the SSH settings of the Windows server

In Windows Server 2019 and Windows 10 and above , the system provides users with OpenSSH components that can be installed and uninstalled separately , including client and server. Generally speaking, the OpenSSH client has been installed by default, and it is the same as this The experiment has little to do with it. Note that the OpenSSH server component needs to be installed and running.
Open Settings ➡️Applications ➡️Optional features , check whether there is " OpenSSH server " in " Installed features ", if not, click " View features " in " Add optional features " on the upper side of the page , search for " OpenSSH server ", tick Select and follow the guide to install. After the installation is complete, it will be shown in the figure below. Search for " Service " in the search bar and open it, find " OpenSSH SSH Server ", right-click Properties , change the startup type to " Automatic " and click Start in the service status to make it in the " Running " state.
Please add a picture description

Please add a picture description

3. Query the server IP address

Use Win+ again Rto open the run box, then type cmd to open a command prompt. Enter the " ipconfig " command to query and record the IP address of the server, as shown in the figure below.
Please add a picture description

4. Remote login on Mac

Open Navicat, click " Connect " ➡️ " MySQL " in the upper left corner. Click " SSH ", check " Use SSH Tunnel ", enter the IP address queried in the third step for "Host", use 22 for the port, and use the Microsoft account and password you used to log in on the Windows server as the user name and password, not sure You can click "Settings" ➡️ "Account" on Windows to view the account written on the right side of the avatar (usually an email address).
If you click "Test Connection" in the lower left corner at this time, you will find that the connection fails, but the gray line with a lock from "Navicat" to "SSH Server" will display green, indicating that the connection to the SSH server has been successful , and further configuration of the database is required. connect.
insert image description here
Switch back to "General", configure the database. Enter the following information, the connection name can be customized, the host is localhost, the port is 3306, the user name is root, and the password is the login password of the server MySQL.
Please add a picture description
Click "Test Connection" in the lower left corner and find that the connection is successful . Please add a picture description
Click OK, then click Save in the lower right corner. So far, we have been able to operate the MySQL database on the Windows server through Navicat on the Mac side.Please add a picture description

5. Possible problems

  1. 99% of the problems can be solved by restarting Navicat, restarting OpenSSH Server, restarting the client, restarting the server, etc.;
  2. The connection refused may be caused by the firewall on the Windows side, which can be solved by disabling the firewall in the control panel.

Guess you like

Origin blog.csdn.net/weixin_43805744/article/details/131611350