Configuring Options for the MySQL Monitor

Throughout this book, you’ve specified the user and password options when starting the monitor program:

$ mysql --user=root --password=the_mysql_root_password
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>

You can save yourself some typing by storing the username and password in an options file and placing it in a location where the monitor will look. The monitor will automatically read in the option values from the file instead of asking you.

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 ...

Get Learning MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.