NOTE: some of you have
asked that the older version of the tutorial with MySQL 4.0 be put back
up. I am putting it back up, but will no longer update it. You can
still find it at
http://www.ricocheting.com/server/mysql4.0.html, however I recommend using the tutorial below with version MySQL 4.1.
Download & Unpack MySQL v4.1
Download and install MySQL from
http://dev.mysql.com/downloads/mysql/4.1.html Just make sure you get a Windows 95/98/NT/2000/XP/2003 (x86) binary "Windows Essentials (x86)" version. (skip all the questions part and scroll down to the mirrors list)
My file was named: mysql-essential-4.1.15-win32.msi
Install MySQL v4.1
Run the MSI file and use the following settings
- Typical Setup
- Skip Sign-Up
- make sure "Configure the MySQL Server now" is checked
- "Detailed Configuration"
- "Developer Machine"
- "Multifunctional Database"
- "InnoDB Tablespace Settings" - leave everything default
- "Decision Support (DSS)/OLAP"
- make sure "Enable TCP/IP Networking" is checked and leave the port number at 3306
(at this point, if you have a firewall, it will usually try to access itself on the localhost)
- "Standard Character Set"
- check "Install As Windows Service"
- I recommend leaving "Include Bin Directory in Windows PATH" checked
- enter your root password and I would recommend checking "Root may only connect from localhost"
- then hit "execute" and it'll install and set it up.
Getting PHP5 to work with MySQL
Unfortunately PHP5 removed built-in support for MySQL. So you'll need
to copy some files by hand. open the folder you unzipped your PHP to.
Copy the libmysql.dll
file (should be located like E:\php\libmysql.dll ) into your Window's
System folder (usually C:\Windows\System32\ although might be
C:\WinNT\System\ or something).
Then open up your php.ini in a text editor and search for ;extension=php_mysql.dll and remove the ; infont of that line.
Restart Apache and see if you get any errors. if it complains about
"php_mysql.dll" either your extention directory isn't correct or
windows can't find libmysql.dll
Testing MySQL
Testing MySQL is not exactly easy. However, here are the common connection strings for PHP and CGI. I recommend downloading phpMyAdmin and using it to create and manage your databases, etc.
PHP Connection test
<?php
// hostname or ip of server (for local testing, localhost should work)
$dbServer='localhost';
// username and password to log onto db server (what you entered in Step 4)
$dbUser='root';
$dbPass='';
// name of database (what you created in step 4)
$dbName='test';
$link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");
print "Connected successfully<br>";
mysql_select_db("$dbName") or die("Could not select database");
print "Database selected successfully<br>";
// close connection
mysql_close($link);
?>
CGI Connection test (Must have DBI module installed)
#!/usr/bin/perl
print "Content-type: text/html\n\n";
# DBI is perl module used to connect to the database
use DBI;
# hostname or ip of server (for local testing, localhost should work)
$config{'dbServer'} = "localhost";
# username and password to log onto db server (what you entered in Step 4)
$config{'dbUser'} = "root";
$config{'dbPass'} = "";
# name of database (what you created in step 4)
$config{'dbName'} = "test";
# MySQL driver (shouldn't need to change)
$config{'dataSource'} = "DBI:mysql:$config{'dbName'}:$config{'dbServer'}";
my $dbh = DBI->connect($config{'dataSource'},$config{'dbUser'},$config{'dbPass'}) or
die "Can't connect to $config{'dataSource'}<br>$DBI::errstr";
print "Connected successfully<br>";
$dbh->disconnect();
|
If you do not know how to install DBI here's how (you can go to www.cpan.org and do it by hand, but this is waaaay easier).
On your start menu there should be a ActiveState ActivePerl 5.8 > Perl Package Manager shortcut. Run it then type install dbi and it will download and install that module. When that finishes type install DBD-mysql and you are ready to go.
|