Using Perl to connect to MySQL, there are many cases on the Internet, and generally we are dbi under the Dbd::mysql this module. Here make a mask get a tips:
Perl DBI MySQL's character set is UTF8
Perl DBI special characters write times wrong
Perl DBI Connection Automatic reconnection or connection timeout
1. When MySQL's character set is UTF8, it needs to be introduced:
Use UTF8;
Binmode (STDOUT, ': Encoding (UTF8) ');
Binmode (STDIN, ': Encoding (UTF8) ');
Binmode (STDERR, ': Encoding (UTF8) ');
Objective:
Resolve Perl connection MySQL to the data after reading the display result is garbled problem.
2. For writing special characters, it is best to use:
My $sth = $dbh->prepare ("INSERT into WUBX. Weekevent VALUES (?,?,?,?,?,?,?) ");
$sth->execute ($OId, $CId, qq/$Time/, $EventType, qq/$CDesc/, $PId, $RFlag);
For strings that may be submitted by the user with a qq//package, reducing the special characters causes SQL to not execute.
3. If you connect two databases with Exchange operations or move data, consider a timeout.
Error: MySQL server has gone away
Treatment methods:
The automatic reconnection of DBI connections is supported after Dbd::mysql 4.012. Need to set:
$DBH->{mysql_auto_reconnect} = 1;
Not supported in earlier modules, simple method:
$DBH->do (' Set session wait_timeout=72000 ');
$DBH->do (' Set session interactive_timeout=72000 ');
This method is applicable in other languages even if the MySQL connection is short lost or the timeout time setting for the server is too short.