将 MySQL Workbench 链接到我的远程服务器
我刚刚下载了 MySQL Workbench。
但我不太明白如何将其与远程服务器上的数据库同步。
工作台要求“主机名”,因此我提供了远程服务器的主机名。我指定端口 3306。
然后提供用户名。这是我登录 PhpAdmin 时使用的用户名——我应该使用其他用户名吗?
然后我提供一个密码,与我用于 PhpAdmin 的密码相同。
但这行不通。
奇怪的是,错误总是告诉我我的用户名是: username@current_network_im_using_to_access_the_internet
但这似乎不对 - 在 phpAdmin 上我的用户名是 username@localhost
。
我不太确定该怎么办。
你能帮助我吗?
I've just downloaded 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.
I then provide a username. This is the username I use when I log into PhpAdmin -- should I be using a different one?
Then I provide a password, again the same one I use for 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
But this doesn't seem right -- on phpAdmin my user name says username@localhost
.
I'm not quite sure what to do.
Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MySQL 将登录视为特定于其源自的主机。您可以在家庭计算机上使用与在服务器本身上使用的密码不同的密码,并且可以从不同的原始主机向同一用户名授予完全不同的权限集。
在 PHPMyadmin 上,数据库与 Web 服务器在同一台服务器上运行,因此将自身称为
localhost
,IP 为127.0.0.1
。安装 Workbench 的计算机必须使用与username@localhost
不同的凭据访问 MySQL。服务器要求您授予您想要连接的任何主机对您的用户名的访问权限。在 PhpMyAdmin 中,您需要从远程主机授予对数据库的访问权限:(另请参阅 Pekka 的答案,了解如何允许来自任何主机的连接)
要查看您当前在
上拥有的所有授权localhost
以便您可以为远程主机复制它们:此外,MySQL 服务器需要首先设置为接受远程连接。情况并非总是如此,尤其是在网络托管平台上。在
my.cnf
文件中,必须删除或注释掉skip-networking
行。如果没有skip-networking
行,则必须注释掉该行:...然后重新启动 MySQL。
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.
On PHPMyadmin, the database is running on the same server as the web server, and therefore refers to itself as
localhost
, with IP127.0.0.1
. Your machine on which Workbench is installed must access MySQL with different credentials than yourusername@localhost
. The server requires you to grant access to your username from any host you intend to connect from.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 any host)
To see all the grants you currently have on
localhost
so that you can duplicate them for the remote host: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.cnf
file, theskip-networking
line has to be removed or commented out. If there is noskip-networking
line, you must comment out the line:...then restart MySQL.
如果您计划使用MySQL工作台来管理远程服务器中的MySQL数据库和表,我建议通过SSH连接。通过关注许多文章和论坛,我尝试了许多其他方法,例如添加绑定地址、使用具有所有权限的 uname@host 添加新用户到 MySql 等。但就我而言,所有这些步骤都是浪费时间,这些步骤将是如果您的服务器如此严格,则很有用。
按照以下步骤操作。
If you are planning to use MySQL workbench for managing MySQL databases and tables in a remote server, I am recommending connect over SSH. by following many articles and forums I tried many other ways by adding bind-address, adding a new user to MySql with uname@host with all privileges, etc. but in my case, all those steps were wasting of time, those steps will be useful if your server is so strict.
Follow the steps below.
您的 phpMyAdmin 似乎与数据库本身在同一台服务器上运行。
因此,它可以使用
username@localhost
来连接到服务器。您需要通过添加另一个用户
username@%
(%
表示“任何主机”)来使 mySQL 接受来自本地主机外部的连接。但请注意,这不是一种好的做法 - 如果您有静态 IP,请考虑限制对该地址的访问。
Your phpMyAdmin seems to run on the same server as the database itself.
Therefore, it can use
username@localhost
to connect to the server.You would need to make mySQL accept connections from outside localhost by adding another user
username@%
(%
meaning "any host").Note however that this is not good practice - if you have a static IP, consider limiting access to that one address.
为了连接到 Windows 10 上安装的 MySQL Workbench,我发现上面由 Shihab 撰写并由 Dharman 编辑的帖子对于立即连接非常有用。但是,以下是我通过 TCP/IP 连接所做的事情,这对于我通过代码连接到 MySQL 也很有用:
第 1 步:更改 MyMySQL 中的绑定地址
在使用 Putty 的 Ubuntu 计算机(安装了我的 MySQL 社区服务器)上,我使用命令“sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf”更改了 mysqld.cnf 文件。使用箭头键,我向下滚动到“绑定地址”行,并将其从“127.0.0.1”更改为“0.0.0.0”。我使用ctrl+x关闭并输入“Y”保存文件。
第2步:重新启动MySQL服务器
您必须重新启动 MySQL 服务器。为此,您可以使用命令“sudo service mysql restart”重新启动。如果无法重新启动,请终止 MySQL 进程。首先使用“ps ax | grep mysql”找到MySQL的进程ID,然后使用“sudo Kill [process_id]”杀死进程
第3步:更改Ubuntu的防火墙设置
要允许外部连接,您应该更改防火墙的设置。我使用 UFW(简单防火墙)来更改设置。如果尚未启用 UFW,请使用命令“sudo ufw enable”启动它。使用“sudo ufw status”检查状态。现在,使用命令“sudo ufw allowed from [ip_address] to any port 3306”启用从特定 IP 地址到 MySql 端口 3306(默认)的连接,或者您可以允许从任何 IP 地址到该端口的所有连接(即您的 IP 地址)使用命令“sudo ufw allowed mysql”不断更改
第4步:在MySQL中创建用户
我在 MySQL 中创建了一个用户,以避免使用 root 登录,使用命令“CREATE USER 'user_name'@'your_IP_Address' IDENTIFIED BY 'password';
第 5 步:通过 MySQL 工作台连接
第 6 步:如果您仍然无法连接
如果上述步骤不起作用,但您仍然想通过快速破解进行连接
高级黑客步骤:通过 SSH 使用 MySQL Workbench 登录
现在,您应该能够进入 MySQL Workbench
其他有用的命令:
第 1 步:sudo apt update
步骤2:sudo apt install mysql-server
步骤3:sudo systemctl启动mysql.service
步骤 4(如果安装过程中出现问题): sudo apt --fix-broken install
To get connected to MySQL Workbench installed on Windows 10, I found the above post written by Shihab and edited by Dharman useful to get connected instantly. But, here are the things that I did to connect via TCP/IP which was also useful for me to connect to MySQL via my code:
Step 1:Changing the bind address in MyMySQL
On the Ubuntu machine (where my MySQL Community Server is installed) using Putty, I changed the mysqld.cnf file with the command "sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf". Using arrow keys, I scrolled down to the row with "bind-address" and I changed it from "127.0.0.1" to "0.0.0.0". I used ctrl+x to close and entered "Y" to save the file.
Step 2: Restart the MySQL Server
You have to restart the MySQL server. To do that, you can restart using the command "sudo service mysql restart". If you are unable to restart, kill MySQL Process. First find the Process ID of MySQL using "ps ax | grep mysql" then kill the process using "sudo kill [process_id]"
Step 3:Changing the Firewall Settings of Ubuntu
To allow outside connections, you should change the settings of the firewall. I used UFW (Uncomplicated FireWall) to change the settings. Start the UFW if it is not yet enabled using the command "sudo ufw enable". Check the status using "sudo ufw status". Now, enable connections to the MySql port 3306 (default) from a particular IP address using the command "sudo ufw allow from [ip_address] to any port 3306" or you can allow all connections to the port from any IP address is your IP address keeps changing using the command "sudo ufw allow mysql"
Step 4: Creating a user in MySQL
I created a user in MySQL to avoid logging in using the root using the command "CREATE USER 'user_name'@'your_IP_Address' IDENTIFIED BY 'password';
Step 5: Connect via the MySQL workbench
Step 6: If you are still not able to connect
If the above steps don't work and still you want to connect via a quick hack
Premium Hack Step: Logging in using MySQL Workbench via SSH
Now, you should be able to enter your MySQL Workbench
Other useful commands:
Step 1: sudo apt update
Step 2: sudo apt install mysql-server
Step 3: sudo systemctl start mysql.service
Step 4 (if something is broken during installation): sudo apt --fix-broken install