1DBD::mysql(3)         User Contributed Perl Documentation        DBD::mysql(3)
2
3
4

NAME

6       DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI)
7

SYNOPSIS

9           use DBI;
10
11           $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
12
13           $dbh = DBI->connect($dsn, $user, $password);
14
15           $drh = DBI->install_driver("mysql");
16           @databases = DBI->data_sources("mysql");
17              or
18           @databases = DBI->data_sources("mysql",
19                                          {"host" => $host, "port" => $port});
20
21           $sth = $dbh->prepare("SELECT * FROM foo WHERE bla");
22              or
23           $sth = $dbh->prepare("LISTFIELDS $table");
24              or
25           $sth = $dbh->prepare("LISTINDEX $table $index");
26           $sth->execute;
27           $numRows = $sth->rows;
28           $numFields = $sth->{'NUM_OF_FIELDS'};
29           $sth->finish;
30
31           $rc = $drh->func('createdb', $database, $host, $user, $password, 'admin');
32           $rc = $drh->func('dropdb', $database, $host, $user, $password, 'admin');
33           $rc = $drh->func('shutdown', $host, $user, $password, 'admin');
34           $rc = $drh->func('reload', $host, $user, $password, 'admin');
35
36           $rc = $dbh->func('createdb', $database, 'admin');
37           $rc = $dbh->func('dropdb', $database, 'admin');
38           $rc = $dbh->func('shutdown', 'admin');
39           $rc = $dbh->func('reload', 'admin');
40

EXAMPLE

42         #!/usr/bin/perl
43
44         use strict;
45         use DBI();
46
47         # Connect to the database.
48         my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
49                                "joe", "joe's password",
50                                {'RaiseError' => 1});
51
52         # Drop table 'foo'. This may fail, if 'foo' doesn't exist.
53         # Thus we put an eval around it.
54         eval { $dbh->do("DROP TABLE foo") };
55         print "Dropping foo failed: $@\n" if $@;
56
57         # Create a new table 'foo'. This must not fail, thus we don't
58         # catch errors.
59         $dbh->do("CREATE TABLE foo (id INTEGER, name VARCHAR(20))");
60
61         # INSERT some data into 'foo'. We are using $dbh->quote() for
62         # quoting the name.
63         $dbh->do("INSERT INTO foo VALUES (1, " . $dbh->quote("Tim") . ")");
64
65         # Same thing, but using placeholders
66         $dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen");
67
68         # Now retrieve data from the table.
69         my $sth = $dbh->prepare("SELECT * FROM foo");
70         $sth->execute();
71         while (my $ref = $sth->fetchrow_hashref()) {
72           print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}\n";
73         }
74         $sth->finish();
75
76         # Disconnect from the database.
77         $dbh->disconnect();
78

DESCRIPTION

80       DBD::mysql is the Perl5 Database Interface driver for the MySQL data‐
81       base. In other words: DBD::mysql is an interface between the Perl pro‐
82       gramming language and the MySQL programming API that comes with the
83       MySQL relational database management system. Most functions provided by
84       this programming API are supported. Some rarely used functions are
85       missing, mainly because noone ever requested them. :-)
86
87       In what follows we first discuss the use of DBD::mysql, because this is
88       what you will need the most. For installation, see the sections on
89       INSTALLATION, and "WIN32 INSTALLATION" below. See EXAMPLE for a simple
90       example above.
91
92       From perl you activate the interface with the statement
93
94           use DBI;
95
96       After that you can connect to multiple MySQL database servers and send
97       multiple queries to any of them via a simple object oriented interface.
98       Two types of objects are available: database handles and statement han‐
99       dles. Perl returns a database handle to the connect method like so:
100
101         $dbh = DBI->connect("DBI:mysql:database=$db;host=$host",
102                             $user, $password, {RaiseError => 1});
103
104       Once you have connected to a database, you can can execute SQL state‐
105       ments with:
106
107         my $query = sprintf("INSERT INTO foo VALUES (%d, %s)",
108                             $number, $dbh->quote("name"));
109         $dbh->do($query);
110
111       See DBI(3) for details on the quote and do methods. An alternative
112       approach is
113
114         $dbh->do("INSERT INTO foo VALUES (?, ?)", undef,
115                  $number, $name);
116
117       in which case the quote method is executed automatically. See also the
118       bind_param method in DBI(3). See "DATABASE HANDLES" below for more
119       details on database handles.
120
121       If you want to retrieve results, you need to create a so-called state‐
122       ment handle with:
123
124         $sth = $dbh->prepare("SELECT * FROM $table");
125         $sth->execute();
126
127       This statement handle can be used for multiple things. First of all you
128       can retreive a row of data:
129
130         my $row = $sth->fetchrow_hashref();
131
132       If your table has columns ID and NAME, then $row will be hash ref with
133       keys ID and NAME. See "STATEMENT HANDLES" below for more details on
134       statement handles.
135
136       But now for a more formal approach:
137
138       Class Methods
139
140       connect
141               use DBI;
142
143               $dsn = "DBI:mysql:$database";
144               $dsn = "DBI:mysql:database=$database;host=$hostname";
145               $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
146
147               $dbh = DBI->connect($dsn, $user, $password);
148
149           A "database" must always be specified.
150
151           host
152           port
153               The hostname, if not specified or specified as '', will default
154               to an MySQL daemon running on the local machine on the default
155               port for the UNIX socket.
156
157               Should the MySQL daemon be running on a non-standard port num‐
158               ber, you may explicitly state the port number to connect to in
159               the "hostname" argument, by concatenating the hostname and port
160               number together separated by a colon ( ":" ) character or by
161               using the  "port" argument.
162
163           mysql_client_found_rows
164               Enables (TRUE value) or disables (FALSE value) the flag
165               CLIENT_FOUND_ROWS while connecting to the MySQL server. This
166               has a somewhat funny effect: Without mysql_client_found_rows,
167               if you perform a query like
168
169                 UPDATE $table SET id = 1 WHERE id = 1
170
171               then the MySQL engine will always return 0, because no rows
172               have changed.  With mysql_client_found_rows however, it will
173               return the number of rows that have an id 1, as some people are
174               expecting. (At least for compatibility to other engines.)
175
176           mysql_compression
177               As of MySQL 3.22.3, a new feature is supported: If your DSN
178               contains the option "mysql_compression=1", then the communica‐
179               tion between client and server will be compressed.
180
181           mysql_connect_timeout
182               If your DSN contains the option "mysql_connect_timeout=##", the
183               connect request to the server will timeout if it has not been
184               successful after the given number of seconds.
185
186           mysql_read_default_file
187           mysql_read_default_group
188               These options can be used to read a config file like
189               /etc/my.cnf or ~/.my.cnf. By default MySQL's C client library
190               doesn't use any config files unlike the client programs (mysql,
191               mysqladmin, ...) that do, but outside of the C client library.
192               Thus you need to explicitly request reading a config file, as
193               in
194
195                   $dsn = "DBI:mysql:test;mysql_read_default_file=/home/joe/my.cnf";
196                   $dbh = DBI->connect($dsn, $user, $password)
197
198               The option mysql_read_default_group can be used to specify the
199               default group in the config file: Usually this is the client
200               group, but see the following example:
201
202                   [client]
203                   host=localhost
204
205                   [perl]
206                   host=perlhost
207
208               (Note the order of the entries! The example won't work, if you
209               reverse the [client] and [perl] sections!)
210
211               If you read this config file, then you'll be typically con‐
212               nected to localhost. However, by using
213
214                   $dsn = "DBI:mysql:test;mysql_read_default_group=perl;"
215                       . "mysql_read_default_file=/home/joe/my.cnf";
216                   $dbh = DBI->connect($dsn, $user, $password);
217
218               you'll be connected to perlhost. Note that if you specify a
219               default group and do not specify a file, then the default con‐
220               fig files will all be read.  See the documentation of the C
221               function mysql_options() for details.
222
223           mysql_socket
224               As of MySQL 3.21.15, it is possible to choose the Unix socket
225               that is used for connecting to the server. This is done, for
226               example, with
227
228                   mysql_socket=/dev/mysql
229
230               Usually there's no need for this option, unless you are using
231               another location for the socket than that built into the
232               client.
233
234           mysql_ssl
235               A true value turns on the CLIENT_SSL flag when connecting to
236               the MySQL database:
237
238                 mysql_ssl=1
239
240               This means that your communication with the server will be
241               encrypted.
242
243               If you turn mysql_ssl on, you might also wish to use the fol‐
244               lowing flags:
245
246           mysql_ssl_client_key
247           mysql_ssl_client_cert
248           mysql_ssl_ca_file
249           mysql_ssl_ca_path
250           mysql_ssl_cipher
251               These are used to specify the respective parameters of a call
252               to mysql_ssl_set, if mysql_ssl is turned on.
253
254           mysql_local_infile
255               As of MySQL 3.23.49, the LOCAL capability for LOAD DATA may be
256               disabled in the MySQL client library by default. If your DSN
257               contains the option "mysql_local_infile=1", LOAD DATA LOCAL
258               will be enabled.  (However, this option is *ineffective* if the
259               server has also been configured to disallow LOCAL.)
260
261           Prepared statement support (server side prepare)
262               To use server side prepared statements, all you need to do is
263               set the variable mysql_server_prepare in the connect:
264
265               $dbh = DBI->connect(
266                                   "DBI:mysql:database=test;host=local‐
267               host:mysql_server_prepare=1",
268                                   "",
269                                   "",
270                                   { RaiseError => 1, AutoCommit => 1 }
271                                   );
272
273               To make sure that the 'make test' step tests whether server
274               prepare works, you just need to export the env variable
275               MYSQL_SERVER_PREPARE:
276
277               export MYSQL_SERVER_PREPARE=1
278
279               Test first without server side prepare, then with.
280
281           mysql_embedded_options
282               The option <mysql_embedded_options> can be used to pass 'com‐
283               mand-line' options to embedded server.
284
285               Example:
286
287               $testdsn="DBI:mysqlEmb:database=test;mysql_embed‐
288               ded_options=--help,--verbose";
289
290           mysql_embedded_groups
291               The option <mysql_embedded_groups> can be used to specify the
292               groups in the config file(my.cnf) which will be used to get
293               options for embedded server.  If not specified [server] and
294               [embedded] groups will be used.
295
296               Example:
297
298               $testdsn="DBI:mysqlEmb:database=test;mysql_embed‐
299               ded_groups=embedded_server,common";
300
301       Private MetaData Methods
302
303       ListDBs
304               my $drh = DBI->install_driver("mysql");
305               @dbs = $drh->func("$hostname:$port", '_ListDBs');
306               @dbs = $drh->func($hostname, $port, '_ListDBs');
307               @dbs = $dbh->func('_ListDBs');
308
309           Returns a list of all databases managed by the MySQL daemon running
310           on $hostname, port $port. This method is rarely needed for data‐
311           bases running on "localhost": You should use the portable method
312
313               @dbs = DBI->data_sources("mysql");
314
315           whenever possible. It is a design problem of this method, that
316           there's no way of supplying a host name or port number to
317           "data_sources", that's the only reason why we still support "List‐
318           DBs". :-(
319
320       Server Administration
321
322       admin
323               $rc = $drh->func("createdb", $dbname, [host, user, password,], 'admin');
324               $rc = $drh->func("dropdb", $dbname, [host, user, password,], 'admin');
325               $rc = $drh->func("shutdown", [host, user, password,], 'admin');
326               $rc = $drh->func("reload", [host, user, password,], 'admin');
327
328                 or
329
330               $rc = $dbh->func("createdb", $dbname, 'admin');
331               $rc = $dbh->func("dropdb", $dbname, 'admin');
332               $rc = $dbh->func("shutdown", 'admin');
333               $rc = $dbh->func("reload", 'admin');
334
335           For server administration you need a server connection. For obtain‐
336           ing this connection you have two options: Either use a driver han‐
337           dle (drh) and supply the appropriate arguments (host, defaults
338           localhost, user, defaults to '' and password, defaults to ''). A
339           driver handle can be obtained with
340
341               $drh = DBI->install_driver('mysql');
342
343           Otherwise reuse the existing connection of a database handle (dbh).
344
345           There's only one function available for administrative purposes,
346           comparable to the m(y)sqladmin programs. The command being execute
347           depends on the first argument:
348
349           createdb
350               Creates the database $dbname. Equivalent to "m(y)sqladmin cre‐
351               ate $dbname".
352
353           dropdb
354               Drops the database $dbname. Equivalent to "m(y)sqladmin drop
355               $dbname".
356
357               It should be noted that database deletion is not prompted for
358               in any way.  Nor is it undo-able from DBI.
359
360                   Once you issue the dropDB() method, the database will be gone!
361
362               These method should be used at your own risk.
363
364           shutdown
365               Silently shuts down the database engine. (Without prompting!)
366               Equivalent to "m(y)sqladmin shutdown".
367
368           reload
369               Reloads the servers configuration files and/or tables. This can
370               be particularly important if you modify access privileges or
371               create new users.
372

