An environment variable has a value that can be accessed by programs that you run. By setting environment variables, you modify your operating environment. One such variable is PATH, which is used by your command interpreter to determine which directories to search when it looks for programs such as mysql that you tell it to execute. If your PATH is set correctly, you can invoke programs easily no matter what your current directory is. If PATH is not set correctly, your command interpreter will not find them. For example, if the PATH value does not include the directory where mysql is installed, a "command not found" error may occur if you attempt to run mysql by entering its name. You must run it either by specifying its full pathname, or by changing location into the directory where it is installed. Both strategies are unpleasant, and more so with repetition. It's much better to set your PATH value to name the directories containing the programs you want to use. Other environment variables are important in other contexts. For example, if you run Perl or Ruby scripts that use module files that you've installed, you may need to set the PERL5LIB or RUBYLIB variable to tell Perl or Ruby where to find those modules. For Java, the JAVA_HOME variable should be set to indicate the location of your Java installation, and CLASSPATH should be set to the list of libraries and class files that your Java programs need. The following discussion describes how to set environment variables. The examples demonstrate how to make it easier to run MySQL programs by modifying your PATH setting to add the directory where MySQL programs are installed. However, the discussion applies to other environment variables as well because the variable-setting syntax is the same. Here are some general principles to keep in mind regarding environment variables:
Setting the PATH Variable on UnixYour choice of command interpreter determines the syntax for setting environment variables. In addition, for settings that you put in a startup file, the file to use is interpreter-specific. The following table shows typical startup files for commonly used Unix command interpreters. If you've never looked through your command interpreter's startup files, it's a good idea to do so to familiarize yourself with their contents.
The examples assume that MySQL programs are installed in the /usr/local/mysql/bin directory and that you want to add that directory to your existing PATH value. That is, the examples assume that there is already a PATH setting in one of your startup files. If you have no PATH setting currently, add the appropriate line or lines to one of the files.
Adjust the instructions for the pathname actually used on your system. Setting the PATH Variable on WindowsTo set environment variables on Windows, click the Start Menu, right-click My Computer C:\WINDOWS;C:\WINDOWS\COMMAND To make it easier to run MySQL programs such as mysql, change the value to include the directory where those programs are installed. Adding a directory of C:\Program Files\MySQL\MySQL Server 5.0\bin results in a PATH setting that should look like this: C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\WINDOWS;C:\WINDOWS\COMMAND |