#!/usr/bin/perl
2 use DBI; #启用DBI接口
3 use strict;
4
5 my $dbh = DBI->connect("DBI:mysql:host=localhost",
6 "root", "PWD",{'RaiseError' => 1});
7 #建库
8 $dbh -> do("DROP database if exists woodformation");
9 $dbh -> do("CREATE DATABASE woodformation DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
#建库并设置字符集
10 my $dbh = DBI->connect('DBI:mysql:woodformation:localhost',"root","PWD") or die "无法连接数据库: " . DBI->errstr;
11
12 #species表
13 $dbh -> do("drop TABLE if exists species");
14 $dbh -> do("CREATE TABLE species
15 (
16 spe varchar(50) NOT NULL PRIMARY KEY,
17 lanspe varchar(100)
#最后一个语句没有逗号
18 )ENGINE=MyISAM DEFAULT CHARSET=utf8;
#设置表的字符集
2 use DBI; #启用DBI接口
3 use strict;
4
5 my $dbh = DBI->connect("DBI:mysql:host=localhost",
6 "root", "PWD",{'RaiseError' => 1});
7 #建库
8 $dbh -> do("DROP database if exists woodformation");
9 $dbh -> do("CREATE DATABASE woodformation DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
#建库并设置字符集
10 my $dbh = DBI->connect('DBI:mysql:woodformation:localhost',"root","PWD") or die "无法连接数据库: " . DBI->errstr;
11
12 #species表
13 $dbh -> do("drop TABLE if exists species");
14 $dbh -> do("CREATE TABLE species
15 (
16 spe varchar(50) NOT NULL PRIMARY KEY,
17 lanspe varchar(100)
#最后一个语句没有逗号
18 )ENGINE=MyISAM DEFAULT CHARSET=utf8;
#设置表的字符集
19 ");
$dbh -> disconnect();