[英]Connection to a MySQL server through a SSH tunnel using Swift 4?
有没有人曾经(或者我应该说编码)使用 Swift 4 通过 SSH 隧道连接到 MySQL 服务器? 提前致谢!
1)使用Shout框架通过 SSH 连接到主机:
let ssh = try SSH(host: "example.com")
try ssh.authenticate(username: "user", privateKey: "~/.ssh/id_rsa")
您只能通过 privateKey 连接
2)通过linux命令行执行mysql命令:
let jsonResult = try ssh.execute("mysql -uLOGIN -hHOST -pPASS -Bs testDB -e \"SELECT json_arrayagg( json_merge( json_object('PersonID', PersonID), json_object('FirstName', FirstName))) from Persons;\"")
您将获得 mysql 查询结果的 JSON 字符串到 jsonResult 值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.