Setting up MySQL for PHP applications

Author: Ruslan Yakushev

Published on March 18, 2009 by iisteam

Updated on March 18, 2009 by iisteam

Average Rating  Rate It (1)

RSS

Overview

This article provides a basic step by step guide on how to install and configure MySQL on the Windows Operating System. For more detailed instructions about installing and configuring MySQL on Windows refer to the official MySQL documentation.

Downloading and Installing MySQL

The MySQL binaries and installer can be downloaded from the official MySQL site. The instructions in this article are based on MySQL version 5.1 Community Edition installed with the Windows MSI installer.

Run the installer and choose the installation option. For a majority of the cases, the typical installation is sufficient:

However, if you want to control which components get installed or if you want to use a non-default installation path then choose the "Custom" option.

When the installation is complete, make sure to check the box to "Configure the MySQL Server now". This will launch the "MySQL Server Instance Configuration Wizard" that will guide you through the configuration process for the MySQL instance.

Configuring MySQL instance

Follow these steps in the "MySQL Server Instance Configuration Wizard" to optimize the MySQL configuration for the kind of tasks you expect it to perform.

On the first page of the wizard choose "Detailed Configuration":

On the next page choose the server type option:

Choose the "Database Usage" option:

The Database usage options control what kind of database storage engine is used on the server:

  • MyISAM – Optimized for high performance SELECT operations. It has low overhead in terms of memory usage and disk utilization, but at the cost of not supporting transactions
  • InnoDB – Provides fully ACID transactional capabilities, but at the cost of more aggressive usage of disk space and memory

For an in-depth comparison of these database engines, refer to MySQL Storage Engine Architecture. As a general recommendation – if the web applications on your server require multi-statement transactions, advanced isolation levels and row-level locking, foreign key constraints, or otherwise have a requirement for ACID features -- use InnoDB. Otherwise, use MyISAM.

Next choose the number of concurrent connections to the server:

On the next page choose networking options :

If you have mysql and web server on the same machine you may consider not enabling TCP/IP networking and instead use named pipes. Note though that some PHP applications may require TCP connection to MySQL. Refer to the application's documentation to confirm if it supports named pipes connection to MySQL.

Choose the default charset to use when creating new databases:

Next ensure that MySQL will be configured as a Windows Service:

Optionally, you can add the MySQL Bin directory to the Windows PATH environment variable. That will make it easier to launch MySQL tools from the command line.

Finally provide the password for the database administrative account, which in called "root" in MySQL. Make sure that you leave the "Create an Anonymous Account" checkbox cleared:

On the next page click "Execute" to apply all the configuration settings and to start the MySQL service:

Now you can logon to MySQL by opening a command line window and typing:

mysql -u root -p
Enter password: ******

If MySQL was configured correctly then the MySQL prompt will be shown:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server Version 5.1.32-community MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

Comments

  1. Submitted on Apr 20 2009 by
    robtheailean
    Hello Ruslan,
    I continue to be plagued by this app.
    Unfortunately, my Ecomm app uses PHP and does not seem to like MSSQL 2008 - and the developers "have no script for MSSQL"

    Running WinS2008/64 SP2; IIS 7.
    when I try to install the 64 bit version, it always failes to start the service (at the final screen.
    (mysql-5.1.32-winx64.msi)
    Followed pretty much word for word in your walk through.
    Edited "root" account (in wizard) to a strong password.

    I was left with the impression, the installer creates the "MySQL" user account and gives it "run as a service" privileges - is this incorrect?
    Rob
  2. Submitted on Jul 29 2009 by
    Giraff
    Can I control all in MySQL through this console ??

    Or do I have to install phpMyAdmin ??
  3. Submitted on Jul 29 2009 by
    ruslany
    You can install phpMyAdmin or you can install the MySQL Administrator GUI tool: http://dev.mysql.com/downloads/gui-tools/5.0.html
  4. Submitted on Aug 28 2009 by
    robtheailean
    Dear Ruslan,
    could you share your ability to format articles for printing with your colleagues?
    It is very frustrating printing out articles (not yours!) to find they are as hard to read as a legal document...
    cheers
    Rob

You must Log In to comment.