Erlang connection MySQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.