«

Setting Up Your Own Web Server on a Windows Machine – Part III (MySQL)

Posted on March 27, 2007
Filed Under Server-Side | 4 Comments     


This tutorial will walk you through the installation process of MySQL server under Windows XP. This part of the tutorial requires you to have Apache HTTP server and PHP installed on your local machine. If you haven't done so, you can read the part one of this tutorial to complete Apache installation. Also, you can complete the second part of this tutorial to have PHP installed. We will use Apache version 2.2.4, PHP 5.2.1 and MySQL 5.0.37 for this tutorial.




Downloading MySQL Distribution

We will use the latest version of MySQL. As the time of writing, the latest version is 5.0.37.

Visit MySQL official download page, choose a Windows distribution, depending on type of your processor: Windows or Windows x64. Download the one with the title Without installer, since we are doing manual installation.

Follow the link Pick a mirror and download it from the location which is closest to you. The downloaded file should have name similar to mysql-noinstall-5.0.37-win32.zip.

MySQL download location

After you downloaded the zip package, extract it to anywhere you want. The suggested location is C:\mysql.

Installing MySQL as a Windows Service

Install MySQL as a Windows Service is the most convenient way to start and stop MySQL server. Let's do it.

We need to run mysqld.exe in command prompt. So open command prompt and navigate to MySQL installation folder (typically C:\mysql). Type cd bin to change the current working directory to bin and type the following command:
mysqld --install

You should receive a message that indicates MySQL service is installed successfully (shown in the figure below).

Type net start mysql to start MySQL service.

net start mysql

You should be notified that MySQL service was started successfully.

Install MySQL as a Windows Service

Verifying MySQL Installation

Open command prompt, navigate to the bin directory of MySQL and type mysql test to verify your MySQL installation. If you see mysql> right before your command prompt cursor, your MySQL server is up and running. Type show databases; you should see a list of pre-created databases.

Run MySQL test

Troubleshooting

If you receive the following error message when you try to start MySQL service, you might need to create an option file under your Windows root:

Error: Could not start the MySQL service on Local Computer. Error 1067: The process terminated unexpectedly

To create an option file, create a new file and save as my.ini under your Windows root directory (type systemroot in the explorer to find out the location of your Windows root directory), and insert the following content:

[mysqld]
# set basedir to your installation path
basedir=E:/mysql
# set datadir to the location of your data directory
datadir=E:/mysql/data

Change basedir and datadir to their appropriate locations. basedir is the root directory of your MySQL installation, and datadir is the location where your database files reside (the default location is basedir/data).

Enabling MySQL as a PHP Extension

In order to run database driven applications from Apache, you need to enable MySQL from PHP.

To proceed, open PHP configuration file php.ini in a text editor, navigate to the line ;extension=php_mysql.dll, uncomment it by remove the comma in front of the line.

enable MySQL extension

Restart Apache service through Apache Service Monitor.

That's it. You are now ready to run many exciting web applications that require a database.

Troubleshooting

  1. First, make sure your PHP's extenstion path is configured correctly
  2. If your receive the following error:
    Error: PHP Startup: Unable to load dynamic library 'PHP_ROOT\ext\php_mysql.dll' - The sepcified module could not be found.
    Make sure php_mysql.dll is visible by Apache. Refer to Enable/Disable Extensions in PHP and PHP official documentation for more information.

Installing phpMyAdmin (Optional)

You certainly can run any SQL queries and data definition statements through command prompt, but it is rather inconvenient. phpMyAdmin can simplify SQL administrative tasks with ease. If you have no idea what phpMyAdmin is, you can find out more at phpMyAdmin official wiki.

Downloading and Installing

Grab a copy of phpMyAdmin distribution from http://www.phpmyadmin.net/home_page/downloads.php. We will use phpMyAdmin version 2.10.0.2.

Extract the downloaded package to Apache's Document Root. If you chose the default root directory during the installation, the Document Root is located at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs. Rename the extracted folder to phpMyAdmin.

phpMyAdmin Folder Name

Restart Apache using Apache Service Monitor.

You can now access phpMyAdmin from http://localhost/phpMyAdmin/. Feel free to create some test databases/tables and run SQL queries.

Conclusion

Congratulations! You are ready to run many exciting database driven web applications on your personal computer. Check them out:

And much more!

Return to tutorial home

If you find this post useful, consider donating a few bucks to help the server running cost.

Go to Top

More interesting posts ...

Subscribe to keep track of your comment.
4 Comments so far
  1. Philip Kyriacou October 24, 2007 2:05 am
    If only all tutorials were like this one, hope I can find a PHP tutorial on your site.
  2. Cuong October 25, 2007 10:17 am
    How about this one "here":http://thecodecentral.com/2007/03/25/setting-up-your-own-web-server-with-apache-http-server-php-and-mysql-on-a-windows-machine-part-ii.
  3. wayne November 10, 2007 7:55 pm
    Hi
    Steffen
    When doing mysql test via cmd prompt get a error 1045(28000):Access denied for user 'ODBC@localhost' report
  4. Cuong November 12, 2007 11:22 am
    In this case, you may need to provide an username, try

    <pre>
    mysql test -u root


    If that doesn't work, you need to supply a password:
    <pre>
    mysql test -u root -p
Code Central Special

Polls

  • Tell other about your screen resolution (pulled from web stats):

    View Results

    Loading ... Loading ...

Recent Comments