Problem Solution Discussion What to Do if mysql Cannot Be Found

m ysql first reads your opt ion file t o see what connect ion param et ers are list ed t here, t hen checks t he com m and line for addit ional param et ers. This m eans you can specify som e opt ions one way, and som e t he ot her way. Com m and- line param et ers t ake precedence over param et ers found in your opt ion file, so if for som e reason you need t o override an opt ion file param et er, j ust specify it on t he com m and line. For exam ple, you m ight list your regular MySQL usernam e and password in t he opt ion file for general purpose use. I f you need t o connect on occasion as t he MySQL root user, specify t he user and password opt ions on t he com m and line t o override t he opt ion file values: mysql -p -u root To explicit ly specify no password when t here is a non- em pt y password in t he opt ion file, use - p on t he com m and line, and t hen j ust press Ret urn when m ysql prom pt s you for t he password: mysql -p Enter password: press Return here

1.8 What to Do if mysql Cannot Be Found

1.8.1 Problem

When you invoke m ysql from t he com m and line, your com m and int erpret er cant find it .

1.8.2 Solution

Add t he direct ory where m ysql is inst alled t o your PATH set t ing. Then youll be able t o run m ysql from any direct ory easily.

1.8.3 Discussion

I f your shell or com m and int erpret er cant find m ysql when you invoke it , youll see som e sort of error m essage. I t m ay look like t his under Unix: mysql mysql: Command not found. Or like t his under Windows: C:\ mysql Bad command or invalid filename One way t o t ell your shell where t o find m ysql is t o t ype it s full pat hnam e each t im e you run it . The com m and m ight look like t his under Unix: usrlocalmysqlbinmysql Or like t his under Windows: C:\ C:\mysql\bin\mysql Typing long pat hnam es get s t iresom e pret t y quickly, t hough. You can avoid doing so by changing int o t he direct ory where m ysql is inst alled before you run it . However, I recom m end t hat you not do t hat . I f you do, t he inevit able result is t hat youll end up put t ing all your dat afiles and query bat ch files in t he sam e direct ory as m ysql, t hus unnecessarily clut t ering up what should be a locat ion int ended only for program s. A bet t er solut ion is t o m ake sure t hat t he direct ory where m ysql is inst alled is included in t he PATH environm ent variable t hat list s pat hnam es of direct ories where t he shell looks for com m ands. See Recipe 1.9 . Then you can invoke m ysql from any direct ory by ent ering j ust it s nam e, and your shell will be able t o find it . This elim inat es a lot of unnecessary pat hnam e t yping. An addit ional benefit is t hat because you can easily run m ysql from anywhere, you will have no need t o put your dat afiles in t he sam e direct ory where m ysql is locat ed. When youre not operat ing under t he burden of running m ysql from a part icular locat ion, youll be free t o organize your files in a way t hat m akes sense t o you, not in a way im posed by som e art ificial necessit y. For exam ple, you can creat e a direct ory under your hom e direct ory for each dat abase you have and put t he files associat ed wit h each dat abase in t he appropriat e direct ory. I ve point ed out t he im port ance of t he search pat h here because I receive m any quest ions from people who arent aware of t he exist ence of such a t hing, and who consequent ly t ry t o do all t heir MySQL- relat ed work in t he bin direct ory where m ysql is inst alled. This seem s part icularly com m on am ong Windows users. Perhaps t he reason is t hat , except for Windows NT and it s derivat ives, t he Windows Help applicat ion seem s t o be silent on t he subj ect of t he com m and int erpret er search pat h or how t o set it . Apparent ly, Windows Help considers it dangerous for people t o know how t o do som et hing useful for t hem selves. Anot her way for Windows users t o avoid t yping t he pat hnam e or changing int o t he m ysql direct ory is t o creat e a short cut and place it in a m ore convenient locat ion. That has t he advant age of m aking it easy t o st art up m ysql j ust by opening t he short cut . To specify com m and- line opt ions or t he st art up direct ory, edit t he short cut s propert ies. I f you dont always invoke m ysql wit h t he sam e opt ions, it m ight be useful t o creat e a short cut corresponding t o each set of opt ions you need—for exam ple, one short cut t o connect as an ordinary user for general work and anot her t o connect as t he MySQL root user for adm inist rat ive purposes.

1.9 Setting Environment Variables