【问题标题】:How do I install a driver in Erlang? (Specifically MySQL-otp driver)如何在 Erlang 中安装驱动程序? (特别是 MySQL-otp 驱动)
【发布时间】:2019-05-10 23:43:17
【问题描述】:

来自documentation,这个驱动看起来很棒。我不知道如何安装它,以便我可以使用它。我在某处读到我应该使用rebar? 虽然我查看了该文档,但它似乎有相反的问题。它说的是如何安装它,而不是如何使用它。


更新

所以看起来安装钢筋后,我可以添加行

{deps, [
    {mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp",
                   {tag, "1.3.3"}}}
]}.

到我的文件 rebar.config。我不知道这是做什么的。我现在必须编译或制作这个文件吗? rebar.config 是否必须与我的项目位于同一目录中?不是 rebar.config 的路径是~/rebar/rebar.config 将我的项目放置在文件层次结构中是否正确?


更新

我用 rebar 文件夹运行 ./rebar get-deps 并得到了

Pulling mysql from {git,"https://github.com/mysql-otp/mysql-otp",
                        {tag,"1.3.3"}}
Cloning into 'mysql'...
==> mysql (get-deps)

我仍然不知道这意味着什么,当我尝试编译我的 erlang 文件时,我收到了结果。

c(erlangFile.erl).
{error,non_existing}

【问题讨论】:

    标签: mysql erlang erlang-otp erl


    【解决方案1】:

    rebar 是 erlang 的构建工具。请通过https://github.com/rebar/rebar/wiki/Rebar-commands 获取命令。 获得依赖后,需要“rebar compile”来编译它。 要使用光束文件,您必须使用Add Path to Erlang Search Path? 提供输出光束路径 这些方法。 然后你就可以在你的代码中使用它了。

    【讨论】:

    • 谢谢。我不认为真的知道什么是光束文件。这个名字敲响了警钟,但我对 Erlang 还很陌生,所以我认为我还没有了解它们是什么。你能在这个特定的背景下解释它们吗? Erlang 路径是否类似于 PythonPath 或 ShellPath,但这个仅适用于 Erlang?再次感谢。
    • 在继续之前,您应该先了解 erlang 的基础知识。通过 learnyousomeerlang.com/content
    • 我只是研究Beam文件,因为我已经阅读了几个类似的教程
    • 我不认为我曾经使用过光束文件,因为我总是在命令行上运行 erl 然后 c(myerlangfile). 在这种情况下我必须使用它们吗?
    【解决方案2】:

    下载你的包,在这种情况下

    git clone https://github.com/mysql-otp/mysql-otp.git
    

    下载一个名为rebar的工具

    git clone git://github.com/rebar/rebar.git
    cd rebar
    ./bootstrap
    

    Add the following to rebar/rebar.config

    {deps, [
        {mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp",
                       {tag, "1.3.3"}}}
    ]}.
    

    在rebar/mysql-otp目录下运行

    ./rebar get-deps
    

    然后在同一个目录下,运行

    ./rebar compile
    

    这会将一堆.beam文件和.app文件放入ebin/目录

    接下来将 ebin/ 目录添加到您的路径中。您可以更新您的 $ERL_LIBS 环境变量 run an include command within the erlang console like

    1> code:add_pathz("~/rebar/mysql-otp/ebin").
    

    1> code:add_pathz("rebar/mysql-otp/ebin")
    

    And theres a few other ways to add it to your Erlang path.


    另外,请确保 mysql 也已安装

    这里有一些对我有用的 mysql 安装说明链接

    https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-centos-7

    No package msyql-server available

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      • 2020-11-02
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 2013-10-17
      相关资源
      最近更新 更多