Databases Reference
In-Depth Information
In the options file, we specify the program that we're interested in—here, it's mysql for
the MySQL monitor—and then list each option on a line of its own:
[mysql]
user=root
password= the_mysql_root_password
If you're using a Linux or Mac OS X system, type these lines using a text editor and
save it with the name .my.cnf in your home directory ( ~/.my.cnf ). Under Windows, save
this file with the name my.cnf in the root of the C: drive ( C:\my.cnf ). You can now start
the monitor without providing the username and password options; the values are read
in automatically from the options file:
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 486 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
This is very convenient! Unfortunately, we now have to spoil the fun and note that it's
generally not a good idea to store passwords unencrypted (in plain-text ); at the very
least, you should ensure that only you can read (and write) the file. On a Linux or Mac
OS X server, you can use the chmod command to do this:
$ chmod u=rw,g=,o= ~/.my.cnf
We discuss permission settings in “Restricting access to files and directories” in Chap-
ter 2. The trade-off between convenience and security is a recurring theme in discus-
sions of protection of systems and data. You need to assess the requirements of each
individual application.
Let's look at another example. Say you want to use the MySQL monitor to connect to
a MySQL server running on port 57777 of the host sadri.learningmysql.com , and wish
to use the music database on this server. For this database, we have the MySQL account
name allmusic and the password the_password . The command to start the monitor
would be (all on one line):
$ mysql \
--host=sadri.learningmysql.com \
--port=57777 \
--user=allmusic \
--password= the_password \
--database=music
This can be tiresome to type all the time, so you could save these values in the options
file as:
[mysql]
host=sadri.learningmysql.com
port=57777
user=allmusic
 
Search WWH ::




Custom Search