erlang mysql连接超时_Erlang数据库-(一)Erlang与Mysql的连接

下载:http://download.csdn.net/detail/hjhjava/7088277

把该文件的东西全部编译好,然后根据下面的解释就可以操作Mysql的。很简单~

0818b9ca8b590ca3270a3433284dd417.png

-record(row,{a1 = 0, a2=0}).

%% 第一个参数是该链接的名字(根据它来操作Mysql),第二参数是本机号(ip地址)

%% ,第三个参数是端口,第四个参数是数据库账号

%% ,第五个参数是数据库密码,第六个参数是数据库(这个数据库要先数据库中创建啊!!!)

mysql:start_link(p1, "localhost", 3306, root, root, test1,fun(_, _, _, _) -> ok end),

%% 第一个参数是该链接的名字(根据它来操作Mysql,由 mysql:start_link来定义的)

%% ,第四个参数是数据库账号,第二参数是本机号(ip地址)

%% ,第五个参数是数据库密码,第六个参数是数据库(这个数据库要先数据库中创建啊!!!)

mysql:connect(p1, "localhost", undefined, root, root, test1, true),

%% fetch主要是操作数据库的。“<<>>”里面写sql语句就可以了。

mysql:fetch(p1, <>),

mysql:fetch(p1, <>),

%% 表为memory的内存数据表

mysql:fetch(p1, <(id int not null auto_increment,

a1 int not null,

a2 int not null,

primary key (id)) engine = memory">>),

%% 表为innodb

mysql:fetch(p1, <

a1 int not null,

a2 int not null,

primary key (id)) engine = innodb">>).

一些基本操作:

%对表mysql_memory插入数据。

mysql:fetch(p1, <>)

%测试innodb类型表的写入时间

%对表mysql_innoDB插入数据。

mysql:fetch(p1, <>)

%% 在mysql_memory中读取id等于Str的行

mysql:fetch(p1, list_to_binary("select * from memory_test where id = " ++ Str))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值