There are various methods of interacting with the MySQL server to develop or work with a MySQL database. The most basic interface that you can use is the mysql client. With it, you can interact with the server from either the command line or within an interface environment.
If MySQL was installed properly on your server,
mysql should be available for use. If not, see Chapter 2. On Unix-based systems, you can type
whereis mysql. Windows, Macintosh, and other GUI-type
systems have a program location utility for finding a program. If you used
the default installation method, the mysql program
probably resides at /usr/local/mysql/bin/mysql. On
Unix systems, if /usr/local/mysql/bin/ is in your
default path (the PATH environment variable), you
can specify mysql without the full pathname. If the
directory is not in your path, you can add it by entering:
PATH=$PATH:/usr/local/mysql/bin export PATH
Assuming that everything is working, you will need a MySQL username and password. If you’re not the administrator, you must obtain these from her. If MySQL was just installed and the root password is not set yet, its password is blank. To learn how to set the root password and to create new users and grant them privileges, see Chapter 2 for starting points and Chapter 4 for more advanced details.
From a shell prompt, log in to MySQL like this:
mysql -hhost-uuser-p
If you’re logging in locally—that is, from the server itself—either
physically or through a remote login method, such as SSH (secure shell),
you can omit the -h host argument.
This is because the default host is localhost, which
refers to the system you are on. In other circumstances, where your
commands actually have to travel over a network to reach the server,
replace the argument
with either a hostname that is translatable to an IP address or the actual
IP address of the MySQL server. You should replace the argument
host with your MySQL
username. This is not necessarily the same as your filesystem
username.user
The -p option instructs
mysql to prompt you for a password. You can also add
the password to the end of the -p option (e.g., enter
-prover where rover is the
password); if you do this, leave no space between -p
and the password. However, entering the password on the command line is
not a good security practice, because it displays the password on the
screen and transmits the password as clear text through the network, as
well as making it visible whenever somebody gets a list of processes
running on the server.
When you’re finished working on the MySQL server, to exit
mysql, type quit or
exit, and press the Enter key.