Problem Solution Discussion Mixing Command-Line and Option File Parameters

I f you want t o find out which opt ions will be t aken from opt ion files by m ysql, use t his com m and: mysql --print-defaults You can also use t he m y_print _default s ut ilit y, which t akes as argum ent s t he nam es of t he opt ion file groups t hat it should read. For exam ple, m ysql looks in bot h t he [client] and [mysql] groups for opt ions, so you can check which values it will t ake from opt ion files like t his: my_print_defaults client mysql

1.6 Protecting Option Files

1.6.1 Problem

Your MySQL usernam e and password are st ored in your opt ion file, and you dont want ot her users reading it .

1.6.2 Solution

Change t he files m ode t o m ake it accessible only by you.

1.6.3 Discussion

I f you use a m ult iple- user operat ing syst em such as Unix, you should prot ect your opt ion file t o prevent ot her users from finding out how t o connect t o MySQL using your account . Use chm od t o m ake t he file privat e by set t ing it s m ode t o allow access only by yourself: chmod 600 .my.cnf

1.7 Mixing Command-Line and Option File Parameters

1.7.1 Problem

Youd rat her not st ore your MySQL password in an opt ion file, but you dont want t o ent er your usernam e and server host m anually.

1.7.2 Solution

Put t he usernam e and host in t he opt ion file, and specify t he password int eract ively when you invoke m ysql; it looks bot h in t he opt ion file and on t he com m and line for connect ion param et ers. I f an opt ion is specified in bot h places, t he one on t he com m and line t akes precedence.

1.7.3 Discussion

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