MySQL 通过终端连接到远程mysql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5340890/
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 19:09:26  来源:igfitidea点击:

Connect to remote mysql via terminal

mysqlconnection

提问by rd42

For a test I set up user mysql user with % access. When I try to connect from a remote machine I get:

为了进行测试,我设置了具有 % 访问权限的用户 mysql 用户。当我尝试从远程机器连接时,我得到:

Enter password:

输入密码:

Then immediately get this:

然后立即得到这个:

ERROR 2003 (HY000): Can't connect to MySQL server on ‘xxxxxxx' (1)

ERROR 2003 (HY000): 无法连接到'xxxxxxx'上的 MySQL 服务器 (1)

Any ideas

有任何想法吗

采纳答案by deepcell

Try to comment the bind-address = 127.0.0.1in your /etc/mysql/my.cnf

尝试bind-address = 127.0.0.1在您的/etc/mysql/my.cnf 中注释

# security:
# using "localhost" in connects uses sockets by default
# skip-networking
# bind-address = 127.0.0.1  --- commented

and watch the results. If not work try to use the IP address and if still not work. roll back the original file.

并观察结果。如果不起作用,请尝试使用 IP 地址,如果仍然不起作用。回滚原始文件。

回答by nos

Verify that you can connect to the mysql port with telnet from that remote machine, e.g.

验证您是否可以从该远程机器使用 telnet 连接到 mysql 端口,例如

telnet 192.168.1.52 3306

If that fails, there's a firewall somewhere preventing you to connect, or you're running mysql on a different port than the default(3306) or mysql isn't configured to listen on the interface/ip address (maybe it's just configured to listen on connections from localhost, check the bind-addressconfiguration in the my.cnf config file)

如果失败,则某处有防火墙阻止您连接,或者您在与默认端口(3306)不同的端口上运行 mysql,或者 mysql 未配置为侦听接口/IP 地址(也许它只是配置为侦听在来自本地主机的连接上,检查bind-addressmy.cnf 配置文件中的配置)

回答by Robert Holland

Can you telnet to the MySQL port 3306? If you can't then check to make sure the MySQL server service is listening on that port. Open a command prompt and type the following example. Example: telnet yourmysqlservername.com 3306

你能 telnet 到 MySQL 的 3306 端口吗?如果不能,则检查以确保 MySQL 服务器服务正在侦听该端口。打开命令提示符并键入以下示例。示例:telnet yourmysqlservername.com 3306