How to install MySQL on Windows

Note

The older MySQL 4.0 tutorial has been completely removed as of Jan 1, 2010. The official site no longer even has the 4.0 binaries available so there's no point in keeping the tutorial. Please use the MySQL 5.1 tutorial below instead.

MySQL 5.1

  1. Download MySQL v5.1

    Download MySQL from http://dev.mysql.com/downloads/mysql/5.1.html and get the Windows Essentials (x86) MSI Installer version. (after you click the download link, if it asks you to login scroll down a little and click the "No thanks, just take me to the downloads!" link under the login form)

    My file was named: mysql-essential-5.1.54-win32.msi
    NOTE about 64-bit
    MySQL is the only software in the main list (Apache, PHP, MySQL) that has a 64-bit Windows version. I did not test the 64-bit version of MySQL, but if you have a 64-bit Windows version, you should be fine if you want to download/install it. Otherwise use the 32-bit version (the 32-bit version will work on either type of machine).
  2. Install MySQL v5.1

    Run the MSI file and use the following settings
    • Typical Setup
    • Skip Sign-Up
    • make sure "Configure the MySQL Server now" is checked
    • "Detailed Configuration"
    • "Developer Machine"
    • "Multifunctional Database"
    • "InnoDB Tablespace Settings" - leave everything default
    • "Decision Support (DSS)/OLAP"
    • make sure "Enable TCP/IP Networking" is checked and leave the port number at 3306 (at this point, if you have a firewall, it will usually try to access itself on the localhost)
      Leave "Enable Strict Mode" checked
    • "Standard Character Set"
    • check "Install As Windows Service" and I would recommend leaving "Launch the MySQL Server automatically" checked.
    • enter a root password (and remember/write it down) and I would recommend leaving "Enable root access from remote machines" unchecked
    • then hit "execute" and it'll install and set it up.
  3. Getting PHP5 to work with MySQL - Official Info

    Then open up your php.ini in a text editor and search for ;extension=php_mysql.dll and remove the ; infont of that line.

    Restart Apache and see if you get any errors. If it complains about "php_mysql.dll" either your PHP extension directory isn't correct or windows can't find libmysql.dll
  4. Testing MySQL

    Testing MySQL is not exactly easy. However, here are the common connection strings for PHP. I recommend downloading phpMyAdmin and using it to create and manage your databases, etc.

    PHP Connection test
    <?php
    // hostname or ip of server (for local testing, localhost should work)
    $dbServer='localhost';
    
    // username and password to log onto db server
    $dbUser='root';
    $dbPass='';
    
    // name of database
    $dbName='test';
    
        $link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect: ". mysql_error());
        print "Connected successfully<br>";
        mysql_select_db("$dbName") or die("Could not select database");
        print "Database selected successfully<br>";
    
    // close connection
    mysql_close($link);
    ?>
    


Comments

Hii..I tried to install MySQL as you suggested but when i try to execute at the last screen....its showing an error message like
Could not start the service.MySQL error:0.

Please Help me!!!Im banging my head against my keyboard to solve this problem from weeks..

I've had several people tell me if they manually change the service name to something other than default (like "dbmysql5") when installing the service it then works for them.

There should also be an error file in the mysql data directory named like <my_hostname>.err that you can open in a text editor. It might provide you with more details.

Also you can try to start mysql from command prompt like:
C:\Program Files\MySQL\MySQL Server 5.0\bin> mysqld-nt.exe --console
which should also give you more details.

May I also suggest that you right-click on the MySQL installer, scroll down to properties and look at the bottom of that window. Some versions of Windows will block files that have been downloaded from the net, until you explicitly go into the properties window for that file and click the unblock button. If your installer was blocked, I would suggest removing your MySQL server instance, then uninstalling MySQL all together, physically go into your program files folder and delete the MySQL folder that will still exist after you uninstall. Then go through and reinstall MySQL as suggested.

I got this error.
Could not connect to Service Control Manager. Error: 0

Please help,
madan712

Your "Could not connect to Service Control Manager. Error: 0" is MySQL complaining it does not have access to Window's service manager.

1) You need to make sure you are installing MySQL as Administrator. You can't do it from a limited account.

2) Your "User Access Control" in Vista (Windows 7 also has a similar setting) might be set to high. The settings for that should be somewhere under Control Panel > User Accounts (I'm currently not at a machine where I can check the exact location or wording).

If you are running a 64-bit version of Windows 7 (such as I am), I noticed that I get the same error if I put libmysql.dll in C:\Windows\System32 as suggested. If libmysql.dll is placed in C:\Windows instead, PHP will see libmysql.

This solution worked for me perfectly. It took me several attempts, but it worked. Whenever you make a change, reboot your computer.

I've been all over the internet and this was really driving me crazy. I finally stumbled on your comment and like magic everything worked!

I have tried your solution and I am getting no result. I have made sure extension=php_mysql.dll is uncommented in php.ini. I have put libmysql.dll in System32, then Windows, then restarted my computer...still no result.

Please, I would appreciate any help.

After some digging, I think the problem has to do with Windows 7 hosts file C:\Windows\System32\drivers\etc\hosts and it not correctly mapping localhost to 127.0.0.1 by default.
Anyway, I used "127.0.0.1", and it worked. Thank you very much! I would have never figured that out. :)

Apparently as of PHP v5.3.0 "libmysql.dll isn't needed anymore as mysqlnd was introduced as client library."

However, if you still refer to their official installation instructions they still talk about libmysql.dll as does the text files including in the zip. That's awesome ...

I'm going to quote my original instructions here for anyone using PHP older than 5.3.0:

Unfortunately PHP5 removed built-in support for MySQL. To get it to work, the easiest way is to copy the mysql library file by hand. Open the folder you unzipped your PHP to. Copy the libmysql.dll file (should be located like C:\php\libmysql.dll ) into your Window's System folder (usually C:\Windows\System32\ although might be C:\WinNT\System\ or something).

People using newer versions of MySQL shouldn't have to worry about it anymore (I did a clean install of everything and it does appear libmysql.dll is not needed anymore).

I updated the tutorial to reflect all this, but it would be nice if someone can confirm all this that it worked for them without messing with libmysql.dll

i get this error while installing mysql server..
the security setting could not be applied to the database because connection has failed with the following error:
Error No.1045
Access denied for user 'root'@'localhost'(using password:YES)

please suggest something as soon as possible...

Am trying to install v. 5.5 for Windows. I get the following error during the configuration step:

mysql-server-5.5-win32-gpl:99 - Unable to configure service.

I did a search on the internet and found one other person had the same issue, but no one has posted a solution. Any help would be greatly appreciated.

For reference, here's the entire configuration step details:

mysql-server-5.5-win32-gpl:9 - Looking for valid template
mysql-server-5.5-win32-gpl:18 - Found valid template.
mysql-server-5.5-win32-gpl:27 - Attempting to process template.
mysql-server-5.5-win32-gpl:36 - Processed template.
mysql-server-5.5-win32-gpl:45 - Attempting to configure service.
mysql-server-5.5-win32-gpl:54 - Configured service.
mysql-server-5.5-win32-gpl:63 - Attempting to start service.
mysql-server-5.5-win32-gpl:99 - Unable to configure service.
mysql-server-5.5-win32-gpl:100 - Product configuration controller finished configuration.

I don't have any answer either, but maybe someone else will. In a general sense, I have seen errors related to config/starting of the mysql service because there was an already existing mysql service (left from a unsuccessful uninstall). But nothing from your message really suggests that could be the problem.

I think I may have solved the problem. On http://dev.mysql.com/doc/refman/5.5/en/windows-server-first-start.html I found some post-installation procedures to start the server. I then created a new connection and a new server instance following the procedures on http://wb.mysql.com/?p=406. Both succeeded. I know next to nothing about db management or db programming, but hope that I can now begin working through some tutorials. Thanks for providing a forum for sharing issues.

On windows 7 there is a hidden folder C:\ProgramData\MySQL\ that will continue to store information even after you uninstall MySQL. If you are later try to reinstall and get a "Cannot start service" error, deleting that folder and then reinstalling may allow the service to start properly.

[SITE ADMIN WARNING: not personally tested]

Big thank you to "Anonymous" above. I spent a whole day fighting and trying to reinstall MySQL. If you have installed MySQL 64-bit on Windows7 and want to install MySQL 32-bit, I recommend doing exactly this:

  1. Run "mysql-workbench-gpl-5.2.35-win32.msi" and choose Remove, if you installed the "MySQL Workbench".
  2. Run "Microsoft Visual C++ 2010 x86 Redistributable Setup" and choose Uninstall. If you installed the "MySQL Workbench" this is installed on your computer, so remove it.
  3. Run the 64-bit MySQL installer again and choose Remove.
  4. If you had problems while installing 32-bit you have to delete C:\Program Files (x86)\MySQL\ folder. Depending if you alredy tried to do a 32-bit install you have to remove this. Otherwise this directory is missing.
  5. DELETE C:\ProgramData\MySQL This is missing piece in every forum on the net... And it is a hidden directory...
  6. Delete your database if you have installed it elsewhere. I donĀ“t know if this is necessary, but I did.
  7. Reboot.
  8. Install MySQL 32-bit
  9. Now reinstall "Microsoft Visual C++ 2010 x86 Redistributable pack" and Mysql-workbench" if you use these programs.
  10. Don't forget to live happily ever after!

Some of my steps above could be unnecessary, but I describe exactly what I did and this works!

[SITE ADMIN WARNING: not personally tested]

Hey! I followed all the steps mentioned in this article however, when restarting apache, I am coming across this error. Can anyone please explain the reason behind this. Thanks in advance!

PHP Startup: Unable to load dynamic library 'C:\php\ext\php_mysql.dll' - The specified modul could not be found.

Ok never mind! I figured the solution to this problem :)

All you have to do is copy the "libmysql.dll" file from your php directory and then store it in C:/windows/system32

I installed php 5.3.8 with apache 2.2.21 and MySQL 5.1.60 on my VISTA machine and tested with no problems but when I did the same installation on my Win 7 machine and ran the recommended test program i get

Fatal error: Call to unudentified function mysql_connect() in c:/........ (where the php program is) on line 12 (which is the calling line of code).

The phpinfo() on the VISTA machine shows both mysql and mysqlnd but the Win 7 machine shows only mysqlnd. I have read most everything on here and tried several different things with no good results.

That usually means PHP is not loading the MySQL library. Doublecheck you uncommented the correct line from step #3 on this page and that your extension_dir from Step #4 on How to install PHP on Windows is set to the correct folder.

Oh finally.

I've copied the libmysql.dll in the php file to C:\WINDOWS\system32 and it worked! Anyway thanks, I found the solution later in the page.

Where do i find libmysql.dll, it's not in my php library.

As you suggested i double checked both items you listed. I believe they are correct as follows but still getting error.

;extension=php_exif.dll ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll ; U

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
extension_dir = "c:\php\ext"
; On windows:
extension_dir = "c:\php\ext"

Are there any other suggestions?

i am havin problem in installing mysql . in last step where i have to tick 4 option . but last option is giving problem. unable to tick that option. please help me out

Error 1045 usually has to do with an incorrect password. I can't be much more help than that. If you need to reset the MySQL password on windows, I do have that instructions for that here.