MySQL installation

Installation

Mysql 4.0 Download

 

Download the latest production version for your operating system - The current (7/11/03) production version is 4.0.16 and my office machine is Windows 2000,

so I downloaded mysql-4.0.16-win.zip to c:

 

Unzip the file to a new directory c:\mysql

 

Run the installer: c:\mysql\SETUP.EXE

 

It installs to c:\mysql by default.

 

Server setup

Run the mysqladmintool : c:\mysql\winmysqladmin.exe

 

Set a server username and password

 

This tool will ensure that the server (For me this is c:\mysql\in\mysqld-nt.exe) will be started on startup.  It will put an icon in the status bar (like traffic lights) – this can be used to stop and start the server. The server must be running for PHP scripts to be able to connect to the database, or just to run the mysql  command line tool.

 

Command line interface

The command line interface is C:\mysql\bin\mysql.exe - make a short cut to this file on the desktop.

 

There are two initial databases : mysql containing admin tables and test which is empty.  There are no usercodes or passwords set by default.

 

Testing SQL

Start the command line interface 

 

enter

show databases;

 

there will be two, mysql and test

 

use mysql

show tables

 

there should be six tables, beginning with columns_priv

 

PHP installation

Installation

PHP download

 

Download the latest production version for your operating system - I downloaded

 

php-4.3.5-installer.exe

 

This will install and configure the local web server - which in my case is IIS

 

By default this will install in C:\php

 

Testing PHP

Create a basic php script, hello.php:

 

<?php print "hello"; ?>

 

and save to the server www home directory.

 

Note: for IIS the root is C:\Inetpub\wwwroot.  If you are unsure of its location, enter http://localhost/ in a browser.  The browser will load a default file – for IIS it is

localstart.asp. Now you can use Start/Find to locate the directory in which this file lives.

 

In Internet explorer, run the script with a URL:

 

http://localhost/hello.php

 

The browser should display 'hello'

 

To see all the PHP settings, add the line:

phpinfo();

 

Testing PHP and MysQL together

Edit the hello.php script to include a statement to connect to MySQL:

 

if(!($dbresult=mysql_connect("localhost","","")) {

 

     print "failed to connect";

}

Run the script from the browser.

 

Note the empty usercode and password - defaults until you change them in MySQL

 

To check you can read tables, add these lines to list the tables in a database:

 

$res=mysql_db_query("mysql","show tables",$dbresult);

while($ta=mysql_fetch_object($res)) {

  print ("<br/>$ta->Tables_in_mysql");

}

 

** change this to access the rows as arrays – avoids having to know the name of this column, since it changes with the database

Setting PHP defaults

PHP defaults are set in the php.ini file in c:\WINNT. These work ok but to run my scripts, you will need to turn register_globals on, so find the line

 

register_globals = off

 

and edit off to on