gpt4 book ai didi

通过 SSH 隧道连接 MySQL 数据库

转载 作者:太空宇宙 更新时间:2023-11-04 11:06:46 25 4
gpt4 key购买 nike

我的新数据库有问题。访问数据库的唯一方法是使用 SSH 隧道。但它不起作用...

我使用以下命令:

sshpass -p <PASSWORD> ssh <USER>@<DOMAIN> -p <PORT> -L 3306:localhost:3306 -f -N

我认为 ssh 隧道有效并已建立。

现在我想通过 Shell-File 连接数据库。

deposit=`mysql -h localhost --port=3306 -u <DATABASEUSER> --password=<DATABASEPASSWORD> --skip-column-names -e "<MYSQLSYNTAX>"`

但是总是出现如下错误:

ERROR 1045 (28000): Access denied for user '<DATABASEUSER>'@'localhost' (using password: YES)

你有什么想法还是我做错了什么?

非常感谢!

最佳答案

假设您的所有权限都没有问题,可能值得将 localhost 换成 127.0.0.1

根据 MySQL 文档:http://dev.mysql.com/doc/refman/5.5/en/connecting.html

On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server.

关于通过 SSH 隧道连接 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24959989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com