Install MySQL

Table of contents

Introduction

MySQL is the world's most popular open source database software, with over 100 million copies of its software downloaded or distributed throughout its history. With its superior speed, reliability, and ease of use, MySQL has become the preferred choice for Web, Web 2.0, SaaS, ISV, Telecom companies and forward-thinking corporate IT Managers because it eliminates the major problems associated with downtime, maintenance and administration for modern, online applications.

MySQL is a key part of LAMP (Linux, Apache, MySQL, PHP / Perl / Python), the fast-growing open source enterprise software stack. More and more companies are using LAMP as an alternative to expensive proprietary software stacks because of its lower cost and freedom from platform lock-in.

The MySQL database is owned, developed and supported by Sun Microsystems, one of the world's largest contributors to open source software. MySQL was originally founded and developed in Sweden by two Swedes and a Finn: David Axmark, Allan Larsson and Michael "Monty" Widenius, who had worked together since the 1980's. More historical information on MySQL is available on Wikipedia.

http://www.mysql.com/about/

Download

Download and install MySQL from http://dev.mysql.com/downloads/. Just make sure you get the free MySQL Community Server release.

In this tutorial we will use the Windows Essentials package.

Install MySQL v5.x

Run the executable file and use the following settings:

  1. Typical setup type
  2. Check Configure the MySQL Server now

    If the MySQL Server Instance Configuration Wizard doesn't show up you may need to hack the C:\<MYSQL_INSTALLATION_FOLDER>\MySQL Server 5.0\bin\MySQLInstanceConfig.exe file.

  3. Choose Detailed Configuration option
  4. Choose Developer Machine option
  5. Choose Multifunctional Database option
  6. In the InnoDB Tablespace Settings screen leave the default values
  7. Choose Decision Support (DSS)/OLAP option
  8. Make sure to check Enable TCP/IP Networking and Enable Strict Mode options and leave the port number at 3306 (if you have a firewall, check the Add firewall exception for this port option)
  9. Choose Best Support For Multilingualism option (UTF-8 as the default character set)
  10. Check Install As Windows Service and Include Bin DIrectory in Windows PATH options
  11. Enter your root password and leave the Enable root access from remote machines option alone
  12. Hit Execute to start the configuration

Getting PHP to work with MySQL

  1. Include C:\php in the system PATH (this process is explained in a FAQ entry).
  2. Then open your php.ini file in a text editor and search for ;extension=php_mysql.dll and remove the ; character in front of the line.
  3. Restart Apache and check for any error. If it complains about php_mysql.dll either your extension folder (i.e. C:\php\ext) isn't correctly configured or windows can't find the C:\php\libmysql.dll file.

Testing MySQL

Create a test.php file in your DocumentRoot folder and put the code hereinafter into it.

<?php
    // hostname or ip of the server (for local testing localhost should work)
    $dbServer = "localhost";

    // username and password to log onto db server (what you entered in MySQL installation)
    $dbUser = "root";
    $dbPass = "";

    // name of database (MySQL by default comes with an empty database named "test")
    $dbName = "test";

    // open server connection
    $link = mysql_connect($dbServer, $dbUser, $dbPass) or die("Could not connect to server");
    echo "<p>Connected successfully</p>";

    // test database connection
    mysql_select_db($dbName) or die("Could not select database");
    echo "<p>Database selected successfully</p>";

    // close server connection
    mysql_close($link);
?>

Open your browser and head to http://localhost/test.php, you should get two success messages.