我不能用Erlang连接到mysql/mariadb。
根据本github-page的要求:https://github.com/mysql-otp/mysql-otp
要求:
Erlang/OTP version R16B or later
MySQL database version 4.1 or later or MariaDB
GNU Make or Rebar or any other tool for building Erlang/OTP applications
版本号:
14> erlang:system_info(otp_release).
"22"
我不确定是否还需要此要求,但我添加了以下内容:[mysqld] default_authentication_plugin=mysql_native_password
到我的/etc/my. cnf。但这可能是无关紧要的,因为错误是一个未定义的函数。我可以编译代码,但我不能运行它。任何帮助,让这个工作非常感谢。
代码:
-module(mydatabase).
-compile(export_all).
connect_to_database() ->
Conn = mysql:start_link([{host, "localhost"}, {user, "user"},
{password, "password"}, {database, "MyDatabase"}]) ,
case Conn of
{ok, Pid} -> io:fwrite("~w~w~n", [ok,Pid]);
{error, ConnErr} -> io:fwrite("error : ~p ~n", [ConnErr])
end.
start() -> connect_to_database().
mariadb正在运行:
sudo systemctl status mariadb
[sudo] password for user:
● mariadb.service - MariaDB 10.4.13 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor >
Active: active (running) since Sun 2020-06-28 15:33:50 CEST; 1h 4min ago
错误消息:
12> c(mydatabase).
mydatabase.erl:2: Warning: export_all flag enabled - all functions will be exported
{ok,mydatabase}
13> mydatabase:start().
** exception error: undefined function mysql:start_link/1
in function mydatabase:connect_to_database/0 (mydatabase.erl, line 1
1条答案
按热度按时间ao218c7q1#
You forgot about this requirement:
GNU Make or Rebar or any other tool for building Erlang/OTP applications
According to the mysql-otp docs :
MySQL/OTP is a driver for connecting Erlang/OTP applications to MySQL and MariaDB databases.
An
OTP application
requires a certain architecture, and the mysql driver needs to be listed as a dependency in the application. Your error is due to the fact that there is no function namedmysql:start_link/1
in Erlang. Rather, that's a third party function that your code has to somehow access, hence the Usage as a Dependency section in the docs.The following steps can be used to create an
OTP application
which employs mysql/mariaDB as a dependency:app
:like this:
src
directory:my_mysql.erl: