Learning Mysql


CHAPTER 11Using an Options File



Download 4.24 Mb.
View original pdf
Page339/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   335   336   337   338   339   340   341   342   ...   366
Learning MySQL
CHAPTER 11
Using an Options File
Over the course of this book, you’ve seen that you can pass options to many of the programs and scripts that are part of the MySQL distribution. For example, you can pass the user and password options to the MySQL monitor. If you don’t specify a value for an option, the default options are used. For example, most client programs try to use the default values localhost and for the server host and port options,
respectively.
If you need to use an option value that’s not the default, you have to specify it each time you run a program that needs that option this is tedious and prone to errors.
Fortunately, you can save option values to an options file, also sometimes called a
configuration file, that most of the key MySQL programs and scripts can read. The programs that read options files include myisamchk
, myisampack
, mysql
, mysqladmin
,
mysqlbinlog
, mysqlcc
, mysqlcheck
, mysqld
, mysqld_safe
, mysqldump
, mysqlhotcopy
,
mysqlimport
, mysql.server
, and mysqlshow
We’ll start our tour of options files with an example using the MySQL monitor.
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 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.
371
V413HAV

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_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 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 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 \

Download 4.24 Mb.

Share with your friends:
1   ...   335   336   337   338   339   340   341   342   ...   366




The database is protected by copyright ©ininet.org 2024
send message

    Main page