【问题标题】:Connection to a MySQL server through a SSH tunnel using Swift 4?使用 Swift 4 通过 SSH 隧道连接到 MySQL 服务器?
【发布时间】:2019-08-01 08:17:04
【问题描述】:

是否有人曾经使用 Swift 4 通过 SSH 隧道连接到 MySQL 服务器(或者我应该说是编码的)? 提前致谢!

【问题讨论】:

    标签: mysql swift ssh


    【解决方案1】:

    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 值。

    【讨论】:

      猜你喜欢
      • 2020-09-30
      • 2016-11-18
      • 2019-11-12
      • 2014-03-21
      • 2017-01-01
      • 2018-10-06
      • 1970-01-01
      相关资源
      最近更新 更多