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.
Table of Contents
- 1 Downloading MySQL Distribution
- 2 Installing MySQL as a Windows Service
- 3 Verifying MySQL Installation
- 4 Enabling MySQL as a PHP Extension
- 5 Installing phpMyAdmin (Optional)
- 6 Conclusion
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.
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:
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.
You should be notified that MySQL service was started successfully.
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.
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:
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:
# set basedir to your installation path
# set datadir to the location of your data directory
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.
Restart Apache service through Apache Service Monitor.
That's it. You are now ready to run many exciting web applications that require a database.
- First, make sure your PHP's extenstion path is configured correctly
- 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 126.96.36.199.
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.
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.
Congratulations! You are ready to run many exciting database driven web applications on your personal computer. Check them out:
And much more!