Using the MySQL DBD

Any Perl script that uses DBI with the MySQL DBD module should begin with the following line:

use Mysql;

Mysql

Note the unusual capitalization of Mysql that is used in the Perl API. The name of this extension is case sensitive.

Connecting to MySQL

You establish a connection to a MySQL database by calling the connect() method on the master Mysql object. The following statement opens a new connection to the database mysql10 on a local MySQL server and assigns a database handle named $dbh.

$dbh = Mysql->connect("localhost", "mysql10", "username" "password");

Mysql->connect() should have exactly four arguments:

  • host— The hostname ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.