http://blog.csdn.net/flyinmind/article/details/7740540
Erlang is used in the project, and MySQL is used as well. Convention, Google.
However, according to the online said to do, some discrepancy, does not work, need to find their own, the following record my groping things.
1, download erlang-mysql-driver;
: Https://github.com/dizzyd/erlang-mysql-driver
2, decompression to the MySQL directory, not wordy;
3. Compiling
To configure the Erlang path First, in/etc/profile, write the bin path of Erlang to the example path= $PATH:/home/erlang/bin
Otherwise, rebar can not find the escript.
In the source directory, run make, without any hint, so do not use this method,
Copy the MYSQL.HRL under include into the SRC directory, and then "ERLC *.erl" to get the beam file
Create the Ebin directory under the source MySQL directory and copy the beam files to Ebin.
The final directory is structured like this
Mysql
|---ebin
|---src
|---include
4. Move the entire MySQL directory into Erlang, assuming your erlang is placed under the/home/erlang
Move MySQL to/home/erlang/lib/erlang/lib, not directly under/home/erlang/lib.
Yes, open Erlang's terminal and test it.
Mysql:start_link (conn, "Database IP or domain name", 3306, "root", "password", "database name", Undefined, UTF8).
{data, Result} = Mysql:fetch (conn, << "SELECT * from T_users" >>).
Rows = mysql:get_result_rows (Result).
5. Remove unnecessary printing information
Add a log function, only allow the error level of printing, the others are not hit.
Log (Module, line, level, Formatfun)
Case level of
Error-
{Format, Arguments} = Formatfun (),
Io:format ("~w:~b:" + + format + + "~n", [Module, line] + + Arguments);
_-O
End
.
Mysql:start_link (conn, "Database IP or domain name", 3306, "root", "password", "Database name", Fun LOG/4, UTF8).
Hope the above content is useful to you and reduce unnecessary waste of time:)
Erlang connection MySQL