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

发布于 2024-11-15 23:20:59 字数 419 浏览 4 评论 0原文

我刚刚下载了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

怕倦 2024-11-22 23:20:59

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

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

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

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

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

SHOW GRANTS FOR yourusername@localhost;

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

bind-address = 127.0.0.1 

...然后重新启动 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 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.

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)

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

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

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.cnf file, the skip-networking line has to be removed or commented out. If there is no skip-networking line, you must comment out the line:

bind-address = 127.0.0.1 

...then restart MySQL.

云朵有点甜 2024-11-22 23:20:59

如果您计划使用MySQL工作台来管理远程服务器中的MySQL数据库和表,我建议通过SSH连接。通过关注许多文章和论坛,我尝试了许多其他方法,例如添加绑定地址、使用具有所有权限的 uname@host 添加新用户到 MySql 等。但就我而言,所有这些步骤都是浪费时间,这些步骤将是如果您的服务器如此严格,则很有用。

按照以下步骤操作。

  1. 单击 MySql 连接标题旁边的 + 按钮添加新连接。
  2. 输入连接名称(无论您需要什么)。
  3. 选择连接方法“标准 TCP/IP over SSH”。
  4. 输入 SSH 详细信息,例如主机(IP/域)、用户名和密码。 (应在服务器中启用使用密码授权的 SSH)
  5. MySQL 主机详细信息,例如主机名(默认 localhost 或 127.0.0.1)、端口(3306)、MySQL 用户名和密码。
  6. 然后点击测试连接。

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.

  1. Click on the + button beside the MySql connections Title to add a new connection.
  2. Enter Connection Name(Whatever you need).
  3. Select connection method Standard TCP/IP over SSH.
  4. Enter the SSH details like Host(IP/Domain), Username, and Password. (SSH using Password Authorisation should be enabled in server)
  5. MySQL host details like Hostname(By Default localhost or 127.0.0.1), port(3306), MySQL username and password.
  6. Then click on test connection.
你曾走过我的故事 2024-11-22 23:20:59

您的 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.

听风念你 2024-11-22 23:20:59

为了连接到 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 工作台连接

  1. 单击数据库
  2. 单击连接到数据库
  3. 在“连接方法”字段中,选择“标准 TCP/IP”
  4. 在“主机名”中,输入您的服务器 IP 地址
  5. 在“服务器端口”中,保留“3306”,除非您已更改服务器中 MySql 的端口
  6. 在“用户名”中,输入您的服务器用户名
  7. 在“密码”中,输入您的服务器密码
  8. 单击“确定”

第 6 步:如果您仍然无法连接

  1. 在您的服务器上,禁用防火墙并检查是否能够连接
  2. 如果能够连接,请使用命令“sudo ufw reset”重置防火墙(确保您对防火墙中的所有连接进行了复制或屏幕截图。您可以使用以下命令获取所有端口命令“sudo ufw状态”)。如果无法连接,请转至步骤 9。
  3. 现在使用命令“sudo ufw allowed 80”、“sudo ufw allowed mysql”等允许之前存在的每个端口。
  4. 使用以下命令禁用和启用防火墙分别命令“sudo ufw禁用”和“sudo ufw启用”。
  5. 检查是否能够通过工作台连接
  6. 如果仍然无法连接,只需使用命令“sudo restart”重新启动服务器即可。
  7. 重新启动完成后,您应该能够连接到 MySQL 服务器。
  8. 如果仍然无法连接,请使用 nmap 软件检查所有开放端口,看看是否可以看到 3306。如果看不到该端口,则必须调试阻止防火墙阻止您的端口的原因。 MySQL 连接。
  9. 使用命令“show grants for 'user_name'@'localhost';”检查您的 MySQL 权限。如果您能够看到授权,则意味着您的 IP 地址不被允许。尝试使用以下命令更新您的 IP 地址的授权:“GRANT ALL PRIVILEGES ON database.* TO 'user'@'yourremotehost' IDENTIFIED BY 'newpassword';”或将数据库上的所有权限授予。* TO 'user'@'yourremotehost' IDENTIFIED BY 'newpassword'; (允许来自任何地方的连接)

如果上述步骤不起作用,但您仍然想通过快速破解进行连接
高级黑客步骤:通过 SSH 使用 MySQL Workbench 登录

  1. 单击“数据库”
  2. 单击“连接到数据库
  3. ” 在“连接方法”字段中,选择“Standard TCP/IP over SSH”
  4. 在 SSH 主机名中,输入您的服务器 IP
  5. 地址在 SSH 用户名中,输入您的服务器用户名
  6. 在 SSH 密码中,输入您的服务器密码
  7. 在 SSH 密钥文件中,不要执行任何操作
  8. 在 MySQL 主机名中,将其保留为“127.0.0.1”
  9. 在服务器中端口,保留为“3306”,除非您更改了服务器中 MySQL 的端口
  10. 在用户名中,输入您在上一步中创建的 MySQL 用户名
  11. 在密码中,输入您在上一步中创建的 MySQL 密码
  12. 单击“确定”
    现在,您应该能够进入 MySQL Workbench

其他有用的命令:

  1. 要检查 MySQL 是否正在运行: systemctl status mysql
  2. 输入 MySQL: sudo mysql -u [用户名] -p (默认用户名是 root,密码是什么(只需按 Enter 键))
  3. 要检查 ufw 的状态: sudo ufw status
  4. 要检查删除端口访问时编号的 ufw 状态: sudo ufw status numbered
  5. 要删除 ufw端口访问: sudo ufw delete [number_of_the_port_to_be_deleted_from_previous_command]
  6. 要启动 MySQL 服务: sudo service mysql start
  7. 要更新所有软件包: sudo apt update
  8. 要卸载 MySQL: sudo apt-get remove mysql*
  9. 要安装 MySQL
    第 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

  1. Click Database
  2. Click Connect to Database
  3. In the Connection Method field, select "Standard TCP/IP"
  4. In the Hostname, enter your server IP address
  5. In the Server Port, leave as it is "3306" unless you have changed the port of MySql in your server
  6. In the Username, enter your server user name
  7. In the Password, enter your server password
  8. Click Ok

Step 6: If you are still not able to connect

  1. On your server, disable the firewall and check if you are able to connect
  2. If you are able to connect, reset the firewall with the command "sudo ufw reset" (Make sure you take a copy or screenshot of all the connections in the firewall. You can get all the ports with the command "sudo ufw status"). If you are unable to connect go to step 9.
  3. Now allow each and every port that was earlier present with the command "sudo ufw allow 80", "sudo ufw allow mysql", etc.
  4. Disable and enable the firewall using the commands "sudo ufw disable" and "sudo ufw enable" respectively.
  5. Check if you are able to connect via the workbench
  6. If you are still not able to connect, just restart the server using the command "sudo reboot"
  7. Once the reboot is complete, you should be able to connect to the MySQL server.
  8. If you are still not able to connect, use something like nmap software to check for all the open ports and see if you can see 3306. If you can't see the port, you have to debug what is stopping the firewall from blocking your MySQL connections.
  9. Check your MySQL privileges with the command "show grants for 'user_name'@'localhost';". If you are able to see the grants, that means your IP address is not allowed. Try to update the grants with your IP address with the following command "GRANT ALL PRIVILEGES ON database.* TO 'user'@'yourremotehost' IDENTIFIED BY 'newpassword';" or GRANT ALL PRIVILEGES ON database.* TO 'user'@'yourremotehost' IDENTIFIED BY 'newpassword'; (To allow connections from everywhere)

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

  1. Click Database
  2. Click Connect to Database
  3. In the Connection Method field, select "Standard TCP/IP over SSH"
  4. In the SSH Hostname, enter your server IP address
  5. In the SSH Username, enter your server user name
  6. In the SSH Password, enter your server password
  7. In the SSH Key file, don't do anything
  8. In the MySQL Hostname, leave it as it is "127.0.0.1"
  9. In the Server Port, leave as it is "3306" unless you have changed the port of MySQL in your server
  10. In the Username, enter your MySQL username that you created in the previous step
  11. In the Password, enter your MySQL password that you created in the previous step
  12. Click Ok
    Now, you should be able to enter your MySQL Workbench

Other useful commands:

  1. To check if MySQL is running: systemctl status mysql
  2. Entering MySQL: sudo mysql -u [username] -p (Default username is root and password is nothing (just press enter key))
  3. To check the status of ufw: sudo ufw status
  4. To check the ufw status numbered for deleting a port access: sudo ufw status numbered
  5. To delete a ufw port access: sudo ufw delete [number_of_the_port_to_be_deleted_from_previous_command]
  6. To start MySQL service: sudo service mysql start
  7. To update all packages: sudo apt update
  8. To uninstall MySQL: sudo apt-get remove mysql*
  9. To install MySQL
    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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文