4/28/09

Installing MySQL

As I mentioned above, MySQL may be downloaded free of charge. Simply proceed to http://dev.mysql.com/downloads/ and choose the recommended stable release (as of this writing, it is MySQL 4.0). On the MySQL 4.0 download page, under the heading Windows downloads, select and download the release that includes the installer. After downloading the file (it’s about 21MB as of this writing), unzip it and run the setup.exe program contained therein. Once installed, MySQL is ready to roll (barring a couple of configuration tasks that we’ll look at shortly), except for one minor issue that only affects you if you’re running Windows NT, 2000, XP, or Server 2003. If you use any of those operating systems, you need to create a file called my.cnf in the root of your C:
drive to indicate where you have installed MySQL. To create this file, simply open Notepad and type these three lines:

[mysqld]
basedir = c:/mysql/
datadir = c:/mysql/data/

If you installed MySQL into a directory other than C:\mysql, replace both occur-rences of c:/mysql in the above with the path to which you installed. Notice the use of forward slashes (/) instead of the usual backslashes (\) in the paths. For instance, on my system I edited the file to read as follows:

[mysqld]
basedir = d:/Program Files/MySQL/
datadir = d:/Program Files/MySQL/data/

Save the file as my.cnf in the root directory of C: drive.
if you don’t like the idea of a MySQL configuration file sitting in the root of your C: drive, instead, you can name it my.ini and put it in your Windows dir-ectory (e.g. C:\WINDOWS or C:\WINNT if Windows is installed on drive C:). MySQL will now run on your Windows NT, 2000, XP, or Server 2003 system! If you’re using Windows 95, 98, or ME, this step is not necessary—MySQL will run just fine as installed.
Just like your Web server, MySQL is a program that should be run in the back-ground so that it may respond to requests for information at any time. The server program may be found in the bin subfolder of the folder into which you installed MySQL. However, to complicate matters, several versions of the MySQL server are available:
mysqld.exe
This is the basic version of MySQL if you run Win-dows 95, 98, or ME. It includes support for all the advanced features, and includes debug code to provide additional information in the case of a crash (if your system is set up to debug programs). As a result of this code, however, the server might run a little slow, and
generally I’ve found that MySQL is so stable that crashes aren’t really a concern.
ysqld-opt.exe
This version of the server lacks a few of the advanced features of the basic server, and does not include the debug code. It’s optimized to run quickly on today’s processors. For beginners, the advanced features are not a big concern. You certainly won’t be using them while you complete the tasks in this book. This is the version of choice for beginners unning Windows 95, 98, or ME.
mysqld-nt.exe
This version of the server is compiled and optimized like mysqld-opt, but is designed to run under Win- dows NT, 2000, XP, or Server 2003 as a service. If you’re using any of those operating systems, this is probably the server for you
mysqld-max.exe
This version is like mysqld-opt.exe, but contains ad- vanced features that support transactions.
mysqld-max-nt.exe
This version’s similar to mysqld-nt.exe, in that it will run as a Windows service, but it has the same ad- vanced features as mysqld-max.exe.

All these versions were installed for you in the bin directory. If you’re running on Win9x/ME, I recommend you stick with mysql-opt for now—move to mysqld-max if you ever need the advanced features. On WinNT/2000/XP/2003, mysqld-nt is my recommendation. Upgrade to mysqld-max-nt when you need more ad- vanced features.
Starting MySQL is also a little different under WinNT/2000/XP/2003, but this time let’s begin with the procedure for Win9x/ME. Open an MS-DOS Command Prompt,proceed to the MySQL bin directory, and run your chosen server pro-gram:
C:\mysql\bin>mysqld-opt
Don’t be surprised when you receive another command prompt. This commandlaunches the server program so that it runs in the background, even after you close the command prompt. If you press Ctrl-Alt-Del to pull up the task list, you should see the MySQL server listed as one of the tasks that’s active on your sys-tem.
To ensure that the server is started whenever Windows starts, you might want to create a shortcut to the program and put it in your Startup folder. This is just like creating a shortcut to any other program on your system. On WinNT/2000/XP/2003, you must install MySQL as a system service. Fortu-nately, this is very easy to do. Simply open a Command Prompt (under Accessories in the Start Menu) and run your chosen server program with the --install op-tion:

C:\mysql\bin>mysqld-nt --install
Service successfully installed.

This will install MySQL as a service that will be started the next time you reboot Windows. To start MySQL manually without having to reboot, just type this command (which can be run from any directory):

C:\>net start mysql
The MySQL service is starting.
The MySQL service was started successfully.

To verify that the MySQL server is running properly, press Ctrl-Alt-Del and open the Task List. If all is well, the server program should be listed on the Processes tab.

No comments:

Post a Comment