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
Download MySQL v5.1
Download MySQL from
http://dev.mysql.com/downloads/mysql/5.1.html Just make sure you get a Windows Essentials (x86) binary version. (after you click the "pick a mirror," 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.33-win32.msi
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.
Getting PHP5 to work with MySQL - Official Info
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).
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
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");
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
Fatal error: Call to undefined function mysql_connect()
I get this error - i did restart apache a few times to make sure
Fatal error: Call to undefined function mysql_connect() in C:\webserver\Apache\htdocs\mysqltest.php on line 12Fatal error: Call to undefined function mysql_connect()
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. However, I did notice that while using a MySQL5.1 server every time I load a page that tries to connect to MySQL, I get a Connection was reset error....
Windows 7
For your "Connection was reset" error, what is that referring to? MySQL resetting its connection to PHP, or Apache resetting the connection to the browser? If it's MySQL, will it let you directly connect via command line?
Also, I've noticed Windows 7 is notorious for not mapping 127.0.0.1 localhost out in C:\Windows\System32\drivers\etc\hosts and I've seen that cause a few weird errors (it's either commented out or just listed as ::localhost).
Answer
Error while installing MySQL
I got this error.
Could not connect to Service Control Manager. Error: 0Please help,
madan712
Answer - Service Control Manager
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 and running 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).
Could not start the service MySQL service error:0
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..
Could not start the service MySQL service error:0
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.
Answer - Further MySQL Debugging
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: