Knowledgebase: Using mySQL
How do I to mySQL through Perl using the mySQLPerl Module?
Posted by Roy Petersen on Feb-15-2007 12:16 PM
Use the following outline to connect and begin querying the mySQL server from a Perl script. Remember that you cannot connect to your databases remotely due to security concerns, you can only connect from localhost .

1. Declarations
You must require the mySQL package for your script to function properly. Do this by including the following line in your code: use Mysql;

2. Connect To The Database
Somewhere near the beginning of your script, you need to make your initial connection to the database server. Using the following form, substitute your database, username, and password for the examples to connect successfully. The database must be a valid one that you have created through the phpMyAdmin interface in the Control Panel. The username must be the one assigned to you and must have adequate permissions to the specified database.


3. Executing A Query
You are now ready to begin querying the database server. Most problems that you may incur will generally occur due to invalid permission settings for the specified user. Remember that you can use our convenient web based PhpMyAdmin interface to view or edit these settings.