Friday, August 20, 2010

How to install MySQL on Windows 7



This blog post is on how to install MySQL on Windows 7 is in continuation to the Apache and PHP installations on the same operating system. Before we begin, I like you to determine the system type - whether your computer is 32 bit or 64 bit. This is important as I had a horrendous time trying to troubleshoot PHP-MySQL connection problem - I have detailed this in a blog post - MySQL on a 64 bit Windows 7. You can know the system type from the "Control Panel" -> "System and Security" -> "System".

Download MySQL installer file
Be sure to choose the MySQL installer file that corresponds to your system type. For me, it was the mysql-essential-5.1.40-winx64.msi file from the MySQL.com web site. I chose the essentials file because it is sufficient for my needs. However, there is nothing stopping you from picking the bulky Windows MSI Installer if you want.

Instructions to install MySQL on Windows 7
The screenshots have been presented in a slideshow below - refer these if you have doubts. The process of installing MySQL is not very difficult, so don't be intimidated by the large number of slides; I just wanted to be thorough.



  • Start MySQL installation by double-clicking the .msi file - click "Run" when prompted - [Slide 1].

  • Click "Next" button in the introductory window - [Slide 2].

  • In the following screen, select Custom installation which will allow you to specify the folder to which MySQL will be installed. You can go ahead with a Typical MySQL setup but this will put MySQL deep down in the "Program Files" folder - [Slide 3].

  • Click the "Change" button and enter C:\MySQL in the Folder name field. Hit "OK" when done - [Slides 4 and 5].

  • The installer will change the MySQL installation folder to the one specified by you - [Slide 6].

  • You are now ready to install MySQL on Windows 7 operating system. Click "Install" - [Slide 7].

  • It would take some time for the progress bar to move ahead... be patient - [Slide 8].

  • You may also get messages along the way - simply click on "Next" to proceed - [Slide 9].

  • When the process finishes, you'll get to see the final screen. Congratulations - MySQL has been installed on your computer. You are now prompted to Configure the MySQL server and register the product. In the interest of time, I had unchecked the second box and clicked "Finish". You can do the same if you want - [Slide 10].

  • MySQL instance configuration is important - you cannot use the software until you do so. Click "Next" to proceed - [Slide 11].

  • Select "Detailed Configuration" option - [Slide 12].

  • Choose "Developer Machine" - [Slide 13].

  • I suggest going ahead with "Multifunctional Database" unless you know what you are doing - [Slide 14].

  • In the following screen, don't mess with the default values and click "Next" - [Slide 15].

  • The same goes for the subsequent screen - click "Next" - [Slide 16].

  • For the networking options configuration, put a check mark in front of "Enable Strict Mode" if it's not there - [Slide 17].

  • Yes, it's recommended to install MySQL as a Windows service and have the system include the MySQL bin directory in the Windows PATH variable - [Slide 18].

  • The password for the MySQL server instance has to be typed in twice. Remember to keep a note of it - Don't lose this MySQL password - [Slide 19].

  • The configuration wizard has received all the information it needs and is ready to create a MySQL server instance. Click "Execute" button - [Slide 20].

  • The instance should be configured without problems. If you do get a message from an anti-virus program or the Windows 7 operating system - choose the option to move ahead - [Slides 21 and 22].

Checking the MySQL installation

The easiest way to check MySQL installation and confirm that it's working properly is to use the MySQL Command Line Client. Fire it up from "All Programs" -> "MySQL" -> "MySQL Server 5.1" - [Slide 23].
Now enter the MySQL password - the characters you type will be replaced by the asterisk sign (the password is not shown for security reasons - obviously) - [Slide 24].
The MySQL client displays the mysql> prompt on successful login - [Slide 25]. Type show databases; (the semi-colon at the end is not a typo) and hit the enter key. This simple SQL command instructs MySQL to display the names of the installed databases, which should be three. Hurray - rejoice because you have been able to correctly install MySQL on Windows 7! [ Slide 26]

Configuring PHP to work with the MySQL installation

The PHP configuration file is php.ini located right in the install directory which should be C:/PHP if you have followed my instructions on how to install PHP on Windows 7 computer. We now have to modify this file so that all the three - Apache, PHP and MySQL - work together.

  • By default, PHP doesn't display error messages. This may be a good idea on a web server (security reasons) but for a developer machine (such as your local computer), you would like to see errors. The PHP error messages can point to the line which is causing your scripts to fail.
    [Slide 27] - Find the line
    error_reporting = E_ALL and change it to error_reporting = E_ALL & ~E_NOTICE
    [Slide 28] - Also change
    display_errors = Off to display_errors = On.

  • PHP also needs to be told the directory in which the extensions reside. Unearth the extension_dir = "./" line and change it to extension_dir = C:\PHP\ext. (I've assumed you've installed PHP in C:/PHP. If not, you have to specify the correct path.) - [Slide 29]

  • We need PHP to work with MySQL and, hence, have to load the required extensions. Locate the 'Extensions' section and uncomment (remove the semicolon in front of) the following lines - [Slide 30].extension=php_mysql.dll
    extension=php_mysqli.dll


  • [Slide 31] - Locate the register_globals = Off line and change it to register_globals = On. Experienced developers would tell you not to go ahead with this modification. I do this because a lot of my scripts won't work otherwise - I leave the decision to you.
Save the php.ini file and restart your computer - this will give you time to stretch your legs. By the way, as I had mentioned in the beginning, you have to a web server for PHP to work - read install Apache on Windows 7 for instructions.
Finally, if you have already been using MySQL on another computer you can quickly transfer the databases and tables using mysqldump and the mysql programs.

0 comments:

Post a Comment

Recommend this

Related Posts Plugin for WordPress, Blogger...