将 MySQL Workbench 链接到我的远程服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6396494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:16:50  来源:igfitidea点击:

Linking MySQL Workbench to my Remote Server

mysqlmysql-workbenchmysql-proxy

提问by Jeff

I've just downloaded MySQL Workbench.

我刚刚下载了 MySQL Workbench。

But I don't quite understand how to syn this with the databases on my remote server.

但我不太明白如何将它与远程服务器上的数据库同步。

Work bench asks for "hostname" so I provided the hostname of my remote server. I designate port 3306.

工作台要求“主机名”,所以我提供了远程服务器的主机名。我指定端口 3306。

I then provide a username. This is the username I use when I log into PhpAdmin -- should I be using a different one?

然后我提供一个用户名。这是我登录 PhpAdmin 时使用的用户名——我应该使用不同的用户名吗?

Then I provide a password, again the same one I use for PhpAdmin.

然后我提供一个密码,同样是我用于 PhpAdmin 的密码。

But this doesn't work.

但这不起作用。

Oddly, the error always tells me my user name is: username@current_network_im_using_to_access_the_internet

奇怪的是,错误总是告诉我我的用户名是: username@current_network_im_using_to_access_the_internet

But this doesn't seem right -- on phpAdmin my user name says username@localhost.

但这似乎不对——在 phpAdmin 上,我的用户名显示为username@localhost

I'm not quite sure what to do.

我不太确定该怎么做。

Can you help me?

你能帮助我吗?

回答by Michael Berkowski

MySQL treats logins as specific to the host they originate from. You can have a different password from your home machine than the one you use on the server itself, and you can have entirely different sets of permissions granted to the same username from different origin hosts.

MySQL 将登录视为特定于它们源自的主机。您可以在家用计算机上使用与在服务器本身上使用的密码不同的密码,并且可以为来自不同源主机的相同用户名授予完全不同的权限集。

On PHPMyadmin, the database is running on the same server as the web server, and therefore refers to itself as localhost, with IP 127.0.0.1. Your machine on which Workbench is installed must access MySQL with different credentials than your username@localhost. The server requires you to grant access to your username from any host you intend to connect from.

在 PHPMyadmin 上,数据库与 Web 服务器在同一台服务器上运行,因此将自身称为localhost,带有 IP 127.0.0.1。安装 Workbench 的机器必须使用与username@localhost. 服务器要求您从您打算连接的任何主机授予对您的用户名的访问权限。

In PhpMyAdmin, you will need to grant access to your database from the remote host: (See also Pekka's answer for how to allow connections from anyhost)

在 PhpMyAdmin 中,您需要从远程主机授予对数据库的访问权限:(另请参阅 Pekka 的回答以了解如何允许来自任何主机的连接)

GRANT ALL PRIVILEGES on dbname.* TO yourusername@your_remote_hostname IDENTIFIED BY 'yourpassword';

To see all the grants you currently have on localhostso that you can duplicate them for the remote host:

要查看您当前拥有的所有授权,localhost以便您可以为远程主机复制它们:

SHOW GRANTS FOR yourusername@localhost;

Additionally, the MySQL server needs to be setup to accept remote connections in the first place. This isn't always the case, especially on web hosting platforms. In the my.cnffile, the skip-networkingline has to be removed or commented out. If there is no skip-networkingline, you must comment out the line:

此外,首先需要将 MySQL 服务器设置为接受远程连接。情况并非总是如此,尤其是在网络托管平台上。在my.cnf文件中,该skip-networking行必须被删除或注释掉。如果没有skip-networking行,则必须注释掉该行:

bind-address = 127.0.0.1 

...then restart MySQL.

...然后重新启动MySQL。

回答by Pekka

Your phpMyAdmin seems to run on the same server as the database itself.

您的 phpMyAdmin 似乎与数据库本身在同一台服务器上运行。

Therefore, it can use username@localhostto connect to the server.

因此,它可以username@localhost用来连接到服务器。

You would need to make mySQL accept connections from outside localhost by adding another user username@%(%meaning "any host").

您需要通过添加另一个用户username@%%意思是“任何主机”)使 mySQL 接受来自本地主机之外的连接。

Note however that this is not good practice - if you have a static IP, consider limiting access to that one address.

但是请注意,这不是一个好习惯 - 如果您有一个静态 IP,请考虑限制对该地址的访问。