Database Reference
In-Depth Information
C:\>
mysql
Bad command or invalid filename
One way to tell your command interpreter where to find
mysql
is to type its full pathname
each time you run it. The command might look like this under Unix:
%
/usr/local/mysql/bin/mysql
Or like this under Windows:
C:\>
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql"
Typing long pathnames gets tiresome pretty quickly. You can avoid doing so by changing
location into the directory where
mysql
is installed before you run it. But if you do that,
you may be tempted to put all your datafiles and SQL batch files in the same directory
as
mysql
, thus unnecessarily cluttering up a location intended only for programs.
A better solution is to modify your
PATH
search-path environment variable, which
specifies directories where the command interpreter looks for commands. Add to the
PATH
value the directory where
mysql
is installed. Then you can invoke
mysql
from any
location by entering only its name, which eliminates pathname typing. For instructions
on setting your
PATH
variable, read “Executing Programs from the Command Line” on
the companion website (see the
Preface
).
A significant additional benefit of being able to easily run
mysql
from anywhere is that
you need not put your datafiles in the directory where
mysql
is located. You're free to
organize your files in a way that makes sense to you, not a way imposed by some artificial
necessity. For example, you can create a directory under your home directory for each
database you have and put the work files associated with a given database in the appro‐
priate directory. (I point out the importance of
PATH
here because many newcomers to
MySQL aren't aware of the existence of such a thing, and consequently try to do all their
MySQL-related work in the
bin
directory where
mysql
is installed.)
On Windows, another way to avoid typing the pathname or changing into the
mysql
directory is to create a shortcut and place it in a more convenient location such as the
desktop. This makes it easy to start
mysql
simply by opening the shortcut. To specify
command options or the startup directory, edit the shortcut's properties. If you don't
always invoke
mysql
with the same options, it might be useful to create one shortcut for
each set of options you need. For example, create one shortcut to connect as an ordinary
user for general work and another to connect as the MySQL
root
user for administrative
purposes.