Using MySQL Programs
229
4.2. Using MySQL Programs
4.2.1. Invoking MySQL Programs
To invoke a MySQL program from the command line (that is, from your shell or command prompt),
enter the program name followed by any options or other arguments needed to instruct the program
what you want it to do. The following commands show some sample program invocations. “
shell>
”
represents the prompt for your command interpreter; it is not part of what you type. The particular
prompt you see depends on your command interpreter. Typical prompts are
$
for
sh
or
bash
,
%
for
csh
or
tcsh
, and
C:\>
for the Windows
command.com
or
cmd.exe
command interpreters.
shell>
mysql --user=root test
shell>
mysqladmin extended-status variables
shell>
mysqlshow --help
shell>
mysqldump -u root personnel
Arguments that begin with a single or double dash (“
-
”, “
--
”) specify program options. Options typically
indicate the type of connection a program should make to the server or affect its operational mode.
Option syntax is described in
Section 4.2.3, “Specifying Program Options”
.
Nonoption arguments (arguments with no leading dash) provide additional information to the program.
For example, the
mysql
program interprets the first nonoption argument as a database name, so the
command
mysql --user=root test
indicates that you want to use the
test
database.
Later sections that describe individual programs indicate which options a program supports and
describe the meaning of any additional nonoption arguments.
Some options are common to a number of programs. The most frequently used of these are the
--
host
[231]
(or
-h
),
--user
[232]
(or
-u
), and
--password
[231]
(or
-p
) options that specify
connection parameters. They indicate the host where the MySQL server is running, and the user
name and password of your MySQL account. All MySQL client programs understand these options;
they enable you to specify which server to connect to and the account to use on that server. Other
connection options are
--port
[231]
(or
-P
) to specify a TCP/IP port number and
--socket
[232]
(or
-S
) to specify a Unix socket file on Unix (or named pipe name on Windows). For more information
on options that specify connection options, see
Section 4.2.2, “Connecting to the MySQL Server”
.
You may find it necessary to invoke MySQL programs using the path name to the
bin
directory in
which they are installed. This is likely to be the case if you get a “program not found” error whenever
you attempt to run a MySQL program from any directory other than the
bin
directory. To make it more
convenient to use MySQL, you can add the path name of the
bin
directory to your
PATH
environment
variable setting. That enables you to run a program by typing only its name, not its entire path name.
For example, if
mysql
is installed in
/usr/local/mysql/bin
, you can run the program by invoking it
as
mysql
, and it is not necessary to invoke it as
/usr/local/mysql/bin/mysql
.
Consult the documentation for your command interpreter for instructions on setting your
PATH
variable.
The syntax for setting environment variables is interpreter-specific. (Some information is given in
Section 4.2.4, “Setting Environment Variables”
.) After modifying your
PATH
setting, open a new console
window on Windows or log in again on Unix so that the setting goes into effect.
4.2.2. Connecting to the MySQL Server
For a client program to be able to connect to the MySQL server, it must use the proper connection
parameters, such as the name of the host where the server is running and the user name and
password of your MySQL account. Each connection parameter has a default value, but you can
override them as necessary using program options specified either on the command line or in an option
file.
The examples here use the
mysql
client program, but the principles apply to other clients such as
mysqldump
,
mysqladmin
, or
mysqlshow
.
This command invokes
mysql
without specifying any connection parameters explicitly:
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...