珠一
caojiangfeng
热爱开源,热爱linux
全部博文(213)
hadoop(3)
perl脚本(4)
jvm调优工具(1)
网络编程(1)
用法与技术(10)
程序(12)
日志相关(1)
sed和awk(9)
循环(1)
有用的shell网址(0)
驱动开发(4)
我的shell脚本(9)
shell(12)
应用配置(11)
模块编程(10)
Kernel(8)
条件语句(2)
其他(6)
命令学习(20)
信号及其信号处理(3)
进程(7)
文件系统(1)
系统配置(12)
2018年(4)
2017年(1)
2015年(1)
2014年(5)
2013年(2)
2012年(2)
2011年(21)
2010年(82)
2009年(72)
2008年(23)
RHCE520
FIGHTERB
simiaoxi
lyanxha
huxuelin
liurhyme
wangxinm
bluesea6
联众集群
wb123456
ui56
uccom1
dahaosha
gu111356
cynthia
w3964549
a5940176
fah9394
分类: LINUX
2010-10-25 17:38:03
sudo -u root -p 密码:******
create database library;
create table members (member_id int(11) NOT NULL auto_increment ,fname varchar(20) NOT NULL,lname varchar(20) NOT NULL,tel varchar(15) NOT NULL ,email varchar(50) NOT NULL,PRIMARY KEY (member_id));
insert into members (1,'ceagle','jiangfeng','123456789','ceaglechina@gmail.com');
insert into members (1,'hu','xuelin','123456789','ceaglechina@gmail.com');
select * from members;
+-----------+--------+-----------+-----------+-----------------------+ | member_id | fname | lname | tel | email | +-----------+--------+-----------+-----------+-----------------------+ | 1 | ceagle | jiangfeng | 123456789 | ceaglechina@gmail.com | | 2 | hu | xuelin | 123456789 | ceaglechina@gmail.com | +-----------+--------+-----------+-----------+-----------------------+ 2 rows in set (0.00 sec)
#!/usr/bin/perl -w #The script is used to connect mysql and show table members of the #database library use DBI(); #connect my $dbh = DBI->connect("DBI:mysql:database=library;host=localhost","root","ceagle", {'RaiseError'=>1,'AutoCommit'=>0}); #iterate through resultset my $sth = $dbh->prepare("SELECT * from members"); $sth->execute(); print "member_id\tfname\tlname\ttel\t\temail","\n"; while (my $ref = $sth->fetchrow_hashref()) { print "$ref->{'member_id'}\t\t$ref->{'fname'}\t$ref->{'lname'}\t$ref->{'tel'}\t$ref->{'email'}\n"; }
if ($@){ print "Transaction aborted:$@"; $dbh->rollback();}#clean up$sth->finish();$dbh->disconnect();
#!/usr/bin/perl -w #The script is used to connect mysql and show table members of the #database library use DBI(); #connect my $dbh = DBI->connect("DBI:mysql:database=library;host=localhost","root","ceagle", {'RaiseError'=>1,'AutoCommit'=>0}); #execute query #my $sth = $dbh->prepare("SELECT * from members"); #$sth->execute(); eval { #insert data to members $dbh->do("insert into members values (NULL,'cao','jiang','55256262','ceaglechina\@gmail.com')"); $dbh->commit(); }; #iterate through resultset my $sth = $dbh->prepare("SELECT * from members"); $sth->execute(); print "member_id\tfname\tlname\ttel\t\temail","\n"; while (my $ref = $sth->fetchrow_hashref()) { print "$ref->{'member_id'}\t\t$ref->{'fname'}\t$ref->{'lname'}\t$ref->{'tel'}\t$ref->{'email'}\n"; } #Delete the data eval { $dbh->do("delete from members where fname = 'cao' "); $dbh->commit(); }; if ($@){ print "Transaction aborted:$@"; $dbh->rollback(); } #clean up $sth->finish(); $dbh->disconnect();
上一篇:Linux使用Shell实现任务多进程化
下一篇:virtualbox无缘无故不能用了
登录 注册