mlegan has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to learn database programming using the DBI interface module together with the MySql driver module. I have the MySql databse engine running on my computer and I can connect to it using the Perl interface and driver modules. What I want to do is use these perl modules to connect to a MySql engine running on a remote host. My question is, where on the web can I find such a host? I don't want to create a MySql database , I want to access already existing ones(preferably interesting ones, and preferably free). Have been searching books and the web for quite some time but can't find the answer to this simple question. Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: DBI question
by JavaFan (Canon) on Oct 18, 2008 at 22:51 UTC
    If you look at the DBD::mysql manual page, the section discussing connect has a whole bunch of examples on how to connect to a remote host. The simplest (IMO) is:
    $dbh = DBI->connect("DBI:mysql;host=HOST;database=DB;", "user", "passw +ord");
Re: DBI question
by Illuminatus (Curate) on Oct 18, 2008 at 23:37 UTC
    How would you connect to a database in a book? :) Seriously, connecting locally using DBI is no different than remotely. There are plenty of sample databases (schemas and/or data) available out there (http://dev.mysql.com/doc/world-setup/en/world-setup.html for example). mysql allows for importing from many other databases, so if you find binaries from another engine, you can probably import it. Load it up locally and have at it.
Re: DBI question
by smiffy (Pilgrim) on Oct 19, 2008 at 04:51 UTC

    If you want to learn database programming, I would say that the first thing that you should do is to become familiar with the database in question - and that means installing and setting it up. MySQL is free to download and works on most platforms.

    As to the existence of free services that you can connect to, they may exist, although I would find this unlikely. "Interesting" databases - ones that contain data - the odds are miniscule that anyone would let you have access to it. Would you let just anyone have remote access to your computer and your data? Most reasonable web hosting packages give you access to a MySQL database (or databases.) If you then go and install a ready-to-use Perl web application, you should then have an "interesting" database to examine. Look at the data from the command line client, do things to the application, look at the command line client again to see what has happened. (Note - not all hosting packages support Perl, nor will they all give you a command prompt to work with. You will not encounter this problem if you run things on your own machine(s).)

    I would also suggest that you make the effort to get your head around MySQL before you start trying to do it through Perl. The DBI/DBD layer adds an extra level of complexity. Using the MySQL command line client, you can test your queries and get familiar with the way things work, then try to do the same thing through DBI. I write web applications with Perl and MySQL; if anything should ever behave strangely, the first thing I do is to copy the SQL that Perl is using and paste it into the MySQL command line client - it is far easier to find errors this way.

    If you are really set about learning database programming with Perl, please, do your self a favour, go to dev.mysql.com and download the latest stable version for your platform. Then be sure to read the MySQL documentation and read the DBI documentation.

    And above all, have fun! There's nothing so magical and wonderful as having Perl and SQL working together.

Re: DBI question
by Xilman (Hermit) on Oct 19, 2008 at 11:11 UTC

    To start, I'll make clear that I don't know of a freely accessible MySql engine. That's an admission of ignorance, not a statement that they do not exist.

    However, I find that accessing other (relatively sane) databases is not particularly difficult once you can access any other. All you need to do install the appropriate DBD and start speaking SQL to it. The interface differences are quite minor and if you already know how to contact MySql a fewn minutes reading TFM and changing a few details in the code you arelady have will get you started.

    So if you're willing to pay the entry fee (well worth paying, purely for the education you receive in return IMO), you may like to visit a FlyBase forum posting to gain free, read-only access to a massive PostgreSQL database of genetic information. The FlyBase site is driven by the underlying database and so you can see what the data looks like at a higher level than raw SQL. I'd start by first examining the table definitions and then examining some of the simpler taples, especially the "pub" (i.e. publication) table which is a relatively straightforward implementation of a bibliographic database.

    Disclaimer: I work for FlyBase and I'm biased towards the pub table and its related tables because I'm the guy who, by and large, is in charge of the biblio portion of FlyBase.