Problem Solution Discussion Setting Environment Variables

1.9 Setting Environment Variables

1.9.1 Problem

You need t o m odify your operat ing environm ent , for exam ple, t o change your shells PATH set t ing.

1.9.2 Solution

Edit t he appropriat e shell st art up file. Under Windows NT- based syst em s, anot her alt ernat ive is t o use t he Syst em cont rol panel.

1.9.3 Discussion

The shell or com m and int erpret er you use t o run program s from t he com m and- line prom pt includes an environm ent in which you can st ore variable values. Som e of t hese variables are used by t he shell it self. For exam ple, it uses PATH t o det erm ine which direct ories t o look in for program s such as m ysql. Ot her variables are used by ot her program s such as PERL5LIB , which t ells Perl where t o look for library files used by Perl script s . Your shell det erm ines t he synt ax used t o set environm ent variables, as well as t he st art up file in w hich t o place t he set t ings. Typical st art up files for various shells are shown in t he following t able. I f youve never looked t hrough your shells st art up files, it s a good idea t o do so t o fam iliarize yourself wit h t heir cont ent s. Sh e ll Possible st a r t u p file s csh, t csh .login, .cshrc, .t cshrc sh, bash, ksh .profile .bash_profile, .bash_login, .bashrc DOS prom pt C: \ AUTOEXEC.BAT The following exam ples show how t o set t he PATH variable so t hat it includes t he direct ory where t he m ysql program is inst alled. The exam ples assum e t here is an exist ing PATH set t ing in one of your st art up files. I f you have no PATH set t ing current ly, sim ply add t he appropriat e line or lines t o one of t he files. I f youre reading t his sect ion because youve been referred here from anot her chapt er, youll probably be m ore int erest ed in changing som e variable ot her t han PATH . The inst ruct ions are sim ilar because you use t he sam e synt ax. The PATH variable list s t he pat hnam es for one or m ore direct ories. I f an environm ent variables value consist s of m ult iple pat hnam es, it s convent ional under Unix t o separat e t hem using t he colon charact er : . Under Windows, pat hnam es m ay cont ain colons, so t he separat or is t he sem icolon charact er ; . To set t he value of PATH , use t he inst ruct ions t hat pert ain t o your shell: • For csh or t csh, look for a setenv PATH com m and in your st art up files, t hen add t he appropriat e direct ory t o t he line. Suppose your search pat h is set by a line like t his in your .login file: setenv PATH bin:usrbin:usrlocalbin I f m ysql is inst alled in usr local m ysql bin, add t hat direct ory t o t he search pat h by changing t he setenv line t o look like t his: setenv PATH usrlocalmysqlbin:bin:usrbin:usrlocalbin I t s also possible t hat your pat h will be set wit h set path , which uses different synt ax: set path = usrlocalmysqlbin bin usrbin usrlocalbin • For a shell in t he Bourne shell fam ily such as sh, bash, or ksh, look in your st art up files for a line t hat set s up and export s t he PATH variable: export PATH=bin:usrbin:usrlocalbin The assignm ent and t he export m ight be on separat e lines: PATH=bin:usrbin:usrlocalbin export PATH Change t he set t ing t o t his: export PATH=usrlocalmysqlbin:bin:usrbin:usrlocalbin Or: PATH=usrlocalmysqlbin:bin:usrbin:usrlocalbin export PATH • Under Windows, check for a line t hat set s t he PATH variable in your AUTOEXEC.BAT file. I t m ight look like t his: PATH=C:\WINDOWS;C:\WINDOWS\COMMAND Or like t his: SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND Change t he PATH value t o include t he direct ory where m ysql is inst alled. I f t his is C: \ m ysql\ bin, t he result ing PATH set t ing looks like t his: PATH=C:\mysql\bin;C:\WINDOWS;C:\WINDOWS\COMMAND Or: SET PATH=C:\mysql\bin;C:\WINDOWS;C:\WINDOWS\COMMAND • Under Windows NT- based syst em s, anot her way t o change t he PATH value is t o use t he Syst em cont rol panel use it s Environm ent or Advanced t ab, whichever is present . I n ot her versions of Windows, you can use t he Regist ry Edit or applicat ion. Unfort unat ely, t he nam e of t he Regist ry Edit or key t hat cont ains t he pat h value seem s t o vary am ong versions of Windows. For exam ple, on t he Windows m achines t hat I use, t he key has one nam e under Windows Me and a different nam e under Windows 98; under Windows 95, I couldnt find t he key at all. I t s probably sim pler j ust t o edit AUTOEXEC.BAT. Aft er set t ing an environm ent variable, youll need t o cause t he m odificat ion t o t ake effect . Under Unix, you can log out and log in again. Under Windows, if you set PATH using t he Syst em cont rol panel, you can sim ply open a new DOS window. I f you edit ed AUTOEXEC.BAT inst ead, rest art t he m achine.

1.10 Issuing Queries