可以在命令提示符下设置环境变量以影响当前命令处理器的调用,或者永久设置以影响将来的调用。要永久设置变量,可以在启动文件中设置,或者使用系统为此提供的界面。有关具体细节,请查阅命令解释器的文档。第 6.9 节,“环境变量”,列出了所有影响 MySQL 程序操作的环境变量。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.
要为环境变量指定值,请使用适合您命令处理器的语法。例如,在 Windows 上,您可以设置USER变量以指定您的 MySQL 账户名。为此,请使用以下语法:To specify a value for an environment variable, use the syntax
appropriate for your command processor. For example, on Windows,
you can set the USER variable to specify your
MySQL account name. To do so, use this syntax:
SET USER=your_name
Unix 上的语法取决于你的 shell。假设你想使用 MYSQL_TCP_PORT 变量来指定 TCP/IP 端口号。典型的语法(例如用于 sh、ksh、bash、zsh 等)如下:The syntax on Unix depends on your shell. Suppose that you want to
specify the TCP/IP port number using the
MYSQL_TCP_PORT variable. Typical syntax (such
as for sh, ksh,
bash, zsh, and so on) is as
follows:
MYSQL_TCP_PORT=3306 export MYSQL_TCP_PORT
第一个命令设置变量,而 export 命令将变量导出到 shell 环境,使其值可供 MySQL 和其他进程访问。The first command sets the variable, and the
export command exports the variable to the
shell environment so that its value becomes accessible to MySQL
and other processes.
对于 csh 和 tcsh,使用 setenv 使 shell 变量可用于环境:For csh and tcsh, use setenv 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.
在 Windows 系统中,你可以通过系统控制面板(在高级设置下)设置环境变量。On Windows, you can set environment variables using the System Control Panel (under Advanced).
在 Unix 系统中,典型的 shell 启动文件是 .bashrc 或 .bash_profile(用于 bash),或者是 .tcshrc(用于 tcsh)。On Unix, typical shell startup files are
.bashrc or .bash_profile
for bash, or .tcshrc for
tcsh.
假设你的 MySQL 程序安装在 /usr/local/mysql/bin,并且你希望能够方便地调用这些程序。为此,需要将 PATH 环境变量的值设置为包含该目录。例如,如果你的 shell 是 bash,在你的 .bashrc 文件中添加以下一行: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 the
PATH environment variable to include that
directory. For example, if your shell is bash,
add the following line to your .bashrc file:
PATH=${PATH}:/usr/local/mysql/bin
bash 对于登录和非登录 shell 使用不同的启动文件,因此你可能希望将该设置添加到 .bashrc(用于登录 shell)和 .bash_profile(用于非登录 shell),以确保无论如何都设置了 PATH。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 that PATH is set regardless.
如果你的 shell 是 tcsh,请将以下行添加到你的 .tcshrc 文件中:If your shell is tcsh, 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.
在修改了您的 PATH 设置后,请在 Windows 上打开一个新的控制台窗口,或在 Unix 上重新登录,以使设置生效。After modifying your PATH setting, open a new
console window on Windows or log in again on Unix so that the
setting goes into effect.