DBIモジュールとMySQLのDBDモジュールをインストール
[vagrant@localhost ~]$ sudo yum -y install perl-DBI perl-DBD-MySQL
mysql
create database perldb;
use perldb;
create table t1(
a int,
b varchar(10)
);
insert into t1 values(1, ‘asakura’),(2, ‘adachi’),(3, ‘kobayakawa’);
select * from t1;
use DBI; $user = 'root'; $passwd = ''; $db = DBI->connect('DBI:mysql:perldb:localhost', $user, $passwd); $sth = $db->prepare("INSERT INTO t1 VALUES (1,'1st')"); $sth->execute; $sth->finish; $db->disconnect;
mysql> select * from t1;
+——+————+
| a | b |
+——+————+
| 1 | asakura |
| 2 | adachi |
| 3 | kobayakawa |
| 1 | 1st |
+——+————+
4 rows in set (0.00 sec)