In the options file, we specify the program that we’re interested inhere, 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_passwordIf 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
mysqlWelcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 486 to server version 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.cnfWe discuss permission settings in Restricting access to files and directories in Chapter. The trade-off between convenience and security is a recurring theme in discussions 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 \Share with your friends: