Access mSQL and MySQL through Perl _ MySQL

Source: Internet
Author: User
Access the content of mSQL and MySQL through Perl 1) knowledge preparation:
  
To use Perl to access the content of the mSQL and MySQL databases, you must install some API modules. The following lists the names of required modules and their download URLs: I) regular installation required module: DBI-1.13 Perl language database universal interface Data-ShowTable-3.3 Perl5 a module that defines a series of child routines, used to display the data output as beautiful four formats: simple table, boxed table, list style, and HTML format.
  
Msql-Mysql-modules-1.2209 contains two Database Drivers: DBD: mSQL and DBD: mysql, that is, mSQL and MySQL on the Perl language database universal interface driver, specifically, DBD (database driver) http://www.mysql.com/downloads/api-dbi.html ii for mSQL and MySQL database access) to use the DBD: Proxy driver and DBD: ProxyServer module that comes with the common database interfaces in Perl, you must install the following modules: net-Daemon-0.31 is an abstract basic subclass for easy implementation of portable server applications, which provides a way to implement a Daemon common task: start, log on, connect to the client, authenticate, set environment variables for security, and enter the working status.
  
Storable-0.6.11 makes data storage more continuous and stable. You can store any data structure to the disk in a recursive way. you can also retrieve data from the storage file and recreate the same structure in the memory. PlRPC-0.2012 RPC: PlServer-Perl language extensions for implementing PlRPC. It is a server-side package. it communicates with RPC: client through the share package RPC: Comm. PlRPC uses Perl to implement RPC (remote process call) by defining a series of methods that can be executed by the client (methods). http://www.perl.com/CPAN-local/modules/
  
2) installation process:
  
Download the above mentioned module installation file (all file names are followed by the module name. Tar.gz), it is best to save it in the directory:/usr/local/src, and decompress: tar zxvf ***** .tar.gz (***** indicates the module name ). this will generate the installation file directories for each module.
  
(I) install the software from left to right according to the sequence listed below, so that the system supports using the DBD: Proxy driver and DBD: ProxyServer module. Net-Daemon-0.31-Storable-0.6.11-the PlRPC-0.2012 uses the standard CPAN module installation process: perl Makefile. PL-make test-make install
  
Ii) general installation: follow the steps from left to right listed below: DBI-1.13-Data-ShowTable-3.3-installation of Msql-Mysql-modules-1.2209 modules and DBI-1.13 modules using standard CPAN module installation process: perl Makefile. PL-make test-make install the installation of the Data-ShowTable-3.3 module should be specially handled: a) This module has a test suite error, ignore the make test process. The installation process is perl Makefile. PL--make install B) completes the perl Makefile. after PL, edit ShowTable. in the pm file, locate the "= head1" section and add a line: "= head1 SYNOPSIS". save and exit. Complete the make and make file processes.
  
3) Test: Use the MySQL database (or use mSQL) to create a database: abacus and write a simple perl program: perlmysql. cgi, which reads all the table names from a database abacus and displays them.
  
#! /Usr/bin/perl
  
Use DBI; print "Content-type: text/htmlnn"; print "n"; $ driver = "mysql"; $ dbh = DBI-> connect ("DBI: mysql: abacus: mysql.szabacus.com "," root "," abcde ") | die" can not connect database "; $…… = $ dbh-> prepare (" show tables ") | die "occur an error when query database"; $ TH-> execute (); $ numRows = $ TH-> rows; while (@ row = $ TH-> fetchrow_array) {print "Table: $ row [0] n";} print "query lines = $ numRowsn"; $ Something-> finish (); $ dbh-> disconnect (); exit;
  
Save the program to the CGI directory of the system and run: chmod 755 perlmysql. cgi, and then execute: perl perlmysql in the command line. cgi. all the table names in the database abacus are displayed after normal installation. You can also use the url in IE.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.