DATABASE HANDLES

374       The DBD::mysql driver supports the following attributes of database
375       handles (read only):
376
377         $errno = $dbh->{'mysql_errno'};
378         $error = $dbh->{'mysql_error};
379         $info = $dbh->{'mysql_hostinfo'};
380         $info = $dbh->{'mysql_info'};
381         $insertid = $dbh->{'mysql_insertid'};
382         $info = $dbh->{'mysql_protoinfo'};
383         $info = $dbh->{'mysql_serverinfo'};
384         $info = $dbh->{'mysql_stat'};
385         $threadId = $dbh->{'mysql_thread_id'};
386
387       These correspond to mysql_errno(), mysql_error(),
388       mysql_get_host_info(), mysql_info(), mysql_insert_id(),
389       mysql_get_proto_info(), mysql_get_server_info(), mysql_stat() and
390       mysql_thread_id(), respectively.
391
392        $info_hashref = $dhb->{mysql_dbd_stats}
393
394       DBD::mysql keeps track of some statistics in the mysql_dbd_stats
395       attribute.  The following stats are being maintained:
396
397       auto_reconnects_ok
398           The number of times that DBD::mysql successfully reconnected to the
399           mysql server.
400
401       auto_reconnects_failed
402           The number of times that DBD::mysql tried to reconnect to mysql but
403           failed.
404
405       The DBD::mysql driver also supports the following attribute(s) of data‐
406       base handles (read/write):
407
408        $bool_value = $dbh->{mysql_auto_reconnect};
409        $dbh->{mysql_auto_reconnect} = $AutoReconnect ? 1 : 0;
410
411       mysql_auto_reconnect
412           This attribute determines whether DBD::mysql will automatically
413           reconnect to mysql if the connection be lost. This feature defaults
414           to off; however, if either the GATEWAY_INTERFACE or MOD_PERL
415           envionment variable is set, DBD::mysql will turn mysql_auto_recon‐
416           nect on.  Setting mysql_auto_reconnect to on is not advised if
417           'lock tables' is used because if DBD::mysql reconnect to mysql all
418           table locks will be lost.  This attribute is ignored when AutoCom‐
419           mit is turned off, and when AutoCommit is turned off, DBD::mysql
420           will not automatically reconnect to the server.
421
422       mysql_use_result
423           This attribute forces the driver to use mysql_use_result rather
424           than mysql_store_result. The former is faster and less memory con‐
425           suming, but tends to block other processes. (That's why
426           mysql_store_result is the default.)
427
428       It is possible to set default value of the "mysql_use_result" attribute
429       for $dbh using several ways:
430
431        - through DSN
432
433          $dbh= DBI->connect("DBI:mysql:test;mysql_use_result=1", "root", "");
434
435        - after creation of database handle
436
437          $dbh->{'mysql_use_result'}=0; #disable
438          $dbh->{'mysql_use_result'}=1; #enable
439
440       It is possible to set/unset the "mysql_use_result" attribute after cre‐
441       ation of statement handle. See below.
442

STATEMENT HANDLES

444       The statement handles of DBD::mysql support a number of attributes. You
445       access these by using, for example,
446
447         my $numFields = $sth->{'NUM_OF_FIELDS'};
448
449       Note, that most attributes are valid only after a successfull execute.
450       An "undef" value will returned in that case. The most important excep‐
451       tion is the "mysql_use_result" attribute: This forces the driver to use
452       mysql_use_result rather than mysql_store_result. The former is faster
453       and less memory consuming, but tends to block other processes. (That's
454       why mysql_store_result is the default.)
455
456       To set the "mysql_use_result" attribute, use either of the following:
457
458         my $sth = $dbh->prepare("QUERY", { "mysql_use_result" => 1});
459
460       or
461
462         my $sth = $dbh->prepare("QUERY");
463         $sth->{"mysql_use_result"} = 1;
464
465       Column dependent attributes, for example NAME, the column names, are
466       returned as a reference to an array. The array indices are correspond‐
467       ing to the indices of the arrays returned by fetchrow and similar meth‐
468       ods. For example the following code will print a header of table names
469       together with all rows:
470
471         my $sth = $dbh->prepare("SELECT * FROM $table");
472         if (!$sth) {
473             die "Error:" . $dbh->errstr . "\n";
474         }
475         if (!$sth->execute) {
476             die "Error:" . $sth->errstr . "\n";
477         }
478         my $names = $sth->{'NAME'};
479         my $numFields = $sth->{'NUM_OF_FIELDS'};
480         for (my $i = 0;  $i < $numFields;  $i++) {
481             printf("%s%s", $i ? "," : "", $$names[$i]);
482         }
483         print "\n";
484         while (my $ref = $sth->fetchrow_arrayref) {
485             for (my $i = 0;  $i < $numFields;  $i++) {
486                 printf("%s%s", $i ? "," : "", $$ref[$i]);
487             }
488             print "\n";
489         }
490
491       For portable applications you should restrict yourself to attributes
492       with capitalized or mixed case names. Lower case attribute names are
493       private to DBD::mysql. The attribute list includes:
494
495       ChopBlanks
496           this attribute determines whether a fetchrow will chop preceding
497           and trailing blanks off the column values. Chopping blanks does not
498           have impact on the max_length attribute.
499
500       mysql_insertid
501           MySQL has the ability to choose unique key values automatically. If
502           this happened, the new ID will be stored in this attribute. An
503           alternative way for accessing this attribute is via
504           $dbh->{'mysql_insertid'}.  (Note we are using the $dbh in this
505           case!)
506
507       mysql_is_blob
508           Reference to an array of boolean values; TRUE indicates, that the
509           respective column is a blob. This attribute is valid for MySQL
510           only.
511
512       mysql_is_key
513           Reference to an array of boolean values; TRUE indicates, that the
514           respective column is a key. This is valid for MySQL only.
515
516       mysql_is_num
517           Reference to an array of boolean values; TRUE indicates, that the
518           respective column contains numeric values.
519
520       mysql_is_pri_key
521           Reference to an array of boolean values; TRUE indicates, that the
522           respective column is a primary key.
523
524       mysql_is_auto_increment
525           Reference to an array of boolean values; TRUE indicates that the
526           respective column is an AUTO_INCREMENT column.  This is only valid
527           for MySQL.
528
529       mysql_length
530       mysql_max_length
531           A reference to an array of maximum column sizes. The max_length is
532           the maximum physically present in the result table, length gives
533           the theoretically possible maximum. max_length is valid for MySQL
534           only.
535
536       NAME
537           A reference to an array of column names.
538
539       NULLABLE
540           A reference to an array of boolean values; TRUE indicates that this
541           column may contain NULL's.
542
543       NUM_OF_FIELDS
544           Number of fields returned by a SELECT or LISTFIELDS statement.  You
545           may use this for checking whether a statement returned a result: A
546           zero value indicates a non-SELECT statement like INSERT, DELETE or
547           UPDATE.
548
549       mysql_table
550           A reference to an array of table names, useful in a JOIN result.
551
552       TYPE
553           A reference to an array of column types. The engine's native column
554           types are mapped to portable types like DBI::SQL_INTEGER() or
555           DBI::SQL_VARCHAR(), as good as possible. Not all native types have
556           a meaningfull equivalent, for example DBD::mysql::FIELD_TYPE_INTER‐
557           VAL is mapped to DBI::SQL_VARCHAR().  If you need the native column
558           types, use mysql_type. See below.
559
560       mysql_type
561           A reference to an array of MySQL's native column types, for example
562           DBD::mysql::FIELD_TYPE_SHORT() or DBD::mysql::FIELD_TYPE_STRING().
563           Use the TYPE attribute, if you want portable types like
564           DBI::SQL_SMALLINT() or DBI::SQL_VARCHAR().
565
566       mysql_type_name
567           Similar to mysql, but type names and not numbers are returned.
568           Whenever possible, the ANSI SQL name is preferred.
569

TRANSACTION SUPPORT

571       Beginning with DBD::mysql 2.0416, transactions are supported.  The
572       transaction support works as follows:
573
574       ·   By default AutoCommit mode is on, following the DBI specifications.
575
576       ·   If you execute
577
578               $dbh->{'AutoCommit'} = 0;
579
580           or
581
582               $dbh->{'AutoCommit'} = 1;
583
584           then the driver will set the MySQL server variable autocommit to 0
585           or 1, respectively. Switching from 0 to 1 will also issue a COMMIT,
586           following the DBI specifications.
587
588       ·   The methods
589
590               $dbh->rollback();
591               $dbh->commit();
592
593           will issue the commands COMMIT and ROLLBACK, respectively. A ROLL‐
594           BACK will also be issued if AutoCommit mode is off and the database
595           handles DESTROY method is called. Again, this is following the DBI
596           specifications.
597
598       Given the above, you should note the following:
599
600       ·   You should never change the server variable autocommit manually,
601           unless you are ignoring DBI's transaction support.
602
603       ·   Switching AutoCommit mode from on to off or vice versa may fail.
604           You should always check for errors, when changing AutoCommit mode.
605           The suggested way of doing so is using the DBI flag RaiseError.  If
606           you don't like RaiseError, you have to use code like the following:
607
608             $dbh->{'AutoCommit'} = 0;
609             if ($dbh->{'AutoCommit'}) {
610               # An error occurred!
611             }
612
613       ·   If you detect an error while changing the AutoCommit mode, you
614           should no longer use the database handle. In other words, you
615           should disconnect and reconnect again, because the transaction mode
616           is unpredictable. Alternatively you may verify the transaction mode
617           by checking the value of the server variable autocommit.  However,
618           such behaviour isn't portable.
619
620       ·   DBD::mysql has a "reconnect" feature that handles the so-called
621           MySQL "morning bug": If the server has disconnected, most probably
622           due to a timeout, then by default the driver will reconnect and
623           attempt to execute the same SQL statement again. However, this be‐
624           haviour is disabled when AutoCommit is off: Otherwise the transac‐
625           tion state would be completely unpredictable after a reconnect.
626
627       ·   The "reconnect" feature of DBD::mysql can be toggled by using the
628           mysql_auto_reconnect attribute. This behaviour should be turned off
629           in code that uses LOCK TABLE because if the database server time
630           out and DBD::mysql reconnect, table locks will be lost without any
631           indication of such loss.
632

MULTITHREADING

634       The multithreading capabilities of DBD::mysql depend completely on the
635       underlying C libraries: The modules are working with handle data only,
636       no global variables are accessed or (to the best of my knowledge)
637       thread unsafe functions are called. Thus DBD::mysql is believed to be
638       completely thread safe, if the C libraries are thread safe and you
639       don't share handles among threads.
640
641       The obvious question is: Are the C libraries thread safe?  In the case
642       of MySQL the answer is "mostly" and, in theory, you should be able to
643       get a "yes", if the C library is compiled for being thread safe (By
644       default it isn't.) by passing the option -with-thread-safe-client to
645       configure. See the section on How to make a threadsafe client in the
646       manual.
647

INSTALLATION

649       Windows users may skip this section and pass over to "WIN32 INSTALLA‐
650       TION" below. Others, go on reading.
651
652       First of all, you do not need an installed MySQL server for installing
653       DBD::mysql. However, you need at least the client libraries and possi‐
654       bly the header files, if you are compiling DBD::mysql from source. In
655       the case of MySQL you can create a client-only version by using the
656       configure option --without-server.  If you are using precompiled bina‐
657       ries, then it may be possible to use just selected RPM's like MySQL-
658       client and MySQL-devel or something similar, depending on the distribu‐
659       tion.
660
661       First you need to install the DBI module. For using dbimon, a simple
662       DBI shell it is recommended to install Data::ShowTable another Perl
663       module.
664
665       I recommend trying automatic installation via the CPAN module. Try
666
667         perl -MCPAN -e shell
668
669       If you are using the CPAN module for the first time, it will prompt you
670       a lot of questions. If you finally receive the CPAN prompt, enter
671
672         install Bundle::DBD::mysql
673
674       If this fails (which may be the case for a number of reasons, for exam‐
675       ple because you are behind a firewall or don't have network access),
676       you need to do a manual installation. First of all you need to fetch
677       the modules from CPAN search
678
679          http://search.cpan.org/
680
681       The following modules are required
682
683         DBI
684         Data::ShowTable
685         DBD::mysql
686
687       Then enter the following commands (note - versions are just examples):
688
689         gzip -cd DBI-(version).tar.gz ⎪ tar xf -
690         cd DBI-(version)
691         perl Makefile.PL
692         make
693         make test
694         make install
695
696         cd ..
697         gzip -cd Data-ShowTable-(version).tar.gz ⎪ tar xf -
698         cd Data-ShowTable-(version)
699         perl Makefile.PL
700         make
701         make install
702
703         cd ..
704         gzip -cd DBD-mysql-(version)-tar.gz ⎪ tar xf -
705         cd DBD-mysql-(version)
706         perl Makefile.PL
707         make
708         make test
709         make install
710
711       During "perl Makefile.PL" you will be prompted some questions.  Other
712       questions are the directories with header files and libraries.  For
713       example, of your file mysql.h is in /usr/include/mysql/mysql.h, then
714       enter the header directory /usr, likewise for /usr/lib/mysql/libmysql‐
715       client.a or /usr/lib/libmysqlclient.so.
716

WIN32 INSTALLATION

718       If you are using ActivePerl, you may use ppm to install DBD-mysql.  For
719       Perl 5.6, upgrade to Build 623 or later, then it is sufficient to run
720
721         ppm install DBI
722         ppm install DBD::mysql
723
724       If you need an HTTP proxy, you might need to set the environment vari‐
725       able http_proxy, for example like this:
726
727         set http_proxy=http://myproxy.com:8080/
728
729       As of this writing, DBD::mysql is missing in the ActivePerl 5.8.0
730       repository. However, Randy Kobes has kindly donated an own distribution
731       and the following might succeed:
732
733         ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD-mysql.ppd
734
735       Otherwise you definitely *need* a C compiler. And it *must* be the same
736       compiler that was being used for compiling Perl itself. If you don't
737       have a C compiler, the file README.win32 from the Perl source distribu‐
738       tion tells you where to obtain freely distributable C compilers like
739       egcs or gcc. The Perl sources are available via CPAN search
740
741           http://search.cpan.org
742
743       I recommend using the win32clients package for installing DBD::mysql
744       under Win32, available for download on www.tcx.se. The following steps
745       have been required for me:
746
747       -   The current Perl versions (5.6, as of this writing) do have a prob‐
748           lem with detecting the C libraries. I recommend to apply the fol‐
749           lowing patch:
750
751             *** c:\Perl\lib\ExtUtils\Liblist.pm.orig Sat Apr 15 20:03:40 2000
752             --- c:\Perl\lib\ExtUtils\Liblist.pm      Sat Apr 15 20:03:45 2000
753             ***************
754             *** 230,235 ****
755             --- 230,239 ----
756                 # add "$Config{installarchlib}/CORE" to default search path
757                 push @libpath, "$Config{installarchlib}/CORE";
758
759             +     if ($VC  and  exists($ENV{LIB})  and  defined($ENV{LIB})) {
760             +       push(@libpath, split(/;/, $ENV{LIB}));
761             +     }
762             +
763                 foreach (Text::ParseWords::quotewords('\s+', 0, $potential_libs)){
764
765                   $thislib = $_;
766
767       -   Extract sources into C:\. This will create a directory C:\mysql
768           with subdirectories include and lib.
769
770           IMPORTANT: Make sure this subdirectory is not shared by other TCX
771           files! In particular do *not* store the MySQL server in the same
772           directory. If the server is already installed in C:\mysql, choose a
773           location like C:\tmp, extract the win32clients there.  Note that
774           you can remove this directory entirely once you have installed
775           DBD::mysql.
776
777       -   Extract the DBD::mysql sources into another directory, for example
778           C:\src\siteperl
779
780       -   Open a DOS shell and change directory to C:\src\siteperl.
781
782       -   The next step is only required if you repeat building the modules:
783           Make sure that you have a clean build tree by running
784
785             nmake realclean
786
787           If you don't have VC++, replace nmake with your flavour of make. If
788           error messages are reported in this step, you may safely ignore
789           them.
790
791       -   Run
792
793             perl Makefile.PL
794
795           which will prompt you for some settings. The really important ones
796           are:
797
798             Which DBMS do you want to use?
799
800           enter a 1 here (MySQL only), and
801
802             Where is your mysql installed? Please tell me the directory that
803             contains the subdir include.
804
805           where you have to enter the win32clients directory, for example
806           C:\mysql or C:\tmp\mysql.
807
808       -   Continued in the usual way:
809
810             nmake
811             nmake install
812
813       If you want to create a PPM package for the ActiveState Perl version,
814       then modify the above steps as follows: Run
815
816         perl Makefile.PL NAME=DBD-mysql BINARY_LOCATION=DBD-mysql.tar.gz
817         nmake ppd
818         nmake
819
820       Once that is done, use tar and gzip (for example those from the Cyg‐
821       Win32 distribution) to create an archive:
822
823         mkdir x86
824         tar cf x86/DBD-mysql.tar blib
825         gzip x86/DBD-mysql.tar
826
827       Put the files x86/DBD-mysql.tar.gz and DBD-mysql.ppd onto some WWW
828       server and install them by typing
829
830         install http://your.server.name/your/directory/DBD-mysql.ppd
831
832       in the PPM program.
833

AUTHORS

835       A good part of the current version of DBD::mysql is written by Jochen
836       Wiedmann, then was maintained by Rudy Lippan (rlippan@remotelinux.com),
837       and Prepared Statement code written by Alexey Stroganov and Patrick
838       Galbraith, and now maintained by Patrick Galbraith (patg@mysql.com),
839       with the help of various people in the community. The first version's
840       author was Alligator Descartes (descarte@symbolstone.org), who has been
841       aided and abetted by Gary Shea, Andreas König and Tim Bunce amongst
842       others.
843
844       The Mysql module was originally written by Andreas König <koenig@kul‐
845       turbox.de>. The current version, mainly an emulation layer, is from
846       Jochen Wiedmann.
847
849       This module is Large Portions Copyright (c) 2004-2006 MySQL Patrick
850       Galbraith, Alexey Stroganov, Large Portions Copyright (c) 2003-2005
851       Rudolf Lippan; Large Portions Copyright (c) 1997-2003 Jochen Wiedmann,
852       with code portions Copyright (c)1994-1997 their original authors This
853       module is released under the same license as Perl itself. See the Perl
854       README for details.
855

MAILING LIST SUPPORT

857       This module is maintained and supported on a mailing list,
858
859           perl@lists.mysql.com
860
861       To subscribe to this list, send a mail to
862
863           perl-subscribe@lists.mysql.com
864
865       or
866
867           perl-digest-subscribe@lists.mysql.com
868
869       Mailing list archives are available at
870
871           http://www.progressive-comp.com/Lists/?l=msql-mysql-modules
872
873       Additionally you might try the dbi-user mailing list for questions
874       about DBI and its modules in general. Subscribe via
875
876           http://www.fugue.com/dbi
877
878       Mailing list archives are at
879
880            http://www.rosat.mpe-garching.mpg.de/mailing-lists/PerlDB-Interest/
881            http://outside.organic.com/mail-archives/dbi-users/
882            http://www.coe.missouri.edu/~faq/lists/dbi.html
883

ADDITIONAL DBI INFORMATION

885       Additional information on the DBI project can be found on the World
886       Wide Web at the following URL:
887
888           http://www.symbolstone.org/technology/perl/DBI
889
890       where documentation, pointers to the mailing lists and mailing list ar‐
891       chives and pointers to the most current versions of the modules can be
892       used.
893
894       Information on the DBI interface itself can be gained by typing:
895
896           perldoc DBI
897
898       right now!
899
900
901
902perl v5.8.8                       2006-10-16                     DBD::mysql(3)
Impressum