Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 43.3Mb
PDF (A4) - 43.4Mb
Man Pages (TGZ) - 297.2Kb
Man Pages (Zip) - 402.4Kb
Info (Gzip) - 4.3Mb
Info (Zip) - 4.3Mb
Excerpts from this Manual

MySQL 8.0 Reference Manual  / ...  / MySQL Programs  / Using MySQL Programs  /  Setting Environment Variables

6.2.9 Setting Environment Variables

Environment variables can be set at the command prompt to affect the current invocation of your command processor, or set permanently to affect future invocations. To set a variable permanently, you can set it in a startup file or by using the interface provided by your system for this purpose. Consult the documentation for your command interpreter for specific details.Section 6.9, “Environment Variables”, lists all environment variables that affect MySQL program operation.

To specify a value for an environment variable, use the syntax appropriate for your command processor. For example, on Windows, you can set theUSER variable to specify your MySQL account name. To do so, use this syntax:

SET USER=your_name

The syntax on Unix depends on your shell. Suppose that you want to specify the TCP/IP port number using theMYSQL_TCP_PORT variable. Typical syntax (such as forsh,ksh,bash,zsh, and so on) is as follows:

MYSQL_TCP_PORT=3306export MYSQL_TCP_PORT

The first command sets the variable, and theexport command exports the variable to the shell environment so that its value becomes accessible to MySQL and other processes.

Forcsh andtcsh, usesetenv to make the shell variable available to the environment:

setenv MYSQL_TCP_PORT 3306

The commands to set environment variables can be executed at your command prompt to take effect immediately, but the settings persist only until you log out. To have the settings take effect each time you log in, use the interface provided by your system or place the appropriate command or commands in a startup file that your command interpreter reads each time it starts.

On Windows, you can set environment variables using the System Control Panel (under Advanced).

On Unix, typical shell startup files are.bashrc or.bash_profile forbash, or.tcshrc fortcsh.

Suppose that your MySQL programs are installed in/usr/local/mysql/bin and that you want to make it easy to invoke these programs. To do this, set the value of thePATH environment variable to include that directory. For example, if your shell isbash, add the following line to your.bashrc file:

PATH=${PATH}:/usr/local/mysql/bin

bash uses different startup files for login and nonlogin shells, so you might want to add the setting to.bashrc for login shells and to.bash_profile for nonlogin shells to make sure thatPATH is set regardless.

If your shell istcsh, add the following line to your.tcshrc file:

setenv PATH ${PATH}:/usr/local/mysql/bin

If the appropriate startup file does not exist in your home directory, create it with a text editor.

After modifying yourPATH setting, open a new console window on Windows or log in again on Unix so that the setting goes into effect.