title: From CSV to MySQL Database Using Perl
body: <p>I tried to upload some data from CSV to MySQL database - But it not working</p>
  
  <p>Below one is my code</p>
  
  <pre><code>#!/usr/bin/perl -w
  use DBI;
  use strict;
  use TEXT::CSV;
  use warnings;
  
  my $driver       = "mysql"; 
  my $database     = "test";
  my $host         = "localhost"
  my $databaseport = "3306";
  my $userid       = "root";
  my $password     = "password";
  my $csv          = "C:/Perl/scripts/table.csv";
  
  my $dsn          = "dbi:mysql:dbname=$databasename;host=$dbhost;port=$dbport;";
  
  open (CSV, "$csv") or die "Couldn't open csvfile: $!";
  my $dbh = DBI-&gt;connect($dsn, $userid, $password,{ RaiseError =&gt; 1})
  or die "Could not connect to database! $DBI::errstr";
  { 
   local $/ = undef; 
    $dbh-&gt;do("INSERT INTO student (stud_id,stud_name,dept_id,stud_mark,stud_address) 
  
    values (?, ?, ?, ?, ?)", undef, &lt;CSV&gt;);
   }
   $dbh-&gt;disconnect;
  close CSV;
  </code></pre>