Note: If you're planning to use MySQL with PHP, follow the tutorial Installing PHP 5.3 and Apache HTTP Server on Windows 7 first, if you haven't done so already.
At the time of writing, the latest stable version is 5.5.13.
- Get it from here:
(Don't be fooled! You don't need to create an account. Follow the link "No thanks! Just take me to the downloads.")
Grab the installer ó it's much smaller than the zip archive.
You can use either the 32 or 64-bit version. Both will work with a 32-bit PHP.
- Proceed through the wizard, selecting a 'Typical' installation.
You will see a 'MySQL Enterprise' popup at some point. Dismiss it.
- Once the wizard has finished, the MySQL Server Instance Configuration Wizard starts.
- Select 'Detailed Configuration'.
- Select 'Developer Machine'.
- Select 'Multifunctional database'.
- Select a drive.
- Select 'Manual setting', then enter a small number of concurrent connections.
- The default server port is 3306. If you change this, you'll need to specify the port in any applications that connect to the server.
- Select 'Best Support for Multilingualism'. This will set the default character set to UTF-8.
- Select "Include Bin Directory in Windows PATH".
- Enter a password, then finish the wizard.
The settings will be written to a file (my.ini).
If the wizard freezes for more than about 20 seconds at this point, close it and run it again... It's in bin under the directory where you installed MySQL.
- Test the installation by running the MySQL command-line client.
- Create a test database. We'll use this in the next section.
Configuring the MySQL Client
If this is a development machine, you might want to set up your client to log in as 'root' by default. To do this, set up a file called my.cnf and place it in your C:\ directory.
(On Unix platforms, the MySQL client looks in your home directory for this file. Frustratingly, the Windows client does not do this.)
Connecting to MySQL from PHP
- Open the php.ini configuration file in a text editor.
Find the line ; extension_dir = "ext" and change it to:
(If you installed PHP into a different directory, use that path instead.)
extension_dir = "c:\php\ext\"
- Find the line ;extension=php_pdo_mysql.dll and uncomment it by removing the semicolon.
- Restart the Apache server.
- Copy the following listing into a new file under your htdocs directory.
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', 'PASSWORD');
$st = $dbh->prepare('select bar from foo');
- Navigate to that file using your web browser. You should see something like this